Bug 1156659 - Added offline network throttling to devtools. r=devtools-reviewers,bomsy,devtools-backward-compat-reviewers
☠☠ backed out by 4555a3b2b53e ☠ ☠
authordylan <dotoole@mozilla.com>
Mon, 02 Oct 2023 04:13:43 +0000
changeset 680348 af64e5a0109a36289cd4239c3feac5f20a5b1229
parent 680347 7e9b86bce76b2a80021d8489ad561afe15f30aa0
child 680349 ad659db7e0360a29dc71b15abc7d4743fe4e7172
push id41234
push user[email protected]
push dateTue, 03 Oct 2023 09:33:18 +0000
treeherdermozilla-central@53af11a26cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdevtools-reviewers, bomsy, devtools-backward-compat-reviewers
bugs1156659
milestone120.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
devtools/client/netmonitor/src/connector/index.js
devtools/client/shared/components/throttling/profiles.js
devtools/docs/user/network_monitor/throttling/index.rst
devtools/docs/user/responsive_design_mode/index.rst
devtools/server/actors/target-configuration.js
devtools/shared/commands/target-configuration/tests/browser_target_configuration_command.js
devtools/shared/specs/target-configuration.js
toolkit/components/telemetry/Events.yaml
--- a/devtools/client/netmonitor/src/connector/index.js
+++ b/devtools/client/netmonitor/src/connector/index.js
@@ -507,24 +507,30 @@ class Connector {
 
     const state = this.getState();
     return getDisplayedTimingMarker(state, name);
   }
 
   async updateNetworkThrottling(enabled, profile) {
     if (!enabled) {
       this.networkFront.clearNetworkThrottling();
+      await this.commands.targetConfigurationCommand.updateConfiguration({
+        setTabOffline: false,
+      });
     } else {
       // The profile can be either a profile id which is used to
       // search the predefined throttle profiles or a profile object
       // as defined in the trottle tests.
       if (typeof profile === "string") {
         profile = throttlingProfiles.find(({ id }) => id == profile);
       }
       const { download, upload, latency } = profile;
+      await this.commands.targetConfigurationCommand.updateConfiguration({
+        setTabOffline: !download,
+      });
       await this.networkFront.setNetworkThrottling({
         downloadThroughput: download,
         uploadThroughput: upload,
         latency,
       });
     }
 
     this.emitForTests(TEST_EVENTS.THROTTLING_CHANGED, { profile });
--- a/devtools/client/shared/components/throttling/profiles.js
+++ b/devtools/client/shared/components/throttling/profiles.js
@@ -94,11 +94,17 @@ const profiles = [
     latency: 5,
   },
   {
     id: "Wi-Fi",
     download: 30 * MBps,
     upload: 15 * MBps,
     latency: 2,
   },
+  {
+    id: "Offline",
+    download: 0,
+    upload: 0,
+    latency: 5,
+  },
 ].map(profile => new ThrottlingProfile(profile));
 
 module.exports = profiles;
--- a/devtools/docs/user/network_monitor/throttling/index.rst
+++ b/devtools/docs/user/network_monitor/throttling/index.rst
@@ -27,16 +27,17 @@ The table below lists the numbers associ
   GPRS, 50 Kbps, 20 Kbps, 500
   Regular 2G, 250 Kbps, 50 Kbps, 300
   Good 2G, 450 Kbps, 150 Kbps, 150
   Regular 3G, 750 Kbps, 250 Kbps, 100
   Good 3G, 1.5 Mbps, 750 Kbps, 40
   Regular 4G/LTE, 4 Mbps, 3 Mbps, 20
   DSL, 2 Mbps, 1 Mbps, 5
   Wi-Fi, 30 Mbps, 15 Mbps, 2
+  Offline, 0 Mbps, 0 Mbps, 5
 
 Network Monitor Features
 ************************
 
 The following articles cover different aspects of using the network monitor:
 
 - :doc:`Toolbar <../toolbar/index>`
 - :doc:`Network request list <../request_list/index>`
--- a/devtools/docs/user/responsive_design_mode/index.rst
+++ b/devtools/docs/user/responsive_design_mode/index.rst
@@ -197,12 +197,17 @@ The table below lists the numbers associ
     - 1 Mb/s
     - 5
 
   * - Wi-Fi
     - 30 Mb/s
     - 15 Mb/s
     - 2
 
+  * - Offline
+    - 0 Mb/s
+    - 0 Mb/s
+    - 5
+
 To select a network, click the list box that's initially labeled "No throttling":
 
 .. image:: rdm_throttling.png
   :class: center
