Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / cursor-finished.js
blobf8b9d7909f019c6d62c800ed3964f638562a88f7
1 description("Ensure cursor calls behave as expected after cursor has run to the end.");
3 function test()
5     setDBNameFromPath();
6     prepareDatabase();
9 function prepareDatabase()
11     preamble();
12     request = evalAndLog("indexedDB.deleteDatabase(dbname)");
13     request.onerror = unexpectedErrorCallback;
14     request.onblocked = unexpectedBlockedCallback;
15     request.onsuccess = onDeleteSuccess;
18 function onDeleteSuccess(evt)
20     preamble(evt);
21     request = evalAndLog("indexedDB.open(dbname, 1)");
22     request.onerror = unexpectedErrorCallback;
23     request.onblocked = unexpectedBlockedCallback;
24     request.onupgradeneeded = onUpgradeNeeded;
25     request.onsuccess = onOpenSuccess;
28 function onUpgradeNeeded(evt)
30     preamble(evt);
31     evalAndLog("db = event.target.result");
32     evalAndLog("store = db.createObjectStore('store')");
33     evalAndLog("store.put(1, 1)");
34     evalAndLog("store.put(2, 2)");
37 function onOpenSuccess(evt)
39     preamble(evt);
40     evalAndLog("db = event.target.result");
41     evalAndLog("transaction = db.transaction('store', 'readwrite')");
42     evalAndLog("store = transaction.objectStore('store')");
43     evalAndLog("count = 0");
44     evalAndLog("cursorRequest = store.openCursor()");
45     cursorRequest.onerror = unexpectedErrorCallback;
46     cursorRequest.onsuccess = onCursorSuccess;
49 function onCursorSuccess(evt)
51     preamble(evt);
52     evalAndLog("cursor = event.target.result");
53     if (count < 2) {
54         shouldBeNonNull("cursor");
55         evalAndLog("count++");
56         evalAndLog("savedCursor = cursor");
57         evalAndLog("cursor.continue()");
58     } else {
59         shouldBeNull("cursor");
60         shouldBeNonNull("savedCursor");
62         debug("");
63         evalAndExpectException("savedCursor.update('value')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
64         evalAndExpectException("savedCursor.advance(1)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
65         evalAndExpectException("savedCursor.continue()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
66         evalAndExpectException("savedCursor.continue('key')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
67         evalAndExpectException("savedCursor.delete()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
69         debug("");
70         finishJSTest();
71     }
74 test();