dom/browser-element/mochitest/browserElement_OpenMixedProcess.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial