Bug 687194 - Basic test for chrome registration/unregistration. r=mossop
☠☠ backed out by fdf012084abd ☠ ☠
authorBlake Kaplan <mrbkap@gmail.com>
Tue, 05 Aug 2014 16:10:21 -0700
changeset 198073 1e2a00dc11cb0db6bcaa9fa845b88016152185d5
parent 198072 4e9cd601aa23b0a0546d5a83cd9d2a2f8db5b16a
child 198074 109af7e5adbf140644b16fab32ff934bbf0551e1
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmossop
bugs687194
milestone34.0a1
Bug 687194 - Basic test for chrome registration/unregistration. r=mossop
toolkit/mozapps/extensions/test/mochitest/file_bug687194.xpi
toolkit/mozapps/extensions/test/mochitest/mochitest.ini
toolkit/mozapps/extensions/test/mochitest/test_bug687194.html
new file mode 100644
index 0000000000000000000000000000000000000000..dfc03505336706dd9f6de4ec0dc43138d172e4e2
GIT binary patch
literal 1602
zc$^FHW@Zs#U|`^2FsuLLk}UfBhCU+$!+j<O1|9|(hNS%blH!u0!~(sn;?NLI24;)Z
z*MdQ~w1S&~k>x8;DOmU3iLu^Hjv{UE|BANnjdCm#Uc~RZB8<sVamzZTM;3C|JAY2F
z+}!5+fA3@W%*Gb;yF7>IJfB-B?^bzSkc(ATW6#`bcfF!zJVwIXv$Kq^*&n~<$`u@<
zoz&gamH7VMzn_UW#7zP>KhWL!sU~J>y7=?6r!U8B(0Dj!mb%XJo80O`^TPaG-^ym}
zWa;(X*exjC;Oz8m9p8KT>VT(wNu~_Wf?nARm8%7o9)EJ`mw7Hvn%$Jj%s&#ns%bhW
z7fm+ZGW%rkwquN5UCLbCYc+IBp6xKdvB3P`V;9BlqFAZJuX=O-lvbSeUcN15R?gF?
z`>vDQBs_BNJFzK-eg0qaB75a~4IZ<JbK3=bZ#PVH(|S?qQ-1$OgM`+v*xIn8o%N;l
zW%iqXUfjzZxqpG4WXvVT#?r6;0l+}#VgP~ZX@6Wie|$JB4`hQdKQPdfGm7$aQ}uEa
z^D@&?i%Y=aez*Qw@Vp+3a8J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
@@ -1,7 +1,9 @@
 [DEFAULT]
 skip-if = buildapp == 'b2g'
 support-files =
   file_empty.html
+  file_bug687194.xpi
 
 [test_bug609794.html]
+[test_bug687194.html]
 [test_bug887098.html]
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/mochitest/test_bug687194.html
@@ -0,0 +1,133 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for registering/unregistering chrome OOP</title>
+  <script type="application/javascript"
+          src="/tests/SimpleTest/SimpleTest.js">
+  </script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+  <script type="application/javascript;version=1.8">
+    "use strict";
+
+    SimpleTest.waitForExplicitFinish();
+
+    const childFrameURL =
+      "data:text/html,<!DOCTYPE HTML><html><body></body></html>";
+
+    function childFrameScript() {
+      "use strict";
+
+      var ios =
+          Components.classes["@mozilla.org/network/io-service;1"]
+                    .getService(Components.interfaces.nsIIOService);
+      let cr =
+          Components.classes["@mozilla.org/chrome/chrome-registry;1"]
+                    .getService(Ci.nsIXULChromeRegistry);
+      addMessageListener("test687194:resolveChromeURI", function(message) {
+        let result;
+        let threw = false;
+        try {
+            let uri = ios.newURI(message.data.URI, null, null);
+            result = cr.convertChromeURL(uri).spec;
+        } catch (e) {
+            threw = true;
+            result = "EXCEPTION: " + e;
+        }
+
+        message.target.sendAsyncMessage("test687194:resolveChromeURI:Answer",
+                                        { threw: threw, result: result });
+      });
+    }
+
+    let test;
+    function* testStructure(mm) {
+      let lastResult;
+
+      mm.addMessageListener("test687194:resolveChromeURI:Answer", function(msg) {
+        test.next(msg.data);
+      });
+
+      mm.sendAsyncMessage("test687194:resolveChromeURI",
+                          { URI: "chrome://bug687194/content/e10sbug.js" });
+      lastResult = yield;
+      is(lastResult.threw, true, "URI shouldn't resolve to begin with");
+
+      let { AddonManager } = SpecialPowers.Cu.import("resource://gre/modules/AddonManager.jsm", {});
+      const INSTALL_URI =
+        "http://mochi.test:8888/tests/toolkit/mozapps/extensions/test/mochitest/file_bug687194.xpi"
+      AddonManager.getInstallForURL(INSTALL_URI, (install) => {
+        install = SpecialPowers.wrap(install);
+        install.addListener({
+          onInstallEnded: function(install, addon) {
+            SimpleTest.executeSoon(() => test.next(addon));
+          }
+        });
+        install.install();
+      }, "application/x-xpinstall");
+
+      let addon = SpecialPowers.wrap(yield);
+
+      mm.sendAsyncMessage("test687194:resolveChromeURI",
+                          { URI: "chrome://bug687194/content/e10sbug.js" });
+      lastResult = yield;
+      is(lastResult.threw, false, "able to resolve after the installation");
+
+      let listener = {
+        onUninstalled: function(removedAddon) {
+          if (SpecialPowers.wrap(removedAddon).id === addon.id) {
+            AddonManager.removeAddonListener(listener);
+            SimpleTest.executeSoon(() => test.next());
+          }
+        }
+      };
+      AddonManager.addAddonListener(listener);
+      addon.uninstall();
+
+      yield;
+
+      mm.sendAsyncMessage("test687194:resolveChromeURI",
+                          { URI: "chrome://bug687194/content/e10sbug.js" });
+      lastResult = yield;
+      is(lastResult.threw, true, "should have unregistered the URI");
+      SimpleTest.finish();
+    }
+
+    function runTests() {
+      info("Browser prefs set.");
+
+      let iframe = document.createElement("iframe");
+      SpecialPowers.wrap(iframe).mozbrowser = true;
+      iframe.id = "iframe";
+      iframe.src = childFrameURL;
+
+      iframe.addEventListener("mozbrowserloadend", function() {
+        info("Got iframe load event.");
+        let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
+        mm.loadFrameScript("data:,(" + childFrameScript.toString() + ")();",
+                           false);
+
+        test = testStructure(mm);
+        test.next();
+      });
+
+      document.body.appendChild(iframe);
+    }
+
+    addEventListener("load", function() {
+      info("Got load event.");
+
+      SpecialPowers.addPermission("browser", true, document);
+      SpecialPowers.pushPrefEnv({
+        "set": [
+          ["dom.ipc.browser_frames.oop_by_default", true],
+          ["dom.mozBrowserFramesEnabled", true],
+          ["browser.pagethumbnails.capturing_disabled", true]
+        ]
+      }, runTests);
+    });
+  </script>
+</body>
+</html>