Bug 1311459: Fix unsafe CPOW warnings in toolkit/mozapps/extensions/test/xpinstall. r?rhelmer draft
authorDave Townsend <dtownsend@oxymoronical.com>
Wed, 19 Oct 2016 11:31:57 -0700
changeset 427107 675e325439f6c8246f053846f91fc5a358f27738
parent 427065 12a9cca092f816fabb67cc8a139e0cbd5b1cea37
child 534382 325d219f2de3bd0881d528d2ce53e679823c67df
push id32924
push userdtownsend@mozilla.com
push dateWed, 19 Oct 2016 19:17:06 +0000
reviewersrhelmer
bugs1311459
milestone52.0a1
Bug 1311459: Fix unsafe CPOW warnings in toolkit/mozapps/extensions/test/xpinstall. r?rhelmer MozReview-Commit-ID: BX51ugGD54x
toolkit/mozapps/extensions/test/xpinstall/browser_amosigned_trigger.js
toolkit/mozapps/extensions/test/xpinstall/browser_amosigned_trigger_iframe.js
toolkit/mozapps/extensions/test/xpinstall/browser_badargs.js
toolkit/mozapps/extensions/test/xpinstall/browser_badargs2.js
toolkit/mozapps/extensions/test/xpinstall/browser_corrupt.js
toolkit/mozapps/extensions/test/xpinstall/browser_offline.js
toolkit/mozapps/extensions/test/xpinstall/browser_relative.js
toolkit/mozapps/extensions/test/xpinstall/browser_unsigned_trigger.js
toolkit/mozapps/extensions/test/xpinstall/browser_unsigned_trigger_iframe.js
toolkit/mozapps/extensions/test/xpinstall/browser_whitelist.js
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_amosigned_trigger.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_amosigned_trigger.js
@@ -31,20 +31,26 @@ function confirm_install(window) {
   is(items[0].signed, "false", "Should have listed the item as unsigned");
   return true;
 }
 
 function install_ended(install, addon) {
   install.cancel();
 }
 
-function finish_test(count) {
+const finish_test = Task.async(function*(count) {
   is(count, 1, "1 Add-on should have been successfully installed");
 
   Services.perms.remove(makeURI("http://example.com"), "install");
 
-  var doc = gBrowser.contentDocument;
-  is(doc.getElementById("return").textContent, "true", "installTrigger should have claimed success");
-  is(doc.getElementById("status").textContent, "0", "Callback should have seen a success");
+  const results = yield ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
+    return {
+      return: content.document.getElementById("return").textContent,
+      status: content.document.getElementById("status").textContent,
+    }
+  })
+
+  is(results.return, "true", "installTrigger should have claimed success");
+  is(results.status, "0", "Callback should have seen a success");
 
   gBrowser.removeCurrentTab();
   Harness.finish();
-}
+});
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_amosigned_trigger_iframe.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_amosigned_trigger_iframe.js
@@ -32,20 +32,26 @@ function confirm_install(window) {
   is(items[0].signed, "false", "Should have listed the item as unsigned");
   return true;
 }
 
 function install_ended(install, addon) {
   install.cancel();
 }
 
-function finish_test(count) {
+const finish_test = Task.async(function*(count) {
   is(count, 1, "1 Add-on should have been successfully installed");
 
   Services.perms.remove(makeURI("http://example.com"), "install");
 
-  var doc = gBrowser.contentWindow.frames[0].document; // Document of iframe
-  is(doc.getElementById("return").textContent, "true", "installTrigger in iframe should have claimed success");
-  is(doc.getElementById("status").textContent, "0", "Callback in iframe should have seen a success");
+  const results = yield ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
+    return {
+      return: content.frames[0].document.getElementById("return").textContent,
+      status: content.frames[0].document.getElementById("status").textContent,
+    }
+  })
+
+  is(results.return, "true", "installTrigger in iframe should have claimed success");
+  is(results.status, "0", "Callback in iframe should have seen a success");
 
   gBrowser.removeCurrentTab();
   Harness.finish();
-}
+});
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_badargs.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_badargs.js
@@ -2,34 +2,35 @@
 // Test whether passing a simple string to InstallTrigger.install throws an
 // exception
 function test() {
   waitForExplicitFinish();
 
   var triggers = encodeURIComponent(JSON.stringify(TESTROOT + "amosigned.xpi"));
   gBrowser.selectedTab = gBrowser.addTab();
 
-  function loadListener() {
-    gBrowser.selectedBrowser.removeEventListener("load", loadListener, true);
-    gBrowser.contentWindow.addEventListener("InstallTriggered", page_loaded, false);
-  }
-
-  gBrowser.selectedBrowser.addEventListener("load", loadListener, true);
+  ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
+    return new Promise(resolve => {
+      addEventListener("load", () => {
+        content.addEventListener("InstallTriggered", () => {
+          resolve(content.document.getElementById("return").textContent);
+        });
+      }, true);
+    });
+  }).then(page_loaded);
 
   // In non-e10s the exception in the content page would trigger a test failure
   if (!gMultiProcessBrowser)
     expectUncaughtException();
 
   gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
 }
 
