test_bug260264.html (3379B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=260264 5 --> 6 <head> 7 <title>Test for Bug 260264</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script src="/tests/SimpleTest/EventUtils.js"></script> 10 <script type="application/javascript" src="utils_bug260264.js"></script> 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 12 </head> 13 <body> 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=260264">Mozilla Bug 260264</a> 15 <p id="display"> 16 <a id="link" href="javascript:(function(){})()">link</a> 17 </p> 18 <div id="content" style="display: none"> 19 20 </div> 21 <pre id="test"> 22 <script type="application/javascript"> 23 24 /** Test for Bug 260264 */ 25 26 SimpleTest.requestFlakyTimeout("untriaged"); 27 28 var a = $("link"), 29 checkOpened = function() { ok(window.open("http://example.com"), "not properly opened") }, 30 checkBlocked = function() { ok(!window.open("http://example.com"), "not properly blocked") }; 31 32 const popupSpamMaximum = 3; 33 const eventInAllowedList = "click"; 34 const eventNotInAllowedList = "mouseup"; 35 36 async function testPopupSpamMaximum() { 37 // Opening a popup from an event in the allowed event list doesn’t affect the 38 // popup spam count. 39 for (var count = 0, n = 0; n < popupSpamMaximum; n++) { 40 sendWithUserActivation(a, eventInAllowedList, checkOpened); 41 } 42 sendWithUserActivation(a, eventInAllowedList, checkOpened); 43 44 for (var count = 0, n = 0; n < popupSpamMaximum; n++) { 45 sendWithUserActivation(a, eventNotInAllowedList, checkOpened); 46 } 47 sendWithUserActivation(a, eventNotInAllowedList, checkBlocked); 48 49 // Close one spam popup. 50 await window.open.close(1); 51 sendWithUserActivation(a, eventNotInAllowedList, checkOpened); 52 sendWithUserActivation(a, eventNotInAllowedList, checkBlocked); 53 // Still allow opening a popup from an event in the allowed event list even if 54 // the popup spam count has reached its maximum. 55 sendWithUserActivation(a, eventInAllowedList, checkOpened); 56 57 await window.open.close(); 58 } 59 60 add_setup(async function init() { 61 await SpecialPowers.pushPrefEnv({"set": [ 62 // Enable popup blocker 63 ["dom.disable_open_during_load", true], 64 ["dom.popup_allowed_events", eventInAllowedList], 65 ["dom.popup_maximum", popupSpamMaximum], 66 ]}); 67 }); 68 69 add_task(async function test_unknown_permission() { 70 await SpecialPowers.pushPermissions([{'type': 'popup', 'remove': true, 'context': document}]); 71 ok(await SpecialPowers.testPermission('popup', UNKNOWN_ACTION, document), 'popup value should have UNKNOWN permission'); 72 73 await testPopupSpamMaximum(); 74 75 await SpecialPowers.popPermissions(); 76 }) 77 78 add_task(async function run_allow_permission() { 79 await SpecialPowers.pushPermissions([{'type': 'popup', 'allow': ALLOW_ACTION, 'context': document}]); 80 ok(await SpecialPowers.testPermission('popup', ALLOW_ACTION, document), 'popup value should have ALLOW permission'); 81 82 await testPopupSpamMaximum(); 83 84 await SpecialPowers.popPermissions(); 85 }); 86 87 add_task(async function run_deny_permission() { 88 await SpecialPowers.pushPermissions([{'type': 'popup', 'allow': DENY_ACTION, 'context': document}]); 89 ok(await SpecialPowers.testPermission('popup', DENY_ACTION, document), 'popup value should have ALLOW permission'); 90 91 await testPopupSpamMaximum(); 92 93 await SpecialPowers.popPermissions(); 94 }); 95 96 </script> 97 </pre> 98 </body> 99 </html>