Bug 1273941 - replace uses of promise.defer in devtools/client/styleeditor; r=jryans
authorTom Tromey <tom@tromey.com>
Thu, 09 Jun 2016 09:06:21 -0600
changeset 302461 3489bbcc48864251f7242fb92f41af1edb031ffa
parent 302460 be8fdffc3665b30242dbe639818f19ed320455ad
child 302462 bdea53872708d0cfcfdbbcd8c2b61724ade3e51f
push id19745
push usercbook@mozilla.com
push dateFri, 24 Jun 2016 07:04:33 +0000
treeherderfx-team@ed1226de3214 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1273941
milestone50.0a1
Bug 1273941 - replace uses of promise.defer in devtools/client/styleeditor; r=jryans MozReview-Commit-ID: EEniVnsuuDd
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_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
@@ -26,16 +26,17 @@ const {
 const {SplitView} = require("resource://devtools/client/shared/SplitView.jsm");
 const {StyleSheetEditor} = require("resource://devtools/client/styleeditor/StyleSheetEditor.jsm");
 loader.lazyImporter(this, "PluralForm", "resource://gre/modules/PluralForm.jsm");
 const {PrefObserver, PREF_ORIG_SOURCES} =
       require("devtools/client/styleeditor/utils");
 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 LOAD_ERROR = "error-load";
 const STYLE_EDITOR_TEMPLATE = "stylesheet";
 const SELECTOR_HIGHLIGHTER_TYPE = "SelectorHighlighter";
 const PREF_MEDIA_SIDEBAR = "devtools.styleeditor.showMediaSidebar";
 const PREF_SIDEBAR_WIDTH = "devtools.styleeditor.mediaSidebarWidth";
@@ -709,17 +710,17 @@ StyleEditorUI.prototype = {
     return promise.all([editorPromise, summaryPromise]);
   },
 
   getEditorSummary: function (editor) {
     if (editor.summary) {
       return promise.resolve(editor.summary);
     }
 
-    let deferred = promise.defer();
+    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);
       }
     });
@@ -727,17 +728,17 @@ StyleEditorUI.prototype = {
     return deferred.promise;
   },
 
   getEditorDetails: function (editor) {
     if (editor.details) {
       return promise.resolve(editor.details);
     }
 
-    let deferred = promise.defer();
+    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);
       }
     });
