1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/bugs/test_bug437361.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,68 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=437361 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 437361</title> 1.11 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.13 + 1.14 + <script class="testbody" type="text/javascript"> 1.15 + 1.16 + /** Test for Bug 437361 **/ 1.17 + 1.18 + function testModalDialogBlockedCleanly() { 1.19 + is(true, SpecialPowers.getBoolPref("dom.disable_open_during_load"), "mozprefs sanity check"); 1.20 + var rv = window.showModalDialog( // should be blocked without exception 1.21 + "data:text/html,<html><body onload='close(); returnValue = 1;' /></html>"); 1.22 + is(rv, undefined, "Modal dialog opened unexpectedly."); 1.23 + } 1.24 + 1.25 + function testModalDialogAllowed() { 1.26 + is(false, SpecialPowers.getBoolPref("dom.disable_open_during_load"), "mozprefs sanity check"); 1.27 + var rv = window.showModalDialog( // should not be blocked this time 1.28 + "data:text/html,<html><body onload='close(); returnValue = 1;' /></html>"); 1.29 + is(rv, 1, "Problem with modal dialog returnValue."); 1.30 + } 1.31 + 1.32 + function testOtherExceptionsNotTrapped() { 1.33 + is(false, SpecialPowers.getBoolPref("dom.disable_open_during_load"), "mozprefs sanity check"); 1.34 + window.showModalDialog('about:config'); // forbidden by SecurityCheckURL 1.35 + } 1.36 + 1.37 + function test(disableOpen, exceptionExpected, testFn, errorMsg) { 1.38 + var oldPrefVal = SpecialPowers.getBoolPref("dom.disable_open_during_load"); 1.39 + try { 1.40 + SpecialPowers.setBoolPref("dom.disable_open_during_load", disableOpen); 1.41 + testFn(); 1.42 + ok(!exceptionExpected, errorMsg); 1.43 + } catch (_) { 1.44 + ok(exceptionExpected, errorMsg); 1.45 + } 1.46 + finally { 1.47 + SpecialPowers.setBoolPref("dom.disable_open_during_load", oldPrefVal); 1.48 + } 1.49 + } 1.50 + 1.51 + test(true, false, testModalDialogBlockedCleanly, 1.52 + "Blocked showModalDialog caused an exception."); 1.53 + 1.54 + test(false, false, testModalDialogAllowed, 1.55 + "showModalDialog was blocked even though dom.disable_open_during_load was false."); 1.56 + 1.57 + test(false, true, testOtherExceptionsNotTrapped, 1.58 + "Incorrectly suppressed insecure showModalDialog exception."); 1.59 + 1.60 + </script> 1.61 +</head> 1.62 +<body> 1.63 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=437361">Mozilla Bug 437361</a> 1.64 +<p id="display"></p> 1.65 +<div id="content" style="display: none"> 1.66 +</div> 1.67 +<pre id="test"> 1.68 +</pre> 1.69 +</body> 1.70 +</html> 1.71 +