Bug 1355523 - Convert defer into new Promise in client/styleeditor; r?tromey draft
authorMatt R <matthieu.rigolot@gmail.com>
Tue, 09 May 2017 16:51:55 +0100
changeset 577161 bc7a351630fa5ad5113babe6cd5fb1aed7458c78
parent 576334 3b96f277325747fe668ca8cd896d2f581238e4ee
child 628446 34aace30dba73ed49a31f4f5fc4d0cbfe87e109e
push id58633
push userbmo:matthieu.rigolot@gmail.com
push dateFri, 12 May 2017 23:26:17 +0000
reviewerstromey
bugs1355523
milestone55.0a1
Bug 1355523 - Convert defer into new Promise in client/styleeditor; r?tromey MozReview-Commit-ID: GRfkPZrW6Fn
devtools/client/styleeditor/StyleEditorUI.jsm
devtools/client/styleeditor/StyleSheetEditor.jsm
devtools/client/styleeditor/test/browser_styleeditor_autocomplete.js
devtools/client/styleeditor/test/browser_styleeditor_filesave.js
devtools/client/styleeditor/test/browser_styleeditor_inline_friendly_names.js
devtools/client/styleeditor/test/browser_styleeditor_media_sidebar.js
devtools/client/styleeditor/test/browser_styleeditor_media_sidebar_sourcemaps.js
devtools/client/styleeditor/test/browser_styleeditor_new.js
devtools/client/styleeditor/test/browser_styleeditor_opentab.js
devtools/client/styleeditor/test/browser_styleeditor_private_perwindowpb.js
devtools/client/styleeditor/test/browser_styleeditor_scroll.js
devtools/client/styleeditor/test/browser_styleeditor_sourcemap_watching.js
devtools/client/styleeditor/test/browser_styleeditor_syncAlreadyOpen.js
devtools/client/styleeditor/test/browser_styleeditor_syncIntoRuleView.js
devtools/client/styleeditor/test/browser_styleeditor_transition_rule.js
devtools/client/styleeditor/test/head.js
--- a/devtools/client/styleeditor/StyleEditorUI.jsm
+++ b/devtools/client/styleeditor/StyleEditorUI.jsm
@@ -24,18 +24,16 @@ const {
   showFilePicker,
 } = require("resource://devtools/client/styleeditor/StyleEditorUtil.jsm");
 const {SplitView} = require("resource://devtools/client/shared/SplitView.jsm");
 const {StyleSheetEditor} = require("resource://devtools/client/styleeditor/StyleSheetEditor.jsm");
 const {PluralForm} = require("devtools/shared/plural-form");
 const {PrefObserver} = require("devtools/client/shared/prefs");
 const csscoverage = require("devtools/shared/fronts/csscoverage");
 const {console} = require("resource://gre/modules/Console.jsm");
-const promise = require("promise");
-const defer = require("devtools/shared/defer");
 const {ResponsiveUIManager} =
   require("resource://devtools/client/responsivedesign/responsivedesign.jsm");
 const {KeyCodes} = require("devtools/client/shared/keycodes");
 
 const LOAD_ERROR = "error-load";
 const STYLE_EDITOR_TEMPLATE = "stylesheet";
 const SELECTOR_HIGHLIGHTER_TYPE = "SelectorHighlighter";
 const PREF_MEDIA_SIDEBAR = "devtools.styleeditor.showMediaSidebar";
@@ -657,17 +655,17 @@ StyleEditorUI.prototype = {
         // selected by the source editor. Only after we select that particular
         // editor and go the required line and column, it will become null.
         this._styleSheetBoundToSelect = this._styleSheetToSelect;
         this._styleSheetToSelect = null;
         return this._selectEditor(editor, toSelect.line, toSelect.col);
       }
     }
 
