Skip to content

Commit

Permalink
IDB WPTs: Extend IDBCursor continue() ObjectStore WPTs to run on workers
Browse files Browse the repository at this point in the history
This set of IndexedDB WPTs currently only run in a window environment.
This change combines them into a single file and extends them to also
run in dedicated, shared, and service worker environments.

Bug: 41455766
Change-Id: Ia5e0e866b90d01345c059df223aed1c361c96559
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5671287
Commit-Queue: Rahul Singh <rahsin@microsoft.com>
Reviewed-by: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1323009}
  • Loading branch information
rahulsingh-msft authored and chromium-wpt-export-bot committed Jul 3, 2024
1 parent 80ff968 commit 8607a1d
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 262 deletions.
215 changes: 215 additions & 0 deletions IndexedDB/idbcursor_continue_objectstore.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
// 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';

function createObjectStoreAndPopulate(db, records) {
let objStore = db.createObjectStore("test", { keyPath: "pKey" });

for (let i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
return objStore;
}

function setOnUpgradeNeeded(dbObj, records) {
return function (event) {
dbObj.db = event.target.result;
createObjectStoreAndPopulate(dbObj.db, records);
};
}

async_test(t => {
let dbObj = {};
let count = 0;

const records = [
{ pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" }
];

let open_rq = createdb(t);
open_rq.onupgradeneeded = setOnUpgradeNeeded(dbObj, records);

open_rq.onsuccess = function (e) {
let store = dbObj.db.transaction("test", "readonly", { durability: 'relaxed' })
.objectStore("test");

let cursor_rq = store.openCursor();
cursor_rq.onsuccess = t.step_func(function (e) {
let cursor = e.target.result;
if (!cursor) {
assert_equals(count, records.length, "cursor run count");
t.done();
}

let record = cursor.value;
assert_equals(record.pKey, records[count].pKey, "primary key");
assert_equals(record.iKey, records[count].iKey, "index key");

cursor.continue();
count++;
});
}
}, "IDBCursor.continue() - object store - iterate to the next record");

async_test(t => {
let dbObj = {};

const records = [
{ pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" }
];

let open_rq = createdb(t);
open_rq.onupgradeneeded = setOnUpgradeNeeded(dbObj, records);

open_rq.onsuccess = function (e) {
let cursor_rq = dbObj.db.transaction("test", "readonly", { durability: 'relaxed' })
.objectStore("test").openCursor();

cursor_rq.onsuccess = t.step_func(function (e) {
let cursor = e.target.result;

assert_true(cursor instanceof IDBCursor, "cursor exists");
assert_throws_dom("DataError",
function () { cursor.continue(-1); });

t.done();
});
}

}, "IDBCursor.continue() - object store - attempt to pass a key parameter is not a valid key");

async_test(t => {
let dbObj = {};

const records = [
{ pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" }
];

let open_rq = createdb(t);
open_rq.onupgradeneeded = setOnUpgradeNeeded(dbObj, records);

open_rq.onsuccess = function (e) {
let cursor_rq = dbObj.db.transaction("test", "readonly", { durability: 'relaxed' })
.objectStore("test")
.openCursor(undefined, "next");

cursor_rq.onsuccess = t.step_func(function (e) {
let cursor = e.target.result;

assert_true(cursor instanceof IDBCursor, "cursor exist");
assert_throws_dom("DataError",
function () { cursor.continue(records[0].pKey); });

t.done();
});
}
}, "IDBCursor.continue() - object store - attempt to iterate to the previous record when the direction is set for the next record");

async_test(t => {
let dbObj = {};

const records = [
{ pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" },
{ pKey: "primaryKey_2" }
];

let open_rq = createdb(t);
open_rq.onupgradeneeded = setOnUpgradeNeeded(dbObj, records);

open_rq.onsuccess = function (e) {
let count = 0,
cursor_rq = dbObj.db.transaction("test", "readonly", { durability: 'relaxed' })
.objectStore("test")
.openCursor(null, "prev");

cursor_rq.onsuccess = t.step_func(function (e) {
let cursor = e.target.result;

assert_true(cursor != null, "cursor exist");

switch (count) {
case 0:
assert_equals(cursor.value.pKey, records[2].pKey, "first cursor pkey");
cursor.continue(records[1].pKey);
break;

case 1:
assert_equals(cursor.value.pKey, records[1].pKey, "second cursor pkey");
assert_throws_dom("DataError",
function () { cursor.continue(records[2].pKey); });
t.done();
break;

default:
assert_unreached("Unexpected count value: " + count);
}

count++;
});
}
}, "IDBCursor.continue() - object store - attempt to iterate to the next record when the direction is set for the next record");

async_test(t => {
let dbObj = {};

const records = [
{ pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" }
];

let open_rq = createdb(t);
open_rq.onupgradeneeded = setOnUpgradeNeeded(dbObj, records);

open_rq.onsuccess = function (e) {
let cursor_rq = dbObj.db.transaction("test", "readonly", { durability: 'relaxed' })
.objectStore("test")
.openCursor();

cursor_rq.onsuccess = t.step_func(function (e) {
let cursor = e.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exists");

e.target.transaction.abort();
assert_throws_dom("TransactionInactiveError",
function () { cursor.continue(); });

t.done();
});
}

}, "Calling continue() should throws an exception TransactionInactiveError when the transaction is not active.");

async_test(t => {
let db;
const records = [
{ pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" }
];

let open_rq = createdb(t);
open_rq.onupgradeneeded = function (e) {
db = e.target.result;
let objStore = createObjectStoreAndPopulate(db, records);

let cursor_rq = objStore.openCursor();

cursor_rq.onsuccess = t.step_func(function (e) {
let cursor = e.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exists");

db.deleteObjectStore("test");
assert_throws_dom("InvalidStateError",
function () { cursor.continue(); });

t.done();
});
}
}, "If the cursor's source or effective object store has been deleted, the implementation MUST throw a DOMException of type InvalidStateError");
46 changes: 0 additions & 46 deletions IndexedDB/idbcursor_continue_objectstore.htm

This file was deleted.

40 changes: 0 additions & 40 deletions IndexedDB/idbcursor_continue_objectstore2.htm

This file was deleted.

40 changes: 0 additions & 40 deletions IndexedDB/idbcursor_continue_objectstore3.htm

This file was deleted.

Loading

0 comments on commit 8607a1d

Please sign in to comment.