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 open request's 'success' event handler.");
12 request = evalAndLog("indexedDB.deleteDatabase(dbname)");
13 request.onsuccess = initiallyDeleted;
14 request.onerror = unexpectedErrorCallback;
17 var sawUpgradeNeeded = false;
18 var sawOpenSuccess = false;
19 var sawVersionChange = false;
20 var sawDeleteBlocked = false;
22 function initiallyDeleted(evt) {
24 evalAndLog("request = indexedDB.open(dbname, 1)");
25 request.onupgradeneeded = upgradeNeededCallback;
26 request.onsuccess = openSuccess;
27 request.onerror = unexpectedErrorCallback;
30 function upgradeNeededCallback(evt)
33 shouldBeFalse("sawUpgradeNeeded");
34 evalAndLog("sawUpgradeNeeded = true");
35 shouldBe("event.oldVersion", "0");
36 shouldBe("event.newVersion", "1");
38 evalAndLog("db = event.target.result");
39 db.onversionchange = versionChangeCallback;
40 evalAndLog("request2 = indexedDB.deleteDatabase(dbname)");
41 evalAndLog("request2.onsuccess = deleteSuccessCallback");
42 request2.onerror = unexpectedErrorCallback;
43 request2.onblocked = deleteBlockedCallback;
46 function openSuccess(evt)
49 shouldBeTrue("sawUpgradeNeeded");
50 shouldBeTrue("sawVersionChange");
51 evalAndLog("sawOpenSuccess = true");
52 evalAndLog("db = event.target.result");
53 shouldBe('db.version', '1');
55 // Event ordering between 'success' and 'blocked' is not strictly defined
56 // in the spec. This documents current Chromium behavior to detect
57 // unexpected changes.
58 debug("Closing here is too late to prevent the in-flight 'blocked' event, but it does unblock the delete.");
59 evalAndLog("db.close()");
62 function versionChangeCallback(evt)
65 shouldBe("event.oldVersion", "1");
66 shouldBeNull("event.newVersion");
67 shouldBeFalse("sawOpenSuccess");
68 evalAndLog("sawVersionChange = true");
69 debug("Connection not closed at the end of 'versionchange', so 'blocked' should fire");
72 function deleteBlockedCallback(evt)
75 shouldBeTrue("sawVersionChange");
76 shouldBeTrue("sawOpenSuccess");
77 evalAndLog("sawDeleteBlocked = true");
80 function deleteSuccessCallback(evt)
83 shouldBeTrue("sawVersionChange");
84 shouldBeTrue("sawDeleteBlocked");