test_fetch-resource.js (1184B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Tests for DevToolsUtils.fetch on resource:// URI's. 6 7 const URL_FOUND = "resource://devtools/shared/DevToolsUtils.js"; 8 const URL_NOT_FOUND = "resource://devtools/this/is/not/here.js"; 9 10 // Disable `xpc::IsInAutomation()` so we don't crash when accessing a 11 // nonexistent resource URI. 12 Services.prefs.setBoolPref( 13 "security.turn_off_all_security_so_that_viruses_can_take_over_this_computer", 14 false 15 ); 16 17 /** 18 * Test that non-existent files are handled correctly. 19 */ 20 add_task(async function test_missing() { 21 await DevToolsUtils.fetch(URL_NOT_FOUND).then( 22 result => { 23 info(result); 24 ok(false, "fetch resolved unexpectedly for non-existent resource:// URI"); 25 }, 26 () => { 27 ok(true, "fetch rejected as the resource:// URI was non-existent."); 28 } 29 ); 30 }); 31 32 /** 33 * Tests that existing files are handled correctly. 34 */ 35 add_task(async function test_normal() { 36 await DevToolsUtils.fetch(URL_FOUND).then(result => { 37 notDeepEqual( 38 result.content, 39 "", 40 "resource:// URI seems to be read correctly." 41 ); 42 }); 43 });