Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
1 /* Any copyright is dedicated to the public domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 // Bug 776129 - If a window w calls window.open, the resultant window should be
5 // remote iff w is remote.
6 //
7 // <iframe mozbrowser> can be default-OOP or default-in-process. But we can
8 // override this default by setting remote=true or remote=false on the iframe.
9 //
10 // This bug arises when we are default-in-process and a OOP iframe calls
11 // window.open, or when we're default-OOP and an in-process iframe calls
12 // window.open. In either case, if the opened iframe gets the default
13 // remotness, it will not match its opener's remoteness, which is bad.
14 //
15 // Since the name of the test determines the OOP-by-default pref, the "inproc"
16 // version of this test opens an OOP frame, and the "oop" version opens an
17 // in-process frame. Enjoy. :)
19 "use strict";
21 SimpleTest.waitForExplicitFinish();
22 browserElementTestHelpers.setEnabledPref(true);
23 browserElementTestHelpers.addPermission();
25 function runTest() {
26 // We're going to open a remote frame if OOP off by default. If OOP is on by
27 // default, we're going to open an in-process frame.
28 var remote = !browserElementTestHelpers.getOOPByDefaultPref();
30 var iframe = document.createElement('iframe');
31 SpecialPowers.wrap(iframe).mozbrowser = true;
32 iframe.setAttribute('remote', remote);
34 // The page we load does window.open, then checks some things and reports
35 // back using alert(). Finally, it calls alert('finish').
36 //
37 // Bug 776129 in particular manifests itself such that the popup frame loads
38 // and the tests in file_browserElement_OpenMixedProcess pass, but the
39 // content of the frame is invisible. To catch this case, we take a
40 // screenshot after we load the content into the popup, and ensure that it's
41 // not blank.
42 var popup;
43 iframe.addEventListener('mozbrowseropenwindow', function(e) {
44 popup = document.body.appendChild(e.detail.frameElement);
45 });
47 iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
48 if (e.detail.message.startsWith('pass')) {
49 ok(true, e.detail.message);
50 }
51 else if (e.detail.message.startsWith('fail')) {
52 ok(false, e.detail.message);
53 }
54 else if (e.detail.message == 'finish') {
55 // We assume here that iframe is completely blank, and spin until popup's
56 // screenshot is not the same as iframe.
57 iframe.getScreenshot(1000, 1000).onsuccess = function(e) {
58 var fr = new FileReader();
59 fr.onloadend = function() { test2(popup, fr.result); };
60 fr.readAsArrayBuffer(e.target.result);
61 };
62 }
63 else {
64 ok(false, e.detail.message, "Unexpected message!");
65 }
66 });
68 document.body.appendChild(iframe);
69 iframe.src = 'file_browserElement_OpenMixedProcess.html';
70 }
72 function arrayBuffersEqual(a, b) {
73 var x = new Int8Array(a);
74 var y = new Int8Array(b);
75 if (x.length != y.length) {
76 return false;
77 }
79 for (var i = 0; i < x.length; i++) {
80 if (x[i] != y[i]) {
81 return false;
82 }
83 }
85 return true;
86 }
88 function test2(popup, blankScreenshotArrayBuffer) {
89 // Take screenshots of popup until it doesn't equal blankScreenshot (or we
90 // time out).
91 popup.getScreenshot(1000, 1000).onsuccess = function(e) {
92 var fr = new FileReader();
93 fr.onloadend = function() {
94 if (!arrayBuffersEqual(blankScreenshotArrayBuffer, fr.result)) {
95 ok(true, "Finally got a non-blank screenshot.");
96 SimpleTest.finish();
97 return;
98 }
100 SimpleTest.executeSoon(function() { test2(popup, blankScreenshot) });
101 };
102 fr.readAsArrayBuffer(e.target.result);
103 };
104 }
106 addEventListener('testready', runTest);