1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test the basics of IndexedDB's IDBCursor objects.");
8 indexedDBTest(prepareDatabase);
9 function prepareDatabase(evt)
12 db = event.target.result;
14 evalAndLog("store = db.createObjectStore('storeName')");
15 evalAndLog("index = store.createIndex('indexName', 'indexOn')");
16 evalAndLog("store.put({indexOn: 'a'}, 0)");
18 request = evalAndLog("store.openCursor()");
19 request.onsuccess = onStoreOpenCursor;
20 request.onerror = unexpectedErrorCallback;
22 request = evalAndLog("store.openKeyCursor()");
23 request.onsuccess = onStoreOpenKeyCursor;
24 request.onerror = unexpectedErrorCallback;
26 request = evalAndLog("index.openCursor()");
27 request.onsuccess = onIndexOpenCursor;
28 request.onerror = unexpectedErrorCallback;
30 request = evalAndLog("index.openKeyCursor()");
31 request.onsuccess = onIndexOpenKeyCursor;
32 request.onerror = unexpectedErrorCallback;
34 event.target.transaction.oncomplete = finishJSTest;
37 function checkCursorProperties() {
38 shouldBeTrue("cursor instanceof IDBCursor");
39 shouldBeTrue("'key' in cursor");
40 shouldBeTrue("'primaryKey' in cursor");
42 shouldBeTrue("'continue' in cursor");
43 shouldBeEqualToString("typeof cursor.continue", "function");
44 shouldBeTrue("'continuePrimaryKey' in cursor");
45 shouldBeEqualToString("typeof cursor.continuePrimaryKey", "function");
46 shouldBeTrue("'advance' in cursor");
47 shouldBeEqualToString("typeof cursor.advance", "function");
48 shouldBeTrue("'update' in cursor");
49 shouldBeEqualToString("typeof cursor.update", "function");
50 shouldBeTrue("'delete' in cursor");
51 shouldBeEqualToString("typeof cursor.delete", "function");
54 function onStoreOpenCursor(evt) {
56 evalAndLog("cursor = event.target.result");
57 shouldBeNonNull("cursor");
58 checkCursorProperties();
60 shouldBe("cursor.key", "0");
61 shouldBe("cursor.primaryKey", "0");
63 shouldBeTrue("cursor instanceof IDBCursorWithValue");
64 shouldBeTrue("'value' in cursor");
65 shouldBeEqualToString("JSON.stringify(cursor.value)", '{"indexOn":"a"}');
68 function onStoreOpenKeyCursor(evt) {
70 evalAndLog("cursor = event.target.result");
71 shouldBeNonNull("cursor");
72 checkCursorProperties();
74 shouldBe("cursor.key", "0");
75 shouldBeTrue("'primaryKey' in cursor");
76 shouldBe("cursor.primaryKey", "0");
78 shouldBeFalse("cursor instanceof IDBCursorWithValue");
79 shouldBeFalse("'value' in cursor");
82 function onIndexOpenCursor(evt) {
84 evalAndLog("cursor = event.target.result");
85 shouldBeNonNull("cursor");
86 checkCursorProperties();
88 shouldBeEqualToString("cursor.key", "a");
89 shouldBe("cursor.primaryKey", "0");
91 shouldBeTrue("cursor instanceof IDBCursorWithValue");
92 shouldBeTrue("'value' in cursor");
93 shouldBeEqualToString("JSON.stringify(cursor.value)", '{"indexOn":"a"}');
96 function onIndexOpenKeyCursor(evt) {
98 evalAndLog("cursor = event.target.result");
99 shouldBeNonNull("cursor");
100 checkCursorProperties();
102 shouldBeEqualToString("cursor.key", "a");
103 shouldBe("cursor.primaryKey", "0");
105 shouldBeFalse("cursor instanceof IDBCursorWithValue");
106 shouldBe("cursor.primaryKey", "0");
107 shouldBeFalse("'value' in cursor");