Bug 1816170 - Disable perftest-on-autoland cron. r=aglavic
[gecko.git] / dom / indexedDB / test / unit / test_remove_objectStore.js
blob95c6cc29cee9aa9935b79893059d90128ec7c965
1 /**
2  * Any copyright is dedicated to the Public Domain.
3  * http://creativecommons.org/publicdomain/zero/1.0/
4  */
6 var testGenerator = testSteps();
8 function* testSteps() {
9   const name = this.window ? window.location.pathname : "Splendid Test";
10   const objectStoreName = "Objects";
12   let request = indexedDB.open(name, 1);
13   request.onerror = errorHandler;
14   request.onupgradeneeded = grabEventAndContinueHandler;
15   request.onsuccess = unexpectedSuccessHandler;
16   let event = yield undefined;
18   request.onupgradeneeded = unexpectedSuccessHandler;
19   request.onsuccess = grabEventAndContinueHandler;
21   let db = event.target.result;
22   is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
24   let objectStore = db.createObjectStore(objectStoreName, { keyPath: "foo" });
26   let addedCount = 0;
28   for (let i = 0; i < 100; i++) {
29     request = objectStore.add({ foo: i });
30     request.onerror = errorHandler;
31     request.onsuccess = function(event) {
32       if (++addedCount == 100) {
33         executeSoon(function() {
34           testGenerator.next();
35         });
36       }
37     };
38   }
39   yield undefined;
41   is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
42   is(db.objectStoreNames.item(0), objectStoreName, "Correct name");
44   event.target.transaction.oncomplete = grabEventAndContinueHandler;
45   event = yield undefined;
47   // Wait for success.
48   event = yield undefined;
50   db.close();
52   request = indexedDB.open(name, 2);
53   request.onerror = errorHandler;
54   request.onupgradeneeded = grabEventAndContinueHandler;
55   request.onsuccess = unexpectedSuccessHandler;
56   event = yield undefined;
58   request.onupgradeneeded = unexpectedSuccessHandler;
59   request.onsuccess = grabEventAndContinueHandler;
61   db = event.target.result;
62   let trans = event.target.transaction;
64   let oldObjectStore = trans.objectStore(objectStoreName);
65   isnot(oldObjectStore, null, "Correct object store prior to deleting");
66   db.deleteObjectStore(objectStoreName);
67   is(db.objectStoreNames.length, 0, "Correct objectStores list");
68   try {
69     trans.objectStore(objectStoreName);
70     ok(false, "should have thrown");
71   } catch (ex) {
72     ok(ex instanceof DOMException, "Got a DOMException");
73     is(ex.name, "NotFoundError", "expect a NotFoundError");
74     is(ex.code, DOMException.NOT_FOUND_ERR, "expect a NOT_FOUND_ERR");
75   }
77   objectStore = db.createObjectStore(objectStoreName, { keyPath: "foo" });
78   is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
79   is(db.objectStoreNames.item(0), objectStoreName, "Correct name");
80   is(
81     trans.objectStore(objectStoreName),
82     objectStore,
83     "Correct new objectStore"
84   );
85   isnot(oldObjectStore, objectStore, "Old objectStore is not new objectStore");
87   request = objectStore.openCursor();
88   request.onerror = errorHandler;
89   request.onsuccess = function(event) {
90     is(event.target.result, null, "ObjectStore shouldn't have any items");
91     testGenerator.next(event);
92   };
93   event = yield undefined;
95   db.deleteObjectStore(objectStore.name);
96   is(db.objectStoreNames.length, 0, "Correct objectStores list");
98   continueToNextStep();
99   yield undefined;
101   trans.oncomplete = grabEventAndContinueHandler;
102   event = yield undefined;
104   // Wait for success.
105   event = yield undefined;
107   db.close();
109   request = indexedDB.open(name, 3);
110   request.onerror = errorHandler;
111   request.onupgradeneeded = grabEventAndContinueHandler;
112   event = yield undefined;
114   db = event.target.result;
115   trans = event.target.transaction;
117   objectStore = db.createObjectStore(objectStoreName, { keyPath: "foo" });
119   request = objectStore.add({ foo: "bar" });
120   request.onerror = errorHandler;
121   request.onsuccess = grabEventAndContinueHandler;
123   db.deleteObjectStore(objectStoreName);
125   event = yield undefined;
127   trans.oncomplete = grabEventAndContinueHandler;
128   event = yield undefined;
130   finishTest();