summaryrefslogtreecommitdiffstats
path: root/devtools/client/shared/components/throttling/profiles.js
blob: cd61f707723acfd14e591f62c644afa1e521f170 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

const K = 1024;
const M = 1024 * 1024;
const Bps = 1 / 8;
const KBps = K * Bps;
const MBps = M * Bps;

const { LocalizationHelper } = require("resource://devtools/shared/l10n.js");
const L10N = new LocalizationHelper(
  "devtools/client/locales/network-throttling.properties"
);

/**
 * Predefined network throttling profiles.
 * Speeds are in bytes per second.  Latency is in ms.
 */

class ThrottlingProfile {
  constructor({ id, download, upload, latency }) {
    this.id = id;
    this.download = download;
    this.upload = upload;
    this.latency = latency;
  }

  get description() {
    const download = this.#toDescriptionData(this.download);
    const upload = this.#toDescriptionData(this.upload);
    return L10N.getFormatStr(
      "throttling.profile.description",
      download.value,
      download.unit,
      upload.value,
      upload.unit,
      this.latency
    );
  }

  #toDescriptionData(val) {
    if (val % MBps === 0) {
      return { value: val / MBps, unit: "Mbps" };
    }
    return { value: val / KBps, unit: "Kbps" };
  }
}

const PROFILE_CONSTANTS = {
  GPRS: "GPRS",
  REGULAR_2G: "Regular 2G",
  GOOD_2G: "Good 2G",
  REGULAR_3G: "Regular 3G",
  GOOD_3G: "Good 3G",
  REGULAR_4G_LTE: "Regular 4G / LTE",
  DSL: "DSL",
  WIFI: "Wi-Fi",
  OFFLINE: "Offline",
};

// Should be synced with devtools/docs/user/network_monitor/throttling/index.rst
const profiles = [
  {
    id: PROFILE_CONSTANTS.GPRS,
    download: 50 * KBps,
    upload: 20 * KBps,
    latency: 500,
  },
  {
    id: PROFILE_CONSTANTS.REGULAR_2G,
    download: 250 * KBps,
    upload: 50 * KBps,
    latency: 300,
  },
  {
    id: PROFILE_CONSTANTS.GOOD_2G,
    download: 450 * KBps,
    upload: 150 * KBps,
    latency: 150,
  },
  {
    id: PROFILE_CONSTANTS.REGULAR_3G,
    download: 750 * KBps,
    upload: 250 * KBps,
    latency: 100,
  },
  {
    id: PROFILE_CONSTANTS.GOOD_3G,
    download: 1.5 * MBps,
    upload: 750 * KBps,
    latency: 40,
  },
  {
    id: PROFILE_CONSTANTS.REGULAR_4G_LTE,
    download: 4 * MBps,
    upload: 3 * MBps,
    latency: 20,
  },
  {
    id: PROFILE_CONSTANTS.DSL,
    download: 2 * MBps,
    upload: 1 * MBps,
    latency: 5,
  },
  {
    id: PROFILE_CONSTANTS.WIFI,
    download: 30 * MBps,
    upload: 15 * MBps,
    latency: 2,
  },
  {
    id: PROFILE_CONSTANTS.OFFLINE,
    download: 0,
    upload: 0,
    latency: 5,
  },
].map(profile => new ThrottlingProfile(profile));

module.exports = { profiles, PROFILE_CONSTANTS };