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