1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 // Test network throttling `offline` mode
8 requestLongerTimeout(2);
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
, {
20 await
selectThrottle(monitor
, PROFILE_CONSTANTS
.OFFLINE
);
21 assertCurrentThrottleSelected(monitor
, PROFILE_CONSTANTS
.OFFLINE
);
23 const offlineEventFired
= SpecialPowers
.spawn(
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
);
50 function assertCurrentThrottleSelected(monitor
, expectedProfile
) {
51 const doc
= monitor
.panelWin
.document
;
53 doc
.querySelector("#network-throttling").innerText
,
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
],
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
],
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
);