summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/mochitest/test_bug687194.html
blob: 8f99ea73a2a35de8a5a06c9b37cd419397097702 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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(SpecialPowers.wrapCallbackObject({
          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 = SpecialPowers.wrapCallbackObject({
        onUninstalled: function(removedAddon) {
          if (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>