IDB: Extend some WPTs to cover workers in addition to window.
web_tests/external/wpt/IndexedDB/ Tests currently only verify in window
environment. Extend tests to cover dedicated, shared & service workers.
Tests related to idbindex_getKey.htm have been extended and
consolidated into one file.
Additionally, file idbindex_getAll.htm has also been extended and
previously extended idbindex_get files have also been consolidated into
one file.
Bug: 41455766
Change-Id: I542b22d318e76efe2ff7a62e875ece2f940b0237
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5322232
Reviewed-by: Evan Stade <estade@chromium.org>
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Commit-Queue: Sneha Agarwal <snehagarwal@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1267478}
diff --git a/IndexedDB/idbindex_get.any.js b/IndexedDB/idbindex_get.any.js
index 601d41d..0da228f 100644
--- a/IndexedDB/idbindex_get.any.js
+++ b/IndexedDB/idbindex_get.any.js
@@ -1,32 +1,190 @@
// META: global=window,worker
-// META: title=IDBIndex.get() - returns the record
+// META: title=IDBIndex.get()
// META: script=resources/support.js
// @author Microsoft <https://www.microsoft.com>
+// @author Intel <http://www.intel.com>
'use_strict';
-let db;
-let index;
-const t = async_test(),
- record = { key: 1, indexedProperty: "data" };
+async_test(t => {
+ let db;
+ let index;
+ const record = { key: 1, indexedProperty: "data" };
-const open_rq = createdb(t);
-open_rq.onupgradeneeded = function(e) {
+ 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);
+ 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();
+ assert_equals(e.target.result.key, record.key);
+ t.done();
});
-}
+ };
+}, 'get() returns the record');
+
+async_test(t => {
+ let db;
+ 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();
+ });
+ };
+}, 'get() returns the record where the index contains duplicate values');
+
+async_test(t => {
+ let db;
+
+ 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();
+ });
+ };
+}, 'get() attempts to retrieve a record that does not exist');
+
+async_test(t => {
+ let db;
+
+ 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);
+ });
+ };
+}, 'get() returns the record with the first key in the range');
+
+async_test(t => {
+ let db;
+ 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();
+ };
+}, 'get() throws DataError when using invalid key');
+
+async_test(t => {
+ let db;
+ 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();
+ };
+}, 'get() throws InvalidStateError when the index is deleted');
+
+async_test(t => {
+ let db;
+ 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" });
+ };
+
+ open_rq.onsuccess = function(e) {
+ db = e.target.result;
+ const tx = db.transaction('store', 'readonly', { durability: 'relaxed' });
+ const index = tx.objectStore('store').index('index');
+ tx.abort();
+
+ assert_throws_dom("TransactionInactiveError", function () {
+ index.get("data");
+ });
+ t.done();
+ };
+}, 'get() throws TransactionInactiveError on aborted transaction');
+
+async_test(t => {
+ let db;
+ 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" });
+
+ e.target.transaction.abort();
+
+ assert_throws_dom("InvalidStateError", function () {
+ index.get("data");
+ });
+ t.done();
+ };
+}, 'get() throws InvalidStateError on index deleted by aborted upgrade');
diff --git a/IndexedDB/idbindex_get2.any.js b/IndexedDB/idbindex_get2.any.js
deleted file mode 100644
index 6790a60..0000000
--- a/IndexedDB/idbindex_get2.any.js
+++ /dev/null
@@ -1,34 +0,0 @@
-// 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();
- });
-};
diff --git a/IndexedDB/idbindex_get3.any.js b/IndexedDB/idbindex_get3.any.js
deleted file mode 100644
index 673621b..0000000
--- a/IndexedDB/idbindex_get3.any.js
+++ /dev/null
@@ -1,22 +0,0 @@
-// 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();
- });
-};
diff --git a/IndexedDB/idbindex_get4.any.js b/IndexedDB/idbindex_get4.any.js
deleted file mode 100644
index 096a29e..0000000
--- a/IndexedDB/idbindex_get4.any.js
+++ /dev/null
@@ -1,35 +0,0 @@
-// 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);
- });
-}
diff --git a/IndexedDB/idbindex_get5.any.js b/IndexedDB/idbindex_get5.any.js
deleted file mode 100644
index d99dfdc..0000000
--- a/IndexedDB/idbindex_get5.any.js
+++ /dev/null
@@ -1,21 +0,0 @@
-// 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();
-};
diff --git a/IndexedDB/idbindex_get6.any.js b/IndexedDB/idbindex_get6.any.js
deleted file mode 100644
index 8cbbe16..0000000
--- a/IndexedDB/idbindex_get6.any.js
+++ /dev/null
@@ -1,24 +0,0 @@
-// 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();
-}
diff --git a/IndexedDB/idbindex_get7.any.js b/IndexedDB/idbindex_get7.any.js
deleted file mode 100644
index 35c8cc8..0000000
--- a/IndexedDB/idbindex_get7.any.js
+++ /dev/null
@@ -1,28 +0,0 @@
-// META: global=window,worker
-// META: title=IDBIndex.get() - throw TransactionInactiveError on aborted transaction
-// 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" });
-}
-open_rq.onsuccess = function(e) {
- db = e.target.result;
- const tx = db.transaction('store', 'readonly', {durability: 'relaxed'});
- const index = tx.objectStore('store').index('index');
- tx.abort();
-
- assert_throws_dom("TransactionInactiveError", function(){
- index.get("data");
- });
- t.done();
-}
diff --git a/IndexedDB/idbindex_get8.any.js b/IndexedDB/idbindex_get8.any.js
deleted file mode 100644
index d6183c1..0000000
--- a/IndexedDB/idbindex_get8.any.js
+++ /dev/null
@@ -1,23 +0,0 @@
-// META: global=window,worker
-// META: title=IDBIndex.get() - throw InvalidStateError on index deleted by aborted upgrade
-// META: script=resources/support.js
-
-'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" });
-
- e.target.transaction.abort();
-
- assert_throws_dom("InvalidStateError", function(){
- index.get("data");
- });
- t.done();
-}
diff --git a/IndexedDB/idbindex_getAll.html b/IndexedDB/idbindex_getAll.any.js
similarity index 77%
rename from IndexedDB/idbindex_getAll.html
rename to IndexedDB/idbindex_getAll.any.js
index bd2a021..36b4c02 100644
--- a/IndexedDB/idbindex_getAll.html
+++ b/IndexedDB/idbindex_getAll.any.js
@@ -1,18 +1,18 @@
-<!DOCTYPE html>
-<title>IndexedDB: Test IDBIndex.getAll.</title>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="resources/support.js"></script>
-<script>
-var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
-var ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
+// META: global=window,worker
+// META: title=IndexedDB: Test IDBIndex.getAll
+// META: script=resources/support.js
+
+'use_strict';
+
+const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
+const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
function getall_test(func, name) {
indexeddb_test(
function(t, connection, tx) {
- var store = connection.createObjectStore('generated',
+ let store = connection.createObjectStore('generated',
{autoIncrement: true, keyPath: 'id'});
- var index = store.createIndex('test_idx', 'upper');
+ let index = store.createIndex('test_idx', 'upper');
alphabet.forEach(function(letter) {
store.put({ch: letter, upper: letter.toUpperCase()});
});
@@ -56,18 +56,18 @@
}
function createGetAllRequest(t, storeName, connection, range, maxCount) {
- var transaction = connection.transaction(storeName, 'readonly');
- var store = transaction.objectStore(storeName);
- var index = store.index('test_idx');
- var req = index.getAll(range, maxCount);
+ const transaction = connection.transaction(storeName, 'readonly');
+ const store = transaction.objectStore(storeName);
+ const index = store.index('test_idx');
+ const req = index.getAll(range, maxCount);
req.onerror = t.unreached_func('getAll request should succeed');
return req;
}
getall_test(function(t, connection) {
- var req = createGetAllRequest(t, 'out-of-line', connection, 'C');
+ const req = createGetAllRequest(t, 'out-of-line', connection, 'C');
req.onsuccess = t.step_func(function(evt) {
- var data = evt.target.result;
+ const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), ['c']);
assert_array_equals(data.map(function(e) { return e.upper; }), ['C']);
@@ -76,7 +76,7 @@
}, 'Single item get');
getall_test(function(t, connection) {
- var req = createGetAllRequest(t, 'empty', connection);
+ const req = createGetAllRequest(t, 'empty', connection);
req.onsuccess = t.step_func(function(evt) {
assert_array_equals(evt.target.result, [],
'getAll() on empty object store should return an empty array');
@@ -85,9 +85,9 @@
}, 'Empty object store');
getall_test(function(t, connection) {
- var req = createGetAllRequest(t, 'out-of-line', connection);
+ const req = createGetAllRequest(t, 'out-of-line', connection);
req.onsuccess = t.step_func(function(evt) {
- var data = evt.target.result;
+ const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), alphabet);
assert_array_equals(data.map(function(e) { return e.upper; }), ALPHABET);
@@ -96,10 +96,10 @@
}, 'Get all keys');
getall_test(function(t, connection) {
- var req = createGetAllRequest(t, 'out-of-line', connection, undefined,
+ const req = createGetAllRequest(t, 'out-of-line', connection, undefined,
10);
req.onsuccess = t.step_func(function(evt) {
- var data = evt.target.result;
+ const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), 'abcdefghij'.split(''));
assert_array_equals(data.map(function(e) { return e.upper; }), 'ABCDEFGHIJ'.split(''));
@@ -108,10 +108,10 @@
}, 'maxCount=10');
getall_test(function(t, connection) {
- var req = createGetAllRequest(t, 'out-of-line', connection,
+ const req = createGetAllRequest(t, 'out-of-line', connection,
IDBKeyRange.bound('G', 'M'));
req.onsuccess = t.step_func(function(evt) {
- var data = evt.target.result;
+ const data = evt.target.result;
assert_array_equals(data.map(function(e) { return e.ch; }), 'ghijklm'.split(''));
assert_array_equals(data.map(function(e) { return e.upper; }), 'GHIJKLM'.split(''));
t.done();
@@ -119,10 +119,10 @@
}, 'Get bound range');
getall_test(function(t, connection) {
- var req = createGetAllRequest(t, 'out-of-line', connection,
+ const req = createGetAllRequest(t, 'out-of-line', connection,
IDBKeyRange.bound('G', 'M'), 3);
req.onsuccess = t.step_func(function(evt) {
- var data = evt.target.result;
+ const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), 'ghi'.split(''));
assert_array_equals(data.map(function(e) { return e.upper; }), 'GHI'.split(''));
@@ -131,10 +131,10 @@
}, 'Get bound range with maxCount');
getall_test(function(t, connection) {
- var req = createGetAllRequest(t, 'out-of-line', connection,
+ const req = createGetAllRequest(t, 'out-of-line', connection,
IDBKeyRange.bound('G', 'K', false, true));
req.onsuccess = t.step_func(function(evt) {
- var data = evt.target.result;
+ const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), 'ghij'.split(''));
assert_array_equals(data.map(function(e) { return e.upper; }), 'GHIJ'.split(''));
@@ -143,10 +143,10 @@
}, 'Get upper excluded');
getall_test(function(t, connection) {
- var req = createGetAllRequest(t, 'out-of-line', connection,
+ const req = createGetAllRequest(t, 'out-of-line', connection,
IDBKeyRange.bound('G', 'K', true, false));
req.onsuccess = t.step_func(function(evt) {
- var data = evt.target.result;
+ const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), 'hijk'.split(''));
assert_array_equals(data.map(function(e) { return e.upper; }), 'HIJK'.split(''));
@@ -155,10 +155,10 @@
}, 'Get lower excluded');
getall_test(function(t, connection) {
- var req = createGetAllRequest(t, 'generated',
+ const req = createGetAllRequest(t, 'generated',
connection, IDBKeyRange.bound(4, 15), 3);
req.onsuccess = t.step_func(function(evt) {
- var data = evt.target.result;
+ const data = evt.target.result;
assert_true(Array.isArray(data));
assert_equals(data.length, 0);
t.done();
@@ -166,7 +166,7 @@
}, 'Get bound range (generated) with maxCount');
getall_test(function(t, connection) {
- var req = createGetAllRequest(t, 'out-of-line',
+ const req = createGetAllRequest(t, 'out-of-line',
connection, "Doesn't exist");
req.onsuccess = t.step_func(function(evt) {
assert_array_equals(evt.target.result, [],
@@ -177,10 +177,10 @@
}, 'Non existent key');
getall_test(function(t, connection) {
- var req = createGetAllRequest(t, 'out-of-line', connection,
+ const req = createGetAllRequest(t, 'out-of-line', connection,
undefined, 0);
req.onsuccess = t.step_func(function(evt) {
- var data = evt.target.result;
+ const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), alphabet);
assert_array_equals(data.map(function(e) { return e.upper; }), ALPHABET);
@@ -189,10 +189,10 @@
}, 'maxCount=0');
getall_test(function(t, connection) {
- var req = createGetAllRequest(t, 'out-of-line-not-unique', connection,
+ const req = createGetAllRequest(t, 'out-of-line-not-unique', connection,
'first');
req.onsuccess = t.step_func(function(evt) {
- var data = evt.target.result;
+ const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), 'abcdefghijklm'.split(''));
assert_true(data.every(function(e) { return e.half === 'first'; }));
@@ -201,10 +201,10 @@
}, 'Retrieve multiEntry key');
getall_test(function(t, connection) {
- var req = createGetAllRequest(t, 'out-of-line-multi', connection,
+ const req = createGetAllRequest(t, 'out-of-line-multi', connection,
'vowel');
req.onsuccess = t.step_func(function(evt) {
- var data = evt.target.result;
+ const data = evt.target.result;
assert_class_string(data, 'Array', 'result should be an array');
assert_array_equals(data.map(function(e) { return e.ch; }), ['a', 'e', 'i', 'o', 'u']);
assert_array_equals(data[0].attribs, ['vowel', 'first']);
@@ -212,5 +212,3 @@
t.done();
});
}, 'Retrieve one key multiple values');
-
-</script>
diff --git a/IndexedDB/idbindex_getAllKeys.html b/IndexedDB/idbindex_getAllKeys.any.js
similarity index 78%
rename from IndexedDB/idbindex_getAllKeys.html
rename to IndexedDB/idbindex_getAllKeys.any.js
index 5640bfd..92f3cc1 100644
--- a/IndexedDB/idbindex_getAllKeys.html
+++ b/IndexedDB/idbindex_getAllKeys.any.js
@@ -1,18 +1,17 @@
-<!DOCTYPE html>
-<title>IndexedDB: Test IDBIndex.getAllKeys.</title>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="resources/support.js"></script>
-<script>
+// META: global=window,worker
+// META: title=IndexedDB: Test IDBIndex.getAllKeys.
+// META: script=resources/support.js
-var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
+'use_strict';
+
+const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
function getall_test(func, name) {
indexeddb_test(
function(t, connection, tx) {
- var store = connection.createObjectStore('generated',
+ let store = connection.createObjectStore('generated',
{autoIncrement: true, keyPath: 'id'});
- var index = store.createIndex('test_idx', 'upper');
+ let index = store.createIndex('test_idx', 'upper');
alphabet.forEach(function(letter) {
store.put({ch: letter, upper: letter.toUpperCase()});
});
@@ -47,25 +46,25 @@
}
function createGetAllKeysRequest(t, storeName, connection, range, maxCount) {
- var transaction = connection.transaction(storeName, 'readonly');
- var store = transaction.objectStore(storeName);
- var index = store.index('test_idx');
- var req = index.getAllKeys(range, maxCount);
+ const transaction = connection.transaction(storeName, 'readonly');
+ const store = transaction.objectStore(storeName);
+ const index = store.index('test_idx');
+ const req = index.getAllKeys(range, maxCount);
req.onerror = t.unreached_func('getAllKeys request should succeed');
return req;
}
getall_test(function(t, connection) {
- var req = createGetAllKeysRequest(t, 'out-of-line', connection, 'C');
+ const req = createGetAllKeysRequest(t, 'out-of-line', connection, 'C');
req.onsuccess = t.step_func(function(evt) {
- var data = evt.target.result;
+ const data = evt.target.result;
assert_array_equals(evt.target.result, ['c']);
t.done();
});
}, 'Single item get');
getall_test(function(t, connection) {
- var req = createGetAllKeysRequest(t, 'empty', connection);
+ const req = createGetAllKeysRequest(t, 'empty', connection);
req.onsuccess = t.step_func(function(evt) {
assert_array_equals(evt.target.result, [],
'getAllKeys() on empty object store should return empty array');
@@ -74,7 +73,7 @@
}, 'Empty object store');
getall_test(function(t, connection) {
- var req = createGetAllKeysRequest(t, 'out-of-line', connection);
+ const req = createGetAllKeysRequest(t, 'out-of-line', connection);
req.onsuccess = t.step_func(function(evt) {
assert_array_equals(evt.target.result, alphabet,
'getAllKeys() should return a..z');
@@ -83,7 +82,7 @@
}, 'Get all keys');
getall_test(function(t, connection) {
- var req = createGetAllKeysRequest(t, 'generated', connection);
+ const req = createGetAllKeysRequest(t, 'generated', connection);
req.onsuccess = t.step_func(function(evt) {
assert_array_equals(evt.target.result,
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
@@ -94,7 +93,7 @@
}, 'Get all generated keys');
getall_test(function(t, connection) {
- var req = createGetAllKeysRequest(t, 'out-of-line', connection, undefined,
+ const req = createGetAllKeysRequest(t, 'out-of-line', connection, undefined,
10);
req.onsuccess = t.step_func(function(evt) {
assert_array_equals(evt.target.result,
@@ -105,7 +104,7 @@
}, 'maxCount=10');
getall_test(function(t, connection) {
- var req = createGetAllKeysRequest(t, 'out-of-line', connection,
+ const req = createGetAllKeysRequest(t, 'out-of-line', connection,
IDBKeyRange.bound('G', 'M'));
req.onsuccess = t.step_func(function(evt) {
assert_array_equals(evt.target.result,
@@ -116,7 +115,7 @@
}, 'Get bound range');
getall_test(function(t, connection) {
- var req = createGetAllKeysRequest(t, 'out-of-line', connection,
+ const req = createGetAllKeysRequest(t, 'out-of-line', connection,
IDBKeyRange.bound('G', 'M'), 3);
req.onsuccess = t.step_func(function(evt) {
assert_array_equals(evt.target.result,
@@ -127,7 +126,7 @@
}, 'Get bound range with maxCount');
getall_test(function(t, connection) {
- var req = createGetAllKeysRequest(t, 'out-of-line', connection,
+ const req = createGetAllKeysRequest(t, 'out-of-line', connection,
IDBKeyRange.bound('G', 'K', false, true));
req.onsuccess = t.step_func(function(evt) {
assert_array_equals(evt.target.result,
@@ -138,7 +137,7 @@
}, 'Get upper excluded');
getall_test(function(t, connection) {
- var req = createGetAllKeysRequest(t, 'out-of-line', connection,
+ const req = createGetAllKeysRequest(t, 'out-of-line', connection,
IDBKeyRange.bound('G', 'K', true, false));
req.onsuccess = t.step_func(function(evt) {
assert_array_equals(evt.target.result,
@@ -149,7 +148,7 @@
}, 'Get lower excluded');
getall_test(function(t, connection) {
- var req = createGetAllKeysRequest(t, 'generated',
+ const req = createGetAllKeysRequest(t, 'generated',
connection, IDBKeyRange.bound(4, 15), 3);
req.onsuccess = t.step_func(function(evt) {
assert_array_equals(evt.target.result, [],
@@ -159,7 +158,7 @@
}, 'Get bound range (generated) with maxCount');
getall_test(function(t, connection) {
- var req = createGetAllKeysRequest(t, 'out-of-line',
+ const req = createGetAllKeysRequest(t, 'out-of-line',
connection, "Doesn't exist");
req.onsuccess = t.step_func(function(evt) {
assert_array_equals(evt.target.result, [],
@@ -170,7 +169,7 @@
}, 'Non existent key');
getall_test(function(t, connection) {
- var req = createGetAllKeysRequest(t, 'out-of-line', connection,
+ const req = createGetAllKeysRequest(t, 'out-of-line', connection,
undefined, 0);
req.onsuccess = t.step_func(function(evt) {
assert_array_equals(evt.target.result, alphabet,
@@ -180,7 +179,7 @@
}, 'maxCount=0');
getall_test(function(t, connection) {
- var req = createGetAllKeysRequest(t, 'out-of-line-multi', connection,
+ const req = createGetAllKeysRequest(t, 'out-of-line-multi', connection,
'vowel');
req.onsuccess = t.step_func(function(evt) {
assert_array_equals(evt.target.result, ['A','E','I','O','U'])
@@ -188,5 +187,3 @@
});
req.onerror = t.unreached_func('getAllKeys request should succeed');
}, 'Retrieve multiEntry keys');
-
-</script>
diff --git a/IndexedDB/idbindex_getKey.any.js b/IndexedDB/idbindex_getKey.any.js
new file mode 100644
index 0000000..677a70e
--- /dev/null
+++ b/IndexedDB/idbindex_getKey.any.js
@@ -0,0 +1,191 @@
+// META: global=window,worker
+// META: title=IDBIndex.getKey()
+// META: script=resources/support.js
+// @author Microsoft <https://www.microsoft.com>
+// @author Intel <http://www.intel.com>
+
+'use_strict';
+
+async_test(t => {
+ let db;
+ const record = { key: 1, 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");
+
+ objStore.add(record);
+ };
+
+ open_rq.onsuccess = function(e) {
+ let rq = db.transaction("test", "readonly", { durability: 'relaxed' })
+ .objectStore("test");
+
+ rq = rq.index("index");
+
+ rq = rq.getKey("data");
+
+ rq.onsuccess = t.step_func(function(e) {
+ assert_equals(e.target.result, record.key);
+ t.done();
+ });
+ };
+}, 'getKey() returns the record\'s primary key');
+
+async_test(t => {
+ let db;
+ 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;
+ var 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")
+ .getKey("data");
+
+ rq.onsuccess = t.step_func(function(e) {
+ assert_equals(e.target.result, records[0].key);
+ t.done();
+ });
+ };
+}, 'getKey() returns the record\'s primary key where the index contains duplicate values');
+
+async_test(t => {
+ let db;
+ const open_rq = createdb(t);
+
+ open_rq.onupgradeneeded = function(e) {
+ db = e.target.result;
+ const rq = db.createObjectStore("test", { keyPath: "key" })
+ .createIndex("index", "indexedProperty")
+ .getKey(1);
+
+ rq.onsuccess = t.step_func(function(e) {
+ assert_equals(e.target.result, undefined);
+ t.done();
+ });
+ };
+}, 'getKey() attempt to retrieve the primary key of a record that doesn\'t exist');
+
+async_test(t => {
+ let db;
+
+ 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")
+ .getKey(IDBKeyRange.bound('data4', 'data7'));
+
+ rq.onsuccess = t.step_func(function(e) {
+ assert_equals(e.target.result, 4);
+
+ step_timeout(function () { t.done(); }, 4)
+ });
+ };
+}, 'getKey() returns the key of the first record within the range');
+
+async_test(t => {
+ let db;
+ 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.getKey(NaN);
+ });
+ t.done();
+ };
+}, 'getKey() throws DataError when using invalid key');
+
+async_test(t => {
+ let db;
+ 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.getKey("data");
+ });
+ t.done();
+ };
+}, 'getKey() throws InvalidStateError when the index is deleted');
+
+async_test(t => {
+ let db;
+
+ 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" });
+ };
+
+ open_rq.onsuccess = function(e) {
+ db = e.target.result;
+ const tx = db.transaction('store', 'readonly', { durability: 'relaxed' });
+ const index = tx.objectStore('store').index('index');
+ tx.abort();
+
+ assert_throws_dom("TransactionInactiveError", function () {
+ index.getKey("data");
+ });
+ t.done();
+ };
+}, 'getKey() throws TransactionInactiveError on aborted transaction');
+
+async_test(t => {
+ let db;
+
+ 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" });
+
+ e.target.transaction.abort();
+
+ assert_throws_dom("InvalidStateError", function () {
+ index.getKey("data");
+ });
+ t.done();
+ };
+}, 'getKey() throws InvalidStateError on index deleted by aborted upgrade');
diff --git a/IndexedDB/idbindex_getKey.htm b/IndexedDB/idbindex_getKey.htm
deleted file mode 100644
index 101e8f0..0000000
--- a/IndexedDB/idbindex_getKey.htm
+++ /dev/null
@@ -1,38 +0,0 @@
-<!DOCTYPE html>
-<meta charset="utf-8">
-<title>IDBIndex.getKey() - returns the record's primary key </title>
-<link rel="author" title="Microsoft" href="http://www.microsoft.com">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="resources/support.js"></script>
-
-<script>
- var db,
- t = async_test(),
- record = { key:1, indexedProperty:"data" };
-
- var open_rq = createdb(t);
- open_rq.onupgradeneeded = function(e) {
- db = e.target.result;
- var objStore = db.createObjectStore("test", { keyPath: "key" });
- objStore.createIndex("index", "indexedProperty");
-
- objStore.add(record);
- };
-
- open_rq.onsuccess = function(e) {
- var rq = db.transaction("test", "readonly", {durability: 'relaxed'})
- .objectStore("test");
-
- rq = rq.index("index");
-
- rq = rq.getKey("data");
-
- rq.onsuccess = t.step_func(function(e) {
- assert_equals(e.target.result, record.key);
- t.done();
- });
- };
-</script>
-
-<div id="log"></div>
diff --git a/IndexedDB/idbindex_getKey2.htm b/IndexedDB/idbindex_getKey2.htm
deleted file mode 100644
index 488368d..0000000
--- a/IndexedDB/idbindex_getKey2.htm
+++ /dev/null
@@ -1,39 +0,0 @@
-<!DOCTYPE html>
-<meta charset="utf-8">
-<title>IDBIndex.getKey() - returns the record's primary key where the index contains duplicate values </title>
-<link rel="author" title="Microsoft" href="http://www.microsoft.com">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="resources/support.js"></script>
-
-<script>
- var db,
- t = async_test(),
- records = [ { key:1, indexedProperty:"data" },
- { key:2, indexedProperty:"data" },
- { key:3, indexedProperty:"data" } ];
-
- var open_rq = createdb(t);
- open_rq.onupgradeneeded = function(e) {
- db = e.target.result;
- var objStore = db.createObjectStore("test", { keyPath: "key" });
- objStore.createIndex("index", "indexedProperty");
-
- for (var i = 0; i < records.length; i++)
- objStore.add(records[i]);
- };
-
- open_rq.onsuccess = function(e) {
- var rq = db.transaction("test", "readonly", {durability: 'relaxed'})
- .objectStore("test")
- .index("index")
- .getKey("data");
-
- rq.onsuccess = t.step_func(function(e) {
- assert_equals(e.target.result, records[0].key);
- t.done();
- });
- };
-</script>
-
-<div id="log"></div>
diff --git a/IndexedDB/idbindex_getKey3.htm b/IndexedDB/idbindex_getKey3.htm
deleted file mode 100644
index 40ed76d..0000000
--- a/IndexedDB/idbindex_getKey3.htm
+++ /dev/null
@@ -1,28 +0,0 @@
-<!DOCTYPE html>
-<meta charset="utf-8">
-<title>IDBIndex.getKey() - attempt to retrieve the primary key of a record that doesn't exist</title>
-<link rel="author" title="Microsoft" href="http://www.microsoft.com">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="resources/support.js"></script>
-
-<script>
- var db,
- t = async_test();
-
-
- var open_rq = createdb(t);
- open_rq.onupgradeneeded = function(e) {
- db = e.target.result;
- var rq = db.createObjectStore("test", { keyPath: "key" })
- .createIndex("index", "indexedProperty")
- .getKey(1);
-
- rq.onsuccess = t.step_func(function(e) {
- assert_equals(e.target.result, undefined);
- t.done();
- });
- };
-</script>
-
-<div id="log"></div>
diff --git a/IndexedDB/idbindex_getKey4.htm b/IndexedDB/idbindex_getKey4.htm
deleted file mode 100644
index 8c81a27..0000000
--- a/IndexedDB/idbindex_getKey4.htm
+++ /dev/null
@@ -1,38 +0,0 @@
-<!DOCTYPE html>
-<meta charset=utf-8>
-<title>IDBIndex.getKey() - returns the key of the first record within the range </title>
-<link rel="author" title="Microsoft" href="http://www.microsoft.com">
-<script src=/resources/testharness.js></script>
-<script src=/resources/testharnessreport.js></script>
-<script src=resources/support.js></script>
-
-<script>
- var db, t = async_test();
-
- var open_rq = createdb(t);
-
- open_rq.onupgradeneeded = function(e) {
- db = e.target.result;
- var store = db.createObjectStore("store", { keyPath: "key" });
- store.createIndex("index", "indexedProperty");
-
- for(var i = 0; i < 10; i++) {
- store.add({ key: i, indexedProperty: "data" + i });
- }
- }
-
- open_rq.onsuccess = function(e) {
- var rq = db.transaction("store", "readonly", {durability: 'relaxed'})
- .objectStore("store")
- .index("index")
- .getKey(IDBKeyRange.bound('data4', 'data7'));
-
- rq.onsuccess = t.step_func(function(e) {
- assert_equals(e.target.result, 4);
-
- step_timeout(function() { t.done(); }, 4)
- });
- }
-</script>
-
-<div id=log></div>
diff --git a/IndexedDB/idbindex_getKey5.htm b/IndexedDB/idbindex_getKey5.htm
deleted file mode 100644
index 3155131..0000000
--- a/IndexedDB/idbindex_getKey5.htm
+++ /dev/null
@@ -1,26 +0,0 @@
-<!DOCTYPE html>
-<meta charset="utf-8">
-<title>IDBIndex.getKey() - throw DataError when using invalid key </title>
-<link rel="author" title="Intel" href="http://www.intel.com">
-<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBIndex-getKey-IDBRequest-any-key">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="resources/support.js"></script>
-<div id="log"></div>
-<script>
- var db,
- t = async_test();
-
- var open_rq = createdb(t);
- open_rq.onupgradeneeded = function(e) {
- db = e.target.result;
-
- var index = db.createObjectStore("test", { keyPath: "key" })
- .createIndex("index", "indexedProperty");
- assert_throws_dom("DataError",function(){
- index.getKey(NaN);
- });
- t.done();
- };
-</script>
-
diff --git a/IndexedDB/idbindex_getKey6.htm b/IndexedDB/idbindex_getKey6.htm
deleted file mode 100644
index b71967d..0000000
--- a/IndexedDB/idbindex_getKey6.htm
+++ /dev/null
@@ -1,29 +0,0 @@
-<!DOCTYPE html>
-<meta charset="utf-8">
-<title>IDBIndex.getKey() - throw InvalidStateError when the index is deleted</title>
-<link rel="author" title="Intel" href="http://www.intel.com">
-<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBIndex-getKey-IDBRequest-any-key">
-<script src=/resources/testharness.js></script>
-<script src=/resources/testharnessreport.js></script>
-<script src=resources/support.js></script>
-<div id="log"></div>
-<script>
- var db,
- t = async_test();
-
- var open_rq = createdb(t);
- open_rq.onupgradeneeded = function(e) {
- db = e.target.result;
- var store = db.createObjectStore("store", { keyPath: "key" });
- var index = store.createIndex("index", "indexedProperty");
-
- store.add({ key: 1, indexedProperty: "data" });
- store.deleteIndex("index");
-
- assert_throws_dom("InvalidStateError", function(){
- index.getKey("data");
- });
- t.done();
- }
-</script>
-
diff --git a/IndexedDB/idbindex_getKey7.htm b/IndexedDB/idbindex_getKey7.htm
deleted file mode 100644
index 6a64df3..0000000
--- a/IndexedDB/idbindex_getKey7.htm
+++ /dev/null
@@ -1,32 +0,0 @@
-<!DOCTYPE html>
-<meta charset="utf-8">
-<title>IDBIndex.getKey() - throw TransactionInactiveError on aborted transaction</title>
-<link rel="author" title="Intel" href="http://www.intel.com">
-<link rel="help" href="https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBIndex-getKey-IDBRequest-any-key">
-<script src=/resources/testharness.js></script>
-<script src=/resources/testharnessreport.js></script>
-<script src=resources/support.js></script>
-<div id="log"></div>
-<script>
- var db,
- t = async_test();
-
- var open_rq = createdb(t);
- open_rq.onupgradeneeded = function(e) {
- db = e.target.result;
- var store = db.createObjectStore("store", { keyPath: "key" });
- var index = store.createIndex("index", "indexedProperty");
- store.add({ key: 1, indexedProperty: "data" });
- }
- open_rq.onsuccess = function(e) {
- db = e.target.result;
- var tx = db.transaction('store', 'readonly', {durability: 'relaxed'});
- var index = tx.objectStore('store').index('index');
- tx.abort();
-
- assert_throws_dom("TransactionInactiveError", function(){
- index.getKey("data");
- });
- t.done();
- }
-</script>
diff --git a/IndexedDB/idbindex_getKey8.htm b/IndexedDB/idbindex_getKey8.htm
deleted file mode 100644
index cf0affb..0000000
--- a/IndexedDB/idbindex_getKey8.htm
+++ /dev/null
@@ -1,27 +0,0 @@
-<!DOCTYPE html>
-<meta charset="utf-8">
-<title>IDBIndex.getKey() - throw InvalidStateError on index deleted by aborted upgrade</title>
-<link rel="help" href="https://w3c.github.io/IndexedDB/#dom-idbindex-getkey">
-<script src=/resources/testharness.js></script>
-<script src=/resources/testharnessreport.js></script>
-<script src=resources/support.js></script>
-<div id="log"></div>
-<script>
- var db,
- t = async_test();
-
- var open_rq = createdb(t);
- open_rq.onupgradeneeded = function(e) {
- db = e.target.result;
- var store = db.createObjectStore("store", { keyPath: "key" });
- var index = store.createIndex("index", "indexedProperty");
- store.add({ key: 1, indexedProperty: "data" });
-
- e.target.transaction.abort();
-
- assert_throws_dom("InvalidStateError", function(){
- index.getKey("data");
- });
- t.done();
- }
-</script>