-    return promise.resolve();
+    return Promise.resolve();
   },
 
   /**
    * Returns whether a given editor is the current editor to be selected. Tests
    * based on href or underlying stylesheet.
    *
    * @param {StyleSheetEditor} editor
    *        The editor to test.
@@ -705,53 +703,51 @@ StyleEditorUI.prototype = {
       editor.sourceEditor.setCursor({line: line, ch: col});
       this._styleSheetBoundToSelect = null;
     });
 
     let summaryPromise = this.getEditorSummary(editor).then((summary) => {
       this._view.activeSummary = summary;
     });
 
-    return promise.all([editorPromise, summaryPromise]);
+    return Promise.all([editorPromise, summaryPromise]);
   },
 
   getEditorSummary: function (editor) {
-    if (editor.summary) {
-      return promise.resolve(editor.summary);
-    }
-
-    let deferred = defer();
     let self = this;
 
-    this.on("editor-added", function onAdd(e, selected) {
-      if (selected == editor) {
-        self.off("editor-added", onAdd);
-        deferred.resolve(editor.summary);
-      }
+    if (editor.summary) {
+      return Promise.resolve(editor.summary);
+    }
+
+    return new Promise(resolve => {
+      this.on("editor-added", function onAdd(e, selected) {
+        if (selected == editor) {
+          self.off("editor-added", onAdd);
+          resolve(editor.summary);
+        }
+      });
     });
-
-    return deferred.promise;
   },
 
   getEditorDetails: function (editor) {
-    if (editor.details) {
-      return promise.resolve(editor.details);
-    }
-
-    let deferred = defer();
     let self = this;
 
-    this.on("editor-added", function onAdd(e, selected) {
-      if (selected == editor) {
-        self.off("editor-added", onAdd);
-        deferred.resolve(editor.details);
-      }
+    if (editor.details) {
+      return Promise.resolve(editor.details);
+    }
+
+    return new Promise(resolve => {
+      this.on("editor-added", function onAdd(e, selected) {
+        if (selected == editor) {
+          self.off("editor-added", onAdd);
+          resolve(editor.details);
+        }
+      });
     });
-
-    return deferred.promise;
   },
 
   /**
    * Returns an identifier for the given style sheet.
    *
    * @param {StyleSheet} styleSheet
    *        The style sheet to be identified.
    */
