test_external_protocol_iframe.html (2237B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test for external protocol URLs blocked for iframes</title> 5 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 6 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 7 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> 8 </head> 9 <body> 10 <div id='foo'><a href='#'>Click here to test this issue</a></div> 11 <script> 12 13 function test_initialize() { 14 ChromeUtils.resetLastExternalProtocolIframeAllowed(); 15 next(); 16 } 17 18 function test_noUserInteraction() { 19 ok(!SpecialPowers.wrap(document).hasValidTransientUserGestureActivation, "No user interaction yet"); 20 is(ChromeUtils.lastExternalProtocolIframeAllowed(), 0, "No iframe loaded before this test!"); 21 22 for (let i = 0; i < 10; ++i) { 23 let ifr = document.createElement('iframe'); 24 ifr.src = "foo+bar:all_good"; 25 document.body.appendChild(ifr); 26 27 is(ChromeUtils.getPopupControlState(), "openAbused", "No user-interaction means: abuse state"); 28 ok(ChromeUtils.lastExternalProtocolIframeAllowed() != 0, "We have 1 iframe loaded"); 29 } 30 31 next(); 32 } 33 34 function test_userInteraction() { 35 let foo = document.getElementById('foo'); 36 foo.addEventListener('click', _ => { 37 ok(SpecialPowers.wrap(document).hasValidTransientUserGestureActivation, "User should've interacted"); 38 39 for (let i = 0; i < 10; ++i) { 40 let ifr = document.createElement('iframe'); 41 ifr.src = "foo+bar:all_good"; 42 document.body.appendChild(ifr); 43 44 ok(!SpecialPowers.wrap(document).hasValidTransientUserGestureActivation, "User interaction should've been consumed"); 45 } 46 47 next(); 48 49 }, {once: true}); 50 51 setTimeout(_ => { 52 synthesizeMouseAtCenter(foo, {}); 53 }, 0); 54 } 55 56 let tests = [ 57 test_initialize, 58 test_noUserInteraction, 59 test_userInteraction, 60 ]; 61 62 function next() { 63 if (!tests.length) { 64 SimpleTest.finish(); 65 return; 66 } 67 68 let test = tests.shift(); 69 SimpleTest.executeSoon(test); 70 } 71 72 SpecialPowers.pushPrefEnv({'set': [ 73 ['dom.block_external_protocol_in_iframes', true], 74 ['dom.delay.block_external_protocol_in_iframes.enabled', true], 75 ]}, next); 76 77 SimpleTest.waitForExplicitFinish(); 78 </script> 79 </body> 80 </html>