Bug 1083989 - Adapting Devtools tests that expect Promise.jsm in the scope. r=paul
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Mon, 27 Oct 2014 22:45:03 +0100
changeset 213385 c2df2cbac90fd36b0bf160b975f6439763a38203
parent 213384 09fbfd40895ad06d6168f1288dbb397969800f0d
child 213386 02c42f877b1b99111d608a87afe2e65324651147
push id27748
push userryanvm@gmail.com
push dateFri, 31 Oct 2014 20:14:33 +0000
treeherdermozilla-central@12ac66e2c016 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaul
bugs1083989
milestone36.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 1083989 - Adapting Devtools tests that expect Promise.jsm in the scope. r=paul
browser/devtools/shared/test/head.js
toolkit/devtools/server/tests/browser/browser_storage_dynamic_windows.js
toolkit/devtools/server/tests/browser/browser_timeline_actors.js
toolkit/devtools/server/tests/browser/browser_timeline_iframes.js
toolkit/devtools/server/tests/browser/head.js
--- a/browser/devtools/shared/test/head.js
+++ b/browser/devtools/shared/test/head.js
@@ -30,19 +30,18 @@ function addTab(aURL, aCallback)
     browser.removeEventListener("load", onTabLoad, true);
     aCallback(browser, tab, browser.contentDocument);
   }
 
   browser.addEventListener("load", onTabLoad, true);
 }
 
 function promiseTab(aURL) {
-  let deferred = Promise.defer();
-  addTab(aURL, deferred.resolve);
-  return deferred.promise;
+  return new Promise(resolve =>
+    addTab(aURL, resolve));
 }
 
 registerCleanupFunction(function tearDown() {
   while (gBrowser.tabs.length > 1) {
     gBrowser.removeCurrentTab();
   }
 
   console = undefined;
@@ -133,16 +132,16 @@ function oneTimeObserve(name, callback) 
   };
   Services.obs.addObserver(func, name, false);
 }
 
 function* createHost(type = "bottom", src = "data:text/html;charset=utf-8,") {
   let host = new Hosts[type](gBrowser.selectedTab);
   let iframe = yield host.create();
 
-  let loaded = Promise.defer();
-  let domHelper = new DOMHelpers(iframe.contentWindow);
-  iframe.setAttribute("src", src);
-  domHelper.onceDOMReady(loaded.resolve);
-  yield loaded.promise;
+  yield new Promise(resolve => {
+    let domHelper = new DOMHelpers(iframe.contentWindow);
+    iframe.setAttribute("src", src);
+    domHelper.onceDOMReady(resolve);
+  });
 
   return [host, iframe.contentWindow, iframe.contentDocument];
 }
