1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test that a deleteDatabase called while handling an upgradeneeded event is queued and fires its events at the right time. The close() call to unblock the delete occurs in the connection's 'versionchange' event handler.");
12 request = evalAndLog("indexedDB.deleteDatabase(dbname)");
13 request.onsuccess = initiallyDeleted;
14 request.onerror = unexpectedErrorCallback;
17 var sawUpgradeNeeded = false;
18 var sawVersionChange = false;
20 function initiallyDeleted(evt) {
22 evalAndLog("request = indexedDB.open(dbname, 1)");
23 request.onupgradeneeded = upgradeNeededCallback;
24 request.onsuccess = unexpectedSuccessCallback;
27 function upgradeNeededCallback(evt)
30 shouldBeFalse("sawUpgradeNeeded");
31 evalAndLog("sawUpgradeNeeded = true");
32 shouldBe("event.oldVersion", "0");
33 shouldBe("event.newVersion", "1");
35 evalAndLog("db = event.target.result");
36 db.onversionchange = versionChangeCallback;
37 request2 = evalAndLog("deleteRequest = indexedDB.deleteDatabase(dbname)");
38 evalAndLog("request2.onsuccess = deleteSuccessCallback");
39 request2.onerror = unexpectedErrorCallback;
40 request2.onblocked = unexpectedBlockedCallback;;
43 function versionChangeCallback(evt) {
45 shouldBe("event.oldVersion", "1");
46 shouldBeNull("event.newVersion");
47 evalAndLog("sawVersionChange = true");
49 debug("Closing the connection before the IDBOpenDBRequest's success fires will cause the open to fail.");
50 evalAndLog("db.close()");
53 function deleteSuccessCallback(evt)
56 shouldBeTrue("sawVersionChange");
57 shouldBeTrue("sawUpgradeNeeded");