1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test IndexedDB database metadata mutation/snapshotting");
8 indexedDBTest(prepareDatabase, snapshotConnection1);
9 function prepareDatabase()
11 connection1 = event.target.result;
12 evalAndLog("connection1store1 = connection1.createObjectStore('store1')");
13 evalAndLog("connection1store1.createIndex('index1', 'path')");
15 shouldBe("connection1.version", "1");
16 shouldBe("connection1.objectStoreNames.length", "1");
17 shouldBe("connection1store1.indexNames.length", "1");
20 function snapshotConnection1()
22 debug("Connection's properties should be snapshotted on close");
23 evalAndLog("connection1.close()");
30 debug("secondOpen():");
31 evalAndLog("request = indexedDB.open(dbname, 2)");
32 request.onerror = unexpectedErrorCallback;
33 request.onblocked = unexpectedBlockedCallback;
34 request.onupgradeneeded = function() {
35 evalAndLog("connection2 = request.result");
36 evalAndLog("trans = request.transaction");
37 evalAndLog("connection2.createObjectStore('store2')");
38 evalAndLog("connection2store1 = trans.objectStore('store1')");
39 evalAndLog("connection2store1.createIndex('index2', 'path')");
41 shouldBe("connection2.version", "2");
42 shouldBe("connection2.objectStoreNames.length", "2");
43 shouldBe("connection2store1.indexNames.length", "2");
45 request.onsuccess = function() {
46 debug("Connection's properties should be snapshotted on close");
47 evalAndLog("connection2.close()");
55 debug("thirdOpen():");
56 evalAndLog("request = indexedDB.open(dbname, 3)");
57 request.onsuccess = unexpectedSuccessCallback;
58 request.onupgradeneeded = function() {
59 evalAndLog("connection3 = request.result");
60 evalAndLog("trans = request.transaction");
61 evalAndLog("connection3.createObjectStore('store3')");
62 evalAndLog("connection3store1 = trans.objectStore('store1')");
63 evalAndLog("connection3store1.createIndex('index3', 'path')");
65 shouldBe("connection3.version", "3");
66 shouldBe("connection3.objectStoreNames.length", "3");
67 shouldBe("connection3store1.indexNames.length", "3");
69 trans.oncomplete = unexpectedCompleteCallback;
70 debug("Connection's properties should be reverted on abort");
71 evalAndLog("trans.abort()");
73 request.onerror = function() {
74 debug("Connection's properties should be snapshotted on close");
75 evalAndLog("connection3.close()");
83 debug("fourthOpen():");
84 evalAndLog("request = indexedDB.open(dbname, 4)");
85 request.onerror = unexpectedErrorCallback;
86 request.onupgradeneeded = function() {
87 evalAndLog("connection4 = request.result");
88 evalAndLog("trans = request.transaction");
89 evalAndLog("connection4.createObjectStore('store4')");
90 evalAndLog("connection4store1 = trans.objectStore('store1')");
91 evalAndLog("connection4store1.createIndex('index4', 'path')");
93 shouldBe("connection4.version", "4");
94 shouldBe("connection4.objectStoreNames.length", "3");
95 shouldBe("connection4store1.indexNames.length", "3");
97 request.onsuccess = function() {
98 debug("Connection's properties should be snapshotted on close");
99 evalAndLog("connection4.close()");
104 function checkState()
107 debug("checkState():");
109 shouldBe("connection1.version", "1");
110 shouldBe("connection1.objectStoreNames.length", "1");
111 shouldBe("connection1store1.indexNames.length", "1");
114 shouldBe("connection2.version", "2");
115 shouldBe("connection2.objectStoreNames.length", "2");
116 shouldBe("connection2store1.indexNames.length", "2");
119 shouldBe("connection3.version", "2");
120 shouldBe("connection3.objectStoreNames.length", "2");
121 shouldBe("connection3store1.indexNames.length", "2");
124 shouldBe("connection4.version", "4");
125 shouldBe("connection4.objectStoreNames.length", "3");
126 shouldBe("connection4store1.indexNames.length", "3");