Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / intversion-open-in-upgradeneeded.js
blob68e4c8f686604aaed2d99277818d14eedd2f3fa6
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Test calling db.open in upgradeneeded.");
8 function test()
10     setDBNameFromPath();
12     request = evalAndLog("indexedDB.deleteDatabase(dbname)");
13     request.onsuccess = deleteSuccess;
14     request.onerror = unexpectedErrorCallback;
17 function deleteSuccess(evt) {
18     evalAndLog("request = indexedDB.open(dbname, 1)");
19     evalAndLog("request.onupgradeneeded = upgradeNeeded1");
20     evalAndLog("request.onsuccess = openSuccess1");
21     request.onblocked = unexpectedBlockedCallback;
22     request.onerror = unexpectedErrorCallback;
25 var sawTransactionComplete = false;
26 function upgradeNeeded1(evt)
28     preamble(evt);
29     evalAndLog("db = event.target.result");
30     shouldBe("event.newVersion", "1");
32     evalAndLog("transaction = event.target.transaction");
33     evalAndLog("db.createObjectStore('os')");
34     transaction.onabort = unexpectedAbortCallback;
35     transaction.oncomplete = function transactionOnComplete() {
36         preamble();
37         evalAndLog("sawTransactionComplete = true");
38     };
39     evalAndLog("db.onversionchange = onVersionChange");
40     evalAndLog("request = indexedDB.open(dbname, 3)");
41     evalAndLog("request.onupgradeneeded = upgradeNeeded2");
42     evalAndLog("request.onsuccess = openSuccess2");
43     request.onblocked = unexpectedBlockedCallback;
44     request.onerror = unexpectedErrorCallback;
47 function openSuccess1(evt)
49     preamble(evt);
50     shouldBeTrue("sawTransactionComplete");
51     db = evalAndLog("db = event.target.result");
52     shouldBe('db.version', "1");
53     debug("Start a transaction to ensure the connection is still open.");
54     evalAndLog("transaction = db.transaction('os')");
57 function onVersionChange(evt)
59     preamble(evt);
60     evalAndLog("db.close()");
63 function upgradeNeeded2(evt)
65     preamble(evt);
66     evalAndLog("db = event.target.result");
67     shouldBe("event.newVersion", "3");
70 function openSuccess2(evt)
72     preamble(evt);
73     evalAndLog("db = event.target.result");
74     shouldBe("db.version", "3");
75     finishJSTest();
78 test();