Bug 742944 - Part 5: Tests for window.open in <iframe mozbrowser>. r=bz

--HG--
extra : rebase_source : 8419648607fbf9f7acd672cb0f94ce7a05a32d88
This commit is contained in:
Justin Lebar 2012-06-12 18:01:25 -04:00
parent 8d7f4a897e
commit 7fde138bc2
14 changed files with 294 additions and 0 deletions

View File

@ -59,6 +59,15 @@ _TEST_FILES = \
browserElement_Close.js \
test_browserElement_oop_Close.html \
test_browserElement_inproc_Close.html \
browserElement_OpenWindow.js \
test_browserElement_oop_OpenWindow.html \
test_browserElement_inproc_OpenWindow.html \
file_browserElement_Open1.html \
file_browserElement_Open2.html \
browserElement_OpenWindowRejected.js \
test_browserElement_oop_OpenWindowRejected.html \
test_browserElement_inproc_OpenWindowRejected.html \
file_browserElement_OpenWindowRejected.html \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -0,0 +1,59 @@
/* Any copyright is dedicated to the public domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Bug 742944 - Test that window.open works with <iframe mozbrowser>.
"use strict";
SimpleTest.waitForExplicitFinish();
function runTest() {
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addToWhitelist();
var iframe = document.createElement('iframe');
iframe.mozbrowser = true;
var gotPopup = false;
iframe.addEventListener('mozbrowseropenwindow', function(e) {
is(gotPopup, false, 'Should get just one popup.');
gotPopup = true;
document.body.appendChild(e.detail.frameElement);
ok(/file_browserElement_Open2\.html$/.test(e.detail.url),
"Popup's URL (got " + e.detail.url + ")");
is(e.detail.name, "name");
is(e.detail.features, "features");
});
iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
ok(gotPopup, 'Got mozbrowseropenwindow event before showmodalprompt event.');
if (e.detail.message.indexOf("success:") == 0) {
ok(true, e.detail.message);
}
else if (e.detail.message.indexOf("failure:") == 0) {
ok(false, e.detail.message);
}
else if (e.detail.message == "finish") {
SimpleTest.finish();
}
else {
ok(false, "Got invalid message: " + e.detail.message);
}
});
/**
* file_browserElementOpen1 does
*
* window.open('file_browserElement_Open2.html', 'name', 'features')
*
* then adds an event listener to the opened window and waits for onload.
*
* Onload, we fire a few alerts saying "success:REASON" or "failure:REASON".
* Finally, we fire a "finish" alert, which ends the test.
*/
iframe.src = 'file_browserElement_Open1.html';
document.body.appendChild(iframe);
}
runTest();

View File

@ -0,0 +1,44 @@
/* Any copyright is dedicated to the public domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Bug 742944 - Do window.open from inside <iframe mozbrowser>. But then
// reject the call. This shouldn't cause problems (crashes, leaks).
"use strict";
SimpleTest.waitForExplicitFinish();
function runTest() {
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addToWhitelist();
var iframe = document.createElement('iframe');
iframe.mozbrowser = true;
iframe.addEventListener('mozbrowseropenwindow', function(e) {
ok(e.detail.url.indexOf('does_not_exist.html') != -1,
'Opened URL; got ' + e.detail.url);
is(e.detail.name, '');
is(e.detail.features, '');
// Don't add e.detail.frameElement to the DOM, so the window.open is
// effectively blocked.
});
iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
var msg = e.detail.message;
if (msg.indexOf('success:') == 0) {
ok(true, msg);
}
else if (msg == 'finish') {
SimpleTest.finish();
}
else {
ok(false, msg);
}
});
iframe.src = 'file_browserElement_OpenWindowRejected.html';
document.body.appendChild(iframe);
}
runTest();

View File

@ -0,0 +1,48 @@
/* Any copyright is dedicated to the public domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Bug 742944 - Do window.open from inside <iframe mozbrowser>. But then
// reject the call. This shouldn't cause problems (crashes, leaks).
//
// This is the same as OpenWindowRejected, except we "reject" the popup by not
// adding the iframe element to our DOM, instead of by not calling
// preventDefault() on the event.
"use strict";
SimpleTest.waitForExplicitFinish();
function runTest() {
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addToWhitelist();
var iframe = document.createElement('iframe');
iframe.mozbrowser = true;
iframe.addEventListener('mozbrowseropenwindow', function(e) {
ok(e.detail.url.indexOf('does_not_exist.html') != -1,
'Opened URL; got ' + e.detail.url);
is(e.detail.name, '');
is(e.detail.features, '');
// Call preventDefault, but don't add the iframe to the DOM. This still
// amounts to rejecting the popup.
e.preventDefault();
});
iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
var msg = e.detail.message;
if (msg.indexOf('success:') == 0) {
ok(true, msg);
}
else if (msg == 'finish') {
SimpleTest.finish();
}
else {
ok(false, msg);
}
});
iframe.src = 'file_browserElement_OpenWindowRejected.html';
}
runTest();

View File

@ -0,0 +1,33 @@
<html>
<body>
<script>
// Because this file is inside <iframe mozbrowser>, the alert() calls below
// don't trigger actual dialogs. Instead, the document which contans the
// iframe receives mozbrowsershowmodalprompt events, which the document uses
// to determine test success/failure.
function is(x, y, reason) {
if (x === y) {
alert("success: " + x + " === " + y + ", " + reason);
}
else {
alert("failure: " + x + " !== " + y + ", " + reason);
}
}
function ok(bool, reason) {
alert((bool ? "success: " : "failure: ") + reason);
}
var w = window.open("file_browserElement_Open2.html", "name", "features");
w.addEventListener("load", function() {
ok(true, "got load");
is(w.opener, window, 'opener property');
is(w.location.href, location.href.replace('Open1', 'Open2'), 'correct location');
is(w.document.getElementById('testElem').innerHTML, 'test', 'elem innerHTML');
alert("finish");
});
</script>
</body>
</html>

View File

@ -0,0 +1,5 @@
<html>
<body>
<div id='testElem'>test</div>
</body>
</html>

View File

@ -0,0 +1,16 @@
<html>
<body>
<script>
var w = window.open('does_not_exist.html');
if (!w) {
alert("success:w is null");
}
else {
alert("failure:w is not null -- " + w);
}
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'. -->
Aloha! My URL is <span id='url'></span>.
<script>
document.getElementById('url').innerHTML = window.location;
</script>

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test of browser element.</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_OpenWindow.js">
</script>
</body>
</html>

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test of browser element.</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_OpenWindowRejected.js">
</script>
</body>
</html>

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test of browser element.</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_OpenWindowRejected.js">
</script>
</body>
</html>

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test of browser element.</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_OpenWindow.js">
</script>
</body>
</html>

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test of browser element.</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_OpenWindowRejected.js">
</script>
</body>
</html>

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test of browser element.</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_OpenWindowRejected.js">
</script>
</body>
</html>