Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / transaction-scope-sequencing.js
blob2de89be70b1f36e758f06cc440edf31d4ad53ce5
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Check that scope restrictions on read-write transactions are enforced.");
8 indexedDBTest(prepareDatabase, runTransactions);
10 function prepareDatabase(evt)
12     preamble(evt);
13     evalAndLog("db = event.target.result");
14     evalAndLog("db.createObjectStore('a')");
15     evalAndLog("db.createObjectStore('b')");
16     evalAndLog("db.createObjectStore('c')");
19 function runTransactions(evt)
21     preamble(evt);
22     evalAndLog("db = event.target.result");
23     debug("");
25     evalAndLog("transaction1 = db.transaction(['a'], 'readwrite')");
26     evalAndLog("transaction1Started = false");
27     evalAndLog("transaction1Complete = false");
28     request = evalAndLog("transaction1.objectStore('a').get(0)");
29     request.onerror = unexpectedErrorCallback;
30     request.onsuccess = function() {
31         debug("");
32         evalAndLog("transaction1Started = true");
33     };
34     transaction1.onabort = unexpectedAbortCallback;
35     transaction1.oncomplete = function() {
36         debug("");
37         evalAndLog("transaction1Complete = true");
38         shouldBeFalse("transaction2Started");
39         shouldBeFalse("transaction3Started");
40     };
42     debug("");
43     debug("transaction2 overlaps with transaction1, so must wait until transaction1 completes");
44     evalAndLog("transaction2 = db.transaction(['a', 'b'], 'readwrite')");
45     evalAndLog("transaction2Started = false");
46     evalAndLog("transaction2Complete = false");
47     request = evalAndLog("transaction2.objectStore('a').get(0)");
48     request.onerror = unexpectedErrorCallback;
49     request.onsuccess = function() {
50         debug("");
51         shouldBeTrue("transaction1Complete");
52         evalAndLog("transaction2Started = true");
53     };
54     transaction2.onabort = unexpectedAbortCallback;
55     transaction2.oncomplete = function() {
56         debug("");
57         evalAndLog("transaction2Complete = true");
58         shouldBeFalse("transaction3Started");
59     };
61     debug("");
62     debug("transaction3 overlaps with transaction2, so must wait until transaction2 completes");
63     debug("even though it does not overlap with transaction1");
64     evalAndLog("transaction3 = db.transaction(['b', 'c'], 'readwrite')");
65     evalAndLog("transaction3Started = false");
66     evalAndLog("transaction3Complete = false");
67     request = evalAndLog("transaction3.objectStore('b').get(0)");
68     request.onerror = unexpectedErrorCallback;
69     request.onsuccess = function() {
70         debug("");
71         shouldBeTrue("transaction1Complete");
72         shouldBeTrue("transaction2Complete");
73         evalAndLog("transaction3Started = true");
74     };
75     transaction3.onabort = unexpectedAbortCallback;
76     transaction3.oncomplete = function() {
77         debug("");
78         evalAndLog("transaction3Complete = true");
79         finishJSTest();
80     };