2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
6 /* exported testGenerator */
7 var testGenerator = testSteps();
9 function generateKey() {
11 name: "RSASSA-PKCS1-v1_5",
14 publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
17 return crypto.subtle.generateKey(algorithm, true, ["sign", "verify"]);
20 const hasCrypto = "crypto" in this;
23 * Test addition of a new index when the existing values in the referenced
24 * object store have potentially unusual structured clone participants.
26 * When a new index is created, the existing object store's contents need to be
27 * processed to derive the index values. This is a special event because
28 * normally index values are extracted at add()/put() time in the content
29 * process using the page/worker's JS context (modulo some spec stuff). But
30 * the index creation operation is actually running in the parent process on the
31 * I/O thread for the given database. So the JS context scenario is suddenly
32 * a lot more complicated, and we need extra test coverage, in particular for
33 * unusual structured clone payloads.
35 * Relationship to other test:
36 * - test_create_index_with_integer_keys.js: This test is derived from that one.
38 function* testSteps() {
39 // -- Create our fancy data that has interesting structured clone issues.
42 // the xpcshell tests normalize self into existence.
44 info("creating crypto key");
45 // (all IDB tests badly need a test driver update...)
46 generateKey().then(grabEventAndContinueHandler);
47 let key = yield undefined;
54 info("not storing crypto key");
57 // -- Create the IDB and populate it with the base data.
58 info("opening initial database");
59 let request = indexedDB.open(
60 this.window ? window.location.pathname : "Splendid Test",
63 request.onerror = errorHandler;
64 request.onupgradeneeded = grabEventAndContinueHandler; // advance onupgradeneeded
65 let event = yield undefined; // wait for onupgradeneeded.
67 let db = event.target.result;
68 db.onerror = errorHandler;
70 event.target.onsuccess = continueToNextStep; // advance when the open completes
72 // Make object store, add data.
73 let objectStore = db.createObjectStore("foo", { keyPath: "id" });
74 for (let datum of allData) {
75 info(`add()ing ${datum.what}`);
76 objectStore.add(datum);
78 // wait for the open to complete following our upgrade transaction self-closing
80 // explicitly close the database so we can open it again. We don't wait for
81 // this, but the upgrade open will block until the close actually happens.
82 info("closing initial database");
85 // -- Trigger an upgrade, adding a new index.
86 info("opening database for upgrade to v2");
87 request = indexedDB.open(
88 this.window ? window.location.pathname : "Splendid Test",
91 request.onerror = errorHandler;
92 request.onupgradeneeded = grabEventAndContinueHandler; // advance onupgradeneeded
93 event = yield undefined; // wait for onupgradeneeded
95 let db2 = event.target.result;
96 db2.onerror = errorHandler;
98 event.target.onsuccess = continueToNextStep; // advance when the open completes
101 info("in upgrade, creating index");
102 event.target.transaction.objectStore("foo").createIndex("foo", "what");
103 yield undefined; // wait for the open to complete
104 info("upgrade completed");