Bug 776129 - Part 2: Test that when a remote <iframe mozbrowser> calls window.open, we get a remote frame, and when an in-process frame calls window.open, we get an in-process frame. r=smaug

--HG--
extra : rebase_source : f58dbae038842c0357fa71b08a215f31ff2cc0db
This commit is contained in:
Justin Lebar 2012-08-17 17:07:54 -04:00
parent 3b4e0b1899
commit 75b1826f74
6 changed files with 149 additions and 1 deletions

View File

@ -127,9 +127,17 @@ MOCHITEST_FILES = \
# OOP tests don't work on Windows (bug 763081) or native-fennec (bug
# 774939).
#
# Both the "inproc" and "oop" versions of OpenMixedProcess open remote frames,
# so we don't run that test on platforms which don't support OOP tests.
ifneq ($(OS_ARCH),WINNT) #{
ifndef MOZ_JAVA_COMPOSITOR #{
MOCHITEST_FILES += \
browserElement_OpenMixedProcess.js \
file_browserElement_OpenMixedProcess.html \
test_browserElement_inproc_OpenMixedProcess.html \
test_browserElement_oop_OpenMixedProcess.html \
test_browserElement_oop_LoadEvents.html \
test_browserElement_oop_DataURI.html \
test_browserElement_oop_ErrorSecurity.html \

View File

@ -0,0 +1,90 @@
/* Any copyright is dedicated to the public domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Bug 776129 - If a window w calls window.open, the resultant window should be
// remote iff w is remote.
//
// <iframe mozbrowser> can be default-OOP or default-in-process. But we can
// override this default by setting remote=true or remote=false on the iframe.
//
// This bug arises when we are default-in-process and a OOP iframe calls
// window.open, or when we're default-OOP and an in-process iframe calls
// window.open. In either case, if the opened iframe gets the default
// remotness, it will not match its opener's remoteness, which is bad.
//
// Since the name of the test determines the OOP-by-default pref, the "inproc"
// version of this test opens an OOP frame, and the "oop" version opens an
// in-process frame. Enjoy. :)
"use strict";
SimpleTest.waitForExplicitFinish();
function runTest() {
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addPermission();
// We're going to open a remote frame if OOP off by default. If OOP is on by
// default, we're going to open an in-process frame.
var remote = !browserElementTestHelpers.getOOPByDefaultPref();
var iframe = document.createElement('iframe');
iframe.mozbrowser = true;
iframe.setAttribute('remote', remote);
// The page we load does window.open, then checks some things and reports
// back using alert(). Finally, it calls alert('finish').
//
// Bug 776129 in particular manifests itself such that the popup frame loads
// and the tests in file_browserElement_OpenMixedProcess pass, but the
// content of the frame is invisible. To catch this case, we take a
// screenshot after we load the content into the popup, and ensure that it's
// not blank.
var popup;
iframe.addEventListener('mozbrowseropenwindow', function(e) {
popup = document.body.appendChild(e.detail.frameElement);
});
iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
if (e.detail.message.startsWith('pass')) {
ok(true, e.detail.message);
}
else if (e.detail.message.startsWith('fail')) {
ok(false, e.detail.message);
}
else if (e.detail.message == 'finish') {
// We assume here that iframe is completely blank, and spin until popup's
// screenshot is not the same as iframe.
iframe.getScreenshot().onsuccess = function(e) {
test2(popup, e.target.result, popup);
};
}
else {
ok(false, e.detail.message, "Unexpected message!");
}
});
document.body.appendChild(iframe);
iframe.src = 'file_browserElement_OpenMixedProcess.html';
}
var prevScreenshot;
function test2(popup, blankScreenshot) {
// Take screenshots of popup until it doesn't equal blankScreenshot (or we
// time out).
popup.getScreenshot().onsuccess = function(e) {
var screenshot = e.target.result;
if (screenshot != blankScreenshot) {
SimpleTest.finish();
return;
}
if (screenshot != prevScreenshot) {
prevScreenshot = screenshot;
dump("Got screenshot: " + screenshot + "\n");
}
SimpleTest.executeSoon(function() { test2(popup, blankScreenshot) });
};
}
runTest();

View File

@ -0,0 +1,22 @@
<html>
<body>
<!-- The test relies on the fact that this file is completely empty. -->
<script>
function ok(b, msg)
{
alert((b ? 'pass:' : 'fail:') + msg);
}
var w = window.open("file_empty.html");
w.addEventListener('load', function() {
ok(true, 'Got load.');
ok(w.document.getElementById('url'), 'Found element with id "url"');
alert('finish');
});
</script>
</body>
</html>

View File

@ -1,7 +1,9 @@
<html>
<body>
<!-- Tests rely on the fact that there's an element in here called 'url'. -->
<!-- Tests rely on the fact that there's an element in here called 'url' and
that there's visible text on the page. -->
Aloha! My URL is <span id='url'></span>.
<script>

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Bug 776129</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript;version=1.7" src="browserElement_OpenMixedProcess.js">
</script>
</body>
</html>

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Bug 776129</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript;version=1.7" src="browserElement_OpenMixedProcess.js">
</script>
</body>
</html>