Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / delete-in-upgradeneeded-close-in-versionchange.js
blob82828735d8f0c6df56b1f8fe0cf167abf5779166
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.");
8 function test()
10     setDBNameFromPath();
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) {
21     preamble(evt);
22     evalAndLog("request = indexedDB.open(dbname, 1)");
23     request.onupgradeneeded = upgradeNeededCallback;
24     request.onsuccess = unexpectedSuccessCallback;
27 function upgradeNeededCallback(evt)
29     preamble(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) {
44     preamble(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)
55     preamble(evt);
56     shouldBeTrue("sawVersionChange");
57     shouldBeTrue("sawUpgradeNeeded");
58     finishJSTest();
61 test();