summaryrefslogtreecommitdiffstats
path: root/LayoutTests/storage/indexeddb/objectstore-clear.html
blob: 7f4034fdeb70db64f2feaf340326470f4a4e57b8 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<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 webkitIDBObjectStore.clear().");
if (window.layoutTestController)
    layoutTestController.waitUntilDone();

function test()
{
    result = evalAndLog("webkitIndexedDB.open('name')");
    verifyResult(result);
    result.onsuccess = startSetVersion;
    result.onerror = unexpectedErrorCallback;
}

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

    result = evalAndLog("db.setVersion('new version')");
    verifyResult(result);
    result.onsuccess = deleteExisting;
    result.onerror = unexpectedErrorCallback;
}

function deleteExisting()
{
    verifySuccessEvent(event);
    window.trans = evalAndLog("trans = event.result");
    shouldBeTrue("trans !== null");

    deleteAllObjectStores(db, createObjectStoreAndAddValue);
}

function createObjectStoreAndAddValue()
{
    store = evalAndLog("store = db.createObjectStore('storeName', null)");

    window.index = evalAndLog("store.createIndex('indexName', '')");
    shouldBeTrue("store.indexNames.contains('indexName')");

    result = evalAndLog("store.add('value', 'key')");
    verifyResult(result);
    result.onsuccess = createSecondObjectStoreAndAddValue;
    result.onerror = unexpectedErrorCallback;
}

function createSecondObjectStoreAndAddValue()
{
    verifySuccessEvent(event);

    otherStore = evalAndLog("otherStore = db.createObjectStore('otherStoreName', null)");

    result = evalAndLog("otherStore.add('value', 'key')");
    verifyResult(result);
    result.onsuccess = clearObjectStore;
    result.onerror = unexpectedErrorCallback;
}

function clearObjectStore()
{
    verifySuccessEvent(event);

    result = evalAndLog("store.clear()");
    verifyResult(result);
    result.onsuccess = clearSuccess;
    result.onerror = unexpectedErrorCallback;
}

function clearSuccess()
{
    verifySuccessEvent(event);
    shouldBeUndefined("event.result");

    result = evalAndLog("store.openCursor()");
    result.onsuccess = openCursorSuccess;
    result.onerror = unexpectedErrorCallback;
}

function openCursorSuccess()
{
    verifySuccessEvent(event);
    shouldBeNull("event.result");

    index = evalAndLog("index = store.index('indexName')");
    result = evalAndLog("index.openKeyCursor()");
    result.onsuccess = openKeyCursorSuccess;
    result.onerror = unexpectedErrorCallback;
}

function openKeyCursorSuccess()
{
    debug("openKeyCursorSuccess():");
    verifySuccessEvent(event);
    shouldBeNull("event.result");

    transaction = evalAndLog("db.transaction({mode: webkitIDBTransaction.READ_WRITE})");
    transaction.onabort = unexpectedErrorCallback;
    var otherStore = evalAndLog("otherStore = transaction.objectStore('otherStoreName')");

    result = evalAndLog("otherStore.get('key')");
    verifyResult(result);
    result.onsuccess = getSuccess;
    result.onerror = unexpectedErrorCallback;
}

function getSuccess()
{
    verifySuccessEvent(event);
    shouldBeEqualToString("event.result", "value");

    done();
}

test();

var successfullyParsed = true;
</script>
</body>
</html>