Backed out 2 changesets (bug 1943998) for causing wd failures @ phases.py CLOSED...
[gecko.git] / devtools / client / netmonitor / test / browser_net_offline_mode.js
blob378d3e8d90b6210033e3a3060c64ab01edd92f47
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 // Test network throttling `offline` mode
6 "use strict";
8 requestLongerTimeout(2);
10 const {
11 PROFILE_CONSTANTS,
12 } = require("resource://devtools/client/shared/components/throttling/profiles.js");
14 add_task(async function () {
15 await pushPref("devtools.cache.disabled", true);
17 const { tab, monitor, toolbox } = await initNetMonitor(HTTPS_CUSTOM_GET_URL, {
18 requestCount: 1,
19 });
20 await selectThrottle(monitor, PROFILE_CONSTANTS.OFFLINE);
21 assertCurrentThrottleSelected(monitor, PROFILE_CONSTANTS.OFFLINE);
23 const offlineEventFired = SpecialPowers.spawn(
24 tab.linkedBrowser,
25 [],
26 async function () {
27 return content.wrappedJSObject.hasOfflineEventFired();
31 ok(offlineEventFired, "The offline event on the page fired");
33 // As the browser is offline, load event won't fire
34 await reloadBrowser({ waitForLoad: false });
36 await assertNavigatorOnlineInConsole(toolbox, "false");
37 await assertPageIsOffline();
39 await selectThrottle(monitor, PROFILE_CONSTANTS.REGULAR_4G_LTE);
40 assertCurrentThrottleSelected(monitor, PROFILE_CONSTANTS.REGULAR_4G_LTE);
42 await reloadBrowser();
44 await assertNavigatorOnlineInConsole(toolbox, "true");
45 await assertPageIsOnline();
47 await teardown(monitor);
48 });
50 function assertCurrentThrottleSelected(monitor, expectedProfile) {
51 const doc = monitor.panelWin.document;
52 is(
53 doc.querySelector("#network-throttling").innerText,
54 expectedProfile,
55 `The '${expectedProfile}' throttle profile is correctly selected`
59 function assertPageIsOffline() {
60 // This is an error page.
61 return SpecialPowers.spawn(
62 gBrowser.selectedTab.linkedBrowser,
63 [HTTPS_CUSTOM_GET_URL],
64 function (uri) {
65 is(
66 content.document.documentURI.substring(0, 27),
67 "about:neterror?e=netOffline",
68 "Document URI is the error page."
71 // But location bar should show the original request.
72 is(content.location.href, uri, "Docshell URI is the original URI.");
77 function assertPageIsOnline() {
78 // This is an error page.
79 return SpecialPowers.spawn(
80 gBrowser.selectedTab.linkedBrowser,
81 [HTTPS_CUSTOM_GET_URL],
82 function (uri) {
83 is(content.document.documentURI, uri, "Document URI is the original URI");
85 // But location bar should show the original request.
86 is(content.location.href, uri, "Docshell URI is the original URI.");
91 async function assertNavigatorOnlineInConsole(toolbox, expectedResultValue) {
92 const input = "navigator.onLine";
93 info(`Assert the value of '${input}' in the console`);
94 await toolbox.openSplitConsole();
95 const { hud } = await toolbox.getPanel("webconsole");
96 hud.setInputValue(input);
97 return waitForEagerEvaluationResult(hud, expectedResultValue);