Bug 981796 - Make tests that use showModalDialog pass. r=smaug

Annoyingly, setting the pref doesn't magically make the function appear on the
current window, so we create an iframe and retrieve it from there.

MozReview-Commit-ID: 9fOr4YJOzXh

--HG--
extra : rebase_source : d23643b388538955cc831a3b6e1473232ab5498a
This commit is contained in:
Blake Kaplan 2017-06-16 12:41:01 -07:00
parent 6fd6916834
commit 4aafd09754
15 changed files with 180 additions and 99 deletions

View File

@ -16,8 +16,16 @@
*/
SimpleTest.waitForExplicitFinish();
function openModal() {
showModalDialog("javascript:opener.winRef = window; \
async function openModal() {
await SpecialPowers.pushPrefEnv({ set: [[
"dom.disable_window_showModalDialog", false ]] });
let iframe = document.createElement("iframe");
document.body.appendChild(iframe);
await new Promise(resolve => {
iframe.addEventListener("load", resolve);
});
iframe.contentWindow.showModalDialog("javascript:opener.winRef = window; \
window.opener.setTimeout(\'winRef.dialogArguments;\', 0);\
window.close();");

View File

@ -487,7 +487,14 @@ function testSyncXHR2() {
then(testModalDialog);
}
function testModalDialog() {
async function testModalDialog() {
await SpecialPowers.pushPrefEnv({ set: [[ "dom.disable_window_showModalDialog", false ]] });
let iframe = document.createElement("iframe");
document.body.appendChild(iframe);
await new Promise(resolve => {
iframe.addEventListener("load", resolve);
});
window.showModalDialog = iframe.contentWindow.showModalDialog;
var didHandleCallback = false;
div.innerHTML = "<span>1</span><span>2</span>";
m = new M(function(records, observer) {

View File

@ -14,11 +14,23 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=391777
<script class="testbody" type="text/javascript">
/** Test for Bug 391777 **/
var arg = {};
arg.testVal = "foo";
var result = window.showModalDialog("javascript:window.returnValue = window.dialogArguments.testVal; window.close(); 'This window should close on its own.';", arg);
ok(true, "We should get here without user interaction");
is(result, "foo", "Unexpected result from showModalDialog");
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({ set: [[ "dom.disable_window_showModalDialog", false ]] }, doTest);
async function doTest() {
let iframe = document.createElement("iframe");
document.body.appendChild(iframe);
await new Promise(resolve => {
iframe.addEventListener("load", resolve);
});
window.showModalDialog = iframe.contentWindow.showModalDialog;
var arg = {};
arg.testVal = "foo";
var result = window.showModalDialog("javascript:window.returnValue = window.dialogArguments.testVal; window.close(); 'This window should close on its own.';", arg);
ok(true, "We should get here without user interaction");
is(result, "foo", "Unexpected result from showModalDialog");
SimpleTest.finish();
}
</script>
</body>

View File

@ -109,7 +109,9 @@ function doTest() {
// file_iframe_j_if3.html has an ok() function that calls window.parent.ok_wrapper.
}
addLoadEvent(doTest);
let loaded = new Promise(resolve => { addLoadEvent(resolve) });
let prefSet = SpecialPowers.pushPrefEnv({ set: [[ "dom.disable_window_showModalDialog", false ]] });
Promise.all([ loaded, prefSet ]).then(doTest);
</script>
<body>

View File

@ -59,7 +59,7 @@ skip-if = toolkit == 'android'
[test_bug265203.html]
[test_bug291377.html]
[test_bug291653.html]
skip-if = toolkit == 'android' #TIMED_OUT
skip-if = e10s || toolkit == 'android' #TIMED_OUT
[test_bug304459.html]
[test_bug308856.html]
[test_bug327891.html]
@ -82,7 +82,7 @@ skip-if = toolkit == 'android' #TIMED_OUT
[test_bug400204.html]
[test_bug404748.html]
[test_bug406375.html]
skip-if = toolkit == 'android'
skip-if = e10s || toolkit == 'android'
[test_bug414291.html]
tags = openwindow
[test_bug427744.html]
@ -90,20 +90,20 @@ skip-if = toolkit == 'android'
[test_bug42976.html]
[test_bug430276.html]
[test_bug437361.html]
skip-if = toolkit == 'android'
skip-if = e10s || toolkit == 'android'
[test_bug440572.html]
[test_bug456151.html]
[test_bug458091.html]
[test_bug459848.html]
[test_bug465263.html]
[test_bug479143.html]
skip-if = toolkit == 'android'
skip-if = e10s || toolkit == 'android'
[test_bug484775.html]
[test_bug492925.html]
[test_bug49312.html]
[test_bug495219.html]
[test_bug504862.html]
skip-if = toolkit == 'android' #RANDOM
skip-if = e10s || toolkit == 'android' #RANDOM
[test_bug529328.html]
[test_bug531176.html]
[test_bug531542.html]

View File

@ -25,13 +25,7 @@ var secondListenerDidRun = false;
var w;
function start() {
if ("showModalDialog" in window) {
w = window.open("file_bug291653.html", "foo", "width=300,height=300");
} else {
// window.showModalDialog doesn't exist in e10s mode, nothing to do in this test.
ok(true, "nothing to do in e10s mode");
SimpleTest.finish();
}
w = window.open("file_bug291653.html", "foo", "width=300,height=300");
}
function closeTest() {
@ -48,7 +42,7 @@ function end() {
setTimeout("closeTest()", 500);
}
start();
SpecialPowers.pushPrefEnv({ set: [[ "dom.disable_window_showModalDialog", false ]] }, start);
</script>
</pre>

View File

@ -22,10 +22,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=406375
SimpleTest.waitForExplicitFinish();
function runTest() {
if ("showModalDialog" in window) {
window.showModalDialog("file_bug406375.html");
}
async function runTest() {
await SpecialPowers.pushPrefEnv({ set: [[ "dom.disable_window_showModalDialog", false ]] });
let iframe = document.createElement("iframe");
document.body.appendChild(iframe);
await new Promise(resolve => {
iframe.addEventListener("load", resolve);
});
window.showModalDialog = iframe.contentWindow.showModalDialog;
window.showModalDialog("file_bug406375.html");
ok(true, "This test should not hang");
SimpleTest.finish();

View File

@ -13,6 +13,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=414291
<script class="testbody" type="text/javascript">
/** Test for Bug 414291 **/
SimpleTest.waitForExplicitFinish();
var result1 = 0;
var result2 = 0;
@ -24,9 +25,20 @@ is(result1, 0, "window should not be opened either as modal or loaded synchronou
window.open("file2_bug414291.html", "w2", "modal=yes");
is(result2, 0, "window should not be opened either as modal or data loaded synchronously.");
if (window.showModalDialog) {
result3 = window.showModalDialog("file3_bug414291.html");
is(result3, 3, "window should be opened as modal.");
SpecialPowers.pushPrefEnv({ set: [[ "dom.disable_window_showModalDialog", false ]] }, runModalTest);
async function runModalTest() {
let iframe = document.createElement("iframe");
document.body.appendChild(iframe);
await new Promise(resolve => {
iframe.addEventListener("load", resolve);
});
window.showModalDialog = iframe.contentWindow.showModalDialog;
if (window.showModalDialog) {
result3 = window.showModalDialog("file3_bug414291.html");
is(result3, 3, "window should be opened as modal.");
}
SimpleTest.finish();
}
</script>

View File

@ -32,32 +32,41 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=437361
}
function test(disableOpen, exceptionExpected, testFn, errorMsg) {
if ("showModalDialog" in window) {
var oldPrefVal = SpecialPowers.getBoolPref("dom.disable_open_during_load");
try {
SpecialPowers.setBoolPref("dom.disable_open_during_load", disableOpen);
testFn();
ok(!exceptionExpected, errorMsg);
} catch (_) {
ok(exceptionExpected, errorMsg);
}
finally {
SpecialPowers.setBoolPref("dom.disable_open_during_load", oldPrefVal);
}
} else {
ok(true, "nothing to do in e10s mode");
var oldPrefVal = SpecialPowers.getBoolPref("dom.disable_open_during_load");
try {
SpecialPowers.setBoolPref("dom.disable_open_during_load", disableOpen);
testFn();
ok(!exceptionExpected, errorMsg);
} catch (_) {
ok(exceptionExpected, errorMsg);
}
finally {
SpecialPowers.setBoolPref("dom.disable_open_during_load", oldPrefVal);
}
}
test(true, false, testModalDialogBlockedCleanly,
"Blocked showModalDialog caused an exception.");
test(false, false, testModalDialogAllowed,
"showModalDialog was blocked even though dom.disable_open_during_load was false.");
SimpleTest.waitForExplicitFinish();
test(false, true, testOtherExceptionsNotTrapped,
"Incorrectly suppressed insecure showModalDialog exception.");
SpecialPowers.pushPrefEnv({ set: [[ "dom.disable_window_showModalDialog", false ]] }, doTest);
async function doTest() {
let iframe = document.createElement("iframe");
document.body.appendChild(iframe);
await new Promise(resolve => {
iframe.addEventListener("load", resolve);
});
window.showModalDialog = iframe.contentWindow.showModalDialog;
test(true, false, testModalDialogBlockedCleanly,
"Blocked showModalDialog caused an exception.");
test(false, false, testModalDialogAllowed,
"showModalDialog was blocked even though dom.disable_open_during_load was false.");
test(false, true, testOtherExceptionsNotTrapped,
"Incorrectly suppressed insecure showModalDialog exception.");
SimpleTest.finish();
}
</script>
</head>
<body>

View File

@ -18,25 +18,32 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=479143
SimpleTest.waitForExplicitFinish();
setTimeout(function() {
if ("showModalDialog" in window) {
var interval = setInterval(function() { var i = 0; i++; }, 10);
SpecialPowers.pushPrefEnv({ set: [[ "dom.disable_window_showModalDialog", false ]] }, doTest);
async function doTest() {
await SpecialPowers.pushPrefEnv({ set: [[ "dom.disable_window_showModalDialog", false ]] });
let iframe = document.createElement("iframe");
document.body.appendChild(iframe);
await new Promise(resolve => {
iframe.addEventListener("load", resolve);
});
window.showModalDialog = iframe.contentWindow.showModalDialog;
var xhr = new XMLHttpRequest();
xhr.open("GET", "test_bug479143.html", false);
xhr.send(null);
var interval = setInterval(function() { var i = 0; i++; }, 10);
window.showModalDialog("javascript:" +
"setTimeout(function() { window.close(); }, 1000);",
null);
var xhr = new XMLHttpRequest();
xhr.open("GET", "test_bug479143.html", false);
xhr.send(null);
clearInterval(interval);
}
window.showModalDialog("javascript:" +
"setTimeout(function() { window.close(); }, 1000);",
null);
clearInterval(interval);
ok(true, "did not crash");
SimpleTest.finish();
}, 0);
}
</script>
</pre>

View File

@ -19,22 +19,26 @@ function onMsgRcv(event)
is(event.data, "args: undefined", "Unexpected cross origin dialog arguments.");
}
function runTest() {
if ("showModalDialog" in window) {
window.addEventListener("message", onMsgRcv);
async function runTest() {
await SpecialPowers.pushPrefEnv({ set: [[ "dom.disable_window_showModalDialog", false ]] });
let iframe = document.createElement("iframe");
document.body.appendChild(iframe);
await new Promise(resolve => {
iframe.addEventListener("load", resolve);
});
window.showModalDialog = iframe.contentWindow.showModalDialog;
var result = window.showModalDialog("file_bug504862.html", "my args");
// NB: We used to clear returnValue on each navigation, but now we do a
// security check on access, so we can safely make returnValue live on
// the browsing context, per spec.
is(result, 3, "window sees previous dialog documents return value.");
window.addEventListener("message", onMsgRcv);
result = window.showModalDialog("http://test1.example.com/tests/dom/tests/mochitest/bugs/file_bug504862.html", "my args");
var result = window.showModalDialog("file_bug504862.html", "my args");
// NB: We used to clear returnValue on each navigation, but now we do a
// security check on access, so we can safely make returnValue live on
// the browsing context, per spec.
is(result, 3, "window sees previous dialog documents return value.");
is(result, undefined, "Able to see return value from cross origin dialog.");
} else {
ok(true, "nothing to do in e10s mode");
}
result = window.showModalDialog("http://test1.example.com/tests/dom/tests/mochitest/bugs/file_bug504862.html", "my args");
is(result, undefined, "Able to see return value from cross origin dialog.");
SimpleTest.finish();
}

View File

@ -220,11 +220,12 @@ var expectedState;
function runtests()
{
SpecialPowers.pushPrefEnv({'set': [["dom.successive_dialog_time_limit", 3]]},
SpecialPowers.pushPrefEnv({'set': [["dom.successive_dialog_time_limit", 3],
["dom.disable_window_showModalDialog", false]]},
runtestsInner);
}
function runtestsInner()
async function runtestsInner()
{
registerMockPromptService();
@ -305,6 +306,13 @@ function runtestsInner()
w.close();
let iframe = document.createElement("iframe");
document.body.appendChild(iframe);
await new Promise(resolve => {
iframe.addEventListener("load", resolve);
});
window.showModalDialog = iframe.contentWindow.showModalDialog;
// Test that showModalDialog() works normally and then gets blocked
// on the second call.
if (window.showModalDialog) {

View File

@ -124,8 +124,7 @@ support-files = test_offsets.js
skip-if = toolkit == 'android' # bug 1230232 - Mouse doesn't select in the same way
[test_showModalDialog.html]
skip-if = e10s || toolkit == 'android' #Don't run modal tests on Android
[test_showModalDialog_e10s.html]
run-if = e10s
[test_showModalDialog_removed.html]
[test_storagePermissionsAccept.html]
[test_storagePermissionsLimitForeign.html]
[test_storagePermissionsReject.html]

View File

@ -24,27 +24,40 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=862918
win.wrappedJSObject.go();
};
var someObj = { foo: 42, bar: "hi"};
var xurl = location.toString()
.replace('mochi.test:8888', 'example.org')
.replace('test_showModal', 'file_showModal');
if (xurl.indexOf('?') != -1)
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);
SimpleTest.waitForExplicitFinish();
// 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');
SpecialPowers.pushPrefEnv({ set: [[ "dom.disable_window_showModalDialog", false ]] }, doTest);
async function doTest() {
let iframe = document.createElement("iframe");
document.body.appendChild(iframe);
await new Promise(resolve => {
iframe.addEventListener("load", resolve);
});
window.showModalDialog = iframe.contentWindow.showModalDialog;
// This test used to assert after gc. Make sure it doesn't.
SpecialPowers.gc();
var someObj = { foo: 42, bar: "hi"};
var xurl = location.toString()
.replace('mochi.test:8888', 'example.org')
.replace('test_showModal', 'file_showModal');
if (xurl.indexOf('?') != -1)
xurl = xurl.substring(0, xurl.indexOf('?'));
is(window.showModalDialog('file_showModalDialog.html'), "rv: undefined");
is(window.showModalDialog(xurl), undefined);
is(window.showModalDialog('file_showModalDialog.html', 3), "rv: 3");
is(window.showModalDialog(xurl, 3), undefined);
is(window.showModalDialog('file_showModalDialog.html', someObj), "rv: " + someObj);
is(window.showModalDialog(xurl, someObj), undefined);
// Test sequential navigations.
is(window.showModalDialog('file_showModalDialog.html?http://mochi.test:8888', 4),
'rv: 4');
is(window.showModalDialog('file_showModalDialog.html?http://example.com', 4), undefined);
is(window.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();
SimpleTest.finish();
}
</script>
</head>

View File

@ -20,7 +20,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1077002
<pre id="test">
<script type="application/javascript">
/** Test for showModalDialog unavailability in e10s **/
/** Test for showModalDialog unavailability in Firefox **/
// NB: This test runs in e10s only. In e10s showModalDialog should not
// exist.