Bug 1602318 - Make xpihandler tests wait for load before starting the test. r=kmag
authorMatt Woodrow <mwoodrow@mozilla.com>
Sun, 26 Apr 2020 00:51:48 +0000
changeset 526106 34931634acb78a051ecd2ea115b9ad3d07531e44
parent 526105 bf51916fa039c4dc2955116e149a8829fe98210d
child 526107 ab3a2afede33ffede263b0d3d779d619ab869aff
push id37350
push usernbeleuzu@mozilla.com
push dateSun, 26 Apr 2020 09:43:12 +0000
treeherdermozilla-central@21659f178a12 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1602318
milestone77.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 1602318 - Make xpihandler tests wait for load before starting the test. r=kmag Differential Revision: https://phabricator.services.mozilla.com/D70623
toolkit/mozapps/extensions/test/xpinstall/browser_datauri.js
toolkit/mozapps/extensions/test/xpinstall/browser_enabled.js
toolkit/mozapps/extensions/test/xpinstall/browser_enabled2.js
toolkit/mozapps/extensions/test/xpinstall/browser_enabled3.js
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_datauri.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_datauri.js
@@ -41,18 +41,20 @@ function runTest() {
 
   setup_redirect({
     Location:
       "data:text/html,<script>window.location.href='" +
       TESTROOT +
       "amosigned.xpi'</script>",
   });
 
-  gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
-  BrowserTestUtils.loadURI(gBrowser, TESTROOT + "redirect.sjs?mode=redirect");
+  BrowserTestUtils.openNewForegroundTab(
+    gBrowser,
+    TESTROOT + "redirect.sjs?mode=redirect"
+  );
 }
 
 function install_blocked(installInfo) {
   is(
     installInfo.installs.length,
     1,
     "Got one AddonInstall instance as expected"
   );
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_enabled.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_enabled.js
@@ -1,16 +1,14 @@
 // ----------------------------------------------------------------------------
 // Test whether an InstallTrigger.enabled is working
-function test() {
-  waitForExplicitFinish();
+add_task(async function test() {
+  await BrowserTestUtils.openNewForegroundTab(gBrowser, TESTROOT);
 
-  gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, TESTROOT);
-
-  ContentTask.spawn(
+  let text = await ContentTask.spawn(
     gBrowser.selectedBrowser,
     TESTROOT + "enabled.html",
     function(url) {
       return new Promise(resolve => {
         function page_loaded() {
           content.removeEventListener("PageLoaded", page_loaded);
           resolve(content.document.getElementById("enabled").textContent);
         }
@@ -20,14 +18,13 @@ function test() {
           content.addEventListener("PageLoaded", page_loaded);
         }
 
         addEventListener("load", load_listener, true);
 
         content.location.href = url;
       });
     }
-  ).then(text => {
-    is(text, "true", "installTrigger should have been enabled");
-    gBrowser.removeCurrentTab();
-    finish();
-  });
-}
+  );
+
+  is(text, "true", "installTrigger should have been enabled");
+  gBrowser.removeCurrentTab();
+});
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_enabled2.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_enabled2.js
@@ -1,16 +1,18 @@
 // ----------------------------------------------------------------------------
 // Test whether an InstallTrigger.enabled is working
-function test() {
+async function test() {
   waitForExplicitFinish();
 
   Services.prefs.setBoolPref("xpinstall.enabled", false);
 
-  gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, TESTROOT);
+  let tab = BrowserTestUtils.addTab(gBrowser, TESTROOT);
+  gBrowser.selectedTab = tab;
+  await BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, TESTROOT);
 
   ContentTask.spawn(
     gBrowser.selectedBrowser,
     TESTROOT + "enabled.html",
     function(url) {
       return new Promise(resolve => {
         function page_loaded() {
           content.removeEventListener("PageLoaded", page_loaded);
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_enabled3.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_enabled3.js
@@ -1,24 +1,26 @@
 // ----------------------------------------------------------------------------
 // Test whether an InstallTrigger.install call fails when xpinstall is disabled
-function test() {
+async function test() {
   Harness.installDisabledCallback = install_disabled;
   Harness.installBlockedCallback = allow_blocked;
   Harness.installConfirmCallback = confirm_install;
   Harness.setup();
 
   Services.prefs.setBoolPref("xpinstall.enabled", false);
 
   var triggers = encodeURIComponent(
     JSON.stringify({
       "Unsigned XPI": TESTROOT + "amosigned.xpi",
     })
   );
-  gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, TESTROOT);
+  let tab = BrowserTestUtils.addTab(gBrowser, TESTROOT);
+  gBrowser.selectedTab = tab;
+  await BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, TESTROOT);
 
   ContentTask.spawn(
     gBrowser.selectedBrowser,
     TESTROOT + "installtrigger.html?" + triggers,
     url => {
       return new Promise(resolve => {
         function page_loaded() {
           content.removeEventListener("PageLoaded", page_loaded);