1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test that continue() calls against cursors are validated by direction.");
8 indexedDBTest(prepareDatabase, testCursors);
9 function prepareDatabase()
11 db = event.target.result;
12 evalAndLog("store = db.createObjectStore('store')");
13 for (i = 1; i <= 10; ++i) {
14 evalAndLog("store.put(" + i + "," + i + ")");
18 function testCursors()
20 evalAndLog("trans = db.transaction('store')");
21 evalAndLog("store = trans.objectStore('store')");
25 function testForwardCursor()
27 evalAndLog("request = store.openCursor(IDBKeyRange.bound(-Infinity, Infinity), 'next')");
28 request.onerror = unexpectedErrorCallback;
29 request.onsuccess = function() {
30 evalAndLog("cursor = request.result");
31 shouldBeNonNull("cursor");
32 debug("Expect DataError if: The parameter is less than or equal to this cursor's position and this cursor's direction is \"next\" or \"nextunique\".");
33 shouldBe("cursor.key", "1");
34 evalAndExpectException("cursor.continue(-1)", "0", "'DataError'");
40 function testReverseCursor()
42 evalAndLog("request = store.openCursor(IDBKeyRange.bound(-Infinity, Infinity), 'prev')");
43 request.onerror = unexpectedErrorCallback;
44 request.onsuccess = function() {
45 evalAndLog("cursor = request.result");
46 shouldBeNonNull("cursor");
47 debug("Expect DataError if: The parameter is greater than or equal to this cursor's position and this cursor's direction is \"prev\" or \"prevunique\".");
48 shouldBe("cursor.key", "10");
49 evalAndExpectException("cursor.continue(11)", "0", "'DataError'");