--- a/toolkit/devtools/server/tests/browser/browser_storage_dynamic_windows.js
+++ b/toolkit/devtools/server/tests/browser/browser_storage_dynamic_windows.js
@@ -123,187 +123,187 @@ function markOutMatched(toBeEmptied, dat
   }
 }
 
 function testReload() {
   info("Testing if reload works properly");
 
   let shouldBeEmptyFirst = Cu.cloneInto(beforeReload,  {});
   let shouldBeEmptyLast = Cu.cloneInto(beforeReload,  {});
-  let reloaded = Promise.defer();
+  return new Promise(resolve => {
 
-  let onStoresUpdate = data => {
-    info("in stores update of testReload");
-    // This might be second time stores update is happening, in which case,
-    // data.deleted will be null.
-    // OR.. This might be the first time on a super slow machine where both
-    // data.deleted and data.added is missing in the first update.
-    if (data.deleted) {
-      markOutMatched(shouldBeEmptyFirst, data.deleted, true);
-    }
+    let onStoresUpdate = data => {
+      info("in stores update of testReload");
+      // This might be second time stores update is happening, in which case,
+      // data.deleted will be null.
+      // OR.. This might be the first time on a super slow machine where both
+      // data.deleted and data.added is missing in the first update.
+      if (data.deleted) {
+        markOutMatched(shouldBeEmptyFirst, data.deleted, true);
+      }
 
-    if (!Object.keys(shouldBeEmptyFirst).length) {
-      info("shouldBeEmptyFirst is empty now");
-    }
+      if (!Object.keys(shouldBeEmptyFirst).length) {
+        info("shouldBeEmptyFirst is empty now");
+      }
 
-    // stores-update call might not have data.added for the first time on slow
-    // machines, in which case, data.added will be null
-    if (data.added) {
-      markOutMatched(shouldBeEmptyLast, data.added);
-    }
+      // stores-update call might not have data.added for the first time on slow
+      // machines, in which case, data.added will be null
+      if (data.added) {
+        markOutMatched(shouldBeEmptyLast, data.added);
+      }
 
-    if (!Object.keys(shouldBeEmptyLast).length) {
-      info("Everything to be received is received.");
-      endTestReloaded();
-    }
-  };
+      if (!Object.keys(shouldBeEmptyLast).length) {
+        info("Everything to be received is received.");
+        endTestReloaded();
+      }
+    };
 
-  let endTestReloaded = () => {
-    gFront.off("stores-update", onStoresUpdate);
-    reloaded.resolve();
-  };
+    let endTestReloaded = () => {
+      gFront.off("stores-update", onStoresUpdate);
+      resolve();
+    };
 
-  gFront.on("stores-update", onStoresUpdate);
+    gFront.on("stores-update", onStoresUpdate);
 
-  content.location.reload();
-  return reloaded.promise;
+    content.location.reload();
+  });
 }
 
 function testAddIframe() {
   info("Testing if new iframe addition works properly");
-  let reloaded = Promise.defer();
+  return new Promise(resolve => {
 
-  let shouldBeEmpty = {
-    localStorage: {
-      "https://sectest1.example.org": ["iframe-s-ls1"]
-    },
-    sessionStorage: {
-      "https://sectest1.example.org": ["iframe-s-ss1"]
-    },
-    cookies: {
-      "sectest1.example.org": ["sc1"]
-    },
-    indexedDB: {
-      // empty because indexed db creation happens after the page load, so at
-      // the time of window-ready, there was no indexed db present.
-      "https://sectest1.example.org": []
-    }
-  };
+    let shouldBeEmpty = {
+      localStorage: {
+        "https://sectest1.example.org": ["iframe-s-ls1"]
+      },
+      sessionStorage: {
+        "https://sectest1.example.org": ["iframe-s-ss1"]
+      },
+      cookies: {
+        "sectest1.example.org": ["sc1"]
+      },
+      indexedDB: {
+        // empty because indexed db creation happens after the page load, so at
+        // the time of window-ready, there was no indexed db present.
+        "https://sectest1.example.org": []
+      }
+    };
 
-  let onStoresUpdate = data => {
-    info("checking if the hosts list is correct for this iframe addition");
+    let onStoresUpdate = data => {
+      info("checking if the hosts list is correct for this iframe addition");
 
-    markOutMatched(shouldBeEmpty, data.added);
+      markOutMatched(shouldBeEmpty, data.added);
 
-    ok(!data.changed || !data.changed.cookies ||
-       !data.changed.cookies["https://sectest1.example.org"],
-       "Nothing got changed for cookies");
-    ok(!data.changed || !data.changed.localStorage ||
-       !data.changed.localStorage["https://sectest1.example.org"],
-       "Nothing got changed for local storage");
-    ok(!data.changed || !data.changed.sessionStorage ||
-       !data.changed.sessionStorage["https://sectest1.example.org"],
-       "Nothing got changed for session storage");
-    ok(!data.changed || !data.changed.indexedDB ||
-       !data.changed.indexedDB["https://sectest1.example.org"],
-       "Nothing got changed for indexed db");
+      ok(!data.changed || !data.changed.cookies ||
+         !data.changed.cookies["https://sectest1.example.org"],
+         "Nothing got changed for cookies");
+      ok(!data.changed || !data.changed.localStorage ||
+         !data.changed.localStorage["https://sectest1.example.org"],
+         "Nothing got changed for local storage");
+      ok(!data.changed || !data.changed.sessionStorage ||
+         !data.changed.sessionStorage["https://sectest1.example.org"],
+         "Nothing got changed for session storage");
+      ok(!data.changed || !data.changed.indexedDB ||
+         !data.changed.indexedDB["https://sectest1.example.org"],
+         "Nothing got changed for indexed db");
 
-    ok(!data.deleted || !data.deleted.cookies ||
-       !data.deleted.cookies["https://sectest1.example.org"],
-       "Nothing got deleted for cookies");
-    ok(!data.deleted || !data.deleted.localStorage ||
-       !data.deleted.localStorage["https://sectest1.example.org"],
-       "Nothing got deleted for local storage");
-    ok(!data.deleted || !data.deleted.sessionStorage ||
-       !data.deleted.sessionStorage["https://sectest1.example.org"],
-       "Nothing got deleted for session storage");
-    ok(!data.deleted || !data.deleted.indexedDB ||
-       !data.deleted.indexedDB["https://sectest1.example.org"],
-       "Nothing got deleted for indexed db");
+      ok(!data.deleted || !data.deleted.cookies ||
+         !data.deleted.cookies["https://sectest1.example.org"],
+         "Nothing got deleted for cookies");
+      ok(!data.deleted || !data.deleted.localStorage ||
+         !data.deleted.localStorage["https://sectest1.example.org"],
+         "Nothing got deleted for local storage");
+      ok(!data.deleted || !data.deleted.sessionStorage ||
+         !data.deleted.sessionStorage["https://sectest1.example.org"],
+         "Nothing got deleted for session storage");
+      ok(!data.deleted || !data.deleted.indexedDB ||
+         !data.deleted.indexedDB["https://sectest1.example.org"],
+         "Nothing got deleted for indexed db");
 
-    if (!Object.keys(shouldBeEmpty).length) {
-      info("Everything to be received is received.");
-      endTestReloaded();
-    }
-  };
+      if (!Object.keys(shouldBeEmpty).length) {
+        info("Everything to be received is received.");
+        endTestReloaded();
+      }
+    };
 
-  let endTestReloaded = () => {
-    gFront.off("stores-update", onStoresUpdate);
-    reloaded.resolve();
-  };
+    let endTestReloaded = () => {
+      gFront.off("stores-update", onStoresUpdate);
+      resolve();
+    };
 
-  gFront.on("stores-update", onStoresUpdate);
+    gFront.on("stores-update", onStoresUpdate);
 
-  let iframe = content.document.createElement("iframe");
-  iframe.src = ALT_DOMAIN_SECURED + "storage-secured-iframe.html";
-  content.document.querySelector("body").appendChild(iframe);
-  return reloaded.promise;
+    let iframe = content.document.createElement("iframe");
+    iframe.src = ALT_DOMAIN_SECURED + "storage-secured-iframe.html";
+    content.document.querySelector("body").appendChild(iframe);
+  });
 }
 
 function testRemoveIframe() {
   info("Testing if iframe removal works properly");
-  let reloaded = Promise.defer();
+  return new Promise(resolve => {
 
-  let shouldBeEmpty = {
-    localStorage: {
-      "http://sectest1.example.org": []
-    },
-    sessionStorage: {
-      "http://sectest1.example.org": []
-    }
-  };
+    let shouldBeEmpty = {
+      localStorage: {
+        "http://sectest1.example.org": []
+      },
+      sessionStorage: {
+        "http://sectest1.example.org": []
+      }
+    };
 
-  let onStoresUpdate = data => {
-    info("checking if the hosts list is correct for this iframe deletion");
+    let onStoresUpdate = data => {
+      info("checking if the hosts list is correct for this iframe deletion");
 
-    markOutMatched(shouldBeEmpty, data.deleted, true);
+      markOutMatched(shouldBeEmpty, data.deleted, true);
 
-    ok(!data.deleted.cookies || !data.deleted.cookies["sectest1.example.org"],
-       "Nothing got deleted for Cookies as the same hostname is still present");
+      ok(!data.deleted.cookies || !data.deleted.cookies["sectest1.example.org"],
+        "Nothing got deleted for Cookies as the same hostname is still present");
 
-    ok(!data.changed || !data.changed.cookies ||
-       !data.changed.cookies["http://sectest1.example.org"],
-       "Nothing got changed for cookies");
-    ok(!data.changed || !data.changed.localStorage ||
-       !data.changed.localStorage["http://sectest1.example.org"],
-       "Nothing got changed for local storage");
-    ok(!data.changed || !data.changed.sessionStorage ||
-       !data.changed.sessionStorage["http://sectest1.example.org"],
-       "Nothing got changed for session storage");
+      ok(!data.changed || !data.changed.cookies ||
+         !data.changed.cookies["http://sectest1.example.org"],
+         "Nothing got changed for cookies");
+      ok(!data.changed || !data.changed.localStorage ||
+         !data.changed.localStorage["http://sectest1.example.org"],
+         "Nothing got changed for local storage");
+      ok(!data.changed || !data.changed.sessionStorage ||
+         !data.changed.sessionStorage["http://sectest1.example.org"],
+         "Nothing got changed for session storage");
 
-    ok(!data.added || !data.added.cookies ||
-       !data.added.cookies["http://sectest1.example.org"],
-       "Nothing got added for cookies");
-    ok(!data.added || !data.added.localStorage ||
-       !data.added.localStorage["http://sectest1.example.org"],
-       "Nothing got added for local storage");
-    ok(!data.added || !data.added.sessionStorage ||
-       !data.added.sessionStorage["http://sectest1.example.org"],
-       "Nothing got added for session storage");
+      ok(!data.added || !data.added.cookies ||
+         !data.added.cookies["http://sectest1.example.org"],
+         "Nothing got added for cookies");
+      ok(!data.added || !data.added.localStorage ||
+         !data.added.localStorage["http://sectest1.example.org"],
+         "Nothing got added for local storage");
+      ok(!data.added || !data.added.sessionStorage ||
+         !data.added.sessionStorage["http://sectest1.example.org"],
+         "Nothing got added for session storage");
 
-    if (!Object.keys(shouldBeEmpty).length) {
-      info("Everything to be received is received.");
-      endTestReloaded();
+      if (!Object.keys(shouldBeEmpty).length) {
+        info("Everything to be received is received.");
+        endTestReloaded();
+      }
+    };
+
+    let endTestReloaded = () => {
+      gFront.off("stores-update", onStoresUpdate);
+      resolve();
+    };
+
+    gFront.on("stores-update", onStoresUpdate);
+
+    for (let iframe of content.document.querySelectorAll("iframe")) {
+      if (iframe.src.startsWith("http:")) {
+        iframe.remove();
+        break;
+      }
     }
-  };
-
-  let endTestReloaded = () => {
-    gFront.off("stores-update", onStoresUpdate);
-    reloaded.resolve();
-  };
-
-  gFront.on("stores-update", onStoresUpdate);
-
-  for (let iframe of content.document.querySelectorAll("iframe")) {
-    if (iframe.src.startsWith("http:")) {
-      iframe.remove();
-      break;
-    }
-  }
-  return reloaded.promise;
+  });
 }
 
 function test() {
   addTab(MAIN_DOMAIN + "storage-dynamic-windows.html").then(function(doc) {
     initDebuggerServer();
 
     let createConnection = () => {
       let client = new DebuggerClient(DebuggerServer.connectPipe());
--- a/toolkit/devtools/server/tests/browser/browser_timeline_actors.js
+++ b/toolkit/devtools/server/tests/browser/browser_timeline_actors.js
@@ -54,16 +54,15 @@ let test = asyncTest(function*() {
  *
  * @param function predicate
  *        Invoked once in a while until it returns true.
  * @param number interval [optional]
  *        How often the predicate is invoked, in milliseconds.
  */
 function waitUntil(predicate, interval = 10) {
   if (predicate()) {
-    return promise.resolve(true);
+    return Promise.resolve(true);
   }
-  let deferred = promise.defer();
-  setTimeout(function() {
-    waitUntil(predicate).then(() => deferred.resolve(true));
-  }, interval);
-  return deferred.promise;
+  return new Promise(resolve =>
+    setTimeout(function() {
+      waitUntil(predicate).then(() => resolve(true));
+    }, interval));
 }
--- a/toolkit/devtools/server/tests/browser/browser_timeline_iframes.js
+++ b/toolkit/devtools/server/tests/browser/browser_timeline_iframes.js
@@ -30,12 +30,11 @@ let test = asyncTest(function*() {
 
   info("Stop timeline marker recording");
   yield front.stop();
   yield closeDebuggerClient(client);
   gBrowser.removeCurrentTab();
 });
 
 function wait(ms) {
-  let def = promise.defer();
-  setTimeout(def.resolve, ms);
-  return def.promise;
+  return new Promise(resolve =>
+    setTimeout(resolve, ms));
 }
--- a/toolkit/devtools/server/tests/browser/head.js
+++ b/toolkit/devtools/server/tests/browser/head.js
@@ -3,17 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/Services.jsm");
 const {console} = Cu.import("resource://gre/modules/devtools/Console.jsm", {});
-const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
 const {devtools: {require}} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
 const {DebuggerClient} = Cu.import("resource://gre/modules/devtools/dbg-client.jsm", {});
 const {DebuggerServer} = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {});
 
 const PATH = "browser/toolkit/devtools/server/tests/browser/";
 const MAIN_DOMAIN = "http://test1.example.org/" + PATH;
 const ALT_DOMAIN = "http://sectest1.example.org/" + PATH;
 const ALT_DOMAIN_SECURED = "https://sectest1.example.org:443/" + PATH;
@@ -38,21 +37,20 @@ let addTab = Task.async(function* (url) 
   let tab = gBrowser.selectedTab = gBrowser.addTab();
   let loaded = once(gBrowser.selectedBrowser, "load", true);
 
   content.location = url;
   yield loaded;
 
   info("URL '" + url + "' loading complete");
 
-  let def = promise.defer();
-  let isBlank = url == "about:blank";
-  waitForFocus(def.resolve, content, isBlank);
-
-  yield def.promise;
+  yield new Promise(resolve => {
+    let isBlank = url == "about:blank";
+    waitForFocus(resolve, content, isBlank);
+  });;
 
   return tab.linkedBrowser.contentWindow.document;
 });
 
 function initDebuggerServer() {
   try {
     // Sometimes debugger server does not get destroyed correctly by previous
     // tests.
@@ -64,65 +62,62 @@ function initDebuggerServer() {
 
 /**
  * Connect a debugger client.
  * @param {DebuggerClient}
  * @return {Promise} Resolves to the selected tabActor form when the client is
  * connected.
  */
 function connectDebuggerClient(client) {
-  let def = promise.defer();
-  client.connect(() => {
-    client.listTabs(tabs => {
-      def.resolve(tabs.tabs[tabs.selected]);
+  return new Promise(resolve => {
+    client.connect(() => {
+      client.listTabs(tabs => {
+        resolve(tabs.tabs[tabs.selected]);
+      });
     });
   });
-  return def.promise;
 }
 
 /**
  * Close a debugger client's connection.
  * @param {DebuggerClient}
  * @return {Promise} Resolves when the connection is closed.
  */
 function closeDebuggerClient(client) {
-  let def = promise.defer();
-  client.close(def.resolve);
-  return def.promise;
+  return new Promise(resolve => client.close(resolve));
 }
 
 /**
  * Wait for eventName on target.
  * @param {Object} target An observable object that either supports on/off or
  * addEventListener/removeEventListener
  * @param {String} eventName
  * @param {Boolean} useCapture Optional, for addEventListener/removeEventListener
  * @return A promise that resolves when the event has been handled
  */
 function once(target, eventName, useCapture=false) {
   info("Waiting for event: '" + eventName + "' on " + target + ".");
 
-  let deferred = promise.defer();
+  return new Promise(resolve => {
 
-  for (let [add, remove] of [
-    ["addEventListener", "removeEventListener"],
-    ["addListener", "removeListener"],
-    ["on", "off"]
-  ]) {
-    if ((add in target) && (remove in target)) {
-      target[add](eventName, function onEvent(...aArgs) {
-        info("Got event: '" + eventName + "' on " + target + ".");
-        target[remove](eventName, onEvent, useCapture);
-        deferred.resolve.apply(deferred, aArgs);
-      }, useCapture);
-      break;
+    for (let [add, remove] of [
+      ["addEventListener", "removeEventListener"],
+      ["addListener", "removeListener"],
+      ["on", "off"]
+    ]) {
+      if ((add in target) && (remove in target)) {
+        target[add](eventName, function onEvent(...aArgs) {
+          info("Got event: '" + eventName + "' on " + target + ".");
+          target[remove](eventName, onEvent, useCapture);
+          resolve(...aArgs);
+        }, useCapture);
+        break;
+      }
     }
-  }
-
-  return deferred.promise;
+  });
 }
 
 /**
  * Forces GC, CC and Shrinking GC to get rid of disconnected docshells and
  * windows.
  */
 function forceCollections() {
   Cu.forceGC();