Bug 1003860 - Simplify storage setup tasks in storage inspector tests. r=mratcliffe
☠☠ backed out by 31648a75b668 ☠ ☠
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 20 Jan 2016 14:09:25 -0800
changeset 303136 22d80ccb4626eaf220e7d00abe713893f88fe26c
parent 303135 afb7e27d06f569b5dbc6d477ce09135101fd5097
child 303137 8d93e84979b502359d728845813f13224378a201
push id8978
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 14:05:32 +0000
treeherdermozilla-aurora@b9a803752a2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmratcliffe
bugs1003860
milestone46.0a1
Bug 1003860 - Simplify storage setup tasks in storage inspector tests. r=mratcliffe
devtools/client/storage/test/head.js
devtools/client/storage/test/storage-complex-values.html
devtools/client/storage/test/storage-listings.html
devtools/client/storage/test/storage-secured-iframe.html
--- a/devtools/client/storage/test/head.js
+++ b/devtools/client/storage/test/head.js
@@ -77,45 +77,30 @@ function addTab(url) {
  * opens the storage inspector and waits for the storage tree and table to be
  * populated.
  *
  * @param url {String} The url to be opened in the new tab
  *
  * @return {Promise} A promise that resolves after storage inspector is ready
  */
 function* openTabAndSetupStorage(url) {
-  /**
-   * This method iterates over iframes in a window and setups the indexed db
-   * required for this test.
-   */
-  let setupIDBInFrames = (w, i, c) => {
-    if (w[i] && w[i].idbGenerator) {
-      w[i].setupIDB = w[i].idbGenerator(() => setupIDBInFrames(w, i + 1, c));
-      w[i].setupIDB.next();
-    } else if (w[i] && w[i + 1]) {
-      setupIDBInFrames(w, i + 1, c);
-    } else {
-      c();
-    }
-  };
-
   let content = yield addTab(url);
 
-  let def = promise.defer();
-  // Setup the indexed db in main window.
   gWindow = content.wrappedJSObject;
-  if (gWindow.idbGenerator) {
-    gWindow.setupIDB = gWindow.idbGenerator(() => {
-      setupIDBInFrames(gWindow, 0, () => {
-        def.resolve();
-      });
-    });
-    gWindow.setupIDB.next();
-    yield def.promise;
+
+  // Setup the async storages in main window and for all its iframes
+  let callSetup = function*(win) {
+    if (typeof(win.setup) == "function") {
+      yield win.setup();
+    }
+    for(var i = 0; i < win.frames.length; i++) {
+      yield callSetup(win.frames[i]);
+    }
   }
+  yield callSetup(gWindow);
 
   // open storage inspector
   return yield openStoragePanel();
 }
 
 /**
  * Open the toolbox, with the storage tool visible.
  *
--- a/devtools/client/storage/test/storage-complex-values.html
+++ b/devtools/client/storage/test/storage-complex-values.html
@@ -29,72 +29,86 @@ localStorage.setItem("ls1", JSON.stringi
 localStorage.setItem("ls2", "foobar-2");
 localStorage.setItem("ls3", "http://foobar.com/baz.php");
 // ... and finally some session storage items too
 sessionStorage.setItem("ss1", "This#is#an#array");
 sessionStorage.setItem("ss2", "This~is~another~array");
 sessionStorage.setItem("ss3", "this#is~an#object~foo#bar");
 console.log("added cookies and stuff from main page");
 
-function success(event) {
-  setupIDB.next(event);
-}
-
-window.idbGenerator = function*(callback) {
+let idbGenerator = function*() {
   let request = indexedDB.open("idb1", 1);
-  request.onupgradeneeded = success;
-  request.onsuccess = success;
   request.onerror = function() {
     throw new Error("error opening db connection");
   };
-  let event = yield undefined;
-  let db = event.target.result;
-  let store1 = db.createObjectStore("obj1", { keyPath: "id" });
-  store1.createIndex("name", "name", { unique: false });
-  store1.createIndex("email", "email", { unique: true });
-  let store2 = db.createObjectStore("obj2", { keyPath: "id2" });
+  let db = yield new Promise(done => {
+    request.onupgradeneeded = event => {
+      let db = event.target.result;
+      let store1 = db.createObjectStore("obj1", { keyPath: "id" });
+      store1.createIndex("name", "name", { unique: false });
+      store1.createIndex("email", "email", { unique: true });
+      db.createObjectStore("obj2", { keyPath: "id2" });
+      store1.transaction.oncomplete = () => {
+        done(db);
+      };
+    };
+  });
 
-  store1.add({id: 1, name: "foo", email: "foo@bar.com"}).onsuccess = success;
-  yield undefined;
-  store1.add({id: 2, name: "foo2", email: "foo2@bar.com"}).onsuccess = success;
-  yield undefined;
-  store1.add({id: 3, name: "foo2", email: "foo3@bar.com"}).onsuccess = success;
-  yield undefined;
+  // Prevents AbortError
+  yield new Promise(done => {
+    request.onsuccess = done;
+  });
+
+  let transaction = db.transaction(["obj1", "obj2"], "readwrite");
+  let store1 = transaction.objectStore("obj1");
+  let store2 = transaction.objectStore("obj2");
+
+  store1.add({id: 1, name: "foo", email: "foo@bar.com"});
+  store1.add({id: 2, name: "foo2", email: "foo2@bar.com"});
+  store1.add({id: 3, name: "foo2", email: "foo3@bar.com"});
   store2.add({
     id2: 1,
     name: "foo",
     email: "foo@bar.com",
-    extra: "baz"}).onsuccess = success;
-  yield undefined;
+    extra: "baz"});
 
-  yield undefined;
   db.close();
 
   request = indexedDB.open("idb2", 1);
-  request.onupgradeneeded = success;
-  request.onsuccess = success;
-  event = yield undefined;
+  let db2 = yield new Promise(done => {
+    request.onupgradeneeded = event => {
+      let db2 = event.target.result;
+      let store3 = db2.createObjectStore("obj3", { keyPath: "id3" });
+      store3.createIndex("name2", "name2", { unique: true });
+      store3.transaction.oncomplete = () => {
+        done(db2);
+      };
+    };
+  });
 
-  let db2 = event.target.result;
-  let store3 = db2.createObjectStore("obj3", { keyPath: "id3" });
-  store3.createIndex("name2", "name2", { unique: true });
+  // Prevents AbortError during close()
+  yield new Promise(done => {
+    request.onsuccess = done;
+  });
 
-  yield undefined;
   db2.close();
   console.log("added cookies and stuff from main page");
-  callback();
 };
 
 function deleteDB(dbName) {
   return new Promise(resolve => {
     dump("removing database " + dbName + " from " + document.location + "\n");
     indexedDB.deleteDatabase(dbName).onsuccess = resolve;
   });
 }
 
+window.setup = function*() {
+  yield idbGenerator();
+};
+
 window.clear = function*() {
   document.cookie = "c1=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/browser";
   document.cookie = "cs2=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
 
   localStorage.clear();
   sessionStorage.clear();
 
   yield deleteDB("idb1");
--- a/devtools/client/storage/test/storage-listings.html
+++ b/devtools/client/storage/test/storage-listings.html
@@ -23,72 +23,89 @@ document.cookie = "c3=foobar-2; secure=t
   new Date(cookieExpiresTime2).toGMTString() + "; path=/";
 // ... and some local storage items ..
 localStorage.setItem("ls1", "foobar");
 localStorage.setItem("ls2", "foobar-2");
 // ... and finally some session storage items too
 sessionStorage.setItem("ss1", "foobar-3");
 dump("added cookies and stuff from main page\n");
 
-function success(event) {
-  setupIDB.next(event);
-}
-
-window.idbGenerator = function*(callback) {
+let idbGenerator = function*() {
   let request = indexedDB.open("idb1", 1);
-  request.onupgradeneeded = success;
-  request.onsuccess = success;
   request.onerror = function() {
     throw new Error("error opening db connection");
   };
-  let event = yield undefined;
-  let db = event.target.result;
-  let store1 = db.createObjectStore("obj1", { keyPath: "id" });
-  store1.createIndex("name", "name", { unique: false });
-  store1.createIndex("email", "email", { unique: true });
-  let store2 = db.createObjectStore("obj2", { keyPath: "id2" });
+  let db = yield new Promise(done => {
+    request.onupgradeneeded = event => {
+      let db = event.target.result;
+      let store1 = db.createObjectStore("obj1", { keyPath: "id" });
+      store1.createIndex("name", "name", { unique: false });
+      store1.createIndex("email", "email", { unique: true });
+      let store2 = db.createObjectStore("obj2", { keyPath: "id2" });
+      store1.transaction.oncomplete = () => {
+        done(db);
+      };
+    };
+  });
 
-  store1.add({id: 1, name: "foo", email: "foo@bar.com"}).onsuccess = success;
-  yield undefined;
-  store1.add({id: 2, name: "foo2", email: "foo2@bar.com"}).onsuccess = success;
-  yield undefined;
-  store1.add({id: 3, name: "foo2", email: "foo3@bar.com"}).onsuccess = success;
-  yield undefined;
+  // Prevents AbortError
+  yield new Promise(done => {
+    request.onsuccess = done;
+  });
+
+  let transaction = db.transaction(["obj1", "obj2"], "readwrite");
+  let store1 = transaction.objectStore("obj1");
+  let store2 = transaction.objectStore("obj2");
+  store1.add({id: 1, name: "foo", email: "foo@bar.com"});
+  store1.add({id: 2, name: "foo2", email: "foo2@bar.com"});
+  store1.add({id: 3, name: "foo2", email: "foo3@bar.com"});
   store2.add({
     id2: 1,
     name: "foo",
     email: "foo@bar.com",
-    extra: "baz"}).onsuccess = success;
-  yield undefined;
+    extra: "baz"
+  });
+  // Prevents AbortError during close()
+  yield new Promise(success => {
+    transaction.oncomplete = success;
+  });
 
-  yield undefined;
   db.close();
 
   request = indexedDB.open("idb2", 1);
-  request.onupgradeneeded = success;
-  request.onsuccess = success;
-  event = yield undefined;
+  let db2 = yield new Promise(done => {
+    request.onupgradeneeded = event => {
+      let db2 = event.target.result;
+      let store3 = db2.createObjectStore("obj3", { keyPath: "id3" });
+      store3.createIndex("name2", "name2", { unique: true });
+      store3.transaction.oncomplete = () => {
+        done(db2);
+      }
+    };
+  });
+  // Prevents AbortError during close()
+  yield new Promise(done => {
+    request.onsuccess = done;
+  });
+  db2.close();
 
-  let db2 = event.target.result;
-  let store3 = db2.createObjectStore("obj3", { keyPath: "id3" });
-  store3.createIndex("name2", "name2", { unique: true });
-
-  yield undefined;
-  db2.close();
   dump("added cookies and stuff from main page\n");
-  callback();
 };
 
 function deleteDB(dbName) {
   return new Promise(resolve => {
     dump("removing database " + dbName + " from " + document.location + "\n");
     indexedDB.deleteDatabase(dbName).onsuccess = resolve;
   });
 }
 
+window.setup = function*() {
+  yield idbGenerator();
+};
+
 window.clear = function*() {
   document.cookie = "c1=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/browser";
   document.cookie =
     "c3=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; secure=true";
   document.cookie =
     "cs2=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=" +
     partialHostname;
 
--- a/devtools/client/storage/test/storage-secured-iframe.html
+++ b/devtools/client/storage/test/storage-secured-iframe.html
@@ -12,60 +12,78 @@ Iframe for testing multiple host detetio
 document.cookie = "sc1=foobar;";
 localStorage.setItem("iframe-s-ls1", "foobar");
 sessionStorage.setItem("iframe-s-ss1", "foobar-2");
 
 function success(event) {
   setupIDB.next(event);
 }
 
-window.idbGenerator = function*(callback) {
+let idbGenerator = function*() {
   let request = indexedDB.open("idb-s1", 1);
-  request.onupgradeneeded = success;
-  request.onsuccess = success;
   request.onerror = function() {
     throw new Error("error opening db connection");
   };
-  let event = yield undefined;
-  let db = event.target.result;
-  let store1 = db.createObjectStore("obj-s1", { keyPath: "id" });
-
-  store1.add({id: 6, name: "foo", email: "foo@bar.com"}).onsuccess = success;
-  yield undefined;
-  store1.add({id: 7, name: "foo2", email: "foo2@bar.com"}).onsuccess = success;
-  yield undefined;
-
-  yield undefined;
+  let db = yield new Promise(done => {
+    request.onupgradeneeded = event => {
+      let db = event.target.result;
+      let store1 = db.createObjectStore("obj-s1", { keyPath: "id" });
+      store1.add({id: 6, name: "foo", email: "foo@bar.com"});
+      store1.add({id: 7, name: "foo2", email: "foo2@bar.com"});
+      store1.transaction.oncomplete = () => {
+        done(db);
+      };
+    };
+  });
+  yield new Promise(done => {
+    request.onsuccess = done;
+  });
   db.close();
+/*
+  let transaction = db.transaction(["obj-s1"], "readwrite");
+  let store1 = transaction.objectStore("obj-s1");
+  store1.add({id: 6, name: "foo", email: "foo@bar.com"});
+  store1.add({id: 7, name: "foo2", email: "foo2@bar.com"});
+  yield new Promise(success => {
+    transaction.oncomplete = success;
+  });
+  */
 
   request = indexedDB.open("idb-s2", 1);
-  request.onupgradeneeded = success;
-  request.onsuccess = success;
-  event = yield undefined;
+  let db2 = yield new Promise(done => {
+    request.onupgradeneeded = event => {
+      let db2 = event.target.result;
+      let store3 =
+        db2.createObjectStore("obj-s2", { keyPath: "id3", autoIncrement: true });
+      store3.createIndex("name2", "name2", { unique: true });
+      store3.add({id3: 16, name2: "foo", email: "foo@bar.com"});
+      store3.transaction.oncomplete = () => {
+        done(db2);
+      };
+    };
+  });
+  yield new Promise(done => {
+    request.onsuccess = done;
+  });
 
-  let db2 = event.target.result;
-  let store3 =
-    db2.createObjectStore("obj-s2", { keyPath: "id3", autoIncrement: true });
-  store3.createIndex("name2", "name2", { unique: true });
-  store3.add({id3: 16, name2: "foo", email: "foo@bar.com"}).onsuccess = success;
-  yield undefined;
-
-  yield undefined;
   db2.close();
   dump("added cookies and stuff from secured iframe\n");
-  callback();
 };
 
 function deleteDB(dbName) {
   return new Promise(resolve => {
     dump("removing database " + dbName + " from " + document.location + "\n");
     indexedDB.deleteDatabase(dbName).onsuccess = resolve;
   });
 }
 
+window.setup = function*() {
+  yield idbGenerator();
+};
+
 window.clear = function*() {
   document.cookie = "sc1=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
 
   localStorage.clear();
   sessionStorage.clear();
 
   yield deleteDB("idb-s1");
   yield deleteDB("idb-s2");