Bug 860941 - Tests. r=jst

We augment the existing showModalDialog tests with test coverage for
dialogArguments and returnValue.
This commit is contained in:
Bobby Holley 2013-05-16 23:33:15 -07:00
parent c845ac4102
commit 0812b158a7
3 changed files with 54 additions and 12 deletions

View File

@ -8,8 +8,8 @@ if (location.toString().match(/^http:\/\/mochi.test:8888/)) {
opener.is(window.dialogArguments, "my args",
"dialog did not get the right arguments.");
// Load a different url, and test that it doesn't see the arguments.
window.location="data:text/html,<html><body onload=\"opener.is(window.dialogArguments, null, 'subsequent dialog document did not get the right arguments.'); close();\">';";
// Load a different url, and test that it sees the arguments (since it's same origin).
window.location="data:text/html,<html><body onload=\"opener.is(window.dialogArguments, 'my args', 'subsequent dialog document did not get the right arguments.'); close();\">';";
} else {
// Post a message containing our arguments to the opener to test
// that this cross origing dialog does *not* see the passed in

View File

@ -2,18 +2,34 @@
<html>
<head>
<script>
ok = window.opener.ok;
is = window.opener.is;
SpecialPowers = window.opener.SpecialPowers;
function go() {
is(SpecialPowers.wrap(window).location.toString(), location.toString(), "sanity");
is(SpecialPowers.Cu.getClassName(window, /* aUnwrap = */ true), "ModalContentWindow", "We are modal");
var iwin = document.getElementById('ifr').contentWindow;
is(SpecialPowers.Cu.getClassName(iwin, /* aUnwrap = */ true), "Window", "Descendant frames should not be modal");
window.close();
if (location.origin != "http://mochi.test:8888") {
is(window.dialogArguments, undefined,
"dialogArguments should be undefined cross-origin: " + location.origin);
}
window.returnValue = "rv: " + window.dialogArguments;
// Allow for testing navigations in series.
if (location.search == "") {
window.close();
} else {
var origins = location.search.split('?')[1].split(',');
var newsearch = '?' + origins.splice(1).join(',');
var newurl = location.toString().replace(location.origin, origins[0])
.replace(location.search, newsearch);
location = newurl;
}
}
</script>
</head>
<body onload="go();">
<body onload="opener.postMessage('dosetup', '*');">
<iframe id="ifr"></iframe>
</body>
</html>

View File

@ -10,13 +10,39 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=862918
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
// This will be fixed in bug 860941.
SimpleTest.expectAssertions(0, 1);
/** Test for window.showModalDialog. **/
window.showModalDialog('file_showModalDialog.html');
// Blame mArguments assertion on this test.
// The modal window needs to touch Cu, which means that it needs
// SpecialPowers. But given the semantics of modal windows, we have to
// do some funny stuff with postMessage to set this up.
window.onmessage = function(evt) {
is(evt.data, 'dosetup', "message from modal window is correct");
var win = SpecialPowers.wrap(evt.source);
win.wrappedJSObject.SpecialPowers = SpecialPowers;
win.wrappedJSObject.is = is;
win.wrappedJSObject.ok = ok;
win.wrappedJSObject.go();
};
var someObj = { foo: 42, bar: "hi"};
var xurl = location.toString()
.replace('mochi.test:8888', 'example.org')
.replace('test_showModal', 'file_showModal');
xurl = xurl.substring(0, xurl.indexOf('?'));
is(showModalDialog('file_showModalDialog.html'), "rv: undefined");
is(showModalDialog(xurl), undefined);
is(showModalDialog('file_showModalDialog.html', 3), "rv: 3");
is(showModalDialog(xurl, 3), undefined);
is(showModalDialog('file_showModalDialog.html', someObj), "rv: " + someObj);
is(showModalDialog(xurl, someObj), undefined);
// Test sequential navigations.
is(showModalDialog('file_showModalDialog.html?http://mochi.test:8888', 4),
'rv: 4');
is(showModalDialog('file_showModalDialog.html?http://example.com', 4), undefined);
is(showModalDialog('file_showModalDialog.html?http://example.com,http://mochi.test:8888', 4), 'rv: 4');
// This test used to assert after gc. Make sure it doesn't.
SpecialPowers.gc();
</script>