Pier Angelo Vendrame pushed to branch mullvad-browser-153.0esr-16.0-1 at The Tor Project / Applications / Mullvad Browser

Commits:

11 changed files:

Changes:

  • browser/app/profile/000-mullvad-browser.js
    ... ... @@ -39,3 +39,20 @@ pref("app.update.url.details", "https://mullvad.net/download/browser");
    39 39
     pref("app.update.badgeWaitTime", 0);
    
    40 40
     // point to our feedback url rather than Mozilla's
    
    41 41
     pref("app.feedback.baseURL", "https://mullvad.net/help/tag/browser/");
    
    42
    +
    
    43
    +// mullvad-browser#446: Default to unconfigured for selective saving mode for alpha
    
    44
    +// Controls what selective saving mode the browser operates in.
    
    45
    +// On initial startup the selective saving toolkit component sets this mode pref
    
    46
    +// when the user hasn't modified any of the prefs this pref controls. Otherwise,
    
    47
    +// the mode is set to selective saving
    
    48
    +//
    
    49
    +// 0 = mode has yet to be configured
    
    50
    +// 1 = always on private browsing mode (old default)
    
    51
    +// 2 = selective saving mode (new default)
    
    52
    +// 3 = normal browsing mode
    
    53
    +pref("browser.selectiveSavingMode", 0);
    
    54
    +#if MOZ_UPDATE_CHANNEL == release
    
    55
    +pref("browser.selectiveSavingMode.enabled", false);
    
    56
    +#else
    
    57
    +pref("browser.selectiveSavingMode.enabled", true);
    
    58
    +#endif

  • toolkit/components/moz.build
    ... ... @@ -78,6 +78,7 @@ DIRS += [
    78 78
         "resistfingerprinting",
    
    79 79
         "search",
    
    80 80
         "securitylevel",
    
    81
    +    "selectivesavingmode",
    
    81 82
         "sessionstore",
    
    82 83
         "shell",
    
    83 84
         "startup",
    

  • toolkit/components/selectivesavingmode/SelectiveSavingMode.manifest
    1
    +category profile-after-change SelectiveSavingMode @torproject.org/selective-saving-mode;1

  • toolkit/components/selectivesavingmode/SelectiveSavingMode.sys.mjs
    1
    +/* This Source Code Form is subject to the terms of the Mozilla Public
    
    2
    + * License, v. 2.0. If a copy of the MPL was not distributed with this
    
    3
    + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    
    4
    +
    
    5
    +// Pref to select browsing mode via this component
    
    6
    +export const kSelectiveSavingModePref = "browser.selectiveSavingMode";
    
    7
    +
    
    8
    +// Selective Saving Mode underlaying functionality prefs
    
    9
    +// Sanitize site data upon shutdown
    
    10
    +const kSanitizeOnShutdown = "privacy.sanitize.sanitizeOnShutdown";
    
    11
    +// Start browser in private window
    
    12
    +const kPrivateBrowsingAutostart = "browser.privatebrowsing.autostart";
    
    13
    +// Keep site permissions stored in memory rather than on disk
    
    14
    +const kKeepPermissionInMemory = "permissions.memory_only";
    
    15
    +
    
    16
    +// Valid options for the browsing mode pref to be set to
    
    17
    +export const SelectiveSavingModes = Object.freeze({
    
    18
    +  unconfigured: 0,
    
    19
    +  total_clearing: 1,
    
    20
    +  selective_saving: 2,
    
    21
    +  normal_browsing: 3,
    
    22
    +  custom: 4,
    
    23
    +});
    
    24
    +
    
    25
    +// A table of all prefs used to move between default browsing modes.
    
    26
    +const kSelectiveSavingModeSettings = {
    
    27
    +  total_clearing: {
    
    28
    +    [kSanitizeOnShutdown]: true,
    
    29
    +    [kPrivateBrowsingAutostart]: true,
    
    30
    +    [kKeepPermissionInMemory]: true,
    
    31
    +  },
    
    32
    +  selective_saving: {
    
    33
    +    [kSanitizeOnShutdown]: true,
    
    34
    +    [kPrivateBrowsingAutostart]: false,
    
    35
    +    [kKeepPermissionInMemory]: false,
    
    36
    +  },
    
    37
    +  normal_browsing: {
    
    38
    +    [kSanitizeOnShutdown]: false,
    
    39
    +    [kPrivateBrowsingAutostart]: false,
    
    40
    +    [kKeepPermissionInMemory]: false,
    
    41
    +  },
    
    42
    +};
    
    43
    +
    
    44
    +/**
    
    45
    + * Selective Saving Mode Pref Controller
    
    46
    + *
    
    47
    + * Listens for and handles changes in prefs relevant to Selective Saving Mode in
    
    48
    + * order to keep the browsing mode pref and the corresponding functionality
    
    49
    + * prefs in sync with each other each time any of the aforementioned prefs are
    
    50
    + * changed
    
    51
    + */
    
    52
    +export class SelectiveSavingPrefController {
    
    53
    +  QueryInterface = ChromeUtils.generateQI(["nsIObserver"]);
    
    54
    +
    
    55
    +  /**
    
    56
    +   * Initialize pref controller
    
    57
    +   */
    
    58
    +  init() {
    
    59
    +    if (!Services.prefs.getBoolPref("browser.selectiveSavingMode.enabled")) {
    
    60
    +      return;
    
    61
    +    }
    
    62
    +
    
    63
    +    if (
    
    64
    +      Services.prefs.getIntPref(kSelectiveSavingModePref) ===
    
    65
    +      SelectiveSavingModes.unconfigured
    
    66
    +    ) {
    
    67
    +      this.#setBrowsingModeFromPrefs();
    
    68
    +    } else {
    
    69
    +      this.#setPrefsFromBrowsingMode();
    
    70
    +    }
    
    71
    +
    
    72
    +    this.#createPreferenceObservers();
    
    73
    +  }
    
    74
    +
    
    75
    +  /**
    
    76
    +   * Shutdown pref controller
    
    77
    +   */
    
    78
    +  shutdown() {
    
    79
    +    this.#removePreferenceObservers();
    
    80
    +  }
    
    81
    +
    
    82
    +  /**
    
    83
    +   * Component hook for observing relevant event messages
    
    84
    +   *
    
    85
    +   * @param {string} aSubject
    
    86
    +   * @param {string} aTopic
    
    87
    +   */
    
    88
    +  observe(aSubject, aTopic) {
    
    89
    +    if (aTopic === "profile-after-change") {
    
    90
    +      this.init();
    
    91
    +    }
    
    92
    +  }
    
    93
    +
    
    94
    +  /**
    
    95
    +   * Sets current Selective Saving browsing mode to closely match how
    
    96
    +   * functionality prefs are configured in kSelectiveSavingModeSettings
    
    97
    +   */
    
    98
    +  #setBrowsingModeFromPrefs() {
    
    99
    +    const currentSanitizePref = Services.prefs.getBoolPref(kSanitizeOnShutdown);
    
    100
    +    const currentAutostartPref = Services.prefs.getBoolPref(
    
    101
    +      kPrivateBrowsingAutostart
    
    102
    +    );
    
    103
    +    const currentPermissionPref = Services.prefs.getBoolPref(
    
    104
    +      kKeepPermissionInMemory
    
    105
    +    );
    
    106
    +
    
    107
    +    for (let [mode, settings] of Object.entries(kSelectiveSavingModeSettings)) {
    
    108
    +      if (
    
    109
    +        currentSanitizePref === settings[kSanitizeOnShutdown] &&
    
    110
    +        currentAutostartPref === settings[kPrivateBrowsingAutostart] &&
    
    111
    +        currentPermissionPref === settings[kKeepPermissionInMemory]
    
    112
    +      ) {
    
    113
    +        Services.prefs.setIntPref(
    
    114
    +          kSelectiveSavingModePref,
    
    115
    +          SelectiveSavingModes[mode]
    
    116
    +        );
    
    117
    +        return;
    
    118
    +      }
    
    119
    +    }
    
    120
    +
    
    121
    +    Services.prefs.setIntPref(
    
    122
    +      kSelectiveSavingModePref,
    
    123
    +      SelectiveSavingModes.custom
    
    124
    +    );
    
    125
    +  }
    
    126
    +
    
    127
    +  /**
    
    128
    +   * A wrapper for setBrowsingModeFromPrefs to reset pref observers
    
    129
    +   */
    
    130
    +  #setModeAndResetObservers = () => {
    
    131
    +    this.#removePreferenceObservers();
    
    132
    +    this.#setBrowsingModeFromPrefs();
    
    133
    +    this.#createPreferenceObservers();
    
    134
    +  };
    
    135
    +
    
    136
    +  /**
    
    137
    +   * Sets current Selective Saving functionality prefs to closely match the
    
    138
    +   * currently assigned browsing mode. Corrects for anomalous settings if present
    
    139
    +   * as well
    
    140
    +   */
    
    141
    +  #setPrefsFromBrowsingMode() {
    
    142
    +    let currentBrowsingMode = Services.prefs.getIntPref(
    
    143
    +      kSelectiveSavingModePref
    
    144
    +    );
    
    145
    +
    
    146
    +    const mode = Object.entries(SelectiveSavingModes).find(
    
    147
    +      ([, value]) => value === currentBrowsingMode
    
    148
    +    )?.[0];
    
    149
    +
    
    150
    +    if (
    
    151
    +      mode === undefined ||
    
    152
    +      currentBrowsingMode === SelectiveSavingModes.unconfigured
    
    153
    +    ) {
    
    154
    +      this.#setBrowsingModeFromPrefs();
    
    155
    +      return;
    
    156
    +    }
    
    157
    +
    
    158
    +    if (kSelectiveSavingModeSettings[mode]) {
    
    159
    +      Services.prefs.setBoolPref(
    
    160
    +        kSanitizeOnShutdown,
    
    161
    +        kSelectiveSavingModeSettings[mode][kSanitizeOnShutdown]
    
    162
    +      );
    
    163
    +      Services.prefs.setBoolPref(
    
    164
    +        kPrivateBrowsingAutostart,
    
    165
    +        kSelectiveSavingModeSettings[mode][kPrivateBrowsingAutostart]
    
    166
    +      );
    
    167
    +      Services.prefs.setBoolPref(
    
    168
    +        kKeepPermissionInMemory,
    
    169
    +        kSelectiveSavingModeSettings[mode][kKeepPermissionInMemory]
    
    170
    +      );
    
    171
    +    }
    
    172
    +  }
    
    173
    +
    
    174
    +  /**
    
    175
    +   * A wrapper for setPrefsFromBrowsingMode to reset pref observers
    
    176
    +   */
    
    177
    +  #setPrefsAndResetObservers = () => {
    
    178
    +    this.#removePreferenceObservers();
    
    179
    +    this.#setPrefsFromBrowsingMode();
    
    180
    +    this.#createPreferenceObservers();
    
    181
    +  };
    
    182
    +
    
    183
    +  /**
    
    184
    +   * A helper function for standing up pref observers with the correct callback
    
    185
    +   */
    
    186
    +  #createPreferenceObservers() {
    
    187
    +    Services.prefs.addObserver(
    
    188
    +      kSelectiveSavingModePref,
    
    189
    +      this.#setPrefsAndResetObservers
    
    190
    +    );
    
    191
    +
    
    192
    +    Services.prefs.addObserver(
    
    193
    +      kSanitizeOnShutdown,
    
    194
    +      this.#setModeAndResetObservers
    
    195
    +    );
    
    196
    +    Services.prefs.addObserver(
    
    197
    +      kPrivateBrowsingAutostart,
    
    198
    +      this.#setModeAndResetObservers
    
    199
    +    );
    
    200
    +    Services.prefs.addObserver(
    
    201
    +      kKeepPermissionInMemory,
    
    202
    +      this.#setModeAndResetObservers
    
    203
    +    );
    
    204
    +  }
    
    205
    +
    
    206
    +  /**
    
    207
    +   * A helper function for disabling pref observers keyed to their respective
    
    208
    +   * callbacks
    
    209
    +   */
    
    210
    +  #removePreferenceObservers() {
    
    211
    +    Services.prefs.removeObserver(
    
    212
    +      kSelectiveSavingModePref,
    
    213
    +      this.#setPrefsAndResetObservers
    
    214
    +    );
    
    215
    +
    
    216
    +    Services.prefs.removeObserver(
    
    217
    +      kSanitizeOnShutdown,
    
    218
    +      this.#setModeAndResetObservers
    
    219
    +    );
    
    220
    +    Services.prefs.removeObserver(
    
    221
    +      kPrivateBrowsingAutostart,
    
    222
    +      this.#setModeAndResetObservers
    
    223
    +    );
    
    224
    +    Services.prefs.removeObserver(
    
    225
    +      kKeepPermissionInMemory,
    
    226
    +      this.#setModeAndResetObservers
    
    227
    +    );
    
    228
    +  }
    
    229
    +} /* Selective Saving Mode Pref Controller */

  • toolkit/components/selectivesavingmode/components.conf
    1
    +# This Source Code Form is subject to the terms of the Mozilla Public
    
    2
    +# License, v. 2.0. If a copy of the MPL was not distributed with this
    
    3
    +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
    
    4
    +
    
    5
    +Classes = [
    
    6
    +    {
    
    7
    +        "cid": "{b4a1073c-9e3c-4ce7-b13b-c100f5c64ccb}",
    
    8
    +        "contract_ids": [
    
    9
    +            "@torproject.org/selective-saving-mode;1",
    
    10
    +        ],
    
    11
    +        "esModule": "moz-src:///toolkit/components/selectivesavingmode/SelectiveSavingMode.sys.mjs",
    
    12
    +        "constructor": "SelectiveSavingPrefController",
    
    13
    +    }
    
    14
    +]

  • toolkit/components/selectivesavingmode/content/broom-clean.svg
    1
    +<?xml version="1.0" encoding="UTF-8"?>
    
    2
    +<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    
    3
    +    <g fill="context-fill" fill-opacity="context-fill-opacity">
    
    4
    +        <path d="m13.5383 14.5627c-.1712-.0053-.3194-.1334-.3505-.3028-.0419-.294-.1441-.5789-.3001-.8369-.2583-.1558-.5436-.2579-.838-.2998-.1694-.0313-.2974-.1793-.3026-.3501-.0053-.1708.1136-.3146.2813-.3402.2944-.0329.5762-.1254.8284-.272.1426-.2476.2313-.5243.2608-.8129.0237-.1679.1662-.2884.3372-.2851.1699.0042.3181.1295.3517.2973.0471.2931.1533.5763.312.8323.2565.1573.5396.263.8326.3109.1682.0345.2929.1836.2958.3536.0028.17-.1171.3116-.2843.3357-.2894.0285-.5669.1172-.8147.2604-.1462.2521-.2386.5335-.2717.8274-.025.167-.1675.2861-.3379.2822z"/>
    
    5
    +        <path d="m6.49858 2.99992c-.14675-.00459-.27377-.11436-.3004-.25961-.03593-.25196-.12354-.49621-.25729-.71731-.22137-.13358-.46594-.22109-.71822-.25699-.14526-.02682-.25492-.15363-.25945-.30004-.00454-.14641.09737-.26967.24112-.29164.25236-.02817.49393-.10747.71013-.233093.12217-.2123.19825-.449454.22353-.696834.0203-.143878.14242-.24714456.28897-.24434753.14565.00358504.27273.11100153.30149.25484453.0404.251183.13139.493923.2674.713349.21988.134841.46256.225461.71364.266481.14417.02957.25114.15744.25358.30313.00244.1457-.10035.26707-.24368.28774-.2481.02441-.48592.10041-.69835.22319-.1253.2161-.20449.45729-.23284.7092-.0214.14312-.14361.24521-.28963.24193z"/>
    
    6
    +        <path d="m1.82093 5.3609c-.15279-.00473-.28512-.11875-.31315-.26981-.02739-.18014-.08781-.35525-.1782-.51643-.16152-.09021-.336989-.15052-.517512-.17788-.151437-.02794-.265749-.16003-.270474-.31254-.004724-.15251.101518-.2809.251381-.30378.181146-.02145.355265-.07593.513815-.16075.08209-.15545.13363-.32622.15197-.50355.02095-.15059.14903-.25861.3025-.25512.15164.00368.28404.11525.31428.26484.03021.18029.09338.35503.18632.51538.16048.09192.33508.15452.51517.18469.1503.0308.26181.164.26435.31577.00254.15176-.10462.27819-.25404.29971-.17764.01914-.34855.07141-.50396.15412-.08502.1582-.13963.33194-.16114.5127-.022.14911-.14912.25571-.30131.25265z"/>
    
    7
    +        <path clip-rule="evenodd" d="m15.3213 1.06694c.2441-.244076.2441-.639804 0-.883882-.2441-.2440775-.6398-.2440774-.8839 0l-5.96506 5.965062h-.50519c-1.996-1.09517-4.49023.42233-6.49079 1.63948-.41545.25277-.80961.49258-1.173597.69335-.16756.10002-.289261.26641-.30145394.48048-.01219156.21407.06079654.41038.21802994.56743l1.243691 1.24224 2.37084-1.02603c.15392-.06661.30331.14022.18601.25753l-1.66213 1.6621 1.46329 1.4616 1.66126-1.6613c.1173-.1173.32413.0321.25752.186l-1.02482 2.3682 1.25462 1.2531c.15724.157.35379.23.56815.2178.19095-.0561.35851-.1561.45869-.3234.20012-.3592.43577-.7455.68321-1.1511 1.22241-2.0039 2.73233-4.47901 1.66484-6.47533v-.49654zm-7.46715 6.55077c1.12692 1.12692.64113 2.69369-.05278 3.70149h-.50137l-3.13-3.1492v-.5c1.00858-.68566 2.56556-1.17088 3.68415-.05229z" fill-rule="evenodd"/>
    
    8
    +    </g>
    
    9
    +</svg>

  • toolkit/components/selectivesavingmode/content/broom-saved.svg
    1
    +<?xml version="1.0" encoding="UTF-8"?>
    
    2
    +<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    
    3
    +    <g fill="context-fill" fill-opacity="context-fill-opacity">
    
    4
    +      <path d="M1.31604 2.56132C1.07376 2.31905 0.680954 2.31905 0.438678 2.56132C0.196403 2.8036 0.196403 3.1964 0.438678 3.43868L12.3649 15.3649C12.6072 15.6072 13 15.6072 13.2423 15.3649C13.4845 15.1226 13.4845 14.7298 13.2423 14.4875L1.31604 2.56132Z" />
    
    5
    +      <path d="M5.75301 6.99811C5.17481 7.10048 4.6182 7.36528 4.17 7.66998V8.16998L7.29989 11.3194H7.80184C8.11144 10.8697 8.37762 10.3082 8.47957 9.72467L9.40926 10.6544C9.01989 11.8129 8.31279 12.978 7.67977 14.0157C7.43234 14.4213 7.19629 14.8079 6.99617 15.1671C6.89602 15.3341 6.72885 15.4342 6.53817 15.4903C6.32389 15.5024 6.12701 15.4295 5.96981 15.2725L4.71492 14.0196L5.74031 11.6514C5.8069 11.4976 5.59983 11.3479 5.4825 11.4649L3.82137 13.126L2.3575 11.6651L4.01961 10.003C4.13689 9.88571 3.98795 9.67869 3.83406 9.74518L1.46297 10.7715L0.219804 9.52936C0.0625708 9.37231 -0.0111371 9.17507 0.00105446 8.961C0.0133896 8.74714 0.135367 8.58049 0.302812 8.48053C0.666747 8.27978 1.06126 8.03989 1.47664 7.78717C2.50628 7.16073 3.6674 6.45677 4.82332 6.06842L5.75301 6.99811ZM14.4375 0.182679C14.6816 -0.0610732 15.0773 -0.0611198 15.3213 0.182679C15.5654 0.426757 15.5654 0.823367 15.3213 1.06744L9.34481 7.04401V7.5401C9.6249 8.06391 9.72625 8.62084 9.70321 9.19342L6.28426 5.77545C6.86809 5.75137 7.43503 5.85671 7.96688 6.1485H8.47274L14.4375 0.182679Z" />
    
    6
    +    </g>
    
    7
    +</svg>

  • toolkit/components/selectivesavingmode/jar.mn
    1
    +# This Source Code Form is subject to the terms of the Mozilla Public
    
    2
    +# License, v. 2.0. If a copy of the MPL was not distributed with this
    
    3
    +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
    
    4
    +
    
    5
    +toolkit.jar:
    
    6
    +  content/global/selectivesaving/broom-clean.svg     (content/broom-clean.svg)
    
    7
    +  content/global/selectivesaving/broom-saved.svg      (content/broom-saved.svg)

  • toolkit/components/selectivesavingmode/moz.build
    1
    +# This Source Code Form is subject to the terms of the Mozilla Public
    
    2
    +# License, v. 2.0. If a copy of the MPL was not distributed with this
    
    3
    +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
    
    4
    +
    
    5
    +XPCSHELL_TESTS_MANIFESTS += [
    
    6
    +    "tests/xpcshell/xpcshell.toml",
    
    7
    +]
    
    8
    +
    
    9
    +MOZ_SRC_FILES += [
    
    10
    +    "SelectiveSavingMode.sys.mjs",
    
    11
    +]
    
    12
    +
    
    13
    +XPCOM_MANIFESTS += [
    
    14
    +    "components.conf",
    
    15
    +]
    
    16
    +
    
    17
    +EXTRA_COMPONENTS += [
    
    18
    +    "SelectiveSavingMode.manifest",
    
    19
    +]
    
    20
    +
    
    21
    +JAR_MANIFESTS += [
    
    22
    +    "jar.mn",
    
    23
    +]

  • toolkit/components/selectivesavingmode/tests/xpcshell/test_selective_saving_mode.js
    1
    +/* This Source Code Form is subject to the terms of the Mozilla Public
    
    2
    + * License, v. 2.0. If a copy of the MPL was not distributed with this
    
    3
    + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    
    4
    +
    
    5
    +"use strict";
    
    6
    +
    
    7
    +const {
    
    8
    +  SelectiveSavingPrefController,
    
    9
    +  SelectiveSavingModes,
    
    10
    +  kSelectiveSavingModePref,
    
    11
    +} = ChromeUtils.importESModule(
    
    12
    +  "moz-src:///toolkit/components/selectivesavingmode/SelectiveSavingMode.sys.mjs"
    
    13
    +);
    
    14
    +
    
    15
    +// secondary prefs
    
    16
    +const kSanitizeOnShutdown = "privacy.sanitize.sanitizeOnShutdown";
    
    17
    +const kPrivateBrowsingAutostart = "browser.privatebrowsing.autostart";
    
    18
    +const kKeepPermissionInMemory = "permissions.memory_only";
    
    19
    +
    
    20
    +const controller = new SelectiveSavingPrefController();
    
    21
    +
    
    22
    +function resetToTotalSavingPrefs() {
    
    23
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
    
    24
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
    
    25
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, true);
    
    26
    +}
    
    27
    +
    
    28
    +registerCleanupFunction(async () => {
    
    29
    +  controller.shutdown();
    
    30
    +});
    
    31
    +
    
    32
    +add_task(async function test_init_from_secondary_prefs() {
    
    33
    +  Services.prefs.setIntPref(
    
    34
    +    kSelectiveSavingModePref,
    
    35
    +    SelectiveSavingModes.unconfigured
    
    36
    +  );
    
    37
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
    
    38
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
    
    39
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, true);
    
    40
    +
    
    41
    +  controller.init();
    
    42
    +
    
    43
    +  Assert.equal(
    
    44
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    45
    +    SelectiveSavingModes.total_clearing,
    
    46
    +    "After pref controller init from unconfigured state, primary pref should be set to total clearing due to the way secondary prefs were set earlier"
    
    47
    +  );
    
    48
    +
    
    49
    +  controller.shutdown();
    
    50
    +
    
    51
    +  Services.prefs.setIntPref(
    
    52
    +    kSelectiveSavingModePref,
    
    53
    +    SelectiveSavingModes.unconfigured
    
    54
    +  );
    
    55
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
    
    56
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
    
    57
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    58
    +
    
    59
    +  controller.init();
    
    60
    +
    
    61
    +  Assert.equal(
    
    62
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    63
    +    SelectiveSavingModes.selective_saving,
    
    64
    +    "After pref controller init from unconfigured state, primary pref should be set to selective saving due to the way secondary prefs were set earlier"
    
    65
    +  );
    
    66
    +
    
    67
    +  controller.shutdown();
    
    68
    +
    
    69
    +  Services.prefs.setIntPref(
    
    70
    +    kSelectiveSavingModePref,
    
    71
    +    SelectiveSavingModes.unconfigured
    
    72
    +  );
    
    73
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
    
    74
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
    
    75
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    76
    +
    
    77
    +  controller.init();
    
    78
    +
    
    79
    +  Assert.equal(
    
    80
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    81
    +    SelectiveSavingModes.normal_browsing,
    
    82
    +    "After pref controller init from unconfigured state, primary pref should be set to normal browsing due to the way secondary prefs were set earlier"
    
    83
    +  );
    
    84
    +
    
    85
    +  controller.shutdown();
    
    86
    +
    
    87
    +  Services.prefs.setIntPref(
    
    88
    +    kSelectiveSavingModePref,
    
    89
    +    SelectiveSavingModes.unconfigured
    
    90
    +  );
    
    91
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
    
    92
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
    
    93
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    94
    +
    
    95
    +  controller.init();
    
    96
    +
    
    97
    +  Assert.equal(
    
    98
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    99
    +    SelectiveSavingModes.custom,
    
    100
    +    "After pref controller init from unconfigured state, primary pref should be set to custom browsing due to the way secondary prefs were set earlier"
    
    101
    +  );
    
    102
    +
    
    103
    +  controller.shutdown();
    
    104
    +});
    
    105
    +
    
    106
    +add_task(async function test_init_from_secondary_prefs() {
    
    107
    +  Services.prefs.setIntPref(
    
    108
    +    kSelectiveSavingModePref,
    
    109
    +    SelectiveSavingModes.total_clearing
    
    110
    +  );
    
    111
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
    
    112
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
    
    113
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, true);
    
    114
    +
    
    115
    +  controller.init();
    
    116
    +
    
    117
    +  Assert.equal(
    
    118
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    119
    +    SelectiveSavingModes.total_clearing,
    
    120
    +    "After pref controller init from total clearing mode configured state (primary and secondary), primary pref shouldn't be changed from total clearing"
    
    121
    +  );
    
    122
    +
    
    123
    +  Assert.equal(
    
    124
    +    Services.prefs.getBoolPref(kSanitizeOnShutdown),
    
    125
    +    true,
    
    126
    +    "After pref controller init from total clearing mode configured state (primary and secondary), secondary pref for sanitize on shutdown should be set to true"
    
    127
    +  );
    
    128
    +
    
    129
    +  Assert.equal(
    
    130
    +    Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
    
    131
    +    true,
    
    132
    +    "After pref controller init from total clearing mode configured state (primary and secondary), secondary pref for pbm autostart should be set to true"
    
    133
    +  );
    
    134
    +
    
    135
    +  Assert.equal(
    
    136
    +    Services.prefs.getBoolPref(kKeepPermissionInMemory),
    
    137
    +    true,
    
    138
    +    "After pref controller init from total clearing mode configured state (primary and secondary), secondary pref for memory only permissions should be set to true"
    
    139
    +  );
    
    140
    +
    
    141
    +  controller.shutdown();
    
    142
    +
    
    143
    +  Services.prefs.setIntPref(
    
    144
    +    kSelectiveSavingModePref,
    
    145
    +    SelectiveSavingModes.selective_saving
    
    146
    +  );
    
    147
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
    
    148
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
    
    149
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    150
    +
    
    151
    +  controller.init();
    
    152
    +
    
    153
    +  Assert.equal(
    
    154
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    155
    +    SelectiveSavingModes.selective_saving,
    
    156
    +    "After pref controller init from selective saving configured state (primary and secondary), primary pref shouldn't be changed from selective saving"
    
    157
    +  );
    
    158
    +
    
    159
    +  Assert.equal(
    
    160
    +    Services.prefs.getBoolPref(kSanitizeOnShutdown),
    
    161
    +    true,
    
    162
    +    "After pref controller init from selective saving mode configured state (primary and secondary), secondary pref for sanitize on shutdown should be set to true"
    
    163
    +  );
    
    164
    +
    
    165
    +  Assert.equal(
    
    166
    +    Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
    
    167
    +    false,
    
    168
    +    "After pref controller init from selective saving mode configured state (primary and secondary), secondary pref for pbm autostart should be set to false"
    
    169
    +  );
    
    170
    +
    
    171
    +  Assert.equal(
    
    172
    +    Services.prefs.getBoolPref(kKeepPermissionInMemory),
    
    173
    +    false,
    
    174
    +    "After pref controller init from selective saving mode configured state (primary and secondary), secondary pref for memory only permissions should be set to false"
    
    175
    +  );
    
    176
    +
    
    177
    +  controller.shutdown();
    
    178
    +
    
    179
    +  Services.prefs.setIntPref(
    
    180
    +    kSelectiveSavingModePref,
    
    181
    +    SelectiveSavingModes.normal_browsing
    
    182
    +  );
    
    183
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
    
    184
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
    
    185
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    186
    +
    
    187
    +  controller.init();
    
    188
    +
    
    189
    +  Assert.equal(
    
    190
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    191
    +    SelectiveSavingModes.normal_browsing,
    
    192
    +    "After pref controller init from normal browsing mode configured state (primary and secondary), primary pref shouldn't be changed from normal browsing"
    
    193
    +  );
    
    194
    +
    
    195
    +  Assert.equal(
    
    196
    +    Services.prefs.getBoolPref(kSanitizeOnShutdown),
    
    197
    +    false,
    
    198
    +    "After pref controller init from normal browsing mode configured state (primary and secondary), secondary pref for sanitize on shutdown should be set to false"
    
    199
    +  );
    
    200
    +
    
    201
    +  Assert.equal(
    
    202
    +    Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
    
    203
    +    false,
    
    204
    +    "After pref controller init from normal browsing mode configured state (primary and secondary), secondary pref for pbm autostart should be set to false"
    
    205
    +  );
    
    206
    +
    
    207
    +  Assert.equal(
    
    208
    +    Services.prefs.getBoolPref(kKeepPermissionInMemory),
    
    209
    +    false,
    
    210
    +    "After pref controller init from normal browsing mode configured state (primary and secondary), secondary pref for memory only permissions should be set to false"
    
    211
    +  );
    
    212
    +
    
    213
    +  controller.shutdown();
    
    214
    +
    
    215
    +  Services.prefs.setIntPref(
    
    216
    +    kSelectiveSavingModePref,
    
    217
    +    SelectiveSavingModes.custom
    
    218
    +  );
    
    219
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
    
    220
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
    
    221
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    222
    +
    
    223
    +  controller.init();
    
    224
    +
    
    225
    +  Assert.equal(
    
    226
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    227
    +    SelectiveSavingModes.custom,
    
    228
    +    "After pref controller init from custom mode configured state (primary and secondary), primary pref shouldn't be changed from custom"
    
    229
    +  );
    
    230
    +
    
    231
    +  Assert.equal(
    
    232
    +    Services.prefs.getBoolPref(kSanitizeOnShutdown),
    
    233
    +    true,
    
    234
    +    "After pref contoller init from total clearing mode configured state (primary and secondary), secondary pref for sanitize on shutdown should be set to true"
    
    235
    +  );
    
    236
    +
    
    237
    +  Assert.equal(
    
    238
    +    Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
    
    239
    +    true,
    
    240
    +    "After pref contoller init from total clearing mode configured state (primary and secondary), secondary pref for pbm autostart should be set to true"
    
    241
    +  );
    
    242
    +
    
    243
    +  Assert.equal(
    
    244
    +    Services.prefs.getBoolPref(kKeepPermissionInMemory),
    
    245
    +    false,
    
    246
    +    "After pref contoller init from total clearing mode configured state (primary and secondary), secondary pref for memory only permissions should be set to false"
    
    247
    +  );
    
    248
    +
    
    249
    +  controller.shutdown();
    
    250
    +
    
    251
    +  Services.prefs.setIntPref(
    
    252
    +    kSelectiveSavingModePref,
    
    253
    +    SelectiveSavingModes.total_clearing
    
    254
    +  );
    
    255
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
    
    256
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
    
    257
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    258
    +
    
    259
    +  controller.init();
    
    260
    +
    
    261
    +  Assert.equal(
    
    262
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    263
    +    SelectiveSavingModes.total_clearing,
    
    264
    +    "After pref controller init from configured state, primary pref shouldn't be changed from total clearing"
    
    265
    +  );
    
    266
    +
    
    267
    +  Assert.equal(
    
    268
    +    Services.prefs.getBoolPref(kSanitizeOnShutdown),
    
    269
    +    true,
    
    270
    +    "After pref contoller init from total clearing mode configured state, secondary pref for sanitize on shutdown should be set to true"
    
    271
    +  );
    
    272
    +
    
    273
    +  Assert.equal(
    
    274
    +    Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
    
    275
    +    true,
    
    276
    +    "After pref contoller init from total clearing mode configured state, secondary pref for pbm autostart should be set to true"
    
    277
    +  );
    
    278
    +
    
    279
    +  Assert.equal(
    
    280
    +    Services.prefs.getBoolPref(kKeepPermissionInMemory),
    
    281
    +    true,
    
    282
    +    "After pref contoller init from total clearing mode configured state, secondary pref for memory only permissions should be set to true"
    
    283
    +  );
    
    284
    +
    
    285
    +  controller.shutdown();
    
    286
    +
    
    287
    +  Services.prefs.setIntPref(
    
    288
    +    kSelectiveSavingModePref,
    
    289
    +    SelectiveSavingModes.selective_saving
    
    290
    +  );
    
    291
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
    
    292
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
    
    293
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    294
    +
    
    295
    +  controller.init();
    
    296
    +
    
    297
    +  Assert.equal(
    
    298
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    299
    +    SelectiveSavingModes.selective_saving,
    
    300
    +    "After pref controller init from configured state, primary pref shouldn't be changed from normal browsing"
    
    301
    +  );
    
    302
    +
    
    303
    +  Assert.equal(
    
    304
    +    Services.prefs.getBoolPref(kSanitizeOnShutdown),
    
    305
    +    true,
    
    306
    +    "After pref contoller init from selective saving mode configured state, secondary pref for sanitize on shutdown should be set to true"
    
    307
    +  );
    
    308
    +
    
    309
    +  Assert.equal(
    
    310
    +    Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
    
    311
    +    false,
    
    312
    +    "After pref contoller init from selective saving mode configured state, secondary pref for pbm autostart should be set to false"
    
    313
    +  );
    
    314
    +
    
    315
    +  Assert.equal(
    
    316
    +    Services.prefs.getBoolPref(kKeepPermissionInMemory),
    
    317
    +    false,
    
    318
    +    "After pref contoller init from selective saving mode configured state, secondary pref for memory only permissions should be set to false"
    
    319
    +  );
    
    320
    +
    
    321
    +  controller.shutdown();
    
    322
    +
    
    323
    +  Services.prefs.setIntPref(
    
    324
    +    kSelectiveSavingModePref,
    
    325
    +    SelectiveSavingModes.normal_browsing
    
    326
    +  );
    
    327
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
    
    328
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
    
    329
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, true);
    
    330
    +
    
    331
    +  controller.init();
    
    332
    +
    
    333
    +  Assert.equal(
    
    334
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    335
    +    SelectiveSavingModes.normal_browsing,
    
    336
    +    "After pref controller init from configured state, primary pref shouldn't be changed from normal browsing"
    
    337
    +  );
    
    338
    +
    
    339
    +  Assert.equal(
    
    340
    +    Services.prefs.getBoolPref(kSanitizeOnShutdown),
    
    341
    +    false,
    
    342
    +    "After pref contoller init from normal browsing mode configured state, secondary pref for sanitize on shutdown should be set to false"
    
    343
    +  );
    
    344
    +
    
    345
    +  Assert.equal(
    
    346
    +    Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
    
    347
    +    false,
    
    348
    +    "After pref contoller init from normal browsing mode configured state, secondary pref for pbm autostart should be set to false"
    
    349
    +  );
    
    350
    +
    
    351
    +  Assert.equal(
    
    352
    +    Services.prefs.getBoolPref(kKeepPermissionInMemory),
    
    353
    +    false,
    
    354
    +    "After pref contoller init from normal browsing mode configured state, secondary pref for memory only permissions should be set to false"
    
    355
    +  );
    
    356
    +
    
    357
    +  controller.shutdown();
    
    358
    +
    
    359
    +  Services.prefs.setIntPref(
    
    360
    +    kSelectiveSavingModePref,
    
    361
    +    SelectiveSavingModes.custom
    
    362
    +  );
    
    363
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
    
    364
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
    
    365
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    366
    +
    
    367
    +  controller.init();
    
    368
    +
    
    369
    +  Assert.equal(
    
    370
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    371
    +    SelectiveSavingModes.custom,
    
    372
    +    "After pref controller init from configured state, primary pref shouldn't be changed from custom"
    
    373
    +  );
    
    374
    +
    
    375
    +  Assert.equal(
    
    376
    +    Services.prefs.getBoolPref(kSanitizeOnShutdown),
    
    377
    +    false,
    
    378
    +    "After pref contoller init from custom mode configured state, secondary pref for sanitize on shutdown should remain unchanged"
    
    379
    +  );
    
    380
    +
    
    381
    +  Assert.equal(
    
    382
    +    Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
    
    383
    +    false,
    
    384
    +    "After pref contoller init from custom mode configured state, secondary pref for pbm autostart should remain unchanged"
    
    385
    +  );
    
    386
    +
    
    387
    +  Assert.equal(
    
    388
    +    Services.prefs.getBoolPref(kKeepPermissionInMemory),
    
    389
    +    false,
    
    390
    +    "After pref contoller init from custom mode configured state, secondary pref for memory only permissions should remain unchanged"
    
    391
    +  );
    
    392
    +});
    
    393
    +
    
    394
    +add_task(async function test_secondary_prefs_update_mode() {
    
    395
    +  controller.init();
    
    396
    +
    
    397
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, true);
    
    398
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
    
    399
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
    
    400
    +
    
    401
    +  Assert.equal(
    
    402
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    403
    +    SelectiveSavingModes.total_clearing,
    
    404
    +    "After pref update mode should be set to total clearing"
    
    405
    +  );
    
    406
    +
    
    407
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    408
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
    
    409
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
    
    410
    +
    
    411
    +  Assert.equal(
    
    412
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    413
    +    SelectiveSavingModes.selective_saving,
    
    414
    +    "After pref update mode should be set to selective saving"
    
    415
    +  );
    
    416
    +
    
    417
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    418
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
    
    419
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
    
    420
    +
    
    421
    +  Assert.equal(
    
    422
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    423
    +    SelectiveSavingModes.normal_browsing,
    
    424
    +    "After pref update mode should be set to normal browsing"
    
    425
    +  );
    
    426
    +
    
    427
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    428
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
    
    429
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
    
    430
    +
    
    431
    +  Assert.equal(
    
    432
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    433
    +    SelectiveSavingModes.normal_browsing,
    
    434
    +    "Duplicate for idempotency. after pref update mode should be set to normal browsing"
    
    435
    +  );
    
    436
    +
    
    437
    +  Assert.equal(
    
    438
    +    Services.prefs.getBoolPref(kSanitizeOnShutdown),
    
    439
    +    false,
    
    440
    +    "Duplicate for idempotency. Changing browsing mode to normal browsing should set sanitize on shutdown to false"
    
    441
    +  );
    
    442
    +
    
    443
    +  Assert.equal(
    
    444
    +    Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
    
    445
    +    false,
    
    446
    +    "Duplicate for idempotency. Changing browsing mode to normal browsing should set pbm autostart to false"
    
    447
    +  );
    
    448
    +
    
    449
    +  Assert.equal(
    
    450
    +    Services.prefs.getBoolPref(kKeepPermissionInMemory),
    
    451
    +    false,
    
    452
    +    "Duplicate for idempotency. Changing browsing mode to normal browsing should set memory only permissions to false"
    
    453
    +  );
    
    454
    +
    
    455
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    456
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
    
    457
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
    
    458
    +
    
    459
    +  Assert.equal(
    
    460
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    461
    +    SelectiveSavingModes.custom,
    
    462
    +    "After pref update mode should be set to custom"
    
    463
    +  );
    
    464
    +
    
    465
    +  resetToTotalSavingPrefs();
    
    466
    +
    
    467
    +  Services.prefs.setIntPref(
    
    468
    +    kSelectiveSavingModePref,
    
    469
    +    SelectiveSavingModes.custom
    
    470
    +  );
    
    471
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    472
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
    
    473
    +
    
    474
    +  Assert.equal(
    
    475
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    476
    +    SelectiveSavingModes.selective_saving,
    
    477
    +    "Manually changing to custom browsing via primary pref then changing secondary prefs to match another browsing mode should leave custom browsing"
    
    478
    +  );
    
    479
    +
    
    480
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
    
    481
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
    
    482
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    483
    +
    
    484
    +  Assert.equal(
    
    485
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    486
    +    SelectiveSavingModes.custom,
    
    487
    +    "Secondary Prefs set to (true, true, false) should result in Custom Browsing Mode"
    
    488
    +  );
    
    489
    +
    
    490
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
    
    491
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
    
    492
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, true);
    
    493
    +
    
    494
    +  Assert.equal(
    
    495
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    496
    +    SelectiveSavingModes.custom,
    
    497
    +    "Secondary Prefs set to (true, false, true) should result in Custom Browsing Mode"
    
    498
    +  );
    
    499
    +
    
    500
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
    
    501
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
    
    502
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, true);
    
    503
    +
    
    504
    +  Assert.equal(
    
    505
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    506
    +    SelectiveSavingModes.custom,
    
    507
    +    "Secondary Prefs set to (false, false, true) should result in Custom Browsing Mode"
    
    508
    +  );
    
    509
    +
    
    510
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
    
    511
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
    
    512
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    513
    +
    
    514
    +  Assert.equal(
    
    515
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    516
    +    SelectiveSavingModes.custom,
    
    517
    +    "Secondary Prefs set to (false, true, false) should result in Custom Browsing Mode"
    
    518
    +  );
    
    519
    +
    
    520
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
    
    521
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
    
    522
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, true);
    
    523
    +
    
    524
    +  Assert.equal(
    
    525
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    526
    +    SelectiveSavingModes.custom,
    
    527
    +    "Secondary Prefs set to (false, true, true) should result in Custom Browsing Mode"
    
    528
    +  );
    
    529
    +});
    
    530
    +
    
    531
    +add_task(async function test_mode_updates_from_secondary_prefs() {
    
    532
    +  controller.init();
    
    533
    +
    
    534
    +  Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
    
    535
    +  Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
    
    536
    +  Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
    
    537
    +
    
    538
    +  Services.prefs.setIntPref(
    
    539
    +    kSelectiveSavingModePref,
    
    540
    +    SelectiveSavingModes.total_clearing
    
    541
    +  );
    
    542
    +
    
    543
    +  Assert.equal(
    
    544
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    545
    +    SelectiveSavingModes.total_clearing,
    
    546
    +    "Changing browsing mode to total clearing should set browsing mode to match"
    
    547
    +  );
    
    548
    +
    
    549
    +  Assert.equal(
    
    550
    +    Services.prefs.getBoolPref(kSanitizeOnShutdown),
    
    551
    +    true,
    
    552
    +    "Changing browsing mode to total clearing should set sanitize on shutdown to true"
    
    553
    +  );
    
    554
    +
    
    555
    +  Assert.equal(
    
    556
    +    Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
    
    557
    +    true,
    
    558
    +    "Changing browsing mode to total clearing should set pbm autostart to true"
    
    559
    +  );
    
    560
    +
    
    561
    +  Assert.equal(
    
    562
    +    Services.prefs.getBoolPref(kKeepPermissionInMemory),
    
    563
    +    true,
    
    564
    +    "Changing browsing mode to total clearing should set memory only permissions to true"
    
    565
    +  );
    
    566
    +
    
    567
    +  Services.prefs.setIntPref(
    
    568
    +    kSelectiveSavingModePref,
    
    569
    +    SelectiveSavingModes.total_clearing
    
    570
    +  );
    
    571
    +
    
    572
    +  Assert.equal(
    
    573
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    574
    +    SelectiveSavingModes.total_clearing,
    
    575
    +    "Duplicate for idempotency. Changing browsing mode to total clearing should set browsing mode to match"
    
    576
    +  );
    
    577
    +
    
    578
    +  Assert.equal(
    
    579
    +    Services.prefs.getBoolPref(kSanitizeOnShutdown),
    
    580
    +    true,
    
    581
    +    "Duplicate for idempotency. Changing browsing mode to total clearing should set sanitize on shutdown to true"
    
    582
    +  );
    
    583
    +
    
    584
    +  Assert.equal(
    
    585
    +    Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
    
    586
    +    true,
    
    587
    +    "Duplicate for idempotency. Changing browsing mode to total clearing should set pbm autostart to true"
    
    588
    +  );
    
    589
    +
    
    590
    +  Assert.equal(
    
    591
    +    Services.prefs.getBoolPref(kKeepPermissionInMemory),
    
    592
    +    true,
    
    593
    +    "Duplicate for idempotency. Changing browsing mode to total clearing should set memory only permissions to true"
    
    594
    +  );
    
    595
    +
    
    596
    +  resetToTotalSavingPrefs();
    
    597
    +
    
    598
    +  Services.prefs.setIntPref(
    
    599
    +    kSelectiveSavingModePref,
    
    600
    +    SelectiveSavingModes.selective_saving
    
    601
    +  );
    
    602
    +
    
    603
    +  Assert.equal(
    
    604
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    605
    +    SelectiveSavingModes.selective_saving,
    
    606
    +    "Changing browsing mode to selective saving should set browsing mode to match"
    
    607
    +  );
    
    608
    +
    
    609
    +  Assert.equal(
    
    610
    +    Services.prefs.getBoolPref(kSanitizeOnShutdown),
    
    611
    +    true,
    
    612
    +    "Changing browsing mode to selective saving should set sanitize on shutdown to true"
    
    613
    +  );
    
    614
    +
    
    615
    +  Assert.equal(
    
    616
    +    Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
    
    617
    +    false,
    
    618
    +    "Changing browsing mode to selective saving should set pbm autostart to false"
    
    619
    +  );
    
    620
    +
    
    621
    +  Assert.equal(
    
    622
    +    Services.prefs.getBoolPref(kKeepPermissionInMemory),
    
    623
    +    false,
    
    624
    +    "Changing browsing mode to selective saving should set memory only permissions to false"
    
    625
    +  );
    
    626
    +
    
    627
    +  resetToTotalSavingPrefs();
    
    628
    +
    
    629
    +  Services.prefs.setIntPref(
    
    630
    +    kSelectiveSavingModePref,
    
    631
    +    SelectiveSavingModes.normal_browsing
    
    632
    +  );
    
    633
    +
    
    634
    +  Assert.equal(
    
    635
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    636
    +    SelectiveSavingModes.normal_browsing,
    
    637
    +    "Changing browsing mode to normal browsing should set browsing mode to match"
    
    638
    +  );
    
    639
    +
    
    640
    +  Assert.equal(
    
    641
    +    Services.prefs.getBoolPref(kSanitizeOnShutdown),
    
    642
    +    false,
    
    643
    +    "Changing browsing mode to normal browsing should set sanitize on shutdown to true"
    
    644
    +  );
    
    645
    +
    
    646
    +  Assert.equal(
    
    647
    +    Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
    
    648
    +    false,
    
    649
    +    "Changing browsing mode to normal browsing should set pbm autostart to false"
    
    650
    +  );
    
    651
    +
    
    652
    +  Assert.equal(
    
    653
    +    Services.prefs.getBoolPref(kKeepPermissionInMemory),
    
    654
    +    false,
    
    655
    +    "Changing browsing mode to normal browsing should set memory only permissions to false"
    
    656
    +  );
    
    657
    +
    
    658
    +  resetToTotalSavingPrefs();
    
    659
    +
    
    660
    +  for (const sanitize of [false, true]) {
    
    661
    +    for (const pbmAutostart of [false, true]) {
    
    662
    +      for (const permissions of [false, true]) {
    
    663
    +        Services.prefs.setBoolPref(kSanitizeOnShutdown, sanitize);
    
    664
    +        Services.prefs.setBoolPref(kPrivateBrowsingAutostart, pbmAutostart);
    
    665
    +        Services.prefs.setBoolPref(kKeepPermissionInMemory, permissions);
    
    666
    +
    
    667
    +        if (sanitize && pbmAutostart && permissions) {
    
    668
    +          Assert.equal(
    
    669
    +            Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    670
    +            SelectiveSavingModes.total_clearing,
    
    671
    +            "pref settings for true true true should result in total clearing"
    
    672
    +          );
    
    673
    +        } else if (sanitize && !pbmAutostart && !permissions) {
    
    674
    +          Assert.equal(
    
    675
    +            Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    676
    +            SelectiveSavingModes.selective_saving,
    
    677
    +            "pref settings for true false false should result in selective saving"
    
    678
    +          );
    
    679
    +        } else if (!sanitize && !pbmAutostart && !permissions) {
    
    680
    +          Assert.equal(
    
    681
    +            Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    682
    +            SelectiveSavingModes.normal_browsing,
    
    683
    +            "pref settings for false false false should result in normal browsing"
    
    684
    +          );
    
    685
    +        } else {
    
    686
    +          Assert.equal(
    
    687
    +            Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    688
    +            SelectiveSavingModes.custom,
    
    689
    +            `pref settings of ${sanitize} ${pbmAutostart} ${permissions} should result in custom browsing`
    
    690
    +          );
    
    691
    +        }
    
    692
    +      }
    
    693
    +    }
    
    694
    +  }
    
    695
    +
    
    696
    +  Services.prefs.setIntPref(
    
    697
    +    kSelectiveSavingModePref,
    
    698
    +    SelectiveSavingModes.custom
    
    699
    +  );
    
    700
    +
    
    701
    +  Assert.equal(
    
    702
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    703
    +    SelectiveSavingModes.custom,
    
    704
    +    "Manually changing to custom browsing via primary pref should happen regardless of secondary prefs"
    
    705
    +  );
    
    706
    +
    
    707
    +  Assert.equal(
    
    708
    +    Services.prefs.getBoolPref(kSanitizeOnShutdown),
    
    709
    +    true,
    
    710
    +    "Changing browsing mode to custom should leave sanitize on shutdown as previously set"
    
    711
    +  );
    
    712
    +
    
    713
    +  Assert.equal(
    
    714
    +    Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
    
    715
    +    true,
    
    716
    +    "Changing browsing mode to custom should leave pbm autostart as previously set"
    
    717
    +  );
    
    718
    +
    
    719
    +  Assert.equal(
    
    720
    +    Services.prefs.getBoolPref(kKeepPermissionInMemory),
    
    721
    +    true,
    
    722
    +    "Changing browsing mode to custom should leave memory only permissions as previously set"
    
    723
    +  );
    
    724
    +
    
    725
    +  resetToTotalSavingPrefs();
    
    726
    +
    
    727
    +  Services.prefs.setIntPref(
    
    728
    +    kSelectiveSavingModePref,
    
    729
    +    SelectiveSavingModes.unconfigured
    
    730
    +  );
    
    731
    +
    
    732
    +  Assert.notEqual(
    
    733
    +    Services.prefs.getIntPref(kSelectiveSavingModePref),
    
    734
    +    SelectiveSavingModes.unconfigured,
    
    735
    +    "Manually changing to unconfigured mode via primary pref should set primary pref based on secondary prefs"
    
    736
    +  );
    
    737
    +
    
    738
    +  Assert.equal(
    
    739
    +    Services.prefs.getBoolPref(kSanitizeOnShutdown),
    
    740
    +    true,
    
    741
    +    "Changing browsing mode to unconfigured should leave sanitize on shutdown as previously set"
    
    742
    +  );
    
    743
    +
    
    744
    +  Assert.equal(
    
    745
    +    Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
    
    746
    +    true,
    
    747
    +    "Changing browsing mode to unconfigured should leave pbm autostart to true as previously set"
    
    748
    +  );
    
    749
    +
    
    750
    +  Assert.equal(
    
    751
    +    Services.prefs.getBoolPref(kKeepPermissionInMemory),
    
    752
    +    true,
    
    753
    +    "Changing browsing mode to unconfigured should leave memory only permissions to true as previously set"
    
    754
    +  );
    
    755
    +});

  • toolkit/components/selectivesavingmode/tests/xpcshell/xpcshell.toml
    1
    +[DEFAULT]
    
    2
    +tags = "mullvad"
    
    3
    +prefs = [
    
    4
    +  "browser.selectiveSavingMode.enabled=true"
    
    5
    +]
    
    6
    +
    
    7
    +["test_selective_saving_mode.js"]