1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test that a database is recreated correctly when an open-with-version call is queued behind both a deleteDatabase and an open-with-version call");
8 indexedDBTest(prepareDatabase, connection1Success);
9 function prepareDatabase(evt)
12 evalAndLog("db = event.target.result");
15 function connection1Success(evt)
18 evalAndLog("connection1 = event.target.result");
19 shouldBe("db", "connection1");
20 evalAndLog("connection1.onversionchange = connection1VersionChangeCallback");
21 evalAndLog("request = indexedDB.open(dbname, 2)");
22 evalAndLog("request.onsuccess = connection2Success");
23 evalAndLog("request.onupgradeneeded = connection2UpgradeNeeded");
24 evalAndLog("request.onblocked = connection2Blocked");
25 request.onerror = unexpectedErrorCallback;
28 function connection1VersionChangeCallback(evt)
31 shouldBeEqualToString("event.type", "versionchange");
32 shouldBe("event.oldVersion", "1");
33 shouldBe("event.newVersion", "2");
36 function connection2Blocked(evt)
39 evalAndLog("request = indexedDB.deleteDatabase(dbname)");
40 evalAndLog("request.onsuccess = deleteDatabaseSuccessCallback");
41 request.onblocked = unexpectedBlockedCallback;
42 request.onerror = unexpectedErrorCallback;
44 evalAndLog("request = indexedDB.open(dbname, 3)");
45 evalAndLog("request.onupgradeneeded = connection3UpgradeNeeded");
46 evalAndLog("request.onsuccess = connection3Success");
47 request.onerror = unexpectedErrorCallback;
48 evalAndLog("connection1.close()");
51 function deleteDatabaseSuccessCallback(evt)
54 shouldBeUndefined("event.target.result");
55 shouldBeEqualToString("event.type", "success");
58 function connection2UpgradeNeeded(evt)
61 shouldBe("event.oldVersion", "1");
62 shouldBe("event.newVersion", "2");
63 evalAndLog("db = event.target.result");
64 shouldBe("db.objectStoreNames.length", "0");
65 evalAndLog("db.createObjectStore('some object store')");
66 evalAndLog("transaction = event.target.transaction");
67 evalAndLog("transaction.oncomplete = connection2TransactionComplete");
70 function connection2Success(evt)
73 evalAndLog("connection2 = event.target.result");
74 connection2.onversionchange = unexpectedVersionChangeCallback;
75 evalAndLog("connection2.close()");
78 function connection2TransactionComplete(evt)
81 shouldBe("db.version", "2");
84 var gotUpgradeNeededEvent = false;
85 function connection3UpgradeNeeded(evt)
88 evalAndLog("gotUpgradeNeededEvent = true");
89 shouldBe("event.newVersion", "3");
90 shouldBe("event.oldVersion", "0");
93 function connection3Success(evt)
96 shouldBeTrue("gotUpgradeNeededEvent");
97 shouldBe("event.target.result.objectStoreNames.length", "0");