Bug 1261785 - Part 1: fix promise rejections in storage inspector tests. r=mratcliffe
authorJarda Snajdr <jsnajdr@gmail.com>
Tue, 19 Apr 2016 01:43:00 +0200
changeset 331651 681e7c3bd5e4f9b988c1e4399303749660f3a6b7
parent 331650 d4cd977c44f0eaa7d7a6ec2f77481950e33833c6
child 331652 acb76d90e6713f6e4277105c2cb6ffba11a8a012
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmratcliffe
bugs1261785
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1261785 - Part 1: fix promise rejections in storage inspector tests. r=mratcliffe
devtools/client/storage/test/browser.ini
devtools/client/storage/test/browser_storage_cookies_edit.js
devtools/client/storage/test/browser_storage_cookies_edit_keyboard.js
devtools/client/storage/test/browser_storage_cookies_tab_navigation.js
devtools/client/storage/test/browser_storage_localstorage_edit.js
devtools/client/storage/test/browser_storage_sessionstorage_edit.js
devtools/client/storage/test/head.js
devtools/client/storage/ui.js
--- a/devtools/client/storage/test/browser.ini
+++ b/devtools/client/storage/test/browser.ini
@@ -25,12 +25,11 @@ support-files =
 [browser_storage_delete.js]
 [browser_storage_delete_all.js]
 [browser_storage_delete_tree.js]
 [browser_storage_dynamic_updates.js]
 [browser_storage_empty_objectstores.js]
 [browser_storage_localstorage_edit.js]
 [browser_storage_overflow.js]
 [browser_storage_search.js]
-skip-if = os == "linux" && e10s # Bug 1240804 - unhandled promise rejections
 [browser_storage_sessionstorage_edit.js]
 [browser_storage_sidebar.js]
 [browser_storage_values.js]
