1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test IndexedDB's IDBObjectStore.get(IDBKeyRange) method.");
8 indexedDBTest(prepareDatabase);
9 function prepareDatabase()
11 db = event.target.result;
12 event.target.transaction.onabort = unexpectedAbortCallback;
14 self.objectStore = evalAndLog("db.createObjectStore('someObjectStore')");
15 self.index = evalAndLog("objectStore.createIndex('someIndex', 'x')");
21 for (var i=0; i<self.testLength; i++) {
22 evalAndLog("objectStore.add({'x': " + i + " }, " + i + ")");
25 evalAndLog("runObjStoreTests()");
28 function runObjStoreTests()
30 getRangeOnlyTest("objectStore", "get", ".x", "runIndexStoreTests()");
33 function runIndexStoreTests()
35 getRangeOnlyTest("index", "get", ".x", "runIndexKeyTests()");
38 function runIndexKeyTests()
40 getRangeOnlyTest("index", "getKey", "", "finishJSTest()");
43 function getRangeOnlyTest(store, method, resultPath, finish)
45 request = evalAndLog(store + "." + method + "(IDBKeyRange.only(3))");
46 request.onerror = unexpectedErrorCallback;
47 request.onsuccess = function()
49 result = event.target.result;
50 shouldBe("result" + resultPath, "3");
52 getRangeLowerTest(store, method, resultPath, finish);
56 // A closed range with a lower bound should just return that value
57 function getRangeLowerTest(store, method, resultPath, finish)
59 request = evalAndLog(store + "." + method + "(IDBKeyRange.lowerBound(5))");
60 request.onerror = unexpectedErrorCallback;
61 request.onsuccess = function()
63 result = event.target.result;
64 shouldBe("result" + resultPath, "5");
66 getRangeLowerOpenTest(store, method, resultPath, finish);
70 // An open range with a lower bound should skip the lower bound value
71 function getRangeLowerOpenTest(store, method, resultPath, finish)
73 request = evalAndLog(store + "." + method + "(IDBKeyRange.lowerBound(5, true))");
74 request.onerror = unexpectedErrorCallback;
75 request.onsuccess = function()
77 result = event.target.result;
78 shouldBe("result" + resultPath, "6");
80 getRangeUpperTest(store, method, resultPath, finish);
84 // range with just upper should just return the first element
85 function getRangeUpperTest(store, method, resultPath, finish)
87 request = evalAndLog(store + "." + method + "(IDBKeyRange.upperBound(7))");
88 request.onerror = unexpectedErrorCallback;
89 request.onsuccess = function()
91 result = event.target.result;
92 shouldBe("result" + resultPath, "0");
94 getRangeUpperOpenTest(store, method, resultPath, finish);
98 // range with just upper should just return the first element
99 function getRangeUpperOpenTest(store, method, resultPath, finish)
101 request = evalAndLog(store + "." + method + "(IDBKeyRange.upperBound(7, true))");
102 request.onerror = unexpectedErrorCallback;
103 request.onsuccess = function()
105 result = event.target.result;
106 shouldBe("result" + resultPath, "0");
108 getRangeLowerFractionTest(store, method, resultPath, finish);
112 function getRangeLowerFractionTest(store, method, resultPath, finish)
114 request = evalAndLog(store + "." + method + "(IDBKeyRange.lowerBound(2.5))");
115 request.onerror = unexpectedErrorCallback;
116 request.onsuccess = function()
118 result = event.target.result;
119 shouldBe("result" + resultPath, "3");
121 getOutOfRangeTest(store, method, resultPath, finish);
125 function getOutOfRangeTest(store, method, resultPath, finish)
127 request = evalAndLog(store + "." + method + "(IDBKeyRange.lowerBound(100))");
128 request.onerror = unexpectedErrorCallback;
129 request.onsuccess = function()
131 result = event.target.result;
132 shouldBe("result", "undefined");
134 getBadOnlyTest(store, method, resultPath, finish);
138 function getBadOnlyTest(store, method, resultPath, finish)
140 request = evalAndLog(store + "." + method + "(IDBKeyRange.only(3.3))");
141 request.onerror = unexpectedErrorCallback;
142 request.onsuccess = function()
144 result = event.target.result;
145 shouldBe("result", "undefined");
147 getNullTest(store, method, resultPath, finish);
151 function getNullTest(store, method, resultPath, finish)
153 evalAndExpectException(store + "." + method + "(null)", "0", "'DataError'");