mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 02:57:38 +00:00
Bug 1907304 - Write a test for DevTools offline mode not making cached requests fail r=jdescottes,devtools-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D220600
This commit is contained in:
parent
dc6b3a7d90
commit
2f46680b7d
@ -512,6 +512,8 @@ fail-if = ["a11y_checks"] # Bug 1849028 clicked element may not be focusable and
|
||||
|
||||
["browser_net_throttle.js"]
|
||||
|
||||
["browser_net_throttling_cached.js"]
|
||||
|
||||
["browser_net_throttling_profiles.js"]
|
||||
|
||||
["browser_net_timeline_ticks.js"]
|
||||
|
@ -0,0 +1,70 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
const {
|
||||
profiles,
|
||||
PROFILE_CONSTANTS,
|
||||
} = require("resource://devtools/client/shared/components/throttling/profiles.js");
|
||||
|
||||
const offlineProfile = profiles.find(
|
||||
profile => profile.id === PROFILE_CONSTANTS.OFFLINE
|
||||
);
|
||||
|
||||
const CACHED_URL = STATUS_CODES_SJS + "?sts=ok&cached&test_cached";
|
||||
|
||||
add_task(async function () {
|
||||
const { monitor } = await initNetMonitor(SIMPLE_URL, { requestCount: 1 });
|
||||
const { connector } = monitor.panelWin;
|
||||
const { updateNetworkThrottling } = connector;
|
||||
|
||||
// Throttle the network before entering the content process
|
||||
await pushPref("devtools.cache.disabled", false);
|
||||
await updateNetworkThrottling(true, offlineProfile);
|
||||
|
||||
// Clear the cache beforehand
|
||||
Services.cache2.clear();
|
||||
|
||||
// The request is blocked since the profile is offline
|
||||
await SpecialPowers.spawn(
|
||||
gBrowser.selectedBrowser,
|
||||
[CACHED_URL],
|
||||
async url => {
|
||||
try {
|
||||
await content.fetch(url);
|
||||
ok(false, "Should not load since profile is offline");
|
||||
} catch (err) {
|
||||
is(err.name, "TypeError", "Should fail since profile is offline");
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Disable throttling
|
||||
await pushPref("devtools.cache.disabled", false);
|
||||
await updateNetworkThrottling(false);
|
||||
|
||||
// Fetch to prime the cache
|
||||
await SpecialPowers.spawn(
|
||||
gBrowser.selectedBrowser,
|
||||
[CACHED_URL],
|
||||
async url => {
|
||||
await content.fetch(url);
|
||||
}
|
||||
);
|
||||
|
||||
// Set profile to offline again
|
||||
await pushPref("devtools.cache.disabled", false);
|
||||
await updateNetworkThrottling(true, offlineProfile);
|
||||
|
||||
// Check that cached resource loaded
|
||||
await SpecialPowers.spawn(
|
||||
gBrowser.selectedBrowser,
|
||||
[CACHED_URL],
|
||||
async url => {
|
||||
await content.fetch(url);
|
||||
}
|
||||
);
|
||||
|
||||
await teardown(monitor);
|
||||
});
|
Loading…
Reference in New Issue
Block a user