Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / deletedatabase-delayed-by-open-and-versionchange.js
blob0f005763d11e640479b84078c93dabe62023e471
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Test that deleteDatabase is delayed if a VERSION_CHANGE transaction is running");
8 indexedDBTest(prepareDatabase, onOpenSuccess);
9 function prepareDatabase(evt)
11     preamble(evt);
12     evalAndLog("sawVersionChange = false");
13     evalAndLog("upgradeTransactionComplete = false");
14     evalAndLog("h = event.target.result");
16     h.onversionchange = function onVersionChange(evt) {
17         preamble(evt);
18         shouldBe("event.target.version", "1");
19         shouldBe("event.oldVersion", "1");
20         shouldBeNull("event.newVersion");
21         evalAndLog("sawVersionChange = true");
22         debug("Connection is not closed, so 'blocked' should fire");
23     };
25     transaction = event.target.transaction;
26     transaction.oncomplete = function transactionOnComplete(evt) {
27         preamble(evt);
28         evalAndLog("upgradeTransactionComplete = true");
29     };
31     request = evalAndLog("indexedDB.deleteDatabase(dbname)");
32     request.onerror = unexpectedErrorCallback;
33     request.onblocked = function deleteDatabaseOnBlocked(evt) {
34         preamble(evt);
35         shouldBeTrue("sawVersionChange");
36     };
37     request.onsuccess = function deleteDatabaseOnSuccess(evt) {
38         preamble(evt);
39         shouldBeTrue("upgradeTransactionComplete");
40         finishJSTest();
41     };
44 function onOpenSuccess(evt)
46     preamble(evt);
47     evalAndLog("h = event.target.result");
48     evalAndLog("h.close()");
49     debug("Closing too late to prevent the in-flight 'blocked' event");
50     // Event ordering between 'success' and 'blocked' is not strictly defined
51     // in the spec. This documents current Chromium behavior to detect
52     // unexpected changes.