/* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ /* Ensure that clicking the button in the Offline mode neterror page makes the browser go online. See bug 435325. */ async function checkSwitchPageToOnlineMode(useFelt) { // Go offline and disable the proxy and cache, then try to load the test URL. Services.io.offline = true; // Tests always connect to localhost, and per bug 87717, localhost is now // reachable in offline mode. To avoid this, disable any proxy. let proxyPrefValue = SpecialPowers.getIntPref("network.proxy.type"); await SpecialPowers.pushPrefEnv({ set: [ ["network.proxy.type", 0], ["browser.cache.disk.enable", false], ["browser.cache.memory.enable", false], ["security.certerrors.felt-privacy-v1", useFelt], ], }); await BrowserTestUtils.withNewTab("about:blank", async function (browser) { let netErrorLoaded = BrowserTestUtils.waitForErrorPage(browser); // eslint-disable-next-line @microsoft/sdl/no-insecure-url BrowserTestUtils.startLoadingURIString(browser, "http://example.com/"); await netErrorLoaded; // Re-enable the proxy so example.com is resolved to localhost, rather than // the actual example.com. await SpecialPowers.pushPrefEnv({ set: [["network.proxy.type", proxyPrefValue]], }); let changeObserved = TestUtils.topicObserved( "network:offline-status-changed" ); // Click on the 'Try again' button. await SpecialPowers.spawn(browser, [useFelt], async function (use_felt) { ok( content.document.documentURI.startsWith("about:neterror?e=netOffline"), "Should be showing error page" ); const button = use_felt ? content.document.querySelector("net-error-card").wrappedJSObject .tryAgainButton : content.document.querySelector( "#netErrorButtonContainer > .try-again" ); button.click(); }); await changeObserved; ok( !Services.io.offline, "After clicking the 'Try Again' button, we're back online." ); }); } add_task(async function runCheckSwitchPageToOnlineMode() { for (const useFelt of [true, false]) { await checkSwitchPageToOnlineMode(useFelt); } }); registerCleanupFunction(function () { Services.io.offline = false; });