summaryrefslogtreecommitdiffstats
path: root/LayoutTests/storage/indexeddb/open-cursor.html
blob: 03d1da09962efd3e820f799d618b9fab072280b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<html>
<head>
<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
<script src="../../fast/js/resources/js-test-pre.js"></script>
<script src="../../fast/js/resources/js-test-post-function.js"></script>
<script src="resources/shared.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>

description("Test IndexedDB's openCursor.");
if (window.layoutTestController)
    layoutTestController.waitUntilDone();

function emptyCursorSuccess()
{
    debug("Empty cursor opened successfully.")
    verifySuccessEvent(event);
    // FIXME: check that we can iterate the cursor.
    done();
}

function openEmptyCursor()
{
    debug("Opening an empty cursor.");
    keyRange = IDBKeyRange.leftBound("InexistentKey");
    result = evalAndLog("objectStore.openCursor(keyRange)");
    verifyResult(result);
    result.onsuccess = emptyCursorSuccess;
    result.onerror = unexpectedErrorCallback;
}

function cursorSuccess()
{
    debug("Cursor opened successfully.")
    verifySuccessEvent(event);
    // FIXME: check that we can iterate the cursor.
    shouldBe("event.result.direction", "0");
    shouldBe("event.result.key", "'myKey'");
    shouldBe("event.result.value", "'myValue'");
    debug("");
    openEmptyCursor();
}

function openCursor()
{
    debug("Opening cursor");
    keyRange = IDBKeyRange.leftBound("myKey");
    result = evalAndLog("objectStore.openCursor(keyRange)");
    verifyResult(result);
    result.onsuccess = cursorSuccess;
    result.onerror = unexpectedErrorCallback;
}

function populateObjectStore(objectStore)
{
    result = evalAndLog("objectStore.add('myValue', 'myKey')");
    verifyResult(result);
    result.onsuccess = openCursor;
    result.onerror = unexpectedErrorCallback;
}

function createObjectStoreSuccess()
{
    verifySuccessEvent(event);
    var objectStore = evalAndLog("objectStore = event.result");
    populateObjectStore(objectStore);
}

function openSuccess()
{
    verifySuccessEvent(event);
    var db = evalAndLog("db = event.result");

    deleteAllObjectStores(db);

    result = evalAndLog("db.createObjectStore('test')");
    verifyResult(result);
    result.onsuccess = createObjectStoreSuccess;
    result.onerror = unexpectedErrorCallback;
}

function test()
{
    result = evalAndLog("indexedDB.open('name', 'description')");
    verifyResult(result);
    result.onsuccess = openSuccess;
    result.onerror = unexpectedErrorCallback;
}

test();

var successfullyParsed = true;

</script>
</body>
</html>