diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/IndexedDB/idbindex-cross-realm-methods.html | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/IndexedDB/idbindex-cross-realm-methods.html')
-rw-r--r-- | testing/web-platform/tests/IndexedDB/idbindex-cross-realm-methods.html | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/testing/web-platform/tests/IndexedDB/idbindex-cross-realm-methods.html b/testing/web-platform/tests/IndexedDB/idbindex-cross-realm-methods.html new file mode 100644 index 0000000000..1e431d3772 --- /dev/null +++ b/testing/web-platform/tests/IndexedDB/idbindex-cross-realm-methods.html @@ -0,0 +1,99 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>Cross-realm IDBIndex methods from detached iframe work as expected</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=resources/support.js></script> + +<body> +<script> +"use strict"; +const INDEX_LOWER = 1000; +const INDEX_UPPER = 1001; +const INDEX_RANGE = IDBKeyRange.bound(INDEX_LOWER, INDEX_UPPER); + +const testCases = [ + { + methodName: "get", + arguments: [INDEX_LOWER], + validateResult: e => { + assert_equals(e.target.result.indexedKey, INDEX_LOWER); + }, + }, + { + methodName: "getKey", + arguments: [INDEX_UPPER], + validateResult: e => { + assert_equals(e.target.result, INDEX_UPPER); + }, + }, + { + methodName: "getAll", + arguments: [INDEX_RANGE], + validateResult: e => { + assert_array_equals(e.target.result.map(v => v.indexedKey), [INDEX_LOWER, INDEX_UPPER]); + }, + }, + { + methodName: "getAllKeys", + arguments: [INDEX_RANGE], + validateResult: e => { + assert_array_equals(e.target.result, [INDEX_LOWER, INDEX_UPPER]); + }, + }, + { + methodName: "count", + arguments: [INDEX_RANGE], + validateResult: e => { + assert_equals(e.target.result, 2); + }, + }, + { + methodName: "openCursor", + arguments: [], + validateResult: e => { + const cursor = e.target.result; + assert_true(cursor instanceof IDBCursor); + assert_equals(cursor.value.indexedKey, INDEX_LOWER); + }, + }, + { + methodName: "openKeyCursor", + arguments: [], + validateResult: e => { + const cursor = e.target.result; + assert_true(cursor instanceof IDBCursor); + assert_equals(cursor.key, INDEX_LOWER); + }, + }, +]; + +for (const testCase of testCases) { + async_test(t => { + const iframe = document.createElement("iframe"); + iframe.onload = t.step_func(() => { + const method = iframe.contentWindow.IDBIndex.prototype[testCase.methodName]; + iframe.remove(); + + let db; + const open_rq = createdb(t); + open_rq.onupgradeneeded = t.step_func(e => { + db = e.target.result; + const objectStore = db.createObjectStore("store"); + objectStore.createIndex("index", "indexedKey"); + objectStore.add({ indexedKey: INDEX_LOWER }, INDEX_LOWER); + objectStore.add({ indexedKey: INDEX_UPPER }, INDEX_UPPER); + }); + + open_rq.onsuccess = t.step_func(() => { + const index = db.transaction("store", "readonly", {durability: 'relaxed'}).objectStore("store").index("index"); + const rq = method.call(index, ...testCase.arguments); + rq.onsuccess = t.step_func_done(e => { + testCase.validateResult(e); + }); + }); + }); + document.body.append(iframe); + }, `Cross-realm IDBIndex::${testCase.methodName}() method from detached <iframe> works as expected`); +} +</script> |