test_ASRouter_shouldShowMessagesToProfile.js (1977B)
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 { ASRouter } = ChromeUtils.importESModule( 8 "resource:///modules/asrouter/ASRouter.sys.mjs" 9 ); 10 11 const { ASRouterTargeting } = ChromeUtils.importESModule( 12 "resource:///modules/asrouter/ASRouterTargeting.sys.mjs" 13 ); 14 15 add_task(async function test_shouldShowMessagesToProfile() { 16 let sandbox = sinon.createSandbox(); 17 // Enable singleProfileMessaging mitigation 18 Services.prefs.setBoolPref( 19 "messaging-system.profile.singleProfileMessaging.disable", 20 false 21 ); 22 registerCleanupFunction(() => { 23 Services.prefs.clearUserPref( 24 "messaging-system.profile.singleProfileMessaging.disable" 25 ); 26 }); 27 28 // shouldShowMessages should return true if the Selectable Profile Service is not enabled 29 Services.prefs.setBoolPref("browser.profiles.enabled", false); 30 31 Assert.equal(ASRouter.shouldShowMessagesToProfile(), true); 32 // should return true if the Selectable Profile Service is enabled but no profiles have been created 33 Services.prefs.setBoolPref("browser.profiles.enabled", true); 34 35 Assert.equal(ASRouter.shouldShowMessagesToProfile(), true); 36 // should return false if the Selectable Profile Service is enabled, and there is a profile but the profile IDs don't match 37 await initSelectableProfileService(); 38 Services.prefs.setBoolPref("browser.profiles.created", true); 39 Services.prefs.setStringPref( 40 "messaging-system.profile.messagingProfileId", 41 "2" 42 ); 43 sandbox.replaceGetter( 44 ASRouterTargeting.Environment, 45 "currentProfileId", 46 function () { 47 return "1"; 48 } 49 ); 50 Assert.equal(ASRouter.shouldShowMessagesToProfile(), false); 51 // should return true if the Selectable Profile Service is enabled, and the profile IDs match 52 Services.prefs.setStringPref( 53 "messaging-system.profile.messagingProfileId", 54 "1" 55 ); 56 Assert.equal(ASRouter.shouldShowMessagesToProfile(), true); 57 });