2 <script src=
"../../resources/js-test.js"></script>
3 <script src=
"resources/shared.js"></script>
6 description("Exercise optional arguments with missing vs. undefined in IndexedDB methods.");
8 indexedDBTest(prepareDatabase
, checkOptionalArguments
);
9 function prepareDatabase(evt
)
12 evalAndLog("db = event.target.result");
13 evalAndLog("store = db.createObjectStore('store', {keyPath: 'id'})");
14 evalAndLog("store.createIndex('by_name', 'name', {unique: true})");
16 evalAndLog("store.put({id: 1, name: 'a'})");
19 function checkOptionalArguments(event
)
21 evalAndLog("tx = db.transaction('store', 'readwrite')");
22 tx
.oncomplete
= finishJSTest
;
24 evalAndLog("store = tx.objectStore('store')");
25 evalAndLog("index = store.index('by_name')");
27 shouldBe("IDBKeyRange.lowerBound(0).lowerOpen", "false");
28 shouldBe("IDBKeyRange.upperBound(0).upperOpen", "false");
29 shouldBe("IDBKeyRange.bound(0, 1).lowerOpen", "false");
30 shouldBe("IDBKeyRange.bound(0, 1).upperOpen", "false");
32 shouldBe("IDBKeyRange.lowerBound(0, undefined).lowerOpen", "false");
33 shouldBe("IDBKeyRange.upperBound(0, undefined).upperOpen", "false");
34 shouldBe("IDBKeyRange.bound(0, 1, undefined, undefined).lowerOpen", "false");
35 shouldBe("IDBKeyRange.bound(0, 1, undefined, undefined).upperOpen", "false");
37 shouldNotThrow("store.add({id: 2, name: 'b'})");
38 shouldNotThrow("store.put({id: 3, name: 'c'})");
39 shouldNotThrow("store.add({id: 4, name: 'd'}, undefined)");
40 shouldNotThrow("store.put({id: 5, name: 'e'}, undefined)");
43 function(callback
) { verifyCursor("store.openCursor()", "next", 5, callback
); },
44 function(callback
) { verifyCursor("store.openCursor(null)", "next", 5, callback
); },
45 function(callback
) { verifyCursor("store.openCursor(IDBKeyRange.lowerBound(4))", "next", 2, callback
); },
46 function(callback
) { verifyCursor("store.openCursor(3)", "next", 1, callback
); },
48 function(callback
) { verifyCursor("store.openKeyCursor()", "next", 5, callback
); },
49 function(callback
) { verifyCursor("store.openKeyCursor(null)", "next", 5, callback
); },
50 function(callback
) { verifyCursor("store.openKeyCursor(IDBKeyRange.lowerBound(4))", "next", 2, callback
); },
51 function(callback
) { verifyCursor("store.openKeyCursor(3)", "next", 1, callback
); },
53 function(callback
) { verifyCursor("index.openCursor()", "next", 5, callback
); },
54 function(callback
) { verifyCursor("index.openCursor(null)", "next", 5, callback
); },
55 function(callback
) { verifyCursor("index.openCursor(IDBKeyRange.lowerBound('b'))", "next", 4, callback
); },
56 function(callback
) { verifyCursor("index.openCursor('c')", "next", 1, callback
); },
58 function(callback
) { verifyCursor("index.openKeyCursor()", "next", 5, callback
); },
59 function(callback
) { verifyCursor("index.openKeyCursor(null)", "next", 5, callback
); },
60 function(callback
) { verifyCursor("index.openKeyCursor(IDBKeyRange.lowerBound('b'))", "next", 4, callback
); },
61 function(callback
) { verifyCursor("index.openKeyCursor('c')", "next", 1, callback
); },
63 function(callback
) { verifyCount("store.count()", 5, callback
); },
64 function(callback
) { verifyCount("store.count(null)", 5, callback
); },
65 function(callback
) { verifyCount("store.count(IDBKeyRange.lowerBound(2))", 4, callback
); },
67 function(callback
) { verifyCount("index.count()", 5, callback
); },
68 function(callback
) { verifyCount("index.count(null)", 5, callback
); },
69 function(callback
) { verifyCount("index.count(IDBKeyRange.lowerBound('b'))", 4, callback
); },
74 function doNextTask() {
75 var task
= tasks
.shift();
83 function verifyCursor(expr
, direction
, expected
, callback
)
88 evalAndLog("request = " + expr
);
89 request
.onerror
= unexpectedErrorCallback
;
91 request
.onsuccess = function() {
94 evalAndLog("cursor = request.result");
95 shouldBeEqualToString("cursor.direction", direction
);
100 shouldBe("continues", JSON
.stringify(expected
));
106 function verifyCount(expr
, expected
, callback
)
109 evalAndLog("request = " + expr
);
110 request
.onerror
= unexpectedErrorCallback
;
112 request
.onsuccess = function() {
113 shouldBe("request.result", JSON
.stringify(expected
));
118 function continueUndefined(callback
)
122 evalAndLog("request = store.openCursor()");
123 request
.onerror
= unexpectedErrorCallback
;
125 request
.onsuccess = function() {
128 evalAndLog("cursor = request.result");
129 shouldBeNonNull("request.result");
130 shouldNotThrow("cursor.continue(undefined)");