mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-24 19:37:15 +00:00
Bug 1918500 [wpt PR 48132] - IDB WPTs: Extend 3 more IDBCursor continue() objectstore WPTs to workers, a=testonly
Automatic update from web-platform-tests IDB WPTs: Extend 3 more IDBCursor continue() objectstore WPTs to workers These IndexedDB WPTs currently only run in a window environment. This change moves 2 of them into idbcursor_continue_objectstore.any.js. The last test, idbcursor_iterating.htm involves multiple iterations and deletions. It's been converted in place to idbcursor_iterating.any.js. These updates extend these tests to also run in dedicated, shared, and service worker environments. NOTE for CHROMIUM GARDENERS: idbcursor_iterating.htm has been updated to run on workers. Outgoing file has been removed from TestExpectations. If the new tests (suffixed with window.html or *worker.html) are flaky, please add them to TestExpectations vs. reverting this CL. Thank you! Bug: 41455766 Change-Id: I8ca7066ccb4cfd07ed9ada6867f6b2f622f2d00b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5854934 Reviewed-by: Evan Stade <estade@chromium.org> Commit-Queue: Rahul Singh <rahsin@microsoft.com> Cr-Commit-Position: refs/heads/main@{#1354842} -- wpt-commits: d536d5f30c0f5abe0d290ef3c641b5124e17ef5f wpt-pr: 48132
This commit is contained in:
parent
f7b0d12370
commit
52aa480566
@ -1,8 +1,6 @@
|
||||
// META: global=window,worker
|
||||
// META: title=IDBCursor.continue() - object store
|
||||
// META: script=resources/support.js
|
||||
// @author Microsoft <https://www.microsoft.com>
|
||||
// @author Intel <http://www.intel.com>
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -22,6 +20,17 @@ function setOnUpgradeNeeded(dbObj, records) {
|
||||
};
|
||||
}
|
||||
|
||||
function setOnUpgradeNeededWithCleanup(t, dbObj, records) {
|
||||
return function (e) {
|
||||
dbObj.db = e.target.result;
|
||||
t.add_cleanup(function () {
|
||||
dbObj.db.close();
|
||||
indexedDB.deleteDatabase(dbObj.db.name);
|
||||
});
|
||||
createObjectStoreAndPopulate(dbObj.db, records);
|
||||
};
|
||||
}
|
||||
|
||||
async_test(t => {
|
||||
let dbObj = {};
|
||||
let count = 0;
|
||||
@ -54,7 +63,7 @@ async_test(t => {
|
||||
count++;
|
||||
});
|
||||
}
|
||||
}, "IDBCursor.continue() - object store - iterate to the next record");
|
||||
}, "Iterate to the next record");
|
||||
|
||||
async_test(t => {
|
||||
let dbObj = {};
|
||||
@ -82,7 +91,7 @@ async_test(t => {
|
||||
});
|
||||
}
|
||||
|
||||
}, "IDBCursor.continue() - object store - attempt to pass a key parameter is not a valid key");
|
||||
}, "Attempt to pass a key parameter is not a valid key");
|
||||
|
||||
async_test(t => {
|
||||
let dbObj = {};
|
||||
@ -110,7 +119,7 @@ async_test(t => {
|
||||
t.done();
|
||||
});
|
||||
}
|
||||
}, "IDBCursor.continue() - object store - attempt to iterate to the previous record when the direction is set for the next record");
|
||||
}, "Attempt to iterate to the previous record when the direction is set for the next record");
|
||||
|
||||
async_test(t => {
|
||||
let dbObj = {};
|
||||
@ -155,7 +164,7 @@ async_test(t => {
|
||||
count++;
|
||||
});
|
||||
}
|
||||
}, "IDBCursor.continue() - object store - attempt to iterate to the next record when the direction is set for the next record");
|
||||
}, "Attempt to iterate to the next record when the direction is set for the next record");
|
||||
|
||||
async_test(t => {
|
||||
let dbObj = {};
|
||||
@ -213,3 +222,85 @@ async_test(t => {
|
||||
});
|
||||
}
|
||||
}, "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError");
|
||||
|
||||
async_test(t => {
|
||||
let dbObj = {};
|
||||
let count = 0;
|
||||
const records = [
|
||||
{ pKey: "primaryKey_0" },
|
||||
{ pKey: "primaryKey_1" },
|
||||
{ pKey: "primaryKey_2" }
|
||||
];
|
||||
|
||||
const expected_records = [
|
||||
{ pKey: "primaryKey_0" },
|
||||
{ pKey: "primaryKey_2" }
|
||||
];
|
||||
|
||||
let open_rq = createdb(t);
|
||||
open_rq.onupgradeneeded = setOnUpgradeNeededWithCleanup(t, dbObj, records);
|
||||
|
||||
open_rq.onsuccess = function (e) {
|
||||
let cursor_rq = dbObj.db.transaction("test", "readwrite", { durability: 'relaxed' })
|
||||
.objectStore("test")
|
||||
.openCursor();
|
||||
|
||||
cursor_rq.onsuccess = t.step_func(function (e) {
|
||||
let cursor = e.target.result;
|
||||
if (!cursor) {
|
||||
assert_equals(count, 2, "cursor run count");
|
||||
t.done();
|
||||
}
|
||||
|
||||
let record = cursor.value;
|
||||
if (record.pKey == "primaryKey_0") {
|
||||
e.target.source.delete("primaryKey_1");
|
||||
}
|
||||
assert_equals(record.pKey, expected_records[count].pKey, "primary key");
|
||||
|
||||
cursor.continue();
|
||||
count++;
|
||||
});
|
||||
}
|
||||
}, "Delete next element, and iterate to it");
|
||||
|
||||
async_test(t => {
|
||||
let dbObj = {};
|
||||
let count = 0;
|
||||
const records = [
|
||||
{ pKey: "primaryKey_0" },
|
||||
{ pKey: "primaryKey_2" }
|
||||
];
|
||||
|
||||
const expected_records = [
|
||||
{ pKey: "primaryKey_0" },
|
||||
{ pKey: "primaryKey_1" },
|
||||
{ pKey: "primaryKey_2" }
|
||||
];
|
||||
|
||||
let open_rq = createdb(t);
|
||||
open_rq.onupgradeneeded = setOnUpgradeNeededWithCleanup(t, dbObj, records);
|
||||
|
||||
open_rq.onsuccess = function (e) {
|
||||
let cursor_rq = dbObj.db.transaction("test", "readwrite", { durability: 'relaxed' })
|
||||
.objectStore("test")
|
||||
.openCursor();
|
||||
|
||||
cursor_rq.onsuccess = t.step_func(function (e) {
|
||||
let cursor = e.target.result;
|
||||
if (!cursor) {
|
||||
assert_equals(count, 3, "cursor run count");
|
||||
t.done();
|
||||
}
|
||||
|
||||
let record = cursor.value;
|
||||
if (record.pKey == "primaryKey_0") {
|
||||
e.target.source.add({ pKey: "primaryKey_1" });
|
||||
}
|
||||
assert_equals(record.pKey, expected_records[count].pKey, "primary key");
|
||||
|
||||
cursor.continue();
|
||||
count++;
|
||||
});
|
||||
}
|
||||
}, "Add next element, and iterate to it");
|
||||
|
107
testing/web-platform/tests/IndexedDB/idbcursor_iterating.any.js
Normal file
107
testing/web-platform/tests/IndexedDB/idbcursor_iterating.any.js
Normal file
@ -0,0 +1,107 @@
|
||||
// META: global=window,worker
|
||||
// META: title=IDBCursor.continue() - object store
|
||||
// META: script=resources/support.js
|
||||
|
||||
'use strict';
|
||||
|
||||
async_test(t => {
|
||||
let db;
|
||||
let count = 0;
|
||||
|
||||
let open_rq = createdb(t);
|
||||
open_rq.onupgradeneeded = function (e) {
|
||||
db = e.target.result;
|
||||
t.add_cleanup(function () { db.close(); indexedDB.deleteDatabase(db.name); });
|
||||
let objStore = db.createObjectStore("test", { keyPath: "key" });
|
||||
|
||||
for (let i = 0; i < 500; i++)
|
||||
objStore.add({ key: i, val: "val_" + i });
|
||||
|
||||
let rq = objStore.add({ key: 500, val: "val_500" });
|
||||
|
||||
rq.onsuccess = t.step_func(function () {
|
||||
for (let i = 999; i > 500; i--)
|
||||
objStore.add({ key: i, val: "val_" + i });
|
||||
});
|
||||
|
||||
objStore.createIndex('index', ['key', 'val']);
|
||||
};
|
||||
|
||||
open_rq.onsuccess = function (e) {
|
||||
let cursor_rq = db.transaction("test", "readwrite", { durability: 'relaxed' })
|
||||
.objectStore("test")
|
||||
.openCursor();
|
||||
|
||||
cursor_rq.onsuccess = t.step_func(function (e) {
|
||||
let cursor = e.target.result,
|
||||
store = e.target.source;
|
||||
if (!cursor) {
|
||||
assert_equals(count, 997, "cursor run count");
|
||||
|
||||
let rq = e.target.source.count();
|
||||
rq.onsuccess = t.step_func(function (e) {
|
||||
assert_equals(e.target.result, 995, "object count");
|
||||
t.done();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
switch (cursor.key) {
|
||||
case 10:
|
||||
assert_equals(count, cursor.key, "count");
|
||||
store.delete(11);
|
||||
break;
|
||||
|
||||
case 12:
|
||||
case 499:
|
||||
case 500:
|
||||
case 501:
|
||||
assert_equals(count, cursor.key - 1, "count");
|
||||
break;
|
||||
|
||||
// Delete the next key
|
||||
case 510:
|
||||
store.delete(511);
|
||||
break;
|
||||
|
||||
// Delete randomly
|
||||
case 512:
|
||||
store.delete(611);
|
||||
store.delete(499);
|
||||
store.delete(500);
|
||||
break;
|
||||
|
||||
// Delete and add a new key
|
||||
case 520:
|
||||
store.delete(521);
|
||||
store.add({ key: 521, val: "new" });
|
||||
break;
|
||||
|
||||
case 521:
|
||||
assert_equals(cursor.value.val, "new");
|
||||
break;
|
||||
|
||||
// We should only be here once although we're basically making the index
|
||||
// "heavier" with its new key.
|
||||
case 530:
|
||||
assert_equals(cursor.value.val, "val_530");
|
||||
cursor.update({ key: 530, val: "val_531" })
|
||||
|
||||
store.get(530).onsuccess = t.step_func(function (e) {
|
||||
assert_equals(e.target.result.val, "val_531");
|
||||
});
|
||||
break;
|
||||
|
||||
// Shouldn't happen.
|
||||
case 11:
|
||||
case 511:
|
||||
case 611:
|
||||
assert_unreached(cursor.key + " should be deleted and never run");
|
||||
break;
|
||||
}
|
||||
|
||||
cursor.continue();
|
||||
count++;
|
||||
});
|
||||
};
|
||||
}, "Iterate and Delete elements");
|
@ -1,109 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<title>IDBCursor.continue() - objectstore - delete next element, and iterate to it</title>
|
||||
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/support.js"></script>
|
||||
|
||||
<script>
|
||||
var db,
|
||||
count = 0,
|
||||
t = async_test();
|
||||
|
||||
var open_rq = createdb(t);
|
||||
open_rq.onupgradeneeded = function(e) {
|
||||
db = e.target.result;
|
||||
t.add_cleanup(function() { db.close(); indexedDB.deleteDatabase(db.name); });
|
||||
var objStore = db.createObjectStore("test", { keyPath: "key" });
|
||||
|
||||
for (var i = 0; i < 500; i++)
|
||||
objStore.add({ key: i, val: "val_"+i });
|
||||
|
||||
var rq = objStore.add({ key: 500, val: "val_500" });
|
||||
|
||||
rq.onsuccess = t.step_func(function() {
|
||||
for (var i = 999; i > 500; i--)
|
||||
objStore.add({ key: i, val: "val_"+i });
|
||||
});
|
||||
|
||||
objStore.createIndex('index', ['key', 'val']);
|
||||
};
|
||||
|
||||
open_rq.onsuccess = function(e) {
|
||||
var cursor_rq = db.transaction("test", "readwrite", {durability: 'relaxed'})
|
||||
.objectStore("test")
|
||||
.openCursor();
|
||||
|
||||
cursor_rq.onsuccess = t.step_func(function(e) {
|
||||
var cursor = e.target.result,
|
||||
store = e.target.source;
|
||||
if (!cursor) {
|
||||
assert_equals(count, 997, "cursor run count");
|
||||
|
||||
var rq = e.target.source.count();
|
||||
rq.onsuccess = t.step_func(function(e) {
|
||||
assert_equals(e.target.result, 995, "object count");
|
||||
t.done();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
switch (cursor.key) {
|
||||
case 10:
|
||||
assert_equals(count, cursor.key, "count");
|
||||
store.delete(11);
|
||||
break;
|
||||
|
||||
case 12:
|
||||
case 499:
|
||||
case 500:
|
||||
case 501:
|
||||
assert_equals(count, cursor.key - 1, "count");
|
||||
break;
|
||||
|
||||
// Delete the next key
|
||||
case 510:
|
||||
store.delete(511);
|
||||
break;
|
||||
|
||||
// Delete randomly
|
||||
case 512:
|
||||
store.delete(611);
|
||||
store.delete(499);
|
||||
store.delete(500);
|
||||
break;
|
||||
|
||||
// Delete and add a new key
|
||||
case 520:
|
||||
store.delete(521);
|
||||
store.add({ key: 521, val: "new"});
|
||||
break;
|
||||
|
||||
case 521:
|
||||
assert_equals(cursor.value.val, "new");
|
||||
break;
|
||||
|
||||
// We should only be here once although we're basically making the index
|
||||
// "heavier" with its new key.
|
||||
case 530:
|
||||
assert_equals(cursor.value.val, "val_530");
|
||||
cursor.update({ key: 530, val: "val_531" })
|
||||
|
||||
store.get(530).onsuccess = t.step_func(function(e) {
|
||||
assert_equals(e.target.result.val, "val_531");
|
||||
});
|
||||
break;
|
||||
|
||||
// Shouldn't happen.
|
||||
case 11:
|
||||
case 511:
|
||||
case 611:
|
||||
assert_unreached(cursor.key + " should be deleted and never run");
|
||||
break;
|
||||
}
|
||||
|
||||
cursor.continue();
|
||||
count++;
|
||||
});
|
||||
};
|
||||
</script>
|
@ -1,50 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<title>IDBCursor.continue() - objectstore - delete next element, and iterate to it</title>
|
||||
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/support.js"></script>
|
||||
|
||||
<script>
|
||||
var db,
|
||||
count = 0,
|
||||
t = async_test(),
|
||||
records = [ { pKey: "primaryKey_0" },
|
||||
{ pKey: "primaryKey_1" },
|
||||
{ pKey: "primaryKey_2" } ],
|
||||
expected_records = [ { pKey: "primaryKey_0" },
|
||||
{ pKey: "primaryKey_2" }];
|
||||
|
||||
var open_rq = createdb(t);
|
||||
open_rq.onupgradeneeded = function(e) {
|
||||
db = e.target.result;
|
||||
t.add_cleanup(function() { db.close(); indexedDB.deleteDatabase(db.name); });
|
||||
var objStore = db.createObjectStore("test", {keyPath:"pKey"});
|
||||
|
||||
for (var i = 0; i < records.length; i++)
|
||||
objStore.add(records[i]);
|
||||
};
|
||||
|
||||
open_rq.onsuccess = function(e) {
|
||||
var cursor_rq = db.transaction("test", "readwrite", {durability: 'relaxed'})
|
||||
.objectStore("test")
|
||||
.openCursor();
|
||||
|
||||
cursor_rq.onsuccess = t.step_func(function(e) {
|
||||
var cursor = e.target.result;
|
||||
if (!cursor) {
|
||||
assert_equals(count, 2, "cursor run count");
|
||||
t.done();
|
||||
}
|
||||
|
||||
var record = cursor.value;
|
||||
if (record.pKey == "primaryKey_0") {
|
||||
e.target.source.delete("primaryKey_1");
|
||||
}
|
||||
assert_equals(record.pKey, expected_records[count].pKey, "primary key");
|
||||
|
||||
cursor.continue();
|
||||
count++;
|
||||
});
|
||||
};
|
||||
</script>
|
@ -1,50 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<title>IDBCursor.continue() - objectstore - add next element, and iterate to it</title>
|
||||
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/support.js"></script>
|
||||
|
||||
<script>
|
||||
var db,
|
||||
count = 0,
|
||||
t = async_test(),
|
||||
records = [ { pKey: "primaryKey_0" },
|
||||
{ pKey: "primaryKey_2" } ],
|
||||
expected_records = [ { pKey: "primaryKey_0" },
|
||||
{ pKey: "primaryKey_1" },
|
||||
{ pKey: "primaryKey_2" } ];
|
||||
|
||||
var open_rq = createdb(t);
|
||||
open_rq.onupgradeneeded = function(e) {
|
||||
db = e.target.result;
|
||||
t.add_cleanup(function() { db.close(); indexedDB.deleteDatabase(db.name); });
|
||||
var objStore = db.createObjectStore("test", {keyPath:"pKey"});
|
||||
|
||||
for (var i = 0; i < records.length; i++)
|
||||
objStore.add(records[i]);
|
||||
};
|
||||
|
||||
open_rq.onsuccess = function(e) {
|
||||
var cursor_rq = db.transaction("test", "readwrite", {durability: 'relaxed'})
|
||||
.objectStore("test")
|
||||
.openCursor();
|
||||
|
||||
cursor_rq.onsuccess = t.step_func(function(e) {
|
||||
var cursor = e.target.result;
|
||||
if (!cursor) {
|
||||
assert_equals(count, 3, "cursor run count");
|
||||
t.done();
|
||||
}
|
||||
|
||||
var record = cursor.value;
|
||||
if (record.pKey == "primaryKey_0") {
|
||||
e.target.source.add({ pKey: "primaryKey_1" });
|
||||
}
|
||||
assert_equals(record.pKey, expected_records[count].pKey, "primary key");
|
||||
|
||||
cursor.continue();
|
||||
count++;
|
||||
});
|
||||
};
|
||||
</script>
|
Loading…
x
Reference in New Issue
Block a user