• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
4<script src="../../fast/js/resources/js-test-pre.js"></script>
5<script src="../../fast/js/resources/js-test-post-function.js"></script>
6<script src="resources/shared.js"></script>
7</head>
8<body>
9<p id="description"></p>
10<div id="console"></div>
11<script>
12
13description("Test IndexedDB's openCursor.");
14if (window.layoutTestController)
15    layoutTestController.waitUntilDone();
16
17function emptyCursorSuccess()
18{
19    debug("Empty cursor opened successfully.")
20    // FIXME: check that we can iterate the cursor.
21    done();
22}
23
24function openEmptyCursor()
25{
26    debug("Opening an empty cursor.");
27    keyRange = webkitIDBKeyRange.lowerBound("InexistentKey");
28    request = evalAndLog("objectStore.openCursor(keyRange)");
29    request.onsuccess = emptyCursorSuccess;
30    request.onerror = unexpectedErrorCallback;
31}
32
33function cursorSuccess()
34{
35    debug("Cursor opened successfully.")
36    // FIXME: check that we can iterate the cursor.
37    shouldBe("event.target.result.direction", "0");
38    shouldBe("event.target.result.key", "'myKey'");
39    shouldBe("event.target.result.value", "'myValue'");
40    debug("");
41    try {
42        debug("Passing an invalid key into .continue().");
43        event.target.result.continue([]);
44        testFailed("No exception thrown");
45    } catch (e) {
46        testPassed("Caught exception: " + e.toString());
47    }
48    debug("");
49    openEmptyCursor();
50}
51
52function openCursor()
53{
54    debug("Opening cursor");
55    keyRange = webkitIDBKeyRange.lowerBound("myKey");
56    request = evalAndLog("event.target.source.openCursor(keyRange)");
57    request.onsuccess = cursorSuccess;
58    request.onerror = unexpectedErrorCallback;
59}
60
61function setVersionSuccess()
62{
63    debug("setVersionSuccess():");
64    window.trans = evalAndLog("trans = event.target.result");
65    shouldBeTrue("trans !== null");
66    trans.onabort = unexpectedAbortCallback;
67
68    deleteAllObjectStores(db);
69
70    var objectStore = evalAndLog("objectStore = db.createObjectStore('test')");
71    request = evalAndLog("objectStore.add('myValue', 'myKey')");
72    request.onsuccess = openCursor;
73    request.onerror = unexpectedErrorCallback;
74}
75
76function openSuccess()
77{
78    var db = evalAndLog("db = event.target.result");
79
80    request = evalAndLog("db.setVersion('new version')");
81    request.onsuccess = setVersionSuccess;
82    request.onerror = unexpectedErrorCallback;
83}
84
85function test()
86{
87    request = evalAndLog("webkitIndexedDB.open('open-cursor')");
88    request.onsuccess = openSuccess;
89    request.onerror = unexpectedErrorCallback;
90}
91
92test();
93
94var successfullyParsed = true;
95
96</script>
97</body>
98</html>
99