browser_block_sync_xhr_system_requests.js (933B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 add_task(async function test_block_sync_xhr_requests() { 5 await SpecialPowers.pushPrefEnv({ 6 set: [["network.xhr.block_sync_system_requests", true]], 7 }); 8 9 Assert.throws( 10 () => { 11 let xhr = new XMLHttpRequest(); 12 // false means a synchronous request 13 xhr.open("GET", "https://example.com", false); 14 xhr.send(); 15 }, 16 /NetworkError/, 17 "Sync XHR coming from system requests should be blocked" 18 ); 19 }); 20 21 add_task(async function test_not_block_sync_xhr_requests() { 22 await SpecialPowers.pushPrefEnv({ 23 set: [["network.xhr.block_sync_system_requests", false]], 24 }); 25 26 let xhr = new XMLHttpRequest(); 27 xhr.open("GET", "https://example.com", false); 28 xhr.send(); 29 30 is( 31 xhr.status, 32 200, 33 "Sync XHR coming from system requests should be allowed when pref is false" 34 ); 35 });