summaryrefslogtreecommitdiffstats
path: root/LayoutTests/storage/indexeddb/objectstore-removeobjectstore.html
blob: f9b1e78b3ae404ad5ca09e4e7a1c9b0216b7520b (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
<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.deleteObjectStore().");
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 = getValue;
    result.onerror = unexpectedErrorCallback;
}

function getValue()
{
    verifySuccessEvent(event);

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

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

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

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

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

    evalAndLog("db.deleteObjectStore('storeName')");
    createObjectStoreAgain();
}

function createObjectStoreAgain()
{
    evalAndLog("db.createObjectStore('storeName', null)");
    getValueAgain();
}

function getValueAgain()
{
    transaction = evalAndLog("db.transaction({mode: webkitIDBTransaction.READ_WRITE})");
    transaction.onabort = unexpectedErrorCallback;
    var store = evalAndLog("store = transaction.objectStore('storeName')");

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

function verifyNotFound()
{
    verifySuccessEvent(event);
    shouldBe("event.result", "undefined");
    shouldBeFalse("event.source.indexNames.contains('indexName')");

    done();
}

test();

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