JS Test Harness: Remove successfullyParsed from more tests
[WebKit-https.git] / LayoutTests / storage / indexeddb / mozilla / object-cursors.html
1 <!DOCTYPE html>
2 <!--
3   original test: http://mxr.mozilla.org/mozilla2.0/source/dom/indexedDB/test/test_objectCursors.html
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's index cursors");
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
27     name = window.location.pathname;
28     description = "My Test Database";
29     request = evalAndLog("indexedDB.open(name, description)");
30     request.onsuccess = openSuccess;
31     request.onerror = unexpectedErrorCallback;
32 }
33
34 function openSuccess()
35 {
36     db = evalAndLog("db = event.target.result");
37
38     request = evalAndLog("request = db.setVersion('1')");
39     request.onsuccess = cleanDatabase;
40     request.onerror = unexpectedErrorCallback;
41 }
42
43 function cleanDatabase()
44 {
45     deleteAllObjectStores(db);
46     autoIncrement = evalAndLog("autoIncrement = false;");
47     objectStore = evalAndLog("objectStore = db.createObjectStore('a', { keyPath: 'id', autoIncrement: autoIncrement });");
48     indexes = [
49         { name: "a", options: { } },
50         { name: "b", options: { unique: true } }
51     ];
52     for (j in indexes) {
53         evalAndLog("objectStore.createIndex(indexes[j].name, 'name', indexes[j].options);");
54     }
55     data = evalAndLog("data = { name: 'Ben', id: 1 };");
56     request = evalAndLog("request = objectStore.add(data);");
57     request.onsuccess = postAdd;
58     request.onerror = unexpectedErrorCallback;
59 }
60
61 function postAdd()
62 {
63     numIndexes = indexes.length;
64     indexesFinished = 0;
65     for (j in indexes) {
66         index = evalAndLog("index = objectStore.index(indexes[j].name);");
67         request = evalAndLog("request = index.openCursor();");
68         request.onerror = unexpectedErrorCallback;
69         request.onsuccess = function(event) {
70             shouldBe("event.target.result.value.name", "'Ben'");
71             if (++indexesFinished == numIndexes) {
72                 if (autoIncrement) {
73                     done();
74                 } else {
75                     setupAutoIncrement();
76                 }
77             }
78         };
79     }
80 }
81
82 function setupAutoIncrement()
83 {
84     autoIncrement = evalAndLog("autoIncrement = true;");
85     objectStore = evalAndLog("objectStore = db.createObjectStore('b', { keyPath: 'id', autoIncrement: autoIncrement });");
86     for (j in indexes) {
87         evalAndLog("objectStore.createIndex(indexes[j].name, 'name', indexes[j].options);");
88     }
89     data = evalAndLog("data = { name: 'Ben' };");
90     request = evalAndLog("request = objectStore.add(data);");
91     request.onsuccess = postAdd;
92     request.onerror = unexpectedErrorCallback;
93 }
94
95
96 test();
97
98 </script>
99 </body>
100 </html>
101