Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / intversion-persistence.js
blob26d64a7b55a5117a306a7563fafd9444d5a346bc
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Test that integer versions are retained when backing store is opened/closed/re-opened.");
8 function test()
10     setDBNameFromPath();
12     // NOTE: deleteDatabase is not used, otherwise it would set the backing store schema version
13     // which would conceal the failure being tested for. Instead, a unique name is used each time.
14     evalAndLog("dbname = dbname + Date.now()");
16     openFirstTime();
19 function openFirstTime() {
20     preamble();
21     request = evalAndLog("indexedDB.open(dbname, 1)");
22     request.onerror = unexpectedErrorCallback;
23     request.onblocked = unexpectedBlockedCallback;
24     upgradeNeededFired = false;
25     request.onupgradeneeded = function() {
26         evalAndLog("db = request.result");
27         evalAndLog("upgradeNeededFired = true");
28         shouldBe("db.version", "1");
29         shouldBe("db.objectStoreNames.length", "0");
30         evalAndLog("db.createObjectStore('store')");
31     };
32     request.onsuccess = function() {
33         shouldBeTrue("upgradeNeededFired");
34         evalAndLog("db = request.result");
35         shouldBe("db.version", "1");
36         shouldBe("db.objectStoreNames.length", "1");
37         evalAndLog("db.close()");
38         openSecondTime();
39     };
42 function openSecondTime() {
43     preamble();
44     request = evalAndLog("indexedDB.open(dbname, 1)");
45     request.onerror = unexpectedErrorCallback;
46     request.onblocked = unexpectedBlockedCallback;
47     request.onupgradeneeded = unexpectedUpgradeNeededCallback;
48     request.onsuccess = function() {
49         evalAndLog("db = request.result");
50         shouldBe("db.version", "1");
51         shouldBe("db.objectStoreNames.length", "1");
52         evalAndLog("db.close()");
53         debug("");
54         finishJSTest();
55     };
58 test();