browser_offline_mode.js (1437B)
1 "use strict"; 2 3 // Test the offline mode in RDM 4 5 const TEST_URL = "https://example.net/document-builder.sjs?html=offline"; 6 7 addRDMTask(TEST_URL, async function ({ browser, ui }) { 8 // switch to offline mode 9 await selectNetworkThrottling(ui, "Offline"); 10 11 // reload w/o cache 12 browser.reloadWithFlags(Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE); 13 await BrowserTestUtils.browserLoaded(browser, false, TEST_URL, true); 14 15 // check page is offline 16 await assertPageIsOffline(TEST_URL); 17 18 // switch back to online mode 19 await selectNetworkThrottling(ui, "No Throttling"); 20 21 // reload 22 browser.reload(); 23 await BrowserTestUtils.browserLoaded(browser, false, TEST_URL, false); 24 25 // check page is online 26 await assertPageIsOnline(TEST_URL); 27 }); 28 29 function assertPageIsOnline(url) { 30 return SpecialPowers.spawn( 31 gBrowser.selectedTab.linkedBrowser, 32 [url], 33 function (uri) { 34 is(content.document.documentURI, uri, `Document URI is actual page.`); 35 is(content.location.href, uri, "Docshell URI is the original URI."); 36 } 37 ); 38 } 39 40 function assertPageIsOffline(url) { 41 return SpecialPowers.spawn( 42 gBrowser.selectedTab.linkedBrowser, 43 [url], 44 function (uri) { 45 is( 46 content.document.documentURI.substring(0, 27), 47 "about:neterror?e=netOffline", 48 "Document URI is the error page." 49 ); 50 51 is(content.location.href, uri, "Docshell URI is the original URI."); 52 } 53 ); 54 }