1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/browser-element/mochitest/browserElement_OpenMixedProcess.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,106 @@ 1.4 +/* Any copyright is dedicated to the public domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Bug 776129 - If a window w calls window.open, the resultant window should be 1.8 +// remote iff w is remote. 1.9 +// 1.10 +// <iframe mozbrowser> can be default-OOP or default-in-process. But we can 1.11 +// override this default by setting remote=true or remote=false on the iframe. 1.12 +// 1.13 +// This bug arises when we are default-in-process and a OOP iframe calls 1.14 +// window.open, or when we're default-OOP and an in-process iframe calls 1.15 +// window.open. In either case, if the opened iframe gets the default 1.16 +// remotness, it will not match its opener's remoteness, which is bad. 1.17 +// 1.18 +// Since the name of the test determines the OOP-by-default pref, the "inproc" 1.19 +// version of this test opens an OOP frame, and the "oop" version opens an 1.20 +// in-process frame. Enjoy. :) 1.21 + 1.22 +"use strict"; 1.23 + 1.24 +SimpleTest.waitForExplicitFinish(); 1.25 +browserElementTestHelpers.setEnabledPref(true); 1.26 +browserElementTestHelpers.addPermission(); 1.27 + 1.28 +function runTest() { 1.29 + // We're going to open a remote frame if OOP off by default. If OOP is on by 1.30 + // default, we're going to open an in-process frame. 1.31 + var remote = !browserElementTestHelpers.getOOPByDefaultPref(); 1.32 + 1.33 + var iframe = document.createElement('iframe'); 1.34 + SpecialPowers.wrap(iframe).mozbrowser = true; 1.35 + iframe.setAttribute('remote', remote); 1.36 + 1.37 + // The page we load does window.open, then checks some things and reports 1.38 + // back using alert(). Finally, it calls alert('finish'). 1.39 + // 1.40 + // Bug 776129 in particular manifests itself such that the popup frame loads 1.41 + // and the tests in file_browserElement_OpenMixedProcess pass, but the 1.42 + // content of the frame is invisible. To catch this case, we take a 1.43 + // screenshot after we load the content into the popup, and ensure that it's 1.44 + // not blank. 1.45 + var popup; 1.46 + iframe.addEventListener('mozbrowseropenwindow', function(e) { 1.47 + popup = document.body.appendChild(e.detail.frameElement); 1.48 + }); 1.49 + 1.50 + iframe.addEventListener('mozbrowsershowmodalprompt', function(e) { 1.51 + if (e.detail.message.startsWith('pass')) { 1.52 + ok(true, e.detail.message); 1.53 + } 1.54 + else if (e.detail.message.startsWith('fail')) { 1.55 + ok(false, e.detail.message); 1.56 + } 1.57 + else if (e.detail.message == 'finish') { 1.58 + // We assume here that iframe is completely blank, and spin until popup's 1.59 + // screenshot is not the same as iframe. 1.60 + iframe.getScreenshot(1000, 1000).onsuccess = function(e) { 1.61 + var fr = new FileReader(); 1.62 + fr.onloadend = function() { test2(popup, fr.result); }; 1.63 + fr.readAsArrayBuffer(e.target.result); 1.64 + }; 1.65 + } 1.66 + else { 1.67 + ok(false, e.detail.message, "Unexpected message!"); 1.68 + } 1.69 + }); 1.70 + 1.71 + document.body.appendChild(iframe); 1.72 + iframe.src = 'file_browserElement_OpenMixedProcess.html'; 1.73 +} 1.74 + 1.75 +function arrayBuffersEqual(a, b) { 1.76 + var x = new Int8Array(a); 1.77 + var y = new Int8Array(b); 1.78 + if (x.length != y.length) { 1.79 + return false; 1.80 + } 1.81 + 1.82 + for (var i = 0; i < x.length; i++) { 1.83 + if (x[i] != y[i]) { 1.84 + return false; 1.85 + } 1.86 + } 1.87 + 1.88 + return true; 1.89 +} 1.90 + 1.91 +function test2(popup, blankScreenshotArrayBuffer) { 1.92 + // Take screenshots of popup until it doesn't equal blankScreenshot (or we 1.93 + // time out). 1.94 + popup.getScreenshot(1000, 1000).onsuccess = function(e) { 1.95 + var fr = new FileReader(); 1.96 + fr.onloadend = function() { 1.97 + if (!arrayBuffersEqual(blankScreenshotArrayBuffer, fr.result)) { 1.98 + ok(true, "Finally got a non-blank screenshot."); 1.99 + SimpleTest.finish(); 1.100 + return; 1.101 + } 1.102 + 1.103 + SimpleTest.executeSoon(function() { test2(popup, blankScreenshot) }); 1.104 + }; 1.105 + fr.readAsArrayBuffer(e.target.result); 1.106 + }; 1.107 +} 1.108 + 1.109 +addEventListener('testready', runTest);