Modern IDB: Remove unneeded "Alert: " string from storage/indexeddb/modern tests.
[WebKit-https.git] / LayoutTests / storage / indexeddb / modern / resources / idbobjectstore-count-failures.js
1 description("This tests some obvious failures that can happen while calling IDBObjectStore.count().");
2
3 if (window.testRunner) {
4     testRunner.waitUntilDone();
5     testRunner.dumpAsText();
6 }
7
8 function done()
9 {
10     finishJSTest();
11 }
12
13 var createRequest = window.indexedDB.open("IDBObjectStoreCountFailuresDatabase", 1);
14 var database;
15
16 createRequest.onupgradeneeded = function(event) {
17     debug("Initial upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
18
19     var versionTransaction = createRequest.transaction;
20     database = event.target.result;
21     var objectStore = database.createObjectStore("TestObjectStore");
22     var request = objectStore.put("bar", "foo");
23
24     request.onsuccess = function() {
25         try {
26             objectStore.count(NaN);
27         } catch(e) {
28             debug("Failed to count records in object store with an invalid key");
29         }
30         
31         database.deleteObjectStore("TestObjectStore");
32         
33         try {
34             objectStore.count();
35         } catch(e) {
36             debug("Failed to count records in object store that's been deleted");
37         } 
38
39         // Recreate the objectstore because we'll need it in phase 2.
40         var objectStore = database.createObjectStore("TestObjectStore");
41         objectStore.put("bar", "foo");    
42     }
43     
44     versionTransaction.onabort = function(event) {
45         debug("Initial upgrade versionchange transaction unexpected aborted");
46         done();
47     }
48
49     versionTransaction.oncomplete = function(event) {
50         debug("Initial upgrade versionchange transaction complete");
51         continueTest1();
52     }
53
54     versionTransaction.onerror = function(event) {
55         debug("Initial upgrade versionchange transaction unexpected error" + event);
56         done();
57     }
58 }
59
60 function continueTest1()
61 {
62     var transaction = database.transaction("TestObjectStore", "readonly");
63     var objectStore = transaction.objectStore("TestObjectStore");
64
65     // Spin the transaction with get requests to keep it alive long enough for the setTimeout to fire.
66     var canFinish = false;
67     var spinGet = function() { 
68         objectStore.get("foo").onsuccess = function() {
69             if (!canFinish)
70                 spinGet();
71         }
72     }
73     spinGet();
74     
75     var getWhileInactive = function() {
76         try {
77             objectStore.count();
78         } catch(e) {
79             debug("Failed to count records in object store while transaction is inactive");
80         }
81         canFinish = true;
82     }
83     
84     setTimeout(getWhileInactive, 0);
85     
86     transaction.onabort = function(event) {
87         debug("readonly transaction unexpected abort" + event);
88         done();
89     }
90
91     transaction.oncomplete = function(event) {
92         debug("readonly transaction complete");
93         done();
94     }
95
96     transaction.onerror = function(event) {
97         debug("readonly transaction unexpected error" + event);
98         done();
99     }
100 }
101
102