Skip to content

Commit b4d73f6

Browse files
committedOct 2, 2023
Bug 1156659 - Added offline network throttling to devtools. r=devtools-reviewers,bomsy,devtools-backward-compat-reviewers
Depends on D187704 Differential Revision: https://phabricator.services.mozilla.com/D187705
1 parent b37b5aa commit b4d73f6

File tree

8 files changed

+65
-1
lines changed

8 files changed

+65
-1
lines changed
 

‎devtools/client/netmonitor/src/connector/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,9 @@ class Connector {
512512
async updateNetworkThrottling(enabled, profile) {
513513
if (!enabled) {
514514
this.networkFront.clearNetworkThrottling();
515+
await this.commands.targetConfigurationCommand.updateConfiguration({
516+
setTabOffline: false,
517+
});
515518
} else {
516519
// The profile can be either a profile id which is used to
517520
// search the predefined throttle profiles or a profile object
@@ -520,6 +523,9 @@ class Connector {
520523
profile = throttlingProfiles.find(({ id }) => id == profile);
521524
}
522525
const { download, upload, latency } = profile;
526+
await this.commands.targetConfigurationCommand.updateConfiguration({
527+
setTabOffline: !download,
528+
});
523529
await this.networkFront.setNetworkThrottling({
524530
downloadThroughput: download,
525531
uploadThroughput: upload,

‎devtools/client/shared/components/throttling/profiles.js

+6
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ const profiles = [
9999
upload: 15 * MBps,
100100
latency: 2,
101101
},
102+
{
103+
id: "Offline",
104+
download: 0,
105+
upload: 0,
106+
latency: 5,
107+
},
102108
].map(profile => new ThrottlingProfile(profile));
103109

104110
module.exports = profiles;

‎devtools/docs/user/network_monitor/throttling/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The table below lists the numbers associated with each network type, but please
3232
Regular 4G/LTE, 4 Mbps, 3 Mbps, 20
3333
DSL, 2 Mbps, 1 Mbps, 5
3434
Wi-Fi, 30 Mbps, 15 Mbps, 2
35+
Offline, 0 Mbps, 0 Mbps, 5
3536

3637
Network Monitor Features
3738
************************

‎devtools/docs/user/responsive_design_mode/index.rst

+5
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ The table below lists the numbers associated with each network type, but please
202202
- 15 Mb/s
203203
- 2
204204

205+
* - Offline
206+
- 0 Mb/s
207+
- 0 Mb/s
208+
- 5
209+
205210
To select a network, click the list box that's initially labeled "No throttling":
206211

207212
.. image:: rdm_throttling.png

‎devtools/server/actors/target-configuration.js

+17
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const SUPPORTED_OPTIONS = {
4747
restoreFocus: true,
4848
// Enable service worker testing over HTTP (instead of HTTPS only).
4949
serviceWorkersTestingEnabled: true,
50+
// Set the current tab offline
51+
setTabOffline: true,
5052
// Enable touch events simulation
5153
touchEventsOverride: true,
5254
// Use simplified highlighters when prefers-reduced-motion is enabled.
@@ -266,6 +268,9 @@ class TargetConfigurationActor extends Actor {
266268
case "cacheDisabled":
267269
this._setCacheDisabled(value);
268270
break;
271+
case "setTabOffline":
272+
this._setTabOffline(value);
273+
break;
269274
}
270275
}
271276

@@ -282,6 +287,7 @@ class TargetConfigurationActor extends Actor {
282287
this._setServiceWorkersTestingEnabled(false);
283288
this._setPrintSimulationEnabled(false);
284289
this._setCacheDisabled(false);
290+
this._setTabOffline(false);
285291

286292
// Restore the color scheme simulation only if it was explicitly updated
287293
// by this actor. This will avoid side effects caused when destroying additional
@@ -453,6 +459,17 @@ class TargetConfigurationActor extends Actor {
453459
}
454460
}
455461

462+
/**
463+
* Set the browsing context to offline.
464+
*
465+
* @param {Boolean} offline: Whether the network throttling is set to offline
466+
*/
467+
_setTabOffline(offline) {
468+
if (!this._browsingContext.isDiscarded) {
469+
this._browsingContext.forceOffline = offline;
470+
}
471+
}
472+
456473
destroy() {
457474
Services.obs.removeObserver(
458475
this._onBrowsingContextAttached,

‎devtools/shared/commands/target-configuration/tests/browser_target_configuration_command.js

+28
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,34 @@ add_task(async function () {
6262
"Option colorSchemeSimulation was set, with a string value"
6363
);
6464

65+
await targetConfigurationCommand.updateConfiguration({
66+
setTabOffline: true,
67+
});
68+
compareOptions(
69+
targetConfigurationCommand.configuration,
70+
{
71+
cacheDisabled: false,
72+
colorSchemeSimulation: "dark",
73+
javascriptEnabled: false,
74+
setTabOffline: true,
75+
},
76+
"Option setTabOffline was set on"
77+
);
78+
79+
await targetConfigurationCommand.updateConfiguration({
80+
setTabOffline: false,
81+
});
82+
compareOptions(
83+
targetConfigurationCommand.configuration,
84+
{
85+
setTabOffline: false,
86+
cacheDisabled: false,
87+
colorSchemeSimulation: "dark",
88+
javascriptEnabled: false,
89+
},
90+
"Option setTabOffline was set off"
91+
);
92+
6593
targetCommand.destroy();
6694
await commands.destroy();
6795
});

‎devtools/shared/specs/target-configuration.js

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ types.addDictType("target-configuration.configuration", {
2323
reloadOnTouchSimulationToggle: "nullable:boolean",
2424
restoreFocus: "nullable:boolean",
2525
serviceWorkersTestingEnabled: "nullable:boolean",
26+
setTabOffline: "nullable:boolean",
2627
touchEventsOverride: "nullable:string",
2728
});
2829

‎toolkit/components/telemetry/Events.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,7 @@ devtools.main:
23532353
release_channel_collection: opt-out
23542354
expiry_version: never
23552355
extra_keys:
2356-
mode: No throttling, GPRS, Regular 2G, Good 2G, Regular 3G, Good 3G, Regular 4G / LTE, DSL or WI-FI.
2356+
mode: No throttling, GPRS, Regular 2G, Good 2G, Regular 3G, Good 3G, Regular 4G / LTE, DSL, WI-FI, or Offline.
23572357
session_id: The toolbox session start time e.g. 13963.
23582358
tool_timer:
23592359
objects: ["animationinspector", "compatibilityview", "computedview", "changesview", "fontinspector", "layoutview", "ruleview"]

0 commit comments

Comments
 (0)
Failed to load comments.