Backed out changeset 2d025ff107cc (bug 1730481) for causing mochitest-remote failures on browser_emulateNetworkConditions.js. CLOSED TREE

This commit is contained in:
Cristian Tuns 2021-09-13 10:10:58 -04:00
parent 0430d9aecd
commit bf5b256e92

View File

@ -6,18 +6,6 @@
const pageEmptyURL =
"http://example.com/browser/remote/cdp/test/browser/page/doc_empty.html";
/*
* Set the optional preference to disallow access to localhost when offline. This is
* required because `example.com` resolves to `localhost` in the tests and therefore
* would still be accessible even though we are simulating being offline.
* By setting this preference, we make sure that these connections to `localhost`
* (and by extension, to `example.com`) will fail when we are offline.
*/
Services.prefs.setBoolPref("network.disable-localhost-when-offline", true);
registerCleanupFunction(() => {
Services.prefs.clearUserPref("network.disable-localhost-when-offline");
});
/**
* Acts just as `add_task`, but does cleanup afterwards
* @param taskFn
@ -196,11 +184,45 @@ add_networking_task(async function emulateOnlineWhileOffline({ client }) {
* Navigates to a page, and asserting any status code to appear
*/
async function assertOfflineNavigationFails() {
const browser = gBrowser.selectedTab.linkedBrowser;
let netErrorLoaded = BrowserTestUtils.waitForErrorPage(browser);
// Tests always connect to localhost, and per bug 87717, localhost is now
// reachable in offline mode. To avoid this, disable any proxy.
const proxyPrefValue = SpecialPowers.getIntPref("network.proxy.type");
const diskPrefValue = SpecialPowers.getBoolPref("browser.cache.disk.enable");
const memoryPrefValue = SpecialPowers.getBoolPref(
"browser.cache.memory.enable"
);
SpecialPowers.pushPrefEnv({
set: [
["network.proxy.type", 0],
["browser.cache.disk.enable", false],
["browser.cache.memory.enable", false],
],
});
BrowserTestUtils.loadURI(browser, pageEmptyURL);
await netErrorLoaded;
try {
const browser = gBrowser.selectedTab.linkedBrowser;
let netErrorLoaded = BrowserTestUtils.waitForErrorPage(browser);
BrowserTestUtils.loadURI(browser, pageEmptyURL);
await netErrorLoaded;
await SpecialPowers.spawn(browser, [], () => {
ok(
content.document.documentURI.startsWith("about:neterror?e=netOffline"),
"Should be showing error page"
);
});
} finally {
// Re-enable the proxy so example.com is resolved to localhost, rather than
// the actual example.com.
SpecialPowers.pushPrefEnv({
set: [
["network.proxy.type", proxyPrefValue],
["browser.cache.disk.enable", diskPrefValue],
["browser.cache.memory.enable", memoryPrefValue],
],
});
}
}
/**