testing/web-platform/tests/IndexedDB/idbindex-cross-realm-methods.html
author Sandor Molnar <smolnar@mozilla.com>
Fri, 11 Jul 2025 19:57:29 +0300 (5 hours ago)
changeset 796221 8ba6984a5604ac7dcf50325b1a0ebadf9e305d22
parent 768825 2ae11d3ec11d21eaf4f41136ad4160551d40127f
permissions -rw-r--r--
Revert "Bug 1972411 - give gnome-shell and pipewire more time to start, and retry the task if we time out. r=jmaher" for causing linux perma failures This reverts commit 2b905fe7199c9210434f7c7f8326b57025c91c55. Revert "Bug 1972411 - make /builds/worker/fetches a volume in the test docker image. r=releng-reviewers,Eijebong" This reverts commit 9d15aecaf6a08b98d3c47f2d0e644e35341b2520.
<!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").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>