JS Test Harness: Remove successfullyParsed from more tests
[WebKit-https.git] / LayoutTests / storage / indexeddb / mozilla / remove-objectstore.html
1 <!DOCTYPE html>
2 <!--
3   original test: http://mxr.mozilla.org/mozilla2.0/source/dom/indexedDB/test/test_remove_objectStore.html?force=1
4   license of original test:
5     " Any copyright is dedicated to the Public Domain.
6       http://creativecommons.org/publicdomain/zero/1.0/ "
7 -->
8 <html>
9 <head>
10 <script src="../../../fast/js/resources/js-test-pre.js"></script>
11 <script src="../resources/shared.js"></script>
12 </head>
13 <body>
14 <p id="description"></p>
15 <div id="console"></div>
16 <script>
17
18 description("Test IndexedDB deleting an object store");
19 if (window.layoutTestController)
20     layoutTestController.waitUntilDone();
21
22 function test()
23 {
24     indexedDB = evalAndLog("indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;");
25     shouldBeFalse("indexedDB == null");
26     IDBDatabaseException = evalAndLog("IDBDatabaseException = window.IDBDatabaseException || window.webkitIDBDatabaseException;");
27     shouldBeFalse("IDBDatabaseException == null");
28
29     name = window.location.pathname;
30     description = "My Test Database";
31     request = evalAndLog("indexedDB.open(name, description)");
32     request.onsuccess = openSuccess;
33     request.onerror = unexpectedErrorCallback;
34 }
35
36 function openSuccess()
37 {
38     db = evalAndLog("db = event.target.result");
39     shouldBe("db.objectStoreNames.length", "0");
40
41     request = evalAndLog("request = db.setVersion('1')");
42     request.onsuccess = createAndPopulateObjectStore;
43     request.onerror = unexpectedErrorCallback;
44 }
45
46 function createAndPopulateObjectStore()
47 {
48     deleteAllObjectStores(db);
49
50     objectStoreName = evalAndLog("objectStoreName = 'Objects';");
51     objectStore = evalAndLog("objectStore = db.createObjectStore(objectStoreName, { keyPath: 'foo' });");
52
53     addedCount = evalAndLog("addedCount = 0;");
54     for (i = 0; i < 100; i++) {
55         request = evalAndLog("request = objectStore.add({foo: i});");
56         request.onerror = unexpectedErrorCallback;
57         request.onsuccess = function(event) {
58             if (++addedCount == 100) {
59                 checkObjectStore();
60             }
61         }
62     }
63 }
64
65 function checkObjectStore()
66 {
67     shouldBe("db.objectStoreNames.length", "1");
68     shouldBe("db.objectStoreNames.item(0)", "objectStoreName");
69
70     request = db.setVersion('2');
71     request.onerror = unexpectedErrorCallback;
72     request.onsuccess = postSetVersion2;
73 }
74
75 function postSetVersion2()
76 {
77     evalAndLog("db.deleteObjectStore(objectStore.name);");
78     shouldBe("db.objectStoreNames.length", "0");
79
80     objectStore = evalAndLog("objectStore = db.createObjectStore(objectStoreName, { keyPath: 'foo' });");
81     shouldBe("db.objectStoreNames.length", "1");
82     shouldBe("db.objectStoreNames.item(0)", "objectStoreName");
83
84     request = evalAndLog("request = objectStore.openCursor();");
85     request.onerror = unexpectedErrorCallback;
86     request.onsuccess = function(event) {
87         shouldBe("event.target.result", "null");
88         deleteSecondObjectStore();
89     }
90 }
91
92 function deleteSecondObjectStore()
93 {
94     evalAndLog("db.deleteObjectStore(objectStore.name);");
95     shouldBe("db.objectStoreNames.length", "0");
96     setVersion3();
97 }
98
99 function setVersion3()
100 {
101     request = evalAndLog("request = db.setVersion('3');");
102     request.onerror = unexpectedErrorCallback;
103     request.onsuccess = postSetVersion3;
104 }
105
106 function postSetVersion3()
107 {
108     objectStore = evalAndLog("objectStore = db.createObjectStore(objectStoreName, { keyPath: 'foo' });");
109     request = evalAndLog("request = objectStore.add({foo:'bar'});");
110     request.onerror = unexpectedErrorCallback;
111     request.onsuccess = deleteThirdObjectStore;
112 }
113
114 function deleteThirdObjectStore()
115 {
116     evalAndLog("db.deleteObjectStore(objectStoreName);");
117     done();
118 }
119
120
121 test();
122
123 </script>
124 </body>
125 </html>
126