Modern IDB: Remove unneeded "Alert: " string from storage/indexeddb/modern tests.
[WebKit-https.git] / LayoutTests / storage / indexeddb / modern / resources / transaction-scheduler-6.js
1 description("This test starts two read-only transactions to an object store followed by a read-write transaction. \
2 It verifies that the read-write doesn't start until both read-onlys have finished.");
3
4
5 if (window.testRunner) {
6     testRunner.waitUntilDone();
7     testRunner.dumpAsText();
8 }
9
10 function done()
11 {
12     finishJSTest();
13 }
14
15 var createRequest = window.indexedDB.open("TransactionScheduler6Database");
16 var database;
17
18 createRequest.onupgradeneeded = function(event) {
19     debug("Upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
20
21     var versionTransaction = createRequest.transaction;
22     database = event.target.result;
23     var objectStore = database.createObjectStore("TestObjectStore");
24     var request = objectStore.put("foo", "bar");
25
26     request.onerror = function(event) {
27         debug("put FAILED - " + event);
28         done();
29     }
30     
31     versionTransaction.onabort = function(event) {
32         debug("versionchange transaction aborted");
33         done();
34     }
35
36     versionTransaction.oncomplete = function(event) {
37         debug("versionchange transaction completed");
38         continueTest();
39     }
40
41     versionTransaction.onerror = function(event) {
42         debug("versionchange transaction error'ed - " + event);
43         done();
44     }
45 }
46
47 function continueTest()
48 {
49     startTransactionLoop(database.transaction("TestObjectStore", "readonly"), true);
50     startTransactionLoop(database.transaction("TestObjectStore", "readonly"), true);
51     
52     var transaction = database.transaction("TestObjectStore", "readwrite");
53     var objectStore = transaction.objectStore("TestObjectStore");
54     var request = objectStore.put("baz", "foo");
55
56     request.onsuccess = function(event) {
57         debug("Write in readwrite transaction succeeded");
58     }
59     
60     request.onerror = function(event) {
61         debug("Write in readwrite transaction unexpectedly failed");
62         done();
63     }
64     
65     transaction.onabort = function(event) {
66         debug("readwrite transaction expectedly aborted");
67         done();
68     }
69
70     transaction.oncomplete = function(event) {
71         debug("readwrite transaction completed");
72         done();
73     }
74
75     transaction.onerror = function(event) {
76         debug("readwrite transaction error'ed - " + event);
77         done();
78     }
79 }
80
81 var numberOfOpenTransactions = 0;
82
83 function startTransactionLoop(transaction, isFirstTime)
84 {
85     var objectStore = transaction.objectStore("TestObjectStore");
86     var request = objectStore.get("bar");
87     
88     request.onsuccess = function(event) {
89         if (isFirstTime) {
90             debug("Starting a readonly transaction");
91             numberOfOpenTransactions++;
92         }
93         
94         if (numberOfOpenTransactions == 2)
95             return;
96
97         startTransactionLoop(event.target.transaction, false);
98     }
99
100     request.onerror = function(event) {
101         debug("Unexpected request error - " + event);
102         done();
103     }
104
105     transaction.onerror = function(event) {
106         debug("Unexpected transaction error - " + event);
107         done();
108     }
109
110     transaction.onabort = function(event) {
111         --numberOfOpenTransactions;
112         debug("Unexpected transaction abort - " + event);
113         done();
114     }
115
116     transaction.oncomplete = function(event) {
117         --numberOfOpenTransactions;
118         debug("readonly transaction completed");
119     }
120 }
121
122