3 original test: http://mxr.mozilla.org/mozilla2.0/source/dom/indexedDB/test/test_remove_objectStore.html?force=1
4 license of original test:
5 " Any copyright is dedicated to the Public Domain.
6 http://creativecommons.org/publicdomain/zero/1.0/ "
10 <script src="../../../fast/js/resources/js-test-pre.js"></script>
11 <script src="../resources/shared.js"></script>
14 <p id="description"></p>
15 <div id="console"></div>
18 description("Test IndexedDB deleting an object store");
19 if (window.layoutTestController)
20 layoutTestController.waitUntilDone();
24 indexedDB = evalAndLog("indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;");
25 shouldBeFalse("indexedDB == null");
26 IDBDatabaseException = evalAndLog("IDBDatabaseException = window.IDBDatabaseException || window.webkitIDBDatabaseException;");
27 shouldBeFalse("IDBDatabaseException == null");
29 name = window.location.pathname;
30 description = "My Test Database";
31 request = evalAndLog("indexedDB.open(name, description)");
32 request.onsuccess = openSuccess;
33 request.onerror = unexpectedErrorCallback;
36 function openSuccess()
38 db = evalAndLog("db = event.target.result");
39 shouldBe("db.objectStoreNames.length", "0");
41 request = evalAndLog("request = db.setVersion('1')");
42 request.onsuccess = createAndPopulateObjectStore;
43 request.onerror = unexpectedErrorCallback;
46 function createAndPopulateObjectStore()
48 deleteAllObjectStores(db);
50 objectStoreName = evalAndLog("objectStoreName = 'Objects';");
51 objectStore = evalAndLog("objectStore = db.createObjectStore(objectStoreName, { keyPath: 'foo' });");
53 addedCount = evalAndLog("addedCount = 0;");
54 for (i = 0; i < 100; i++) {
55 request = evalAndLog("request = objectStore.add({foo: i});");
56 request.onerror = unexpectedErrorCallback;
57 request.onsuccess = function(event) {
58 if (++addedCount == 100) {
65 function checkObjectStore()
67 shouldBe("db.objectStoreNames.length", "1");
68 shouldBe("db.objectStoreNames.item(0)", "objectStoreName");
70 request = db.setVersion('2');
71 request.onerror = unexpectedErrorCallback;
72 request.onsuccess = postSetVersion2;
75 function postSetVersion2()
77 evalAndLog("db.deleteObjectStore(objectStore.name);");
78 shouldBe("db.objectStoreNames.length", "0");
80 objectStore = evalAndLog("objectStore = db.createObjectStore(objectStoreName, { keyPath: 'foo' });");
81 shouldBe("db.objectStoreNames.length", "1");
82 shouldBe("db.objectStoreNames.item(0)", "objectStoreName");
84 request = evalAndLog("request = objectStore.openCursor();");
85 request.onerror = unexpectedErrorCallback;
86 request.onsuccess = function(event) {
87 shouldBe("event.target.result", "null");
88 deleteSecondObjectStore();
92 function deleteSecondObjectStore()
94 evalAndLog("db.deleteObjectStore(objectStore.name);");
95 shouldBe("db.objectStoreNames.length", "0");
99 function setVersion3()
101 request = evalAndLog("request = db.setVersion('3');");
102 request.onerror = unexpectedErrorCallback;
103 request.onsuccess = postSetVersion3;
106 function postSetVersion3()
108 objectStore = evalAndLog("objectStore = db.createObjectStore(objectStoreName, { keyPath: 'foo' });");
109 request = evalAndLog("request = objectStore.add({foo:'bar'});");
110 request.onerror = unexpectedErrorCallback;
111 request.onsuccess = deleteThirdObjectStore;
114 function deleteThirdObjectStore()
116 evalAndLog("db.deleteObjectStore(objectStoreName);");