--- a/devtools/client/styleeditor/StyleSheetEditor.jsm
+++ b/devtools/client/styleeditor/StyleSheetEditor.jsm
@@ -9,17 +9,16 @@ this.EXPORTED_SYMBOLS = ["StyleSheetEdit
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
 const Editor = require("devtools/client/sourceeditor/editor");
 const promise = require("promise");
-const defer = require("devtools/shared/defer");
 const {shortSource, prettifyCSS} = require("devtools/shared/inspector/css-logic");
 const {console} = require("resource://gre/modules/Console.jsm");
 const Services = require("Services");
 const EventEmitter = require("devtools/shared/event-emitter");
 const {Task} = require("devtools/shared/task");
 const {FileUtils} = require("resource://gre/modules/FileUtils.jsm");
 const {NetUtil} = require("resource://gre/modules/NetUtil.jsm");
 const {TextDecoder, OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
@@ -474,25 +473,27 @@ StyleSheetEditor.prototype = {
 
   /**
    * Get the source editor for this editor.
    *
    * @return {Promise}
    *         Promise that will resolve with the editor.
    */
   getSourceEditor: function () {
-    let deferred = defer();
+    let self = this;
 
     if (this.sourceEditor) {
-      return promise.resolve(this);
+      return Promise.resolve(this);
     }
-    this.on("source-editor-load", () => {
-      deferred.resolve(this);
+
+    return new Promise(resolve => {
+      this.on("source-editor-load", () => {
+        resolve(self);
+      });
     });
-    return deferred.promise;
   },
 
   /**
    * Focus the Style Editor input.
    */
   focus: function () {
     if (this.sourceEditor) {
       this.sourceEditor.focus();
--- a/devtools/client/styleeditor/test/browser_styleeditor_autocomplete.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_autocomplete.js
@@ -151,49 +151,48 @@ function testState(testCases, index, sou
 
   let ready = sourceEditor.once(evt);
   EventUtils.synthesizeKey(key, mods, panelWindow);
 
   return ready;
 }
 
 function checkState(testCases, index, sourceEditor, popup) {
-  let deferred = defer();
-  executeSoon(() => {
-    let [, details] = testCases[index];
-    details = details || {};
-    let {total, current, inserted} = details;
+  return new Promise(resolve => {
+    executeSoon(() => {
+      let [, details] = testCases[index];
+      details = details || {};
+      let {total, current, inserted} = details;
 
-    if (total != undefined) {
-      ok(popup.isOpen, "Popup is open for index " + index);
-      is(total, popup.itemCount,
-         "Correct total suggestions for index " + index);
-      is(current, popup.selectedIndex,
-         "Correct index is selected for index " + index);
-      if (inserted) {
-        let { text } = popup.getItemAtIndex(current);
-        let { line, ch } = sourceEditor.getCursor();
-        let lineText = sourceEditor.getText(line);
-        is(lineText.substring(ch - text.length, ch), text,
-           "Current suggestion from the popup is inserted into the editor.");
+      if (total != undefined) {
+        ok(popup.isOpen, "Popup is open for index " + index);
+        is(total, popup.itemCount,
+           "Correct total suggestions for index " + index);
+        is(current, popup.selectedIndex,
+           "Correct index is selected for index " + index);
+        if (inserted) {
+          let { text } = popup.getItemAtIndex(current);
+          let { line, ch } = sourceEditor.getCursor();
+          let lineText = sourceEditor.getText(line);
+          is(lineText.substring(ch - text.length, ch), text,
+             "Current suggestion from the popup is inserted into the editor.");
+        }
+      } else {
+        ok(!popup.isOpen, "Popup is closed for index " + index);
+        if (inserted) {
+          let { text } = popup.getItemAtIndex(current);
+          let { line, ch } = sourceEditor.getCursor();
+          let lineText = sourceEditor.getText(line);
+          is(lineText.substring(ch - text.length, ch), text,
+             "Current suggestion from the popup is inserted into the editor.");
+        }
       }
-    } else {
-      ok(!popup.isOpen, "Popup is closed for index " + index);
-      if (inserted) {
-        let { text } = popup.getItemAtIndex(current);
-        let { line, ch } = sourceEditor.getCursor();
-        let lineText = sourceEditor.getText(line);
-        is(lineText.substring(ch - text.length, ch), text,
-           "Current suggestion from the popup is inserted into the editor.");
-      }
-    }
-    deferred.resolve();
+      resolve();
+    });
   });
-
-  return deferred.promise;
 }
 
 /**
  * Returns a list of all property names and a map of property name vs possible
  * CSS values provided by the Gecko engine.
  *
  * @return {Object} An object with following properties:
  *         - CSSProperties {Array} Array of string containing all the possible
--- a/devtools/client/styleeditor/test/browser_styleeditor_filesave.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_filesave.js
@@ -46,21 +46,20 @@ add_task(function* () {
   yield dirty;
 
   is(editor.sourceEditor.isClean(), true, "Editor is clean.");
   ok(!editor.summary.classList.contains("unsaved"),
      "Star icon is not present in the corresponding summary.");
 });
 
 function copy(srcChromeURL, destFileName) {
-  let deferred = defer();
-  let destFile = FileUtils.getFile("ProfD", [destFileName]);
-  write(read(srcChromeURL), destFile, deferred.resolve);
-
-  return deferred.promise;
+  return new Promise(resolve => {
+    let destFile = FileUtils.getFile("ProfD", [destFileName]);
+    write(read(srcChromeURL), destFile, resolve);
+  });
 }
 
 function read(srcChromeURL) {
   let scriptableStream = Cc["@mozilla.org/scriptableinputstream;1"]
     .getService(Ci.nsIScriptableInputStream);
 
   let channel = NetUtil.newChannel({
     uri: srcChromeURL,
--- a/devtools/client/styleeditor/test/browser_styleeditor_inline_friendly_names.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_inline_friendly_names.js
@@ -41,27 +41,25 @@ function testIndentifierGeneration(ui) {
     "URI is the identifier of style sheet file.");
 
   is(ui.getStyleSheetIdentifier(fakeInlineStyleSheet),
     "inline-2-at-http://example.com/",
     "Inline sheets are identified by their page and position in the page.");
 }
 
 function saveFirstInlineStyleSheet(ui) {
-  let deferred = defer();
-  let editor = ui.editors[0];
-
-  let destFile = FileUtils.getFile("ProfD", [SAVE_PATH]);
+  return new Promise(resolve => {
+    let editor = ui.editors[0];
+    let destFile = FileUtils.getFile("ProfD", [SAVE_PATH]);
 
-  editor.saveToFile(destFile, function (file) {
-    ok(file, "File was correctly saved.");
-    deferred.resolve();
+    editor.saveToFile(destFile, function (file) {
+      ok(file, "File was correctly saved.");
+      resolve();
+    });
   });
-
-  return deferred.promise;
 }
 
 function testFriendlyNamesAfterSave(ui) {
   let firstEditor = ui.editors[0];
   let secondEditor = ui.editors[1];
 
   // The friendly name of first sheet should've been remembered, the second
   // should not be the same (bug 969900).
--- a/devtools/client/styleeditor/test/browser_styleeditor_media_sidebar.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_media_sidebar.js
@@ -126,18 +126,18 @@ function testRule(rule, text, matches, l
 
 function openEditor(editor) {
   getLinkFor(editor).click();
 
   return editor.getSourceEditor();
 }
 
 function listenForMediaChange(UI) {
-  let deferred = defer();
-  UI.once("media-list-changed", () => {
-    deferred.resolve();
+  return new Promise(resolve => {
+    UI.once("media-list-changed", () => {
+      resolve();
+    });
   });
-  return deferred.promise;
 }
 
 function getLinkFor(editor) {
   return editor.summary.querySelector(".stylesheet-name");
 }
--- a/devtools/client/styleeditor/test/browser_styleeditor_media_sidebar_sourcemaps.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_media_sidebar_sourcemaps.js
@@ -54,18 +54,18 @@ function testRule(rule, text, lineno) {
 
 function openEditor(editor) {
   getLinkFor(editor).click();
 
   return editor.getSourceEditor();
 }
 
 function listenForMediaChange(UI) {
-  let deferred = defer();
-  UI.once("media-list-changed", () => {
-    deferred.resolve();
+  return new Promise(resolve => {
+    UI.once("media-list-changed", () => {
+      resolve();
+    });
   });
-  return deferred.promise;
 }
 
 function getLinkFor(editor) {
   return editor.summary.querySelector(".stylesheet-name");
 }
--- a/devtools/client/styleeditor/test/browser_styleeditor_new.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_new.js
@@ -22,47 +22,44 @@ add_task(function* () {
 
   yield waitForPropertyChange;
 
   testUpdated(editor, originalHref);
 });
 
 function createNew(ui, panelWindow) {
   info("Creating a new stylesheet now");
-  let deferred = defer();
 
-  ui.once("editor-added", (ev, editor) => {
-    editor.getSourceEditor().then(deferred.resolve);
-  });
+  return new Promise(resolve => {
+    ui.once("editor-added", (ev, editor) => {
+      editor.getSourceEditor().then(resolve);
+    });
 
-  waitForFocus(function () {
-    // create a new style sheet
-    let newButton = panelWindow.document
-      .querySelector(".style-editor-newButton");
-    ok(newButton, "'new' button exists");
+    waitForFocus(function () {
+      // create a new style sheet
+      let newButton = panelWindow.document
+        .querySelector(".style-editor-newButton");
+      ok(newButton, "'new' button exists");
 
-    EventUtils.synthesizeMouseAtCenter(newButton, {}, panelWindow);
-  }, panelWindow);
-
-  return deferred.promise;
+      EventUtils.synthesizeMouseAtCenter(newButton, {}, panelWindow);
+    }, panelWindow);
+  });
 }
 
 function onPropertyChange(editor) {
-  let deferred = defer();
-
-  editor.styleSheet.on("property-change", function onProp(property) {
-    // wait for text to be entered fully
-    let text = editor.sourceEditor.getText();
-    if (property == "ruleCount" && text == TESTCASE_CSS_SOURCE + "}") {
-      editor.styleSheet.off("property-change", onProp);
-      deferred.resolve();
-    }
+  return new Promise(resolve => {
+    editor.styleSheet.on("property-change", function onProp(property) {
+      // wait for text to be entered fully
+      let text = editor.sourceEditor.getText();
+      if (property == "ruleCount" && text == TESTCASE_CSS_SOURCE + "}") {
+        editor.styleSheet.off("property-change", onProp);
+        resolve();
+      }
+    });
   });
-
-  return deferred.promise;
 }
 
 function* testInitialState(editor) {
   info("Testing the initial state of the new editor");
 
   let summary = editor.summary;
 
   ok(editor.sourceLoaded, "new editor is loaded when attached");
@@ -78,28 +75,26 @@ function* testInitialState(editor) {
     selector: "body",
     name: "background-color"
   });
   is(color, "rgb(255, 255, 255)",
      "content's background color is initially white");
 }
 
 function typeInEditor(editor, panelWindow) {
-  let deferred = defer();
+  return new Promise(resolve => {
+    waitForFocus(function () {
+      for (let c of TESTCASE_CSS_SOURCE) {
+        EventUtils.synthesizeKey(c, {}, panelWindow);
+      }
+      ok(editor.unsaved, "new editor has unsaved flag");
 
-  waitForFocus(function () {
-    for (let c of TESTCASE_CSS_SOURCE) {
-      EventUtils.synthesizeKey(c, {}, panelWindow);
-    }
-    ok(editor.unsaved, "new editor has unsaved flag");
-
-    deferred.resolve();
-  }, panelWindow);
-
-  return deferred.promise;
+      resolve();
+    }, panelWindow);
+  });
 }
 
 function testUpdated(editor, originalHref) {
   info("Testing the state of the new editor after editing it");
 
   is(editor.sourceEditor.getText(), TESTCASE_CSS_SOURCE + "}",
      "rule bracket has been auto-closed");
 
--- a/devtools/client/styleeditor/test/browser_styleeditor_opentab.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_opentab.js
@@ -17,103 +17,97 @@ add_task(function* () {
   is(ui._openLinkNewTabItem.getAttribute("hidden"), "false",
     "The menu item is not hidden");
 
   let url = "https://example.com/browser/devtools/client/styleeditor/test/" +
     "simple.css";
   is(ui._contextMenuStyleSheet.href, url, "Correct URL for sheet");
 
   let originalOpenUILinkIn = ui._window.openUILinkIn;
-  let tabOpenedDefer = defer();
+  let tabOpenedDefer = new Promise(resolve => {
+    ui._window.openUILinkIn = newUrl => {
+      // Reset the actual openUILinkIn function before proceeding.
+      ui._window.openUILinkIn = originalOpenUILinkIn;
 
-  ui._window.openUILinkIn = newUrl => {
-    // Reset the actual openUILinkIn function before proceeding.
-    ui._window.openUILinkIn = originalOpenUILinkIn;
-
-    is(newUrl, url, "The correct tab has been opened");
-    tabOpenedDefer.resolve();
-  };
+      is(newUrl, url, "The correct tab has been opened");
+      resolve();
+    };
+  });
 
   ui._openLinkNewTabItem.click();
 
   info(`Waiting for a tab to open - ${url}`);
-  yield tabOpenedDefer.promise;
+  yield tabOpenedDefer;
 
   yield rightClickInlineStyleSheet(ui, ui.editors[1]);
   is(ui._openLinkNewTabItem.getAttribute("disabled"), "true",
     "The menu item is disabled");
   is(ui._openLinkNewTabItem.getAttribute("hidden"), "false",
     "The menu item is not hidden");
 
   yield rightClickNoStyleSheet(ui);
   is(ui._openLinkNewTabItem.getAttribute("hidden"), "true",
     "The menu item is not hidden");
 });
 
 function onPopupShow(contextMenu) {
-  let deferred = defer();
-  contextMenu.addEventListener("popupshown", function () {
-    deferred.resolve();
-  }, {once: true});
-  return deferred.promise;
+  return new Promise(resolve => {
+    contextMenu.addEventListener("popupshown", function () {
+      resolve();
+    }, {once: true});
+  });
 }
 
 function onPopupHide(contextMenu) {
-  let deferred = defer();
-  contextMenu.addEventListener("popuphidden", function () {
-    deferred.resolve();
-  }, {once: true});
-  return deferred.promise;
+  return new Promise(resolve => {
+    contextMenu.addEventListener("popuphidden", function () {
+      resolve();
+    }, {once: true});
+  });
 }
 
 function rightClickStyleSheet(ui, editor) {
-  let deferred = defer();
+  return new Promise(resolve => {
+    onPopupShow(ui._contextMenu).then(()=> {
+      onPopupHide(ui._contextMenu).then(() => {
+        resolve();
+      });
+      ui._contextMenu.hidePopup();
+    });
 
-  onPopupShow(ui._contextMenu).then(()=> {
-    onPopupHide(ui._contextMenu).then(() => {
-      deferred.resolve();
-    });
-    ui._contextMenu.hidePopup();
+    EventUtils.synthesizeMouseAtCenter(
+      editor.summary.querySelector(".stylesheet-name"),
+      {button: 2, type: "contextmenu"},
+      ui._window);
   });
-
-  EventUtils.synthesizeMouseAtCenter(
-    editor.summary.querySelector(".stylesheet-name"),
-    {button: 2, type: "contextmenu"},
-    ui._window);
-
-  return deferred.promise;
 }
 
 function rightClickInlineStyleSheet(ui, editor) {
-  let deferred = defer();
+  return new Promise(resolve => {
+    onPopupShow(ui._contextMenu).then(()=> {
+      onPopupHide(ui._contextMenu).then(() => {
+        resolve();
+      });
+      ui._contextMenu.hidePopup();
+    });
 
-  onPopupShow(ui._contextMenu).then(()=> {
-    onPopupHide(ui._contextMenu).then(() => {
-      deferred.resolve();
-    });
-    ui._contextMenu.hidePopup();
+    EventUtils.synthesizeMouseAtCenter(
+      editor.summary.querySelector(".stylesheet-name"),
+      {button: 2, type: "contextmenu"},
+      ui._window);
   });
-
-  EventUtils.synthesizeMouseAtCenter(
-    editor.summary.querySelector(".stylesheet-name"),
-    {button: 2, type: "contextmenu"},
-    ui._window);
-
-  return deferred.promise;
 }
 
 function rightClickNoStyleSheet(ui) {
-  let deferred = defer();
+  return new Promise(resolve => {
+    onPopupShow(ui._contextMenu).then(()=> {
+      onPopupHide(ui._contextMenu).then(() => {
+        resolve();
+      });
+      ui._contextMenu.hidePopup();
+    });
 
-  onPopupShow(ui._contextMenu).then(()=> {
-    onPopupHide(ui._contextMenu).then(() => {
-      deferred.resolve();
-    });
-    ui._contextMenu.hidePopup();
+    EventUtils.synthesizeMouseAtCenter(
+      ui._panelDoc.querySelector("#splitview-tpl-summary-stylesheet"),
+      {button: 2, type: "contextmenu"},
+      ui._window);
   });
-
-  EventUtils.synthesizeMouseAtCenter(
-    ui._panelDoc.querySelector("#splitview-tpl-summary-stylesheet"),
-    {button: 2, type: "contextmenu"},
-    ui._window);
-
-  return deferred.promise;
 }
--- a/devtools/client/styleeditor/test/browser_styleeditor_private_perwindowpb.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_private_perwindowpb.js
@@ -41,45 +41,43 @@ add_task(function* () {
     });
   });
   win.close();
   yield onUnload;
 });
 
 function checkDiskCacheFor(host) {
   let foundPrivateData = false;
-  let deferred = defer();
 
-  Visitor.prototype = {
-    onCacheStorageInfo: function (num) {
-      info("disk storage contains " + num + " entries");
-    },
-    onCacheEntryInfo: function (uri) {
-      let urispec = uri.asciiSpec;
-      info(urispec);
-      foundPrivateData |= urispec.includes(host);
-    },
-    onCacheEntryVisitCompleted: function () {
-      is(foundPrivateData, false, "web content present in disk cache");
-      deferred.resolve();
-    }
-  };
-  function Visitor() {}
+  return new Promise(resolve => {
+    Visitor.prototype = {
+      onCacheStorageInfo: function (num) {
+        info("disk storage contains " + num + " entries");
+      },
+      onCacheEntryInfo: function (uri) {
+        let urispec = uri.asciiSpec;
+        info(urispec);
+        foundPrivateData |= urispec.includes(host);
+      },
+      onCacheEntryVisitCompleted: function () {
+        is(foundPrivateData, false, "web content present in disk cache");
+        resolve();
+      }
+    };
+    function Visitor() {}
 
-  let storage = cache.diskCacheStorage(LoadContextInfo.default, false);
-  storage.asyncVisitStorage(new Visitor(),
-    /* Do walk entries */
-    true);
-
-  return deferred.promise;
+    let storage = cache.diskCacheStorage(LoadContextInfo.default, false);
+    storage.asyncVisitStorage(new Visitor(),
+      /* Do walk entries */
+      true);
+  });
 }
 
 function waitForDelayedStartupFinished(win) {
-  let deferred = defer();
-  Services.obs.addObserver(function observer(subject, topic) {
-    if (win == subject) {
-      Services.obs.removeObserver(observer, topic);
-      deferred.resolve();
-    }
-  }, "browser-delayed-startup-finished");
-
-  return deferred.promise;
+  return new Promise(resolve => {
+    Services.obs.addObserver(function observer(subject, topic) {
+      if (win == subject) {
+        Services.obs.removeObserver(observer, topic);
+        resolve();
+      }
+    }, "browser-delayed-startup-finished");
+  });
 }
--- a/devtools/client/styleeditor/test/browser_styleeditor_scroll.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_scroll.js
@@ -33,17 +33,17 @@ add_task(function* () {
   let longEditor = ui.editors[1];
 
   info(`Selecting doc_long.css and scrolling to line ${LINE_TO_SELECT}`);
 
   // We need to wait for editor-selected if we want to check the scroll
   // position as scrolling occurs after selectStyleSheet resolves but before the
   // event is emitted.
   let selectEventPromise = waitForEditorToBeSelected(longEditor, ui);
-  ui.selectStyleSheet(longEditor.styleSheet, LINE_TO_SELECT);
+  yield ui.selectStyleSheet(longEditor.styleSheet, LINE_TO_SELECT);
   yield selectEventPromise;
 
   info("Checking that the correct line is visible after initial load");
 
   let { from, to } = longEditor.sourceEditor.getViewport();
   info(`Lines ${from}-${to} are visible (expected ${LINE_TO_SELECT}).`);
 
   ok(from <= LINE_TO_SELECT, "The editor scrolled too much.");
--- a/devtools/client/styleeditor/test/browser_styleeditor_sourcemap_watching.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_sourcemap_watching.js
@@ -70,41 +70,37 @@ add_task(function* () {
 
   yield styleApplied;
 
   color = yield getComputedStyleProperty({selector: "div", name: "color"});
   is(color, "rgb(0, 0, 255)", "div is blue after saving file");
 });
 
 function editSCSS(editor) {
-  let deferred = defer();
-
-  editor.sourceEditor.setText(CSS_TEXT);
+  return new Promise(resolve => {
+    editor.sourceEditor.setText(CSS_TEXT);
 
-  editor.saveToFile(null, function (file) {
-    ok(file, "Scss file should be saved");
-    deferred.resolve();
+    editor.saveToFile(null, function (file) {
+      ok(file, "Scss file should be saved");
+      resolve();
+    });
   });
-
-  return deferred.promise;
 }
 
 function editCSSFile(CSSFile) {
   return write(CSS_TEXT, CSSFile);
 }
 
 function pauseForTimeChange() {
-  let deferred = defer();
-
-  // We have to wait for the system time to turn over > 1000 ms so that
-  // our file's last change time will show a change. This reflects what
-  // would happen in real life with a user manually saving the file.
-  setTimeout(deferred.resolve, 2000);
-
-  return deferred.promise;
+  return new Promise(resolve => {
+    // We have to wait for the system time to turn over > 1000 ms so that
+    // our file's last change time will show a change. This reflects what
+    // would happen in real life with a user manually saving the file.
+    setTimeout(resolve, 2000);
+  });
 }
 
 /* Helpers */
 
 function getLinkFor(editor) {
   return editor.summary.querySelector(".stylesheet-name");
 }
 
@@ -135,28 +131,26 @@ function read(srcChromeURL) {
   }
   scriptableStream.close();
   input.close();
 
   return data;
 }
 
 function write(data, file) {
-  let deferred = defer();
-
-  let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
-    .createInstance(Ci.nsIScriptableUnicodeConverter);
+  return new Promise(resolve => {
+    let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
+      .createInstance(Ci.nsIScriptableUnicodeConverter);
 
-  converter.charset = "UTF-8";
+    converter.charset = "UTF-8";
 
-  let istream = converter.convertToInputStream(data);
-  let ostream = FileUtils.openSafeFileOutputStream(file);
+    let istream = converter.convertToInputStream(data);
+    let ostream = FileUtils.openSafeFileOutputStream(file);
 
-  NetUtil.asyncCopy(istream, ostream, function (status) {
-    if (!Components.isSuccessCode(status)) {
-      info("Coudln't write to " + file.path);
-      return;
-    }
-    deferred.resolve(file);
+    NetUtil.asyncCopy(istream, ostream, function (status) {
+      if (!Components.isSuccessCode(status)) {
+        info("Coudln't write to " + file.path);
+        return;
+      }
+      resolve(file);
+    });
   });
-
-  return deferred.promise;
 }
--- a/devtools/client/styleeditor/test/browser_styleeditor_syncAlreadyOpen.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_syncAlreadyOpen.js
@@ -24,27 +24,28 @@ add_task(function* () {
 
   let { inspector, view, toolbox } = yield openRuleView();
 
   // In this test, make sure the style editor is open before making
   // changes in the inspector.
   let { ui } = yield openStyleEditor();
   let editor = yield ui.editors[0].getSourceEditor();
 
-  let onEditorChange = defer();
-  editor.sourceEditor.on("change", onEditorChange.resolve);
+  let onEditorChange = new Promise(resolve => {
+    editor.sourceEditor.on("change", resolve);
+  });
 
   yield toolbox.getPanel("inspector");
   yield selectNode("#testid", inspector);
   let ruleEditor = getRuleViewRuleEditor(view, 1);
 
   // Disable the "font-size" property.
   let propEditor = ruleEditor.rule.textProps[0].editor;
   let onModification = view.once("ruleview-changed");
   propEditor.enable.click();
   yield onModification;
 
   yield openStyleEditor();
-  yield onEditorChange.promise;
+  yield onEditorChange;
 
   let text = editor.sourceEditor.getText();
   is(text, expectedText, "style inspector changes are synced");
 });
--- a/devtools/client/styleeditor/test/browser_styleeditor_syncIntoRuleView.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_syncIntoRuleView.js
@@ -28,21 +28,19 @@ add_task(function* () {
   yield typeInEditor(editor, panel.panelWindow);
   yield waitForRuleView;
 
   let value = getRuleViewPropertyValue(view, "#testid", "color");
   is(value, "chartreuse", "check that edits were synced to rule view");
 });
 
 function typeInEditor(editor, panelWindow) {
-  let deferred = defer();
+  return new Promise(resolve => {
+    waitForFocus(function () {
+      for (let c of TESTCASE_CSS_SOURCE) {
+        EventUtils.synthesizeKey(c, {}, panelWindow);
+      }
+      ok(editor.unsaved, "new editor has unsaved flag");
 
-  waitForFocus(function () {
-    for (let c of TESTCASE_CSS_SOURCE) {
-      EventUtils.synthesizeKey(c, {}, panelWindow);
-    }
-    ok(editor.unsaved, "new editor has unsaved flag");
-
-    deferred.resolve();
-  }, panelWindow);
-
-  return deferred.promise;
+      resolve();
+    }, panelWindow);
+  });
 }
--- a/devtools/client/styleeditor/test/browser_styleeditor_transition_rule.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_transition_rule.js
@@ -40,12 +40,12 @@ add_task(function* () {
 function openEditor(editor) {
   let link = editor.summary.querySelector(".stylesheet-name");
   link.click();
 
   return editor.getSourceEditor();
 }
 
 function listenForStyleChange(sheet) {
-  let deferred = defer();
-  sheet.on("style-applied", deferred.resolve);
-  return deferred.promise;
+  return new Promise(resolve => {
+    sheet.on("style-applied", resolve);
+  });
 }
--- a/devtools/client/styleeditor/test/head.js
+++ b/devtools/client/styleeditor/test/head.js
@@ -18,49 +18,47 @@ const TEST_HOST = "mochi.test:8888";
 /**
  * Add a new test tab in the browser and load the given url.
  * @param {String} url The url to be loaded in the new tab
  * @param {Window} win The window to add the tab to (default: current window).
  * @return a promise that resolves to the tab object when the url is loaded
  */
 var addTab = function (url, win) {
   info("Adding a new tab with URL: '" + url + "'");
-  let def = defer();
 
-  let targetWindow = win || window;
-  let targetBrowser = targetWindow.gBrowser;
+  return new Promise(resolve => {
+    let targetWindow = win || window;
+    let targetBrowser = targetWindow.gBrowser;
 
-  let tab = targetBrowser.selectedTab = targetBrowser.addTab(url);
-  BrowserTestUtils.browserLoaded(targetBrowser.selectedBrowser)
-    .then(function () {
-      info("URL '" + url + "' loading complete");
-      def.resolve(tab);
-    });
-
-  return def.promise;
+    let tab = targetBrowser.selectedTab = targetBrowser.addTab(url);
+    BrowserTestUtils.browserLoaded(targetBrowser.selectedBrowser)
+      .then(function () {
+        info("URL '" + url + "' loading complete");
+        resolve(tab);
+      });
+  });
 };
 
 /**
  * Navigate the currently selected tab to a new URL and wait for it to load.
  * @param {String} url The url to be loaded in the current tab.
  * @return a promise that resolves when the page has fully loaded.
  */
-var navigateTo = Task.async(function* (url) {
+var navigateTo = function (url) {
   info(`Navigating to ${url}`);
   let browser = gBrowser.selectedBrowser;
 
-  let navigating = defer();
-  browser.addEventListener("load", function () {
-    navigating.resolve();
-  }, {capture: true, once: true});
+  return new Promise(resolve => {
+    browser.addEventListener("load", function () {
+      resolve();
+    }, {capture: true, once: true});
 
-  browser.loadURI(url);
-
-  yield navigating.promise;
-});
+    browser.loadURI(url);
+  });
+};
 
 var navigateToAndWaitForStyleSheets = Task.async(function* (url, ui) {
   let onReset = ui.once("stylesheets-reset");
   yield navigateTo(url);
   yield onReset;
 });
 
 var reloadPageAndWaitForStyleSheets = Task.async(function* (ui) {