--- a/devtools/server/actors/target-configuration.js
+++ b/devtools/server/actors/target-configuration.js
@@ -42,16 +42,18 @@ const SUPPORTED_OPTIONS = {
   // Enable allocation tracking, if set, contains an object defining the tracking configurations
   recordAllocations: true,
   // Reload the page when the touch simulation state changes (only works alongside touchEventsOverride)
   reloadOnTouchSimulationToggle: true,
   // Restore focus in the page after closing DevTools.
   restoreFocus: true,
   // Enable service worker testing over HTTP (instead of HTTPS only).
   serviceWorkersTestingEnabled: true,
+  // Set the current tab offline
+  setTabOffline: true,
   // Enable touch events simulation
   touchEventsOverride: true,
   // Use simplified highlighters when prefers-reduced-motion is enabled.
   useSimpleHighlightersForReducedMotion: true,
 };
 /* eslint-disable sort-keys */
 
 /**
@@ -261,32 +263,36 @@ class TargetConfigurationActor extends A
           this._setServiceWorkersTestingEnabled(value);
           break;
         case "touchEventsOverride":
           this._setTouchEventsOverride(value);
           break;
         case "cacheDisabled":
           this._setCacheDisabled(value);
           break;
+        case "setTabOffline":
+          this._setTabOffline(value);
+          break;
       }
     }
 
     if (shouldReload) {
       this._browsingContext.reload(Ci.nsIWebNavigation.LOAD_FLAGS_NONE);
     }
   }
 
   _restoreParentProcessConfiguration() {
     if (!this._shouldHandleConfigurationInParentProcess()) {
       return;
     }
 
     this._setServiceWorkersTestingEnabled(false);
     this._setPrintSimulationEnabled(false);
     this._setCacheDisabled(false);
+    this._setTabOffline(false);
 
     // Restore the color scheme simulation only if it was explicitly updated
     // by this actor. This will avoid side effects caused when destroying additional
     // targets (e.g. RDM target, WebExtension target, …).
     // TODO: We may want to review other configuration values to see if we should use
     // the same pattern (Bug 1701553).
     if (this._resetColorSchemeSimulationOnDestroy) {
       this._setColorSchemeSimulation(null);
@@ -448,16 +454,27 @@ class TargetConfigurationActor extends A
     const value = disabled
       ? Ci.nsIRequest.LOAD_BYPASS_CACHE
       : Ci.nsIRequest.LOAD_NORMAL;
     if (this._browsingContext.defaultLoadFlags != value) {
       this._browsingContext.defaultLoadFlags = value;
     }
   }
 
+  /**
+   * Set the browsing context to offline.
+   *
+   * @param {Boolean} offline: Whether the network throttling is set to offline
+   */
+  _setTabOffline(offline) {
+    if (!this._browsingContext.isDiscarded) {
+      this._browsingContext.forceOffline = offline;
+    }
+  }
+
   destroy() {
     Services.obs.removeObserver(
       this._onBrowsingContextAttached,
       "browsing-context-attached"
     );
     this.watcherActor.off(
       "bf-cache-navigation-pageshow",
       this._onBfCacheNavigation
--- a/devtools/shared/commands/target-configuration/tests/browser_target_configuration_command.js
+++ b/devtools/shared/commands/target-configuration/tests/browser_target_configuration_command.js
@@ -57,16 +57,44 @@ add_task(async function () {
     {
       cacheDisabled: false,
       colorSchemeSimulation: "dark",
       javascriptEnabled: false,
     },
     "Option colorSchemeSimulation was set, with a string value"
   );
 
+  await targetConfigurationCommand.updateConfiguration({
+    setTabOffline: true,
+  });
+  compareOptions(
+    targetConfigurationCommand.configuration,
+    {
+      cacheDisabled: false,
+      colorSchemeSimulation: "dark",
+      javascriptEnabled: false,
+      setTabOffline: true,
+    },
+    "Option setTabOffline was set on"
+  );
+
+  await targetConfigurationCommand.updateConfiguration({
+    setTabOffline: false,
+  });
+  compareOptions(
+    targetConfigurationCommand.configuration,
+    {
+      setTabOffline: false,
+      cacheDisabled: false,
+      colorSchemeSimulation: "dark",
+      javascriptEnabled: false,
+    },
+    "Option setTabOffline was set off"
+  );
+
   targetCommand.destroy();
   await commands.destroy();
 });
 
 function compareOptions(options, expected, message) {
   is(
     Object.keys(options).length,
     Object.keys(expected).length,
--- a/devtools/shared/specs/target-configuration.js
+++ b/devtools/shared/specs/target-configuration.js
@@ -18,16 +18,17 @@ types.addDictType("target-configuration.
   customUserAgent: "nullable:string",
   javascriptEnabled: "nullable:boolean",
   overrideDPPX: "nullable:number",
   printSimulationEnabled: "nullable:boolean",
   rdmPaneOrientation: "nullable:json",
   reloadOnTouchSimulationToggle: "nullable:boolean",
   restoreFocus: "nullable:boolean",
   serviceWorkersTestingEnabled: "nullable:boolean",
+  setTabOffline: "nullable:boolean",
   touchEventsOverride: "nullable:string",
 });
 
 const targetConfigurationSpec = generateActorSpec({
   typeName: "target-configuration",
 
   methods: {
     updateConfiguration: {
--- a/toolkit/components/telemetry/Events.yaml
+++ b/toolkit/components/telemetry/Events.yaml
@@ -2348,17 +2348,17 @@ devtools.main:
     products:
       - "firefox"
       - "fennec"
     record_in_processes: ["main"]
     description: User has changed the throttle setting in the netmonitor.
     release_channel_collection: opt-out
     expiry_version: never
     extra_keys:
-      mode: No throttling, GPRS, Regular 2G, Good 2G, Regular 3G, Good 3G, Regular 4G / LTE, DSL or WI-FI.
+      mode: No throttling, GPRS, Regular 2G, Good 2G, Regular 3G, Good 3G, Regular 4G / LTE, DSL, WI-FI, or Offline.
       session_id: The toolbox session start time e.g. 13963.
   tool_timer:
     objects: ["animationinspector", "compatibilityview", "computedview", "changesview", "fontinspector", "layoutview", "ruleview"]
     bug_numbers: [1483817, 1639454]
     notification_emails: ["[email protected]"]
     products:
       - "firefox"
       - "fennec"