--- a/devtools/client/storage/test/browser_storage_cookies_edit.js
+++ b/devtools/client/storage/test/browser_storage_cookies_edit.js
@@ -3,18 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Basic test to check the editing of cookies.
 
 "use strict";
 
 add_task(function* () {
   yield openTabAndSetupStorage(MAIN_DOMAIN + "storage-cookies.html");
-  yield gUI.table.once(TableWidget.EVENTS.FIELDS_EDITABLE);
-
   showAllColumns(true);
 
   yield editCell("test3", "name", "newTest3");
   yield editCell("newTest3", "path", "/");
   yield editCell("newTest3", "host", "test1.example.org");
   yield editCell("newTest3", "expires", "Tue, 14 Feb 2040 17:41:14 GMT");
   yield editCell("newTest3", "value", "newValue3");
   yield editCell("newTest3", "isSecure", "true");
--- a/devtools/client/storage/test/browser_storage_cookies_edit_keyboard.js
+++ b/devtools/client/storage/test/browser_storage_cookies_edit_keyboard.js
@@ -3,18 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Basic test to check the editing of cookies with the keyboard.
 
 "use strict";
 
 add_task(function* () {
   yield openTabAndSetupStorage(MAIN_DOMAIN + "storage-cookies.html");
-  yield gUI.table.once(TableWidget.EVENTS.FIELDS_EDITABLE);
-
   showAllColumns(true);
 
   yield startCellEdit("test4", "name");
   yield typeWithTerminator("test6", "VK_TAB");
   yield typeWithTerminator("/", "VK_TAB");
   yield typeWithTerminator(".example.org", "VK_TAB");
   yield typeWithTerminator("Tue, 25 Dec 2040 12:00:00 GMT", "VK_TAB");
   yield typeWithTerminator("test6value", "VK_TAB");
--- a/devtools/client/storage/test/browser_storage_cookies_tab_navigation.js
+++ b/devtools/client/storage/test/browser_storage_cookies_tab_navigation.js
@@ -3,18 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Basic test to check cookie table tab navigation.
 
 "use strict";
 
 add_task(function* () {
   yield openTabAndSetupStorage(MAIN_DOMAIN + "storage-cookies.html");
-  yield gUI.table.once(TableWidget.EVENTS.FIELDS_EDITABLE);
-
   showAllColumns(true);
 
   yield startCellEdit("test1", "name");
 
   PressKeyXTimes("VK_TAB", 18);
   is(getCurrentEditorValue(), "value3",
      "We have tabbed to the correct cell.");
 
--- a/devtools/client/storage/test/browser_storage_localstorage_edit.js
+++ b/devtools/client/storage/test/browser_storage_localstorage_edit.js
@@ -5,17 +5,16 @@
 // Basic test to check the editing of localStorage.
 
 "use strict";
 
 add_task(function* () {
   yield openTabAndSetupStorage(MAIN_DOMAIN + "storage-localstorage.html");
 
   yield selectTreeItem(["localStorage", "http://test1.example.org"]);
-  yield gUI.table.once(TableWidget.EVENTS.FIELDS_EDITABLE);
 
   yield editCell("TestLS1", "name", "newTestLS1");
   yield editCell("newTestLS1", "value", "newValueLS1");
 
   yield editCell("TestLS3", "name", "newTestLS3");
   yield editCell("newTestLS3", "value", "newValueLS3");
 
   yield editCell("TestLS5", "name", "newTestLS5");
--- a/devtools/client/storage/test/browser_storage_sessionstorage_edit.js
+++ b/devtools/client/storage/test/browser_storage_sessionstorage_edit.js
@@ -5,17 +5,16 @@
 // Basic test to check the editing of localStorage.
 
 "use strict";
 
 add_task(function* () {
   yield openTabAndSetupStorage(MAIN_DOMAIN + "storage-sessionstorage.html");
 
   yield selectTreeItem(["sessionStorage", "http://test1.example.org"]);
-  yield gUI.table.once(TableWidget.EVENTS.FIELDS_EDITABLE);
 
   yield editCell("TestSS1", "name", "newTestSS1");
   yield editCell("newTestSS1", "value", "newValueSS1");
 
   yield editCell("TestSS3", "name", "newTestSS3");
   yield editCell("newTestSS3", "value", "newValueSS3");
 
   yield editCell("TestSS5", "name", "newTestSS5");
--- a/devtools/client/storage/test/head.js
+++ b/devtools/client/storage/test/head.js
@@ -29,23 +29,29 @@ var gToolbox, gPanelWindow, gWindow, gUI
 
 // Services.prefs.setBoolPref(DUMPEMIT_PREF, true);
 // Services.prefs.setBoolPref(DEBUGGERLOG_PREF, true);
 
 Services.prefs.setBoolPref(STORAGE_PREF, true);
 Services.prefs.setBoolPref(CACHES_ON_HTTP_PREF, true);
 DevToolsUtils.testing = true;
 registerCleanupFunction(() => {
+  DevToolsUtils.testing = false;
   gToolbox = gPanelWindow = gWindow = gUI = null;
   Services.prefs.clearUserPref(STORAGE_PREF);
   Services.prefs.clearUserPref(SPLIT_CONSOLE_PREF);
   Services.prefs.clearUserPref(DUMPEMIT_PREF);
   Services.prefs.clearUserPref(DEBUGGERLOG_PREF);
   Services.prefs.clearUserPref(CACHES_ON_HTTP_PREF);
-  DevToolsUtils.testing = false;
+});
+
+registerCleanupFunction(function* cleanup() {
+  let target = TargetFactory.forTab(gBrowser.selectedTab);
+  yield gDevTools.closeToolbox(target);
+
   while (gBrowser.tabs.length > 1) {
     gBrowser.removeCurrentTab();
   }
 });
 
 /**
  * Add a new test tab in the browser and load the given url.
  *
@@ -655,17 +661,17 @@ function getCellValue(id, column) {
  *        The uniqueId of the changed row.
  */
 function* editCell(id, column, newValue, validate = true) {
   let row = getRowCells(id, true);
   let editableFieldsEngine = gUI.table._editableFieldsEngine;
 
   editableFieldsEngine.edit(row[column]);
 
-  return yield typeWithTerminator(newValue, "VK_RETURN", validate);
+  yield typeWithTerminator(newValue, "VK_RETURN", validate);
 }
 
 /**
  * Begin edit mode for a cell.
  *
  * @param {String} id
  *        The uniqueId of the row.
  * @param {String} column
--- a/devtools/client/storage/ui.js
+++ b/devtools/client/storage/ui.js
@@ -189,25 +189,22 @@ StorageUI.prototype = {
   },
 
   getCurrentActor: function() {
     let type = this.table.datatype;
 
     return this.storageTypes[type];
   },
 
-  makeFieldsEditable: function() {
+  makeFieldsEditable: function* () {
     let actor = this.getCurrentActor();
 
     if (typeof actor.getEditableFields !== "undefined") {
-      actor.getEditableFields().then(fields => {
-        this.table.makeFieldsEditable(fields);
-      }).catch(() => {
-        // Do nothing
-      });
+      let fields = yield actor.getEditableFields();
+      this.table.makeFieldsEditable(fields);
     } else if (this.table._editableFieldsEngine) {
       this.table._editableFieldsEngine.destroy();
     }
   },
 
   editItem: function(eventType, data) {
     let actor = this.getCurrentActor();
 
@@ -399,43 +396,41 @@ StorageUI.prototype = {
    *        The type of storage. Ex. "cookies"
    * @param {string} host
    *        Hostname
    * @param {array} names
    *        Names of particular store objects. Empty if all are requested
    * @param {Constant} reason
    *        See REASON constant at top of file.
    */
-  fetchStorageObjects: function(type, host, names, reason) {
+  fetchStorageObjects: Task.async(function* (type, host, names, reason) {
     let fetchOpts = reason === REASON.NEXT_50_ITEMS ? {offset: this.itemOffset}
                                                     : {};
     let storageType = this.storageTypes[type];
 
     if (reason !== REASON.NEXT_50_ITEMS &&
         reason !== REASON.UPDATE &&
         reason !== REASON.NEW_ROW &&
         reason !== REASON.POPULATE) {
       throw new Error("Invalid reason specified");
     }
 
-    storageType.getStoreObjects(host, names, fetchOpts).then(({data}) => {
-      if (!data.length) {
-        this.emit("store-objects-updated");
-        return;
+    try {
+      let {data} = yield storageType.getStoreObjects(host, names, fetchOpts);
+      if (data.length) {
+        if (reason === REASON.POPULATE) {
+          yield this.resetColumns(data[0], type, host);
+        }
+        this.populateTable(data, reason);
       }
-      if (reason === REASON.POPULATE) {
-        this.resetColumns(data[0], type);
-        this.table.host = host;
-      }
-      this.populateTable(data, reason);
       this.emit("store-objects-updated");
-
-      this.makeFieldsEditable();
-    }, Cu.reportError);
-  },
+    } catch (ex) {
+      Cu.reportError(ex);
+    }
+  }),
 
   /**
    * Populates the storage tree which displays the list of storages present for
    * the page.
    *
    * @param {object} storageTypes
    *        List of storages and their corresponding hosts returned by the
    *        StorageFront.listStores call.
@@ -661,35 +656,40 @@ StorageUI.prototype = {
    * Resets the column headers in the storage table with the pased object `data`
    *
    * @param {object} data
    *        The object from which key and values will be used for naming the
    *        headers of the columns
    * @param {string} type
    *        The type of storage corresponding to the after-reset columns in the
    *        table.
+   * @param {string} host
+   *        The host name corresponding to the table after reset.
    */
-  resetColumns: function(data, type) {
+  resetColumns: function* (data, type, host) {
     let columns = {};
     let uniqueKey = null;
     for (let key in data) {
       if (!uniqueKey) {
         this.table.uniqueId = uniqueKey = key;
       }
       columns[key] = key;
       try {
         columns[key] = L10N.getStr("table.headers." + type + "." + key);
       } catch (e) {
         console.error("Unable to localize table header type:" + type +
                       " key:" + key);
       }
     }
     this.table.setColumns(columns, null, HIDDEN_COLUMNS);
     this.table.datatype = type;
+    this.table.host = host;
     this.hideSidebar();
+
+    yield this.makeFieldsEditable();
   },
 
   /**
    * Populates or updates the rows in the storage table.
    *
    * @param {array[object]} data
    *        Array of objects to be populated in the storage table
    * @param {Constant} reason