1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
<!DOCTYPE html>
<meta charset=utf-8>
<title>Cross-realm IDBObjectStore 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 KEY_EXISTING_LOWER = 1000;
const KEY_EXISTING_UPPER = 1001;
const KEY_EXISTING_RANGE = IDBKeyRange.bound(KEY_EXISTING_LOWER, KEY_EXISTING_UPPER);
const KEY_NEWLY_ADDED = 1002;
const VALUE_EXISTING_LOWER = "VALUE_EXISTING_LOWER";
const VALUE_EXISTING_UPPER = "VALUE_EXISTING_UPPER";
const VALUE_NEWLY_ADDED = "VALUE_NEWLY_ADDED";
const testCases = [
{
methodName: "put",
arguments: [KEY_NEWLY_ADDED, KEY_EXISTING_LOWER],
validateResult: (t, e) => {
assert_equals(e.target.result, KEY_EXISTING_LOWER);
const rq = e.target.source.getAll();
rq.onsuccess = t.step_func_done(e => {
assert_array_equals(e.target.result, [KEY_NEWLY_ADDED, VALUE_EXISTING_UPPER]);
});
},
},
{
methodName: "add",
arguments: [VALUE_NEWLY_ADDED, KEY_NEWLY_ADDED],
validateResult: (t, e) => {
assert_equals(e.target.result, KEY_NEWLY_ADDED);
const rq = e.target.source.getAll();
rq.onsuccess = t.step_func_done(e => {
assert_array_equals(e.target.result, [VALUE_EXISTING_LOWER, VALUE_EXISTING_UPPER, VALUE_NEWLY_ADDED]);
});
},
},
{
methodName: "delete",
arguments: [KEY_EXISTING_LOWER],
validateResult: (t, e) => {
assert_equals(e.target.result, undefined);
const rq = e.target.source.getAllKeys();
rq.onsuccess = t.step_func_done(e => {
assert_array_equals(e.target.result, [KEY_EXISTING_UPPER]);
});
},
},
{
methodName: "clear",
arguments: [],
validateResult: (t, e) => {
assert_equals(e.target.result, undefined);
const rq = e.target.source.count();
rq.onsuccess = t.step_func_done(e => {
assert_equals(e.target.result, 0);
});
},
},
{
methodName: "get",
arguments: [KEY_EXISTING_UPPER],
validateResult: (t, e) => {
assert_equals(e.target.result, VALUE_EXISTING_UPPER);
t.done();
},
},
{
methodName: "getKey",
arguments: [KEY_EXISTING_LOWER],
validateResult: (t, e) => {
assert_equals(e.target.result, KEY_EXISTING_LOWER);
t.done();
},
},
{
methodName: "getAll",
arguments: [KEY_EXISTING_RANGE],
validateResult: (t, e) => {
assert_array_equals(e.target.result, [VALUE_EXISTING_LOWER, VALUE_EXISTING_UPPER]);
t.done();
},
},
{
methodName: "getAllKeys",
arguments: [KEY_EXISTING_RANGE],
validateResult: (t, e) => {
assert_array_equals(e.target.result, [KEY_EXISTING_LOWER, KEY_EXISTING_UPPER]);
t.done();
},
},
{
methodName: "count",
arguments: [],
validateResult: (t, e) => {
assert_equals(e.target.result, 2);
t.done();
},
},
{
methodName: "openCursor",
arguments: [],
validateResult: (t, e) => {
const cursor = e.target.result;
assert_true(cursor instanceof IDBCursor);
assert_equals(cursor.value, VALUE_EXISTING_LOWER);
t.done();
},
},
{
methodName: "openKeyCursor",
arguments: [],
validateResult: (t, e) => {
const cursor = e.target.result;
assert_true(cursor instanceof IDBCursor);
assert_equals(cursor.key, KEY_EXISTING_LOWER);
t.done();
},
},
];
for (const testCase of testCases) {
async_test(t => {
const iframe = document.createElement("iframe");
iframe.onload = t.step_func(() => {
const method = iframe.contentWindow.IDBObjectStore.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.add(VALUE_EXISTING_LOWER, KEY_EXISTING_LOWER);
objectStore.add(VALUE_EXISTING_UPPER, KEY_EXISTING_UPPER);
});
open_rq.onsuccess = t.step_func(() => {
const objectStore = db.transaction("store", "readwrite").objectStore("store");
const rq = method.call(objectStore, ...testCase.arguments);
rq.onsuccess = t.step_func(e => {
testCase.validateResult(t, e);
});
});
});
document.body.append(iframe);
}, `Cross-realm IDBObjectStore::${testCase.methodName}() method from detached <iframe> works as expected`);
}
</script>
|