Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / deletedatabase-delayed-by-versionchange.js
blob2c778220585ec2b981f369361bb0a555e41d6033
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Test the order when there are pending setVersion, delete and open calls.");
8 indexedDBTest(null, h1OpenSuccess);
9 function h1OpenSuccess(evt)
11     preamble(evt);
12     evalAndLog("setVersionBlockedEventFired = false");
13     evalAndLog("versionChangeComplete = false");
14     evalAndLog("deleteDatabaseBlockedEventFired = false");
15     evalAndLog("deleteDatabaseComplete = false");
17     evalAndLog("h1 = event.target.result");
19     h1.onversionchange = function h1OnVersionChange(evt) {
20         preamble(evt);
21         shouldBe("event.target.version", "1");
22         shouldBe("event.oldVersion", "1");
23         shouldBe("event.newVersion", "2");
25         h1.onversionchange = function h1SecondOnVersionChange(evt) {
26             preamble(evt);
27             shouldBe("event.target.version", "1");
28             shouldBe("event.oldVersion", "1");
29             shouldBeNull("event.newVersion");
30         };
31     };
33     debug("Open h2:");
34     request = evalAndLog("indexedDB.open(dbname)");
35     request.onblocked = unexpectedBlockedCallback;
36     request.onerror = unexpectedErrorCallback;
37     request.onsuccess = function h2OpenSuccess(evt) {
38         preamble(evt);
39         h2 = event.target.result;
41         h2.onversionchange = function h2OnVersionChange(evt) {
42             preamble(evt);
43             shouldBe("event.target.version", "1");
44             shouldBe("event.oldVersion", "1");
45             shouldBe("event.newVersion", "2");
47             h2.onversionchange = function h2OnSecondVersionChange(evt) {
48                 preamble(evt);
49                 shouldBe("event.target.version", "1");
50                 shouldBe("event.oldVersion", "1");
51                 shouldBe("event.newVersion", "null");
52             };
53         };
55         debug("Try to open h3:");
56         request = evalAndLog("indexedDB.open(dbname, 2)");
57         request.onerror = unexpectedErrorCallback;
58         request.onsuccess = function h3OpenSuccess(evt) {
59             preamble(evt);
60             h3 = event.target.result;
61             evalAndLog("h3.close()");
62         };
63         request.onblocked = function h3Blocked(evt) {
64             preamble(evt);
65             evalAndLog("setVersionBlockedEventFired = true");
67             debug("Try to open h4:");
68             request = evalAndLog("indexedDB.open(dbname)");
69             request.onblocked = unexpectedBlockedCallback;
70             request.onerror = unexpectedErrorCallback;
71             request.onsuccess = function h4OpenSuccess(evt) {
72                 preamble(evt);
73                 h4 = event.target.result;
74                 h4.onversionchange = unexpectedVersionChangeCallback;
76                 shouldBeTrue("setVersionBlockedEventFired");
77                 shouldBeTrue("versionChangeComplete");
78                 shouldBeTrue("deleteDatabaseBlockedEventFired");
79                 shouldBeTrue("deleteDatabaseComplete");
81                 finishJSTest();
82             };
84             evalAndLog("h2.close()");
85         };
86         request.onupgradeneeded = function h3OnUpgradeneeded(evt) {
87             preamble(evt);
89             transaction = event.target.transaction;
90             transaction.onabort = unexpectedAbortCallback;
91             transaction.oncomplete = function transactionOnComplete(evt) {
92                 preamble(evt);
93                 evalAndLog("versionChangeComplete = true");
94             };
95         };
97         request = evalAndLog("indexedDB.deleteDatabase(dbname)");
98         request.onerror = unexpectedErrorCallback;
99         request.onblocked = function deleteDatabaseOnBlocked(evt) {
100             preamble(evt);
101             evalAndLog("deleteDatabaseBlockedEventFired = true");
103             evalAndLog("h1.close()");
104         };
105         request.onsuccess = function deleteDatabaseOnSuccess(evt) {
106             preamble(evt);
107             evalAndLog("deleteDatabaseComplete = true");
108         };
109     };