Backed out changeset 9d8b4c0b99ed (bug 1945683) for causing btime failures. CLOSED...
[gecko.git] / dom / tests / browser / browser_windowProxy_transplant.js
blob10cd96c9ee014abdf20c536239f7e3b949fb95d7
1 "use strict";
3 const DIRPATH = getRootDirectory(gTestPath).replace(
4 "chrome://mochitests/content/",
5 ""
6 );
7 const PATH = DIRPATH + "file_postMessage_parent.html";
9 const URL1 = `http://mochi.test:8888/${PATH}`;
10 const URL2 = `http://example.com/${PATH}`;
11 const URL3 = `http://example.org/${PATH}`;
13 // A bunch of boilerplate which needs to be dealt with.
14 add_task(async function () {
15 // Open a window with fission force-enabled in it.
16 let win = await BrowserTestUtils.openNewBrowserWindow({
17 fission: true,
18 remote: true,
19 });
20 try {
21 // Get the tab & browser to perform the test in.
22 let tab = win.gBrowser.selectedTab;
23 let browser = tab.linkedBrowser;
25 // Start loading the original URI, then wait until it is loaded.
26 BrowserTestUtils.startLoadingURIString(browser, URL1);
27 await BrowserTestUtils.browserLoaded(browser, false, URL1);
29 info("Chrome script has loaded initial URI.");
30 await SpecialPowers.spawn(
31 browser,
32 [{ URL1, URL2, URL3 }],
33 async ({ URL1, URL2, URL3 }) => {
34 let iframe = content.document.createElement("iframe");
35 content.document.body.appendChild(iframe);
37 info("Chrome script created iframe");
39 // Here and below, we have to store references to things in the
40 // iframes on the content window, because all chrome references
41 // to content will be turned into dead wrappers when the iframes
42 // are closed.
43 content.win0 = iframe.contentWindow;
44 content.bc0 = iframe.browsingContext;
46 ok(
47 !Cu.isDeadWrapper(content.win0),
48 "win0 shouldn't be a dead wrapper before navigation"
51 // Helper for waiting for a load.
52 function waitLoad() {
53 return new Promise(resolve => {
54 iframe.addEventListener(
55 "load",
56 () => {
57 info("Got an iframe load event!");
58 resolve();
60 { once: true }
62 });
65 function askLoad(url) {
66 info("Chrome script asking for load of " + url);
67 iframe.contentWindow.postMessage(
69 action: "navigate",
70 location: url,
72 "*"
74 info("Chrome script done calling PostMessage");
77 // Check that BC and WindowProxy are preserved across navigations.
78 iframe.contentWindow.location = URL1;
79 await waitLoad();
81 content.win1 = iframe.contentWindow;
82 let chromeWin1 = iframe.contentWindow;
83 let chromeWin1x = Cu.waiveXrays(iframe.contentWindow);
84 content.win1x = Cu.waiveXrays(iframe.contentWindow);
86 Assert.notEqual(
87 chromeWin1,
88 chromeWin1x,
89 "waiving xrays creates a new thing?"
92 content.bc1 = iframe.browsingContext;
94 is(
95 content.bc0,
96 content.bc1,
97 "same to same-origin BrowsingContext match"
99 is(content.win0, content.win1, "same to same-origin WindowProxy match");
102 !Cu.isDeadWrapper(content.win1),
103 "win1 shouldn't be a dead wrapper before navigation"
106 !Cu.isDeadWrapper(chromeWin1),
107 "chromeWin1 shouldn't be a dead wrapper before navigation"
110 askLoad(URL2);
111 await waitLoad();
113 content.win2 = iframe.contentWindow;
114 content.bc2 = iframe.browsingContext;
116 // When chrome accesses a remote window proxy in content, the result
117 // should be a remote outer window proxy in the chrome compartment, not an
118 // Xray wrapper around the content remote window proxy. The former will
119 // throw a security error, because @@toPrimitive can't be called cross
120 // process, while the latter will result in an opaque wrapper, because
121 // XPConnect doesn't know what to do when trying to create an Xray wrapper
122 // around a remote outer window proxy. See bug 1556845.
123 Assert.throws(
124 () => {
125 dump("content.win1 " + content.win1 + "\n");
127 /SecurityError: Permission denied to access property Symbol.toPrimitive on cross-origin object/,
128 "Should get a remote outer window proxy when accessing old window proxy"
130 Assert.throws(
131 () => {
132 dump("content.win2 " + content.win2 + "\n");
134 /SecurityError: Permission denied to access property Symbol.toPrimitive on cross-origin object/,
135 "Should get a remote outer window proxy when accessing new window proxy"
138 // If we fail to transplant existing non-remote outer window proxies, then
139 // after we navigate the iframe existing chrome references to the window will
140 // become dead wrappers. Also check content.win1 for thoroughness, though
141 // we don't nuke content-content references.
143 !Cu.isDeadWrapper(content.win1),
144 "win1 shouldn't be a dead wrapper after navigation"
147 !Cu.isDeadWrapper(chromeWin1),
148 "chromeWin1 shouldn't be a dead wrapper after navigation"
151 Cu.isDeadWrapper(chromeWin1x),
152 "chromeWin1x should be a dead wrapper after navigation"
155 Cu.isDeadWrapper(content.win1x),
156 "content.win1x should be a dead wrapper after navigation"
160 content.bc1,
161 content.bc2,
162 "same to cross-origin navigation BrowsingContext match"
165 content.win1,
166 content.win2,
167 "same to cross-origin navigation WindowProxy match"
171 !Cu.isDeadWrapper(content.win1),
172 "win1 shouldn't be a dead wrapper after navigation"
175 askLoad(URL3);
176 await waitLoad();
178 content.win3 = iframe.contentWindow;
179 content.bc3 = iframe.browsingContext;
182 content.bc2,
183 content.bc3,
184 "cross to cross-origin navigation BrowsingContext match"
187 content.win2,
188 content.win3,
189 "cross to cross-origin navigation WindowProxy match"
192 askLoad(URL1);
193 await waitLoad();
195 content.win4 = iframe.contentWindow;
196 content.bc4 = iframe.browsingContext;
199 content.bc3,
200 content.bc4,
201 "cross to same-origin navigation BrowsingContext match"
204 content.win3,
205 content.win4,
206 "cross to same-origin navigation WindowProxy match"
210 } finally {
211 await BrowserTestUtils.closeWindow(win);