tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_ASRouterPreferences_maybeSetMessagingProfileID.js (1837B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/
      3 */
      4 
      5 "use strict";
      6 
      7 const { ASRouterPreferences } = ChromeUtils.importESModule(
      8  "resource:///modules/asrouter/ASRouterPreferences.sys.mjs"
      9 );
     10 
     11 add_task(async function test_maybeSetMessagingProfileID() {
     12  // Enable singleProfileMessaging mitigation
     13  Services.prefs.setBoolPref(
     14    "messaging-system.profile.singleProfileMessaging.disable",
     15    false
     16  );
     17  registerCleanupFunction(() => {
     18    Services.prefs.clearUserPref(
     19      "messaging-system.profile.singleProfileMessaging.disable"
     20    );
     21  });
     22  await initSelectableProfileService();
     23  let currentProfile = sinon
     24    .stub(SelectableProfileService, "currentProfile")
     25    .value({ id: 1 });
     26  sinon.stub(SelectableProfileService, "trackPref").resolves();
     27 
     28  // If the Profile ID pref is unset and a profile exists, set it
     29  Services.prefs.setStringPref(
     30    "messaging-system.profile.messagingProfileId",
     31    ""
     32  );
     33  await ASRouterPreferences._maybeSetMessagingProfileID();
     34 
     35  Assert.equal(
     36    "1",
     37    Services.prefs.getStringPref("messaging-system.profile.messagingProfileId")
     38  );
     39 
     40  // Once the ID has been set, check to see if a profile exists
     41  currentProfile.value({ id: 2 });
     42  let messagingProfile = sinon
     43    .stub(SelectableProfileService, "getProfile")
     44    .returns({ id: 1 });
     45  // If the profile exists, do nothing
     46  await ASRouterPreferences._maybeSetMessagingProfileID();
     47 
     48  Assert.equal(
     49    "1",
     50    Services.prefs.getStringPref("messaging-system.profile.messagingProfileId")
     51  );
     52  // If the profile does not exist, reset the Profile ID pref
     53  messagingProfile.returns(null);
     54 
     55  await ASRouterPreferences._maybeSetMessagingProfileID();
     56 
     57  Assert.equal(
     58    "2",
     59    Services.prefs.getStringPref("messaging-system.profile.messagingProfileId")
     60  );
     61 });