Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / transaction-readwrite-exclusive.js
bloba82ec5b15eea9a2d586f0ab7e84d642f303a6b24
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Check that readwrite transactions with overlapping scopes do not run in parallel.");
8 function test()
10     setDBNameFromPath();
12     request = evalAndLog("indexedDB.deleteDatabase(dbname)");
13     request.onerror = unexpectedBlockedCallback;
14     request.onblocked = unexpectedBlockedCallback;
15     request.onsuccess = openConnection1;
18 function openConnection1()
20     preamble();
21     request = evalAndLog("indexedDB.open(dbname, 1)");
22     request.onerror = unexpectedBlockedCallback;
23     request.onblocked = unexpectedBlockedCallback;
24     request.onupgradeneeded = function openOnUpgradeNeeded1(evt) {
25         preamble(evt);
26         evalAndLog("db = event.target.result");
27         evalAndLog("store = db.createObjectStore('store')");
28     };
29     request.onsuccess = function openOnSuccess(evt) {
30         preamble(evt);
31         evalAndLog("db1 = event.target.result");
32         openConnection2();
33     };
36 function openConnection2()
38     preamble();
39     request = evalAndLog("indexedDB.open(dbname, 1)");
40     request.onerror = unexpectedBlockedCallback;
41     request.onblocked = unexpectedBlockedCallback;
42     request.onupgradeneeded = unexpectedUpgradeNeededCallback;
43     request.onsuccess = function openOnSuccess2(evt) {
44         preamble(evt);
45         evalAndLog("db2 = event.target.result");
46         startWork();
47     };
50 function startWork()
52     preamble();
53     evalAndLog("transaction1 = db1.transaction('store', 'readwrite')");
54     transaction1.onabort = unexpectedAbortCallback;
55     evalAndLog("transaction2 = db2.transaction('store', 'readwrite')");
56     transaction1.onabort = unexpectedAbortCallback;
58     evalAndLog("transaction1PutSuccess = false");
59     evalAndLog("transaction1Complete = false");
60     evalAndLog("transaction2PutSuccess = false");
61     evalAndLog("transaction2Complete = false");
63     debug("");
64     debug("Keep transaction1 alive for a while and ensure transaction2 doesn't start");
66     evalAndLog("count = 0");
68     (function doTransaction1Put() {
69         request = evalAndLog("transaction1.objectStore('store').put(1, count++)");
70         request.onerror = unexpectedErrorCallback;
71         request.onsuccess = function put1OnSuccess(evt) {
72             preamble(evt);
73             evalAndLog("transaction1PutSuccess = true");
74             if (count < 5) {
75                 doTransaction1Put();
76             }
77         };
78     }());
80     transaction1.oncomplete = function onTransaction1Complete(evt) {
81         preamble(evt);
82         evalAndLog("transaction1Complete = true");
83         shouldBeFalse("transaction2PutSuccess");
84         shouldBeFalse("transaction2Complete");
85     };
87     request = evalAndLog("transaction2.objectStore('store').put(2, 0)");
88     request.onerror = unexpectedErrorCallback;
89     request.onsuccess = function put2OnSuccess(evt) {
90         preamble(evt);
91         evalAndLog("transaction2PutSuccess = true");
92         shouldBeTrue("transaction1Complete");
93     };
95     transaction2.oncomplete = function onTransaction2Complete(evt) {
96         preamble(evt);
97         evalAndLog("transaction2Complete = true");
98         shouldBeTrue("transaction1PutSuccess");
99         shouldBeTrue("transaction1Complete");
100         shouldBeTrue("transaction2PutSuccess");
102         finishJSTest();
103     };
106 test();