--- a/devtools/client/styleeditor/StyleSheetEditor.jsm
+++ b/devtools/client/styleeditor/StyleSheetEditor.jsm
@@ -9,16 +9,17 @@ 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 {CssLogic} = 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", {});
@@ -471,17 +472,17 @@ StyleSheetEditor.prototype = {
 
   /**
    * Get the source editor for this editor.
    *
    * @return {Promise}
    *         Promise that will resolve with the editor.
    */
   getSourceEditor: function () {
-    let deferred = promise.defer();
+    let deferred = defer();
 
     if (this.sourceEditor) {
       return promise.resolve(this);
     }
     this.on("source-editor-load", () => {
       deferred.resolve(this);
     });
     return deferred.promise;
--- a/devtools/client/styleeditor/test/browser_styleeditor_autocomplete.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_autocomplete.js
@@ -143,17 +143,17 @@ function testState(index, sourceEditor, 
 
   let ready = sourceEditor.once(evt);
   EventUtils.synthesizeKey(key, mods, panelWindow);
 
   return ready;
 }
 
 function checkState(index, sourceEditor, popup) {
-  let deferred = promise.defer();
+  let deferred = defer();
   executeSoon(() => {
     let [, details] = TEST_CASES[index];
     details = details || {};
     let {total, current, inserted} = details;
 
     if (total != undefined) {
       ok(popup.isOpen, "Popup is open for index " + index);
       is(total, popup.itemCount,
--- a/devtools/client/styleeditor/test/browser_styleeditor_filesave.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_filesave.js
@@ -46,17 +46,17 @@ 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 = promise.defer();
+  let deferred = defer();
   let destFile = FileUtils.getFile("ProfD", [destFileName]);
   write(read(srcChromeURL), destFile, deferred.resolve);
 
   return deferred.promise;
 }
 
 function read(srcChromeURL) {
   let scriptableStream = Cc["@mozilla.org/scriptableinputstream;1"]
--- a/devtools/client/styleeditor/test/browser_styleeditor_inline_friendly_names.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_inline_friendly_names.js
@@ -41,17 +41,17 @@ 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 = promise.defer();
+  let deferred = defer();
   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();
   });
--- a/devtools/client/styleeditor/test/browser_styleeditor_media_sidebar.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_media_sidebar.js
@@ -126,17 +126,17 @@ function testRule(rule, text, matches, l
 
 function openEditor(editor) {
   getLinkFor(editor).click();
 
   return editor.getSourceEditor();
 }
 
 function listenForMediaChange(UI) {
-  let deferred = promise.defer();
+  let deferred = defer();
   UI.once("media-list-changed", () => {
     deferred.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,17 +54,17 @@ function testRule(rule, text, lineno) {
 
 function openEditor(editor) {
   getLinkFor(editor).click();
 
   return editor.getSourceEditor();
 }
 
 function listenForMediaChange(UI) {
-  let deferred = promise.defer();
+  let deferred = defer();
   UI.once("media-list-changed", () => {
     deferred.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,17 +22,17 @@ add_task(function* () {
 
   yield waitForPropertyChange;
 
   testUpdated(editor, originalHref);
 });
 
 function createNew(ui, panelWindow) {
   info("Creating a new stylesheet now");
-  let deferred = promise.defer();
+  let deferred = defer();
 
   ui.once("editor-added", (ev, editor) => {
     editor.getSourceEditor().then(deferred.resolve);
   });
 
   waitForFocus(function () {
     // create a new style sheet
     let newButton = panelWindow.document
@@ -41,17 +41,17 @@ function createNew(ui, panelWindow) {
 
     EventUtils.synthesizeMouseAtCenter(newButton, {}, panelWindow);
   }, panelWindow);
 
   return deferred.promise;
 }
 
 function onPropertyChange(editor) {
-  let deferred = promise.defer();
+  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();
     }
@@ -78,17 +78,17 @@ 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 = promise.defer();
+  let deferred = defer();
 
   waitForFocus(function () {
     for (let c of TESTCASE_CSS_SOURCE) {
       EventUtils.synthesizeKey(c, {}, panelWindow);
     }
     ok(editor.unsaved, "new editor has unsaved flag");
 
     deferred.resolve();
--- a/devtools/client/styleeditor/test/browser_styleeditor_opentab.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_opentab.js
@@ -17,17 +17,17 @@ 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 = promise.defer();
+  let tabOpenedDefer = defer();
 
   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();
   };
@@ -44,78 +44,78 @@ add_task(function* () {
     "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 defer = promise.defer();
+  let deferred = defer();
   contextMenu.addEventListener("popupshown", function onpopupshown() {
     contextMenu.removeEventListener("popupshown", onpopupshown);
-    defer.resolve();
+    deferred.resolve();
   });
-  return defer.promise;
+  return deferred.promise;
 }
 
 function onPopupHide(contextMenu) {
-  let defer = promise.defer();
+  let deferred = defer();
   contextMenu.addEventListener("popuphidden", function popuphidden() {
     contextMenu.removeEventListener("popuphidden", popuphidden);
-    defer.resolve();
+    deferred.resolve();
   });
-  return defer.promise;
+  return deferred.promise;
 }
 
 function rightClickStyleSheet(ui, editor) {
-  let defer = promise.defer();
+  let deferred = defer();
 
   onPopupShow(ui._contextMenu).then(()=> {
     onPopupHide(ui._contextMenu).then(() => {
-      defer.resolve();
+      deferred.resolve();
     });
     ui._contextMenu.hidePopup();
   });
 
   EventUtils.synthesizeMouseAtCenter(
     editor.summary.querySelector(".stylesheet-name"),
     {button: 2, type: "contextmenu"},
     ui._window);
 
-  return defer.promise;
+  return deferred.promise;
 }
 
 function rightClickInlineStyleSheet(ui, editor) {
-  let defer = promise.defer();
+  let deferred = defer();
 
   onPopupShow(ui._contextMenu).then(()=> {
     onPopupHide(ui._contextMenu).then(() => {
-      defer.resolve();
+      deferred.resolve();
     });
     ui._contextMenu.hidePopup();
   });
 
   EventUtils.synthesizeMouseAtCenter(
     editor.summary.querySelector(".stylesheet-name"),
     {button: 2, type: "contextmenu"},
     ui._window);
 
-  return defer.promise;
+  return deferred.promise;
 }
 
 function rightClickNoStyleSheet(ui) {
-  let defer = promise.defer();
+  let deferred = defer();
 
   onPopupShow(ui._contextMenu).then(()=> {
     onPopupHide(ui._contextMenu).then(() => {
-      defer.resolve();
+      deferred.resolve();
     });
     ui._contextMenu.hidePopup();
   });
 
   EventUtils.synthesizeMouseAtCenter(
     ui._panelDoc.querySelector("#splitview-tpl-summary-stylesheet"),
     {button: 2, type: "contextmenu"},
     ui._window);
 
-  return defer.promise;
+  return deferred.promise;
 }
--- a/devtools/client/styleeditor/test/browser_styleeditor_private_perwindowpb.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_private_perwindowpb.js
@@ -29,17 +29,17 @@ add_task(function* () {
 
   yield editor.getSourceEditor();
   yield checkDiskCacheFor(TEST_HOST);
   win.close();
 });
 
 function checkDiskCacheFor(host) {
   let foundPrivateData = false;
-  let deferred = promise.defer();
+  let deferred = defer();
 
   Visitor.prototype = {
     onCacheStorageInfo: function (num) {
       info("disk storage contains " + num + " entries");
     },
     onCacheEntryInfo: function (uri) {
       let urispec = uri.asciiSpec;
       info(urispec);
@@ -56,17 +56,17 @@ function checkDiskCacheFor(host) {
   storage.asyncVisitStorage(new Visitor(),
     /* Do walk entries */
     true);
 
   return deferred.promise;
 }
 
 function waitForDelayedStartupFinished(win) {
-  let deferred = promise.defer();
+  let deferred = defer();
   Services.obs.addObserver(function observer(subject, topic) {
     if (win == subject) {
       Services.obs.removeObserver(observer, topic);
       deferred.resolve();
     }
   }, "browser-delayed-startup-finished", false);
 
   return deferred.promise;
--- a/devtools/client/styleeditor/test/browser_styleeditor_sourcemap_watching.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_sourcemap_watching.js
@@ -48,17 +48,17 @@ add_task(function* () {
   let link = getLinkFor(editor);
   link.click();
 
   yield editor.getSourceEditor();
 
   let color = yield getComputedStyleProperty({selector: "div", name: "color"});
   is(color, "rgb(255, 0, 102)", "div is red before saving file");
 
-  // let styleApplied = promise.defer();
+  // let styleApplied = defer();
   let styleApplied = editor.once("style-applied");
 
   yield pauseForTimeChange();
 
   // Edit and save Sass in the editor. This will start off a file-watching
   // process waiting for the CSS file to change.
   yield editSCSS(editor);
 
@@ -70,34 +70,34 @@ 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 = promise.defer();
+  let deferred = defer();
 
   editor.sourceEditor.setText(CSS_TEXT);
 
   editor.saveToFile(null, function (file) {
     ok(file, "Scss file should be saved");
     deferred.resolve();
   });
 
   return deferred.promise;
 }
 
 function editCSSFile(CSSFile) {
   return write(CSS_TEXT, CSSFile);
 }
 
 function pauseForTimeChange() {
-  let deferred = promise.defer();
+  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;
 }
@@ -135,17 +135,17 @@ function read(srcChromeURL) {
   }
   scriptableStream.close();
   input.close();
 
   return data;
 }
 
 function write(data, file) {
-  let deferred = promise.defer();
+  let deferred = defer();
 
   let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
     .createInstance(Ci.nsIScriptableUnicodeConverter);
 
   converter.charset = "UTF-8";
 
   let istream = converter.convertToInputStream(data);
   let ostream = FileUtils.openSafeFileOutputStream(file);
--- a/devtools/client/styleeditor/test/browser_styleeditor_syncAlreadyOpen.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_syncAlreadyOpen.js
@@ -24,17 +24,17 @@ 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 = promise.defer();
+  let onEditorChange = defer();
   editor.sourceEditor.on("change", onEditorChange.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;
--- a/devtools/client/styleeditor/test/browser_styleeditor_syncIntoRuleView.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_syncIntoRuleView.js
@@ -28,17 +28,17 @@ 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 = promise.defer();
+  let deferred = defer();
 
   waitForFocus(function () {
     for (let c of TESTCASE_CSS_SOURCE) {
       EventUtils.synthesizeKey(c, {}, panelWindow);
     }
     ok(editor.unsaved, "new editor has unsaved flag");
 
     deferred.resolve();
--- 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 = promise.defer();
+  let deferred = defer();
   sheet.on("style-applied", deferred.resolve);
   return deferred.promise;
 }
--- a/devtools/client/styleeditor/test/head.js
+++ b/devtools/client/styleeditor/test/head.js
@@ -18,17 +18,17 @@ 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 = promise.defer();
+  let def = defer();
 
   let targetWindow = win || window;
   let targetBrowser = targetWindow.gBrowser;
 
   let tab = targetBrowser.selectedTab = targetBrowser.addTab(url);
   targetBrowser.selectedBrowser.addEventListener("load", function onload() {
     targetBrowser.selectedBrowser.removeEventListener("load", onload, true);
     info("URL '" + url + "' loading complete");
@@ -42,17 +42,17 @@ var addTab = function (url, win) {
  * 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) {
   info(`Navigating to ${url}`);
   let browser = gBrowser.selectedBrowser;
 
-  let navigating = promise.defer();
+  let navigating = defer();
   browser.addEventListener("load", function onload() {
     browser.removeEventListener("load", onload, true);
     navigating.resolve();
   }, true);
 
   browser.loadURI(url);
 
   yield navigating.promise;