Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / deleted-objects.js
blobaff6a2b9c9fa5c7838be264028cdbb163cce41bb
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Test that IndexedDB objects that have been deleted throw exceptions");
8 indexedDBTest(prepareDatabase);
9 function prepareDatabase()
11     trans = event.target.transaction;
12     connection = event.target.result;
14     testStore();
17 function testStore()
19     preamble();
21     evalAndLog("deletedStore = connection.createObjectStore('deletedStore')");
22     evalAndLog("connection.deleteObjectStore('deletedStore')");
24     debug("");
26     evalAndExpectException("deletedStore.put(0, 0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
27     evalAndExpectException("deletedStore.add(0, 0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
28     evalAndExpectException("deletedStore.delete(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
29     evalAndExpectException("deletedStore.delete(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
30     evalAndExpectException("deletedStore.get(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
31     evalAndExpectException("deletedStore.get(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
32     evalAndExpectException("deletedStore.getAll(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
33     evalAndExpectException("deletedStore.getAll(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
34     evalAndExpectException("deletedStore.getAllKeys(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
35     evalAndExpectException("deletedStore.getAllKeys(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
36     evalAndExpectException("deletedStore.clear()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
37     evalAndExpectException("deletedStore.openCursor()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
38     evalAndExpectException("deletedStore.openCursor(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
39     evalAndExpectException("deletedStore.openCursor(0, 'next')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
40     evalAndExpectException("deletedStore.openCursor(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
41     evalAndExpectException("deletedStore.openCursor(IDBKeyRange.only(0), 'next')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
42     evalAndExpectException("deletedStore.openKeyCursor()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
43     evalAndExpectException("deletedStore.openKeyCursor(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
44     evalAndExpectException("deletedStore.openKeyCursor(0, 'next')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
45     evalAndExpectException("deletedStore.openKeyCursor(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
46     evalAndExpectException("deletedStore.openKeyCursor(IDBKeyRange.only(0), 'next')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
47     evalAndExpectException("deletedStore.createIndex('name', 'path')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
48     evalAndExpectException("deletedStore.index('name')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
49     evalAndExpectException("deletedStore.deleteIndex('name')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
50     evalAndExpectException("deletedStore.count()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
51     evalAndExpectException("deletedStore.count(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
52     evalAndExpectException("deletedStore.count(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
54     testIndex();
57 function testIndex()
59     preamble();
61     evalAndLog("store = connection.createObjectStore('store')");
62     evalAndLog("deletedIndex = store.createIndex('deletedIndex', 'path')");
63     evalAndLog("store.deleteIndex('deletedIndex')");
65     debug("");
67     evalAndExpectException("deletedIndex.openCursor()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
68     evalAndExpectException("deletedIndex.openCursor(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
69     evalAndExpectException("deletedIndex.openCursor(0, 'next')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
70     evalAndExpectException("deletedIndex.openCursor(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
71     evalAndExpectException("deletedIndex.openCursor(IDBKeyRange.only(0), 'next')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
72     evalAndExpectException("deletedIndex.openKeyCursor()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
73     evalAndExpectException("deletedIndex.openKeyCursor(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
74     evalAndExpectException("deletedIndex.openKeyCursor(0, 'next')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
75     evalAndExpectException("deletedIndex.openKeyCursor(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
76     evalAndExpectException("deletedIndex.openKeyCursor(IDBKeyRange.only(0), 'next')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
77     evalAndExpectException("deletedIndex.get(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
78     evalAndExpectException("deletedIndex.get(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
79     evalAndExpectException("deletedIndex.getAll(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
80     evalAndExpectException("deletedIndex.getAll(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
81     evalAndExpectException("deletedIndex.getAllKeys(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
82     evalAndExpectException("deletedIndex.getAllKeys(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
83     evalAndExpectException("deletedIndex.getKey(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
84     evalAndExpectException("deletedIndex.getKey(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
85     evalAndExpectException("deletedIndex.count()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
86     evalAndExpectException("deletedIndex.count(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
87     evalAndExpectException("deletedIndex.count(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
89     testTransitiveDeletion();
92 function testTransitiveDeletion()
94     preamble();
96     evalAndLog("deletedStore = connection.createObjectStore('deletedStore')");
97     evalAndLog("indexOfDeletedStore = deletedStore.createIndex('index', 'path')");
98     evalAndLog("connection.deleteObjectStore('deletedStore')");
100     debug("");
102     evalAndExpectException("indexOfDeletedStore.openCursor()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
103     evalAndExpectException("indexOfDeletedStore.openCursor(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
104     evalAndExpectException("indexOfDeletedStore.openCursor(0, 'next')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
105     evalAndExpectException("indexOfDeletedStore.openCursor(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
106     evalAndExpectException("indexOfDeletedStore.openCursor(IDBKeyRange.only(0), 'next')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
107     evalAndExpectException("indexOfDeletedStore.openKeyCursor()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
108     evalAndExpectException("indexOfDeletedStore.openKeyCursor(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
109     evalAndExpectException("indexOfDeletedStore.openKeyCursor(0, 'next')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
110     evalAndExpectException("indexOfDeletedStore.openKeyCursor(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
111     evalAndExpectException("indexOfDeletedStore.openKeyCursor(IDBKeyRange.only(0), 'next')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
112     evalAndExpectException("indexOfDeletedStore.get(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
113     evalAndExpectException("indexOfDeletedStore.get(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
114     evalAndExpectException("indexOfDeletedStore.getAllKeys(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
115     evalAndExpectException("indexOfDeletedStore.getAllKeys(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
116     evalAndExpectException("indexOfDeletedStore.getKey(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
117     evalAndExpectException("indexOfDeletedStore.getKey(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
118     evalAndExpectException("indexOfDeletedStore.count()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
119     evalAndExpectException("indexOfDeletedStore.count(0)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
120     evalAndExpectException("indexOfDeletedStore.count(IDBKeyRange.only(0))", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
122     testObjectStoreCursor();
125 function testObjectStoreCursor()
127     preamble();
129     evalAndLog("deletedStore = connection.createObjectStore('deletedStore')");
130     evalAndLog("deletedStore.put(0, 0)");
132     request = evalAndLog("deletedStore.openCursor()");
133     request.onerror = unexpectedErrorCallback;
134     request.onsuccess = function() {
135         evalAndLog("cursor = request.result");
136         shouldBe("cursor.key", "0");
137         shouldBe("cursor.value", "0");
139         evalAndLog("connection.deleteObjectStore('deletedStore')");
140         evalAndExpectException("cursor.delete()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
141         evalAndExpectException("cursor.update(1)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
142         evalAndExpectException("cursor.continue()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
143         evalAndExpectException("cursor.advance(1)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
145         testIndexCursor();
146     };
150 function testIndexCursor()
152     preamble();
154     evalAndLog("store.put({id: 123}, 0)");
155     evalAndLog("deletedIndex = store.createIndex('deletedIndex', 'id')");
157     request = evalAndLog("deletedIndex.openCursor()");
158     request.onerror = unexpectedErrorCallback;
159     request.onsuccess = function() {
160         evalAndLog("cursor = request.result");
161         shouldBe("cursor.key", "123");
162         shouldBe("cursor.primaryKey", "0");
164         evalAndLog("store.deleteIndex('deletedIndex')");
165         evalAndExpectException("cursor.delete()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
166         evalAndExpectException("cursor.update(1)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
167         evalAndExpectException("cursor.continue()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
168         evalAndExpectException("cursor.advance(1)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
170         testIndexOfDeletedStoreCursor();
171     };
174 function testIndexOfDeletedStoreCursor()
176     preamble();
178     evalAndLog("deletedStore = connection.createObjectStore('deletedStore')");
179     evalAndLog("deletedStore.put({id: 123}, 0)");
180     evalAndLog("index = deletedStore.createIndex('index', 'id')");
182     request = evalAndLog("index.openCursor()");
183     request.onerror = unexpectedErrorCallback;
184     request.onsuccess = function() {
185         evalAndLog("cursor = request.result");
186         shouldBe("cursor.key", "123");
187         shouldBe("cursor.primaryKey", "0");
189         evalAndLog("connection.deleteObjectStore('deletedStore')");
190         evalAndExpectException("cursor.delete()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
191         evalAndExpectException("cursor.update(1)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
192         evalAndExpectException("cursor.continue()", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
193         evalAndExpectException("cursor.advance(1)", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
195         trans.onabort = unexpectedAbortCallback;
196         trans.oncomplete = finishJSTest;
197     };