Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / intversion-gated-on-delete.js
blob7a589ff04ff6e5bd8429c51606ae86a5c1d053b7
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Test that a database is recreated correctly when an open-with-version call is queued behind a deleteDatabase call");
8 function test()
10     setDBNameFromPath();
11     request = evalAndLog("indexedDB.deleteDatabase(dbname)");
12     request.onsuccess = deleteSuccess;
13     request.onerror = unexpectedErrorCallback;
16 function deleteSuccess(evt) {
17     preamble(evt);
18     debugger;
19     evalAndLog("request = indexedDB.open(dbname)");
20     evalAndLog("request.onsuccess = firstSuccessCallback");
21     request.onerror = unexpectedErrorCallback;
24 function firstSuccessCallback(evt)
26     event = evt;
27     debug("");
28     debug("firstSuccessCallback():");
29     evalAndLog("connection1 = event.target.result");
30     evalAndLog("connection1.onversionchange = connection1VersionChangeCallback");
31     evalAndLog("request = indexedDB.open(dbname)");
32     evalAndLog("request.onsuccess = secondSuccessCallback");
33     request.onerror = unexpectedErrorCallback;
35     evalAndLog("request = indexedDB.deleteDatabase(dbname)");
36     evalAndLog("request.onblocked = deleteDatabaseBlockedCallback");
37     evalAndLog("request.onsuccess = deleteDatabaseSuccessCallback");
38     request.onerror = unexpectedErrorCallback;
40     evalAndLog("request = indexedDB.open(dbname, 1)");
41     evalAndLog("request.onupgradeneeded = upgradeNeededCallback");
42     evalAndLog("request.onsuccess = openWithVersionSuccessCallback");
43     request.onblocked = unexpectedBlockedCallback;
44     request.onerror = unexpectedErrorCallback;
47 function secondSuccessCallback(evt)
49     preamble(evt);
50     evalAndLog("db = event.target.result");
51     evalAndLog("db.onversionchange = connection2VersionChangeCallback");
54 function connection1VersionChangeCallback(evt)
56     preamble(evt);
57     shouldBeEqualToString("event.type", "versionchange");
58     shouldBe("event.oldVersion", "1");
59     shouldBeNull("event.newVersion");
62 function connection2VersionChangeCallback(evt)
64     preamble(evt);
65     shouldBeEqualToString("event.type", "versionchange");
66     evalAndLog("event.target.close()");
69 function deleteDatabaseBlockedCallback(evt)
71     preamble(evt);
72     evalAndLog("connection1.close()");
75 function deleteDatabaseSuccessCallback(evt)
77     preamble(evt);
80 function upgradeNeededCallback(evt)
82     preamble(evt);
83     shouldBe("event.newVersion", "1");
84     shouldBe("event.oldVersion", "0");
87 function openWithVersionSuccessCallback(evt)
89     preamble(evt);
90     shouldBe("event.target.result.objectStoreNames.length", "0");
91     finishJSTest();
94 test();