Bug 1273941 - do not Cu.import promises in devtools; r=jryans
authorTom Tromey <tom@tromey.com>
Thu, 09 Jun 2016 09:08:34 -0600
changeset 302463 6a0db3b0afcf0f7b41195d2cc725c0e472356323
parent 302462 bdea53872708d0cfcfdbbcd8c2b61724ade3e51f
child 302464 ed1226de3214d31b2a66927a71d02a343a902c62
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 - do not Cu.import promises in devtools; r=jryans MozReview-Commit-ID: 57DjVnER13e
devtools/client/performance/components/test/head.js
devtools/server/tests/mochitest/test_connectToChild.html
devtools/server/tests/mochitest/test_inspector-mutations-events.html
devtools/server/tests/mochitest/test_inspector-resize.html
devtools/server/tests/mochitest/test_inspector-search-front.html
devtools/server/tests/mochitest/test_inspector-search.html
--- a/devtools/client/performance/components/test/head.js
+++ b/devtools/client/performance/components/test/head.js
@@ -2,18 +2,18 @@
     yield new Promise(function(){});
    http://creativecommons.org/publicdomain/zero/1.0/ */
 "use strict";
 
 var { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
 
 var { require } = Cu.import("resource://gre/modules/devtools/shared/Loader.jsm", {});
 var { Assert } = require("resource://testing-common/Assert.jsm");
-var promise = require("promise");
 var { BrowserLoader } = Cu.import("resource://devtools/client/shared/browser-loader.js", {});
+var defer = require("devtools/shared/defer");
 var DevToolsUtils = require("devtools/shared/DevToolsUtils");
 var { Task } = require("devtools/shared/task");
 var { TargetFactory } = require("devtools/client/framework/target");
 var { Toolbox } = require("devtools/client/framework/toolbox");
 
 DevToolsUtils.testing = true;
 var { require: browserRequire } = BrowserLoader({
   baseURI: "resource://devtools/client/performance/",
@@ -33,23 +33,23 @@ SimpleTest.waitForExplicitFinish();
 
 function onNextAnimationFrame(fn) {
   return () =>
     requestAnimationFrame(() =>
       requestAnimationFrame(fn));
 }
 
 function setState(component, newState) {
-  var deferred = promise.defer();
+  var deferred = defer();
   component.setState(newState, onNextAnimationFrame(deferred.resolve));
   return deferred.promise;
 }
 
 function setProps(component, newState) {
-  var deferred = promise.defer();
+  var deferred = defer();
   component.setProps(newState, onNextAnimationFrame(deferred.resolve));
   return deferred.promise;
 }
 
 function dumpn(msg) {
   dump(`PERFORMANCE-COMPONENT-TEST: ${msg}\n`);
 }
 
--- a/devtools/server/tests/mochitest/test_connectToChild.html
+++ b/devtools/server/tests/mochitest/test_connectToChild.html
@@ -12,17 +12,17 @@ Bug 966991 - Test DebuggerServer.connect
 <body>
 <pre id="test">
 <script type="application/javascript;version=1.8">
 
 let Cu = Components.utils;
 let Cc = Components.classes;
 let Ci = Components.interfaces;
 
-let { require } = Cu.import("resource://devtools/shared/Loader.jsm");
+let { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
 let { DebuggerClient } = require("devtools/shared/client/main");
 let { DebuggerServer } = require("devtools/server/main");
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
 
   SpecialPowers.pushPrefEnv({
     "set": [
@@ -39,17 +39,17 @@ function runTests() {
   iframe.mozbrowser = true;
   document.body.appendChild(iframe);
 
   let mm = iframe.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager;
 
   // Register a test actor in the child process so that we can know if and when
   // this fake actor is disconnected.
   mm.loadFrameScript("data:text/javascript,new " + function FrameScriptScope() {
-    const { require } = Cu.import("resource://devtools/shared/Loader.jsm");
+    const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
     const { DebuggerServer } = require("devtools/server/main");
 
     if (!DebuggerServer.initialized) {
       DebuggerServer.init();
     }
 
     function TestActor() {dump("instanciate test actor\n");}
     TestActor.prototype = {
--- a/devtools/server/tests/mochitest/test_inspector-mutations-events.html
+++ b/devtools/server/tests/mochitest/test_inspector-mutations-events.html
@@ -9,19 +9,18 @@ https://bugzilla.mozilla.org/show_bug.cg
   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
   <script type="application/javascript;version=1.8" src="inspector-helpers.js"></script>
   <script type="application/javascript;version=1.8">
 
 window.onload = function() {
 
   const Cu = Components.utils;
-  Cu.import("resource://devtools/shared/Loader.jsm");
-  const {InspectorFront} =
-    devtools.require("devtools/shared/fronts/inspector");
+  const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
+  const {InspectorFront} = require("devtools/shared/fronts/inspector");
 
   SimpleTest.waitForExplicitFinish();
 
   let inspectee = null;
   let inspector = null;
   let walker = null;
   let eventListener1 = function () {};
   let eventListener2 = function () {};
--- a/devtools/server/tests/mochitest/test_inspector-resize.html
+++ b/devtools/server/tests/mochitest/test_inspector-resize.html
@@ -8,34 +8,32 @@ https://bugzilla.mozilla.org/show_bug.cg
   <meta charset="utf-8">
   <title>Test for Bug 1222409</title>
   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
   <script type="application/javascript;version=1.8" src="inspector-helpers.js"></script>
   <script type="application/javascript;version=1.8">
 window.onload = function() {
   const Cu = Components.utils;
-  Cu.import("resource://devtools/shared/Loader.jsm");
-  const {Promise: promise} =
-    Cu.import("resource://gre/modules/Promise.jsm", {});
-  const {InspectorFront} =
-    devtools.require("devtools/shared/fronts/inspector");
+  const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
+  const promise = require("promise");
+  const {InspectorFront} = require("devtools/shared/fronts/inspector");
   const {console} = Cu.import("resource://gre/modules/Console.jsm", {});
 
   SimpleTest.waitForExplicitFinish();
 
   let win = null;
   let inspector = null;
 
   addAsyncTest(function* setup() {
     info ("Setting up inspector and walker actors.");
 
     let url = document.getElementById("inspectorContent").href;
 
-    yield new Promise(resolve => {
+    yield new promise(resolve => {
       attachURL(url, function(err, client, tab, doc) {
         win = doc.defaultView;
         inspector = InspectorFront(client, tab);
         resolve();
       });
     });
 
     runNextTest();
@@ -44,17 +42,17 @@ window.onload = function() {
   addAsyncTest(function*() {
     let walker = yield inspector.getWalker();
 
     // We can't receive events from the walker if we haven't first executed a
     // method on the actor to initialize it.
     yield walker.querySelector(walker.rootNode, "img");
 
     let {outerWidth, outerHeight} = win;
-    let onResize = new Promise(resolve => {
+    let onResize = new promise(resolve => {
       walker.once("resize", () => {
         resolve();
       });
     });
     win.resizeTo(800, 600);
     yield onResize;
 
     ok(true, "The resize event was emitted");
--- a/devtools/server/tests/mochitest/test_inspector-search-front.html
+++ b/devtools/server/tests/mochitest/test_inspector-search-front.html
@@ -7,21 +7,19 @@ https://bugzilla.mozilla.org/show_bug.cg
   <meta charset="utf-8">
   <title>Test for Bug 835896</title>
   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
   <script type="application/javascript;version=1.8" src="inspector-helpers.js"></script>
   <script type="application/javascript;version=1.8">
 window.onload = function() {
   const Cu = Components.utils;
-  Cu.import("resource://devtools/shared/Loader.jsm");
-  const {Promise: promise} =
-    Cu.import("resource://gre/modules/Promise.jsm", {});
-  const {InspectorFront} =
-    devtools.require("devtools/shared/fronts/inspector");
+  const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
+  const promise = require("promise");
+  const {InspectorFront} = require("devtools/shared/fronts/inspector");
   const {console} = Cu.import("resource://gre/modules/Console.jsm", {});
 
   SimpleTest.waitForExplicitFinish();
 
   let walkerFront = null;
   let inspectee = null;
   let inspector = null;
 
@@ -30,17 +28,17 @@ window.onload = function() {
   // searches.
   // See also test_inspector-search.html
 
   addAsyncTest(function* setup() {
     info ("Setting up inspector and walker actors.");
 
     let url = document.getElementById("inspectorContent").href;
 
-    yield new Promise(resolve => {
+    yield new promise(resolve => {
       attachURL(url, function(err, client, tab, doc) {
         inspectee = doc;
         inspector = InspectorFront(client, tab);
         resolve();
       });
     });
 
     walkerFront = yield inspector.getWalker();
--- a/devtools/server/tests/mochitest/test_inspector-search.html
+++ b/devtools/server/tests/mochitest/test_inspector-search.html
@@ -7,23 +7,21 @@ https://bugzilla.mozilla.org/show_bug.cg
   <meta charset="utf-8">
   <title>Test for Bug 835896</title>
   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
   <script type="application/javascript;version=1.8" src="inspector-helpers.js"></script>
   <script type="application/javascript;version=1.8">
 window.onload = function() {
   const Cu = Components.utils;
-  Cu.import("resource://devtools/shared/Loader.jsm");
-  const {Promise: promise} =
-    Cu.import("resource://gre/modules/Promise.jsm", {});
-  const {InspectorFront} =
-    devtools.require("devtools/shared/fronts/inspector");
+  const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
+  const promise = require("promise");
+  const {InspectorFront} = require("devtools/shared/fronts/inspector");
   const {WalkerSearch, WalkerIndex} =
-    devtools.require("devtools/server/actors/utils/walker-search");
+    require("devtools/server/actors/utils/walker-search");
   const {console} = Cu.import("resource://gre/modules/Console.jsm", {});
 
   SimpleTest.waitForExplicitFinish();
 
   let walkerActor = null;
   let walkerSearch = null;
   let inspectee = null;
   let inspector = null;
@@ -32,17 +30,17 @@ window.onload = function() {
   // coming back as expected.
   // See also test_inspector-search-front.html.
 
   addAsyncTest(function* setup() {
     info ("Setting up inspector and walker actors.");
 
     let url = document.getElementById("inspectorContent").href;
 
-    yield new Promise(resolve => {
+    yield new promise(resolve => {
       attachURL(url, function(err, client, tab, doc) {
         inspectee = doc;
         inspector = InspectorFront(client, tab);
         resolve();
       });
     });
 
     let walkerFront = yield inspector.getWalker();
@@ -236,33 +234,33 @@ window.onload = function() {
     });
 
     results = walkerSearch.search("h3");
     isDeeply(results, [
       expected[1],
       expected[2]
     ], "Results are updated after removal");
 
-    yield new Promise(resolve => {
+    yield new promise(resolve => {
       info("Waiting for a mutation to happen");
       let observer = new inspectee.defaultView.MutationObserver(() => {
         resolve();
       });
       observer.observe(inspectee, {attributes: true, subtree: true});
       inspectee.body.setAttribute("h3", "true");
     });
 
     results = walkerSearch.search("h3");
     isDeeply(results, [
       {node: inspectee.body, type: "attributeName"},
       expected[1],
       expected[2]
     ], "Results are updated after addition");
 
-    yield new Promise(resolve => {
+    yield new promise(resolve => {
       info("Waiting for a mutation to happen");
       let observer = new inspectee.defaultView.MutationObserver(() => {
         resolve();
       });
       observer.observe(inspectee, {attributes: true, childList: true, subtree: true});
       inspectee.body.removeAttribute("h3");
       expected[1].node.remove();
       expected[2].node.remove();
@@ -272,17 +270,17 @@ window.onload = function() {
     is(results.length, 0, "Results are updated after removal");
 
     runNextTest();
   });
 
   runNextTest();
 
   function mutateDocumentAndWaitForMutation(mutationFn) {
-    return new Promise(resolve => {
+    return new promise(resolve => {
       info("Listening to markup mutation on the inspectee");
       let observer = new inspectee.defaultView.MutationObserver(resolve);
       observer.observe(inspectee, {childList: true, subtree: true});
       mutationFn();
     });
   }
 };
   </script>