test_sharedWorker_thirdparty.html (1713B)
1 <!-- 2 Any copyright is dedicated to the Public Domain. 3 http://creativecommons.org/publicdomain/zero/1.0/ 4 --> 5 <!DOCTYPE HTML> 6 <html> 7 <head> 8 <title>Test for SharedWorker in 3rd Party Iframes</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"> </script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"> 11 </head> 12 <body> 13 <script class="testbody"> 14 15 function testThirdPartyFrame(name) { 16 return new Promise(resolve => { 17 // Let's use a window, loading the same origin, in order to have the new 18 // cookie-policy applied. 19 let w = window.open("sharedWorker_thirdparty_window.html?name=" + name); 20 window.addEventListener('message', function messageListener(evt) { 21 if (evt.data.name !== name) { 22 return; 23 } 24 w.close(); 25 window.removeEventListener('message', messageListener); 26 resolve(evt.data.result); 27 }); 28 }); 29 } 30 31 const COOKIE_BEHAVIOR_ACCEPT = 0; 32 const COOKIE_BEHAVIOR_REJECTFOREIGN = 1; 33 34 add_task(async function allowed() { 35 await SpecialPowers.pushPrefEnv({ set: [ 36 ["network.cookie.cookieBehavior", COOKIE_BEHAVIOR_ACCEPT] 37 ]}); 38 let result = await testThirdPartyFrame('allowed'); 39 ok(result === 'allowed', 40 'SharedWorker should be allowed when 3rd party iframes can access storage'); 41 }); 42 43 add_task(async function blocked() { 44 await SpecialPowers.pushPrefEnv({ set: [ 45 ["network.cookie.cookieBehavior", COOKIE_BEHAVIOR_REJECTFOREIGN] 46 ]}); 47 let result = await testThirdPartyFrame('blocked'); 48 ok(result === 'blocked', 49 'SharedWorker should not be allowed when 3rd party iframes are denied storage'); 50 }); 51 52 </script> 53 </body> 54 </html>