-function page_loaded() {
-  gBrowser.contentWindow.removeEventListener("InstallTriggered", page_loaded, false);
-  var doc = gBrowser.contentDocument;
-  is(doc.getElementById("return").textContent, "exception", "installTrigger should have failed");
+function page_loaded(result) {
+  is(result, "exception", "installTrigger should have failed");
 
   // In non-e10s the exception from the page is thrown after the event so we
   // have to spin the event loop to make sure it arrives so expectUncaughtException
   // sees it.
   executeSoon(() => {
     gBrowser.removeCurrentTab();
     finish();
   });
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_badargs2.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_badargs2.js
@@ -6,34 +6,35 @@ function test() {
 
   var triggers = encodeURIComponent(JSON.stringify({
     "Unsigned XPI": {
       URL: undefined
     }
   }));
   gBrowser.selectedTab = gBrowser.addTab();
 
-  function loadListener() {
-    gBrowser.selectedBrowser.removeEventListener("load", loadListener, true);
-    gBrowser.contentWindow.addEventListener("InstallTriggered", page_loaded, false);
-  }
-
-  gBrowser.selectedBrowser.addEventListener("load", loadListener, true);
+  ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
+    return new Promise(resolve => {
+      addEventListener("load", () => {
+        content.addEventListener("InstallTriggered", () => {
+          resolve(content.document.getElementById("return").textContent);
+        });
+      }, true);
+    });
+  }).then(page_loaded);
 
   // In non-e10s the exception in the content page would trigger a test failure
   if (!gMultiProcessBrowser)
     expectUncaughtException();
 
   gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
 }
 
-function page_loaded() {
-  gBrowser.contentWindow.removeEventListener("InstallTriggered", page_loaded, false);
-  var doc = gBrowser.contentDocument;
-  is(doc.getElementById("return").textContent, "exception", "installTrigger should have failed");
+function page_loaded(result) {
+  is(result, "exception", "installTrigger should have failed");
 
   // In non-e10s the exception from the page is thrown after the event so we
   // have to spin the event loop to make sure it arrives so expectUncaughtException
   // sees it.
   executeSoon(() => {
     gBrowser.removeCurrentTab();
     finish();
   });
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_corrupt.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_corrupt.js
@@ -15,18 +15,24 @@ function test() {
   gBrowser.selectedTab = gBrowser.addTab();
   gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
 }
 
 function download_failed(install) {
   is(install.error, AddonManager.ERROR_CORRUPT_FILE, "Install should fail");
 }
 
-function finish_test(count) {
+const finish_test = Task.async(function*(count) {
   is(count, 0, "No add-ons should have been installed");
   Services.perms.remove(makeURI("http://example.com"), "install");
 
-  var doc = gBrowser.contentDocument;
-  is(doc.getElementById("status").textContent, "-207", "Callback should have seen the failure");
+  const results = yield ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
+    return {
+      return: content.document.getElementById("return").textContent,
+      status: content.document.getElementById("status").textContent,
+    }
+  })
+
+  is(results.status, "-207", "Callback should have seen the failure");
 
   gBrowser.removeCurrentTab();
   Harness.finish();
-}
+});
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_offline.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_offline.js
@@ -29,20 +29,20 @@ function download_progress(addon, value,
   }
 }
 
 function finish_test(count) {
   function wait_for_online() {
     info("Checking if the browser is still offline...");
 
     let tab = gBrowser.selectedTab;
-    ContentTask.spawn(tab.linkedBrowser, null, () => {
-      return ContentTaskUtils.waitForEvent(this, "DOMContentLoaded", true);
-    }).then(() => {
-      let url = tab.linkedBrowser.contentDocument.documentURI;
+    ContentTask.spawn(tab.linkedBrowser, null, function*() {
+      yield ContentTaskUtils.waitForEvent(this, "DOMContentLoaded", true);
+      return content.document.documentURI;
+    }).then(url => {
       info("loaded: " + url);
       if (/^about:neterror\?e=netOffline/.test(url)) {
         wait_for_online();
       } else {
         gBrowser.removeCurrentTab();
         Harness.finish();
       }
     });
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_relative.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_relative.js
@@ -30,20 +30,26 @@ function confirm_install(window) {
   is(items[0].signed, "false", "Should have listed the item as unsigned");
   return true;
 }
 
 function install_ended(install, addon) {
   install.cancel();
 }
 
-function finish_test(count) {
+const finish_test = Task.async(function*(count) {
   is(count, 1, "1 Add-on should have been successfully installed");
 
   Services.perms.remove(makeURI("http://example.com"), "install");
 
-  var doc = gBrowser.contentDocument;
-  is(doc.getElementById("return").textContent, "true", "installTrigger should have claimed success");
-  is(doc.getElementById("status").textContent, "0", "Callback should have seen a success");
+  const results = yield ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
+    return {
+      return: content.document.getElementById("return").textContent,
+      status: content.document.getElementById("status").textContent,
+    }
+  })
+
+  is(results.return, "true", "installTrigger should have claimed success");
+  is(results.status, "0", "Callback should have seen a success");
 
   gBrowser.removeCurrentTab();
   Harness.finish();
-}
+});
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_unsigned_trigger.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_unsigned_trigger.js
@@ -31,20 +31,26 @@ function confirm_install(window) {
   is(items[0].signed, "false", "Should have listed the item as unsigned");
   return true;
 }
 
 function install_ended(install, addon) {
   install.cancel();
 }
 
-function finish_test(count) {
+const finish_test = Task.async(function*(count) {
   is(count, 1, "1 Add-on should have been successfully installed");
 
   Services.perms.remove(makeURI("http://example.com"), "install");
 
-  var doc = gBrowser.contentDocument;
-  is(doc.getElementById("return").textContent, "true", "installTrigger should have claimed success");
-  is(doc.getElementById("status").textContent, "0", "Callback should have seen a success");
+  const results = yield ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
+    return {
+      return: content.document.getElementById("return").textContent,
+      status: content.document.getElementById("status").textContent,
+    }
+  })
+
+  is(results.return, "true", "installTrigger should have claimed success");
+  is(results.status, "0", "Callback should have seen a success");
 
   gBrowser.removeCurrentTab();
   Harness.finish();
-}
+});
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_unsigned_trigger_iframe.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_unsigned_trigger_iframe.js
@@ -32,20 +32,26 @@ function confirm_install(window) {
   is(items[0].signed, "false", "Should have listed the item as unsigned");
   return true;
 }
 
 function install_ended(install, addon) {
   install.cancel();
 }
 
-function finish_test(count) {
+const finish_test = Task.async(function*(count) {
   is(count, 1, "1 Add-on should have been successfully installed");
 
   Services.perms.remove(makeURI("http://example.com"), "install");
 
-  var doc = gBrowser.contentWindow.frames[0].document; // Document of iframe
-  is(doc.getElementById("return").textContent, "true", "installTrigger in iframe should have claimed success");
-  is(doc.getElementById("status").textContent, "0", "Callback in iframe should have seen a success");
+  const results = yield ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
+    return {
+      return: content.frames[0].document.getElementById("return").textContent,
+      status: content.frames[0].document.getElementById("status").textContent,
+    }
+  })
+
+  is(results.return, "true", "installTrigger in iframe should have claimed success");
+  is(results.status, "0", "Callback in iframe should have seen a success");
 
   gBrowser.removeCurrentTab();
   Harness.finish();
-}
+});
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_whitelist.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_whitelist.js
@@ -30,17 +30,24 @@ function confirm_install(window) {
   is(items[0].signed, "false", "Should have listed the item as unsigned");
   return true;
 }
 
 function install_ended(install, addon) {
   install.cancel();
 }
 
-function finish_test(count) {
+const finish_test = Task.async(function*(count) {
   is(count, 1, "1 Add-on should have been successfully installed");
 
-  var doc = gBrowser.contentDocument;
-  is(doc.getElementById("return").textContent, "false", "installTrigger should seen a failure");
+  const results = yield ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
+    return {
+      return: content.document.getElementById("return").textContent,
+      status: content.document.getElementById("status").textContent,
+    }
+  })
+
+  is(results.return, "false", "installTrigger should seen a failure");
+
   gBrowser.removeCurrentTab();
   Harness.finish();
-}
+});
 // ----------------------------------------------------------------------------