Skip to content

Commit

Permalink
Extend Web platform test coverage to workers.
Browse files Browse the repository at this point in the history
web_tests/external/wpt/IndexedDB/ tests are only testing behavior in window environment.
Extend the tests to cover different workers (dedicated, serviceworker, sharedworker).
Tests related to idbindex_get.htm have been extended.

Bug: 41455766

Change-Id: Ib2ffb0715a5aa994a92cd22dfa36932cddb4e637
  • Loading branch information
snehagarwal1 authored and chromium-wpt-export-bot committed Feb 22, 2024
1 parent eb8b11e commit 13165cb
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 255 deletions.
32 changes: 32 additions & 0 deletions IndexedDB/idbindex_get.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// META: global=window,worker
// META: title=IDBIndex.get() - returns the record
// META: script=resources/support.js
// @author Microsoft <https://www.microsoft.com>

'use_strict';

let db;
let index;
const t = async_test(),
record = { key: 1, indexedProperty: "data" };

const open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
const objStore = db.createObjectStore("store", { keyPath: "key" });
index = objStore.createIndex("index", "indexedProperty");

objStore.add(record);
}

open_rq.onsuccess = function(e) {
const rq = db.transaction("store", "readonly", {durability: 'relaxed'})
.objectStore("store")
.index("index")
.get(record.indexedProperty);

rq.onsuccess = t.step_func(function(e) {
assert_equals(e.target.result.key, record.key);
t.done();
});
}
36 changes: 0 additions & 36 deletions IndexedDB/idbindex_get.htm

This file was deleted.

34 changes: 34 additions & 0 deletions IndexedDB/idbindex_get2.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// META: global=window,worker
// META: title=IDBIndex.get() - returns the record where the index contains duplicate values
// META: script=resources/support.js
// @author Microsoft <https://www.microsoft.com>

'use_strict';

let db;
const t = async_test();
const records = [ { key:1, indexedProperty:"data" },
{ key:2, indexedProperty:"data" },
{ key:3, indexedProperty:"data" } ];

const open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
const objStore = db.createObjectStore("test", { keyPath: "key" });
objStore.createIndex("index", "indexedProperty");

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

open_rq.onsuccess = function(e) {
const rq = db.transaction("test", "readonly", {durability: 'relaxed'})
.objectStore("test")
.index("index")
.get("data");

rq.onsuccess = t.step_func(function(e) {
assert_equals(e.target.result.key, records[0].key);
t.done();
});
};
39 changes: 0 additions & 39 deletions IndexedDB/idbindex_get2.htm

This file was deleted.

22 changes: 22 additions & 0 deletions IndexedDB/idbindex_get3.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// META: global=window,worker
// META: title=IDBIndex.get() - attempt to retrieve a record that doesn't exist
// META: script=resources/support.js
// @author Microsoft <https://www.microsoft.com>

'use_strict';

let db;
const t = async_test();

const open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
const rq = db.createObjectStore("test", { keyPath: "key" })
.createIndex("index", "indexedProperty")
.get(1);

rq.onsuccess = t.step_func(function(e) {
assert_equals(e.target.result, undefined);
t.done();
});
};
27 changes: 0 additions & 27 deletions IndexedDB/idbindex_get3.htm

This file was deleted.

35 changes: 35 additions & 0 deletions IndexedDB/idbindex_get4.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// META: global=window,worker
// META: title=IDBIndex.get() - returns the record with the first key in the range
// META: script=resources/support.js
// @author Microsoft <https://www.microsoft.com>

'use_strict';

let db;
const t = async_test();

const open_rq = createdb(t);

open_rq.onupgradeneeded = function(e) {
db = e.target.result;
const store = db.createObjectStore("store", { keyPath: "key" });
store.createIndex("index", "indexedProperty");

for(let i = 0; i < 10; i++) {
store.add({ key: i, indexedProperty: "data" + i });
}
}

open_rq.onsuccess = function(e) {
const rq = db.transaction("store", "readonly", {durability: 'relaxed'})
.objectStore("store")
.index("index")
.get(IDBKeyRange.bound('data4', 'data7'));

rq.onsuccess = t.step_func(function(e) {
assert_equals(e.target.result.key, 4);
assert_equals(e.target.result.indexedProperty, 'data4');

step_timeout(function() { t.done(); }, 4);
});
}
39 changes: 0 additions & 39 deletions IndexedDB/idbindex_get4.htm

This file was deleted.

21 changes: 21 additions & 0 deletions IndexedDB/idbindex_get5.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// META: global=window,worker
// META: title=IDBIndex.get() - throw DataError when using invalid key
// META: script=resources/support.js
// @author Intel <http://www.intel.com>

'use_strict';

let db;
const t = async_test();

const open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;

const index = db.createObjectStore("test", { keyPath: "key" })
.createIndex("index", "indexedProperty");
assert_throws_dom("DataError",function(){
index.get(NaN);
});
t.done();
};
26 changes: 0 additions & 26 deletions IndexedDB/idbindex_get5.htm

This file was deleted.

24 changes: 24 additions & 0 deletions IndexedDB/idbindex_get6.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// META: global=window,worker
// META: title=IDBIndex.get() - throw InvalidStateError when the index is deleted
// META: script=resources/support.js
// @author Intel <http://www.intel.com>

'use_strict';

let db;
const t = async_test();

const open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
const store = db.createObjectStore("store", { keyPath: "key" });
const index = store.createIndex("index", "indexedProperty");

store.add({ key: 1, indexedProperty: "data" });
store.deleteIndex("index");

assert_throws_dom("InvalidStateError", function(){
index.get("data");
});
t.done();
}
29 changes: 0 additions & 29 deletions IndexedDB/idbindex_get6.htm

This file was deleted.

Loading

0 comments on commit 13165cb

Please sign in to comment.