Bug 1454202: Part 2d - Modernize other callback-based AOM UI tests. r=aswan
authorKris Maglione <maglione.k@gmail.com>
Sat, 21 Apr 2018 15:20:28 -0700
changeset 468491 4bb25432060f5e7d7c9bc174961a71c2ea207768
parent 468490 66883c7f740a513e414c00565123cc16355e9119
child 468492 0244913345d307219cf92d90addf2e3cd89348ed
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1454202
milestone61.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 1454202: Part 2d - Modernize other callback-based AOM UI tests. r=aswan MozReview-Commit-ID: KkygJwYZh3z
toolkit/mozapps/extensions/test/browser/browser_bug562797.js
toolkit/mozapps/extensions/test/browser/browser_discovery.js
--- a/toolkit/mozapps/extensions/test/browser/browser_bug562797.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug562797.js
@@ -30,32 +30,44 @@ var gProgressListener = {
   onProgressChange() { },
   onStatusChange() { },
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
                                          Ci.nsISupportsWeakReference]),
 };
 
 function waitForLoad(aManager, aCallback) {
-  var browser = aManager.document.getElementById("discover-browser");
-  browser.addProgressListener(gProgressListener);
+  let promise = new Promise(resolve => {
+    var browser = aManager.document.getElementById("discover-browser");
+    browser.addProgressListener(gProgressListener);
 
-  gLoadCompleteCallback = function() {
-    browser.removeProgressListener(gProgressListener);
-    aCallback();
-  };
+    gLoadCompleteCallback = function() {
+      browser.removeProgressListener(gProgressListener);
+      resolve();
+    };
+  });
+  if (aCallback) {
+    promise.then(aCallback);
+  }
+  return promise;
 }
 
 function clickLink(aManager, aId, aCallback) {
-  waitForLoad(aManager, aCallback);
+  let promise = new Promise(async resolve => {
+    waitForLoad(aManager, resolve);
+
+    var browser = aManager.document.getElementById("discover-browser");
 
-  var browser = aManager.document.getElementById("discover-browser");
-
-  var link = browser.contentDocument.getElementById(aId);
-  EventUtils.sendMouseEvent({type: "click"}, link);
+    var link = browser.contentDocument.getElementById(aId);
+    EventUtils.sendMouseEvent({type: "click"}, link);
+  });
+  if (aCallback) {
+    promise.then(aCallback);
+  }
+  return promise;
 }
 
 function test() {
   requestLongerTimeout(2);
 
   waitForExplicitFinish();
 
   Services.prefs.setCharPref(PREF_DISCOVERURL, MAIN_URL);
@@ -525,161 +537,161 @@ add_test(async function() {
 });
 
 // Tests that navigating the discovery page works when that was the first view
 add_test(async function() {
   let aManager = await open_manager("addons://discover/");
   info("1");
   is_in_discovery(aManager, MAIN_URL, false, false);
 
-  clickLink(aManager, "link-good", function() {
-    info("2");
-    is_in_discovery(aManager, SECOND_URL, true, false);
+  await clickLink(aManager, "link-good");
+  info("2");
+  is_in_discovery(aManager, SECOND_URL, true, false);
 
-    waitForLoad(aManager, function() {
-      info("3");
-      is_in_discovery(aManager, MAIN_URL, false, true);
+  // Execute go_back only after waitForLoad() has had a chance to setup
+  // its listeners.
+  executeSoon(go_back);
 
-      waitForLoad(aManager, async function() {
-        is_in_discovery(aManager, SECOND_URL, true, false);
-
-        EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-plugin"), { }, aManager);
+  await waitForLoad(aManager);
+  info("3");
+  is_in_discovery(aManager, MAIN_URL, false, true);
 
-        aManager = await wait_for_view_load(aManager);
-        is_in_list(aManager, "addons://list/plugin", true, false);
-
-        go_back();
+  // Execute go_forward only after waitForLoad() has had a chance to setup
+  // its listeners.
+  executeSoon(go_forward);
 
-        aManager = await wait_for_view_load(aManager);
-        is_in_discovery(aManager, SECOND_URL, true, true);
+  await waitForLoad(aManager);
+  is_in_discovery(aManager, SECOND_URL, true, false);
+
+  EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-plugin"), { }, aManager);
 
-        go_back();
+  aManager = await wait_for_view_load(aManager);
+  is_in_list(aManager, "addons://list/plugin", true, false);
 
-        waitForLoad(aManager, function() {
-          is_in_discovery(aManager, MAIN_URL, false, true);
+  go_back();
 
-          close_manager(aManager, run_next_test);
-        });
-      });
+  aManager = await wait_for_view_load(aManager);
+  is_in_discovery(aManager, SECOND_URL, true, true);
+
+  go_back();
 
-      go_forward();
-    });
+  await waitForLoad(aManager);
+  is_in_discovery(aManager, MAIN_URL, false, true);
 
-    go_back();
-  });
+  close_manager(aManager, run_next_test);
 });
 
 // Tests that navigating the discovery page works when that was the second view
 add_test(async function() {
   let aManager = await open_manager("addons://list/plugin");
   is_in_list(aManager, "addons://list/plugin", false, false);
 
   EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-discover"), { }, aManager);
 
   aManager = await wait_for_view_load(aManager);
   is_in_discovery(aManager, MAIN_URL, true, false);
 
-  clickLink(aManager, "link-good", function() {
-    is_in_discovery(aManager, SECOND_URL, true, false);
+  await clickLink(aManager, "link-good");
+  is_in_discovery(aManager, SECOND_URL, true, false);
 
-    waitForLoad(aManager, function() {
-      is_in_discovery(aManager, MAIN_URL, true, true);
+  // Execute go_back only after waitForLoad() has had a chance to setup
+  // its listeners.
+  executeSoon(go_back);
 
-      waitForLoad(aManager, async function() {
-        is_in_discovery(aManager, SECOND_URL, true, false);
-
-        EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-plugin"), { }, aManager);
+  await waitForLoad(aManager);
+  is_in_discovery(aManager, MAIN_URL, true, true);
 
-        aManager = await wait_for_view_load(aManager);
-        is_in_list(aManager, "addons://list/plugin", true, false);
+  // Execute go_forward only after waitForLoad() has had a chance to setup
+  // its listeners.
+  executeSoon(go_forward);
 
-        go_back();
+  await waitForLoad(aManager);
+  is_in_discovery(aManager, SECOND_URL, true, false);
 
-        aManager = await wait_for_view_load(aManager);
-        is_in_discovery(aManager, SECOND_URL, true, true);
+  EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-plugin"), { }, aManager);
 
-        go_back();
+  aManager = await wait_for_view_load(aManager);
+  is_in_list(aManager, "addons://list/plugin", true, false);
 
-        waitForLoad(aManager, async function() {
-          is_in_discovery(aManager, MAIN_URL, true, true);
+  go_back();
 
-          go_back();
+  aManager = await wait_for_view_load(aManager);
+  is_in_discovery(aManager, SECOND_URL, true, true);
 
-          aManager = await wait_for_view_load(aManager);
-          is_in_list(aManager, "addons://list/plugin", false, true);
+  go_back();
 
-          go_forward();
+  await waitForLoad(aManager);
+  is_in_discovery(aManager, MAIN_URL, true, true);
 
-          aManager = await wait_for_view_load(aManager);
-          is_in_discovery(aManager, MAIN_URL, true, true);
+  go_back();
 
-          waitForLoad(aManager, function() {
-            is_in_discovery(aManager, SECOND_URL, true, true);
+  aManager = await wait_for_view_load(aManager);
+  is_in_list(aManager, "addons://list/plugin", false, true);
 
-            close_manager(aManager, run_next_test);
-          });
+  go_forward();
+
+  aManager = await wait_for_view_load(aManager);
+  is_in_discovery(aManager, MAIN_URL, true, true);
 
-          go_forward();
-        });
-      });
+  // Execute go_forward only after waitForLoad() has had a chance to setup
+  // its listeners.
+  executeSoon(go_forward);
 
-      go_forward();
-    });
+  await waitForLoad(aManager);
+  is_in_discovery(aManager, SECOND_URL, true, true);
 
-    go_back();
-  });
+  close_manager(aManager, run_next_test);
 });
 
 // Tests that refreshing the disicovery pane integrates properly with history
 add_test(async function() {
   let aManager = await open_manager("addons://list/plugin");
   is_in_list(aManager, "addons://list/plugin", false, false);
 
   EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-discover"), { }, aManager);
 
   aManager = await wait_for_view_load(aManager);
   is_in_discovery(aManager, MAIN_URL, true, false);
 
-  clickLink(aManager, "link-good", function() {
-    is_in_discovery(aManager, SECOND_URL, true, false);
+  await clickLink(aManager, "link-good");
+  is_in_discovery(aManager, SECOND_URL, true, false);
 
-    EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-discover"), { }, aManager);
+  EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-discover"), { }, aManager);
 
-    waitForLoad(aManager, function() {
-      is_in_discovery(aManager, MAIN_URL, true, false);
+  await waitForLoad(aManager);
+  is_in_discovery(aManager, MAIN_URL, true, false);
 
-      go_back();
+  go_back();
 
-      waitForLoad(aManager, function() {
-        is_in_discovery(aManager, SECOND_URL, true, true);
+  await waitForLoad(aManager);
+  is_in_discovery(aManager, SECOND_URL, true, true);
 
-        go_back();
+  go_back();
 
-        waitForLoad(aManager, async function() {
-          is_in_discovery(aManager, MAIN_URL, true, true);
+  await waitForLoad(aManager);
+  is_in_discovery(aManager, MAIN_URL, true, true);
 
-          go_back();
-
-          aManager = await wait_for_view_load(aManager);
-          is_in_list(aManager, "addons://list/plugin", false, true);
+  go_back();
 
-          go_forward();
+  aManager = await wait_for_view_load(aManager);
+  is_in_list(aManager, "addons://list/plugin", false, true);
 
-          aManager = await wait_for_view_load(aManager);
-          is_in_discovery(aManager, MAIN_URL, true, true);
+  go_forward();
 
-          waitForLoad(aManager, function() {
-            is_in_discovery(aManager, SECOND_URL, true, true);
+  aManager = await wait_for_view_load(aManager);
+  is_in_discovery(aManager, MAIN_URL, true, true);
 
-            waitForLoad(aManager, function() {
-              is_in_discovery(aManager, MAIN_URL, true, false);
+  // Execute go_forward only after waitForLoad() has had a chance to setup
+  // its listeners.
+  executeSoon(go_forward);
 
-              close_manager(aManager, run_next_test);
-            });
-            go_forward();
-          });
+  await waitForLoad(aManager);
+  is_in_discovery(aManager, SECOND_URL, true, true);
 
-          go_forward();
-        });
-      });
-    });
-  });
+  // Execute go_forward only after waitForLoad() has had a chance to setup
+  // its listeners.
+  executeSoon(go_forward);
+
+  await waitForLoad(aManager);
+  is_in_discovery(aManager, MAIN_URL, true, false);
+
+  close_manager(aManager, run_next_test);
 });
--- a/toolkit/mozapps/extensions/test/browser/browser_discovery.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_discovery.js
@@ -158,30 +158,36 @@ function isLoading() {
 }
 
 function isError() {
   return gManagerWindow.document.getElementById("discover-view").selectedPanel ==
          gManagerWindow.document.getElementById("discover-error");
 }
 
 function clickLink(aId, aCallback) {
-  var browser = gManagerWindow.document.getElementById("discover-browser");
-  browser.addProgressListener(gProgressListener);
+  let promise = new Promise(resolve => {
+    var browser = gManagerWindow.document.getElementById("discover-browser");
+    browser.addProgressListener(gProgressListener);
+
+    gLoadCompleteCallback = function() {
+      browser.removeProgressListener(gProgressListener);
+      resolve();
+    };
 
-  gLoadCompleteCallback = function() {
-    browser.removeProgressListener(gProgressListener);
-    aCallback();
-  };
+    var link = browser.contentDocument.getElementById(aId);
+    EventUtils.sendMouseEvent({type: "click"}, link);
 
-  var link = browser.contentDocument.getElementById(aId);
-  EventUtils.sendMouseEvent({type: "click"}, link);
-
-  executeSoon(function() {
-    ok(isLoading(), "Clicking a link should show the loading pane");
+    executeSoon(function() {
+      ok(isLoading(), "Clicking a link should show the loading pane");
+    });
   });
+  if (aCallback) {
+    promise.then(aCallback);
+  }
+  return promise;
 }
 
 // Tests that switching to the discovery view displays the right url
 add_test(async function() {
   let aWindow = await open_manager("addons://list/extension");
   gManagerWindow = aWindow;
   gCategoryUtilities = new CategoryUtilities(gManagerWindow);
 
@@ -295,85 +301,81 @@ add_test(async function() {
 add_test(async function() {
   let aWindow = await open_manager("addons://discover/");
   gManagerWindow = aWindow;
   gCategoryUtilities = new CategoryUtilities(gManagerWindow);
 
   var browser = gManagerWindow.document.getElementById("discover-browser");
   is(getURL(browser), MAIN_URL, "Should have loaded the right url");
 
-  clickLink("link-http", async function() {
-    ok(isError(), "Should have shown the error page");
+  await clickLink("link-http");
+  ok(isError(), "Should have shown the error page");
 
-    await gCategoryUtilities.openType("extension");
-    await gCategoryUtilities.openType("discover");
-    is(getURL(browser), MAIN_URL, "Should have loaded the right url");
+  await gCategoryUtilities.openType("extension");
+  await gCategoryUtilities.openType("discover");
+  is(getURL(browser), MAIN_URL, "Should have loaded the right url");
 
-    close_manager(gManagerWindow, run_next_test);
-  });
+  close_manager(gManagerWindow, run_next_test);
 });
 
 // Tests that navigating to a different domain fails
 add_test(async function() {
   let aWindow = await open_manager("addons://discover/");
   gManagerWindow = aWindow;
   gCategoryUtilities = new CategoryUtilities(gManagerWindow);
 
   var browser = gManagerWindow.document.getElementById("discover-browser");
   is(getURL(browser), MAIN_URL, "Should have loaded the right url");
 
-  clickLink("link-domain", async function() {
-    ok(isError(), "Should have shown the error page");
+  await clickLink("link-domain");
+  ok(isError(), "Should have shown the error page");
 
-    await gCategoryUtilities.openType("extension");
-    await gCategoryUtilities.openType("discover");
-    is(getURL(browser), MAIN_URL, "Should have loaded the right url");
+  await gCategoryUtilities.openType("extension");
+  await gCategoryUtilities.openType("discover");
+  is(getURL(browser), MAIN_URL, "Should have loaded the right url");
 
-    close_manager(gManagerWindow, run_next_test);
-  });
+  close_manager(gManagerWindow, run_next_test);
 });
 
 // Tests that navigating to a missing page fails
 add_test(async function() {
   let aWindow = await open_manager("addons://discover/");
   gManagerWindow = aWindow;
   gCategoryUtilities = new CategoryUtilities(gManagerWindow);
 
   var browser = gManagerWindow.document.getElementById("discover-browser");
   is(getURL(browser), MAIN_URL, "Should have loaded the right url");
 
-  clickLink("link-bad", async function() {
-    ok(isError(), "Should have shown the error page");
+  await clickLink("link-bad");
+  ok(isError(), "Should have shown the error page");
 
-    await gCategoryUtilities.openType("extension");
-    await gCategoryUtilities.openType("discover");
-    is(getURL(browser), MAIN_URL, "Should have loaded the right url");
+  await gCategoryUtilities.openType("extension");
+  await gCategoryUtilities.openType("discover");
+  is(getURL(browser), MAIN_URL, "Should have loaded the right url");
 
-    close_manager(gManagerWindow, run_next_test);
-  });
+  close_manager(gManagerWindow, run_next_test);
 });
 
 // Tests that navigating to a page on the same domain works
 add_test(async function() {
   let aWindow = await open_manager("addons://discover/");
   gManagerWindow = aWindow;
   gCategoryUtilities = new CategoryUtilities(gManagerWindow);
 
   var browser = gManagerWindow.document.getElementById("discover-browser");
   is(getURL(browser), MAIN_URL, "Should have loaded the right url");
 
-  clickLink("link-good", async function() {
-    is(getURL(browser), "https://example.com/" + RELATIVE_DIR + "releaseNotes.xhtml", "Should have loaded the right url");
+  await clickLink("link-good");
+  is(getURL(browser), "https://example.com/" + RELATIVE_DIR + "releaseNotes.xhtml", "Should have loaded the right url");
 
-    await gCategoryUtilities.openType("extension");
-    await gCategoryUtilities.openType("discover");
-    is(getURL(browser), MAIN_URL, "Should have loaded the right url");
+  await gCategoryUtilities.openType("extension");
+  await gCategoryUtilities.openType("discover");
+  is(getURL(browser), MAIN_URL, "Should have loaded the right url");
 
-    close_manager(gManagerWindow, run_next_test);
-  });
+  close_manager(gManagerWindow, run_next_test);
 });
 
 // Tests repeated navigation to the same page followed by a navigation to a
 // different domain
 add_test(async function() {
   let aWindow = await open_manager("addons://discover/");
   gManagerWindow = aWindow;
   gCategoryUtilities = new CategoryUtilities(gManagerWindow);
@@ -384,52 +386,49 @@ add_test(async function() {
   var count = 10;
   function clickAgain(aCallback) {
     if (count-- == 0)
       aCallback();
     else
       clickLink("link-normal", clickAgain.bind(null, aCallback));
   }
 
-  clickAgain(function() {
+  clickAgain(async function() {
     is(getURL(browser), MAIN_URL, "Should have loaded the right url");
 
-    clickLink("link-domain", async function() {
-      ok(isError(), "Should have shown the error page");
+    await clickLink("link-domain");
+    ok(isError(), "Should have shown the error page");
 
-      await gCategoryUtilities.openType("extension");
-      await gCategoryUtilities.openType("discover");
-      is(getURL(browser), MAIN_URL, "Should have loaded the right url");
+    await gCategoryUtilities.openType("extension");
+    await gCategoryUtilities.openType("discover");
+    is(getURL(browser), MAIN_URL, "Should have loaded the right url");
 
-      close_manager(gManagerWindow, run_next_test);
-    });
+    close_manager(gManagerWindow, run_next_test);
   });
 });
 
 // Loading an insecure main page should work if that is what the prefs say, should
 // also be able to navigate to a https page and back again
 add_test(async function() {
   Services.prefs.setCharPref(PREF_DISCOVERURL, TESTROOT + "discovery.html");
 
   let aWindow = await open_manager("addons://discover/");
   gManagerWindow = aWindow;
   gCategoryUtilities = new CategoryUtilities(gManagerWindow);
 
   var browser = gManagerWindow.document.getElementById("discover-browser");
   is(getURL(browser), TESTROOT + "discovery.html", "Should have loaded the right url");
 
-  clickLink("link-normal", function() {
-    is(getURL(browser), MAIN_URL, "Should have loaded the right url");
+  await clickLink("link-normal");
+  is(getURL(browser), MAIN_URL, "Should have loaded the right url");
 
-    clickLink("link-http", function() {
-      is(getURL(browser), TESTROOT + "discovery.html", "Should have loaded the right url");
+  await clickLink("link-http");
+  is(getURL(browser), TESTROOT + "discovery.html", "Should have loaded the right url");
 
-      close_manager(gManagerWindow, run_next_test);
-    });
-  });
+  close_manager(gManagerWindow, run_next_test);
 });
 
 // Stopping the initial load should display the error page and then correctly
 // reload when switching away and back again
 add_test(async function() {
   Services.prefs.setCharPref(PREF_DISCOVERURL, MAIN_URL);
 
   let aWindow = await open_manager("addons://list/extension");