1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/bugs/test_bug260264_nested.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,122 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=260264 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 260264</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="application/javascript" src="utils_bug260264.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=260264">Mozilla Bug 260264</a> 1.17 +<p id="display"></p> 1.18 +<div id="content" style="display: none"> 1.19 + 1.20 +</div> 1.21 +<pre id="test"> 1.22 +<script type="application/javascript"> 1.23 + 1.24 +/** Test for Bug 260264 **/ 1.25 + 1.26 +SimpleTest.waitForExplicitFinish(); 1.27 + 1.28 +netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 1.29 +var popupEvents = makePrefAccessor("dom.popup_allowed_events"), 1.30 + blockPopups = makePrefAccessor("dom.disable_open_during_load"), 1.31 + ownPopupPriv = makePopupPrivAccessor(location.href), 1.32 + ecPopupPriv = makePopupPrivAccessor("http://example.com"); 1.33 + 1.34 +function test_nested_frames() { 1.35 + 1.36 + var savedBlockPopups = blockPopups(true); 1.37 + 1.38 + // Grandchild will use this name to refer to the current window: 1.39 + window.name = "parent260264"; 1.40 + 1.41 + function performer(event) { 1.42 + $("display").appendChild(document.createElement("iframe")).src = 1.43 + alter_file(alter_host(location.href, "example.com"), 1.44 + "child_bug260264.html#" + event); 1.45 + } 1.46 + 1.47 + function finisher(old) { 1.48 + popupEvents(old.events); 1.49 + ownPopupPriv(old.ownPriv); 1.50 + ecPopupPriv(old.ecPriv); 1.51 + } 1.52 + 1.53 + function should_have_blocked(popup) { 1.54 + ok(!popup, "popup should have been blocked"); 1.55 + } 1.56 + 1.57 + function should_not_have_blocked(popup) { 1.58 + ok(popup, "popup should not have been blocked"); 1.59 + } 1.60 + 1.61 + /** 1.62 + * The example_priv parameter controls whether or not the child frame has 1.63 + * popup clearance. Neither the top window nor the grandchild frame have 1.64 + * this clearance. The point of these tests is to make sure the child's 1.65 + * clearance (or lack thereof) is properly considered when opening a popup 1.66 + * from the grandchild. 1.67 + */ 1.68 + function makeTest(event, example_priv, reporter, allowed_events) { 1.69 + return { 1.70 + event: event, 1.71 + setup: function(old) { 1.72 + old.events = popupEvents(allowed_events || "click mouseup"); 1.73 + old.ownPriv = ownPopupPriv(DENY_ACTION); 1.74 + old.ecPriv = ecPopupPriv(example_priv); 1.75 + }, 1.76 + report: reporter, 1.77 + perform: performer, 1.78 + finish: finisher 1.79 + }; 1.80 + }; 1.81 + 1.82 + var tests = [ 1.83 + makeTest("mouseup", DENY_ACTION, should_not_have_blocked), 1.84 + makeTest("mouseup", ALLOW_ACTION, should_not_have_blocked), 1.85 + makeTest("mouseup", ALLOW_ACTION, should_not_have_blocked, "click"), 1.86 + makeTest("mouseup", DENY_ACTION, should_have_blocked, "click"), 1.87 + makeTest("mouseover", DENY_ACTION, should_have_blocked), 1.88 + makeTest("mouseover", ALLOW_ACTION, should_not_have_blocked), 1.89 + makeTest("click", DENY_ACTION, should_not_have_blocked), 1.90 + makeTest("click", ALLOW_ACTION, should_not_have_blocked) 1.91 + ]; 1.92 + 1.93 + function resume() { 1.94 + var options = tests[0]; 1.95 + if (options) { 1.96 + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 1.97 + options.setup(tests[0].old = {}); 1.98 + options.perform(options.event); 1.99 + } else { 1.100 + blockPopups(savedBlockPopups); 1.101 + SimpleTest.finish(); 1.102 + } 1.103 + } 1.104 + 1.105 + // Visible to child windows: 1.106 + window.report = function(popup) { 1.107 + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 1.108 + try { tests[0].report(popup) } 1.109 + finally { 1.110 + tests[0].finish(tests[0].old); 1.111 + tests.shift(); 1.112 + resume(); 1.113 + } 1.114 + } 1.115 + 1.116 + resume(); 1.117 + 1.118 +} 1.119 + 1.120 +test_nested_frames(); 1.121 + 1.122 +</script> 1.123 +</pre> 1.124 +</body> 1.125 +</html>