зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1747149 - Consolidate logic for when to show VPN promo and add BrowserUtils test r=dmose,preferences-reviewers,prathiksha,Gijs
Differential Revision: https://phabricator.services.mozilla.com/D134874
This commit is contained in:
Родитель
202996c4ad
Коммит
dd4f534a63
|
@ -7,6 +7,9 @@
|
|||
var EXPORTED_SYMBOLS = ["AboutPrivateBrowsingParent"];
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { BrowserUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/BrowserUtils.jsm"
|
||||
);
|
||||
const { XPCOMUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
@ -27,7 +30,6 @@ XPCOMUtils.defineLazyPreferenceGetter(
|
|||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
Region: "resource://gre/modules/Region.jsm",
|
||||
UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm",
|
||||
});
|
||||
|
||||
|
@ -161,13 +163,7 @@ class AboutPrivateBrowsingParent extends JSWindowActorParent {
|
|||
break;
|
||||
}
|
||||
case "ShouldShowVPNPromo": {
|
||||
const homeRegion = Region.home || "";
|
||||
const currentRegion = Region.current || "";
|
||||
return (
|
||||
homeRegion.toLowerCase() !== "cn" &&
|
||||
currentRegion.toLowerCase() !== "cn" &&
|
||||
Services.policies.status !== Services.policies.ACTIVE
|
||||
);
|
||||
return BrowserUtils.shouldShowVPNPromo();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
BrowserUtils: "resource://gre/modules/BrowserUtils.jsm",
|
||||
fxAccounts: "resource://gre/modules/FxAccounts.jsm",
|
||||
FXA_PWDMGR_HOST: "resource://gre/modules/FxAccountsCommon.js",
|
||||
FXA_PWDMGR_REALM: "resource://gre/modules/FxAccountsCommon.js",
|
||||
|
@ -314,7 +315,7 @@ class AboutProtectionsParent extends JSWindowActorParent {
|
|||
async VPNSubStatus() {
|
||||
// For testing, set vpn sub status manually
|
||||
if (gTestOverride && "vpnOverrides" in gTestOverride) {
|
||||
return gTestOverride.vpnOverrides().hasSubscription;
|
||||
return gTestOverride.vpnOverrides();
|
||||
}
|
||||
|
||||
let vpnToken;
|
||||
|
@ -345,33 +346,6 @@ class AboutProtectionsParent extends JSWindowActorParent {
|
|||
return false;
|
||||
}
|
||||
|
||||
// VPN shows if we are in a supported region and supported languages
|
||||
// VPN does not show in China - VPNs are illegal there, this is a requirement to hardcode, and not use in a pref.
|
||||
VPNShouldShow() {
|
||||
let currentRegion = "";
|
||||
if (gTestOverride && "vpnOverrides" in gTestOverride) {
|
||||
currentRegion = gTestOverride.vpnOverrides().location;
|
||||
} else {
|
||||
// The region we have detected the user to be in
|
||||
// We cannot run this in tests due to it using a request
|
||||
currentRegion = Region.current ? Region.current.toLowerCase() : "";
|
||||
}
|
||||
|
||||
// The region that the user has set as their home region
|
||||
const homeRegion = Region.home.toLowerCase() || "";
|
||||
const regionsWithVPN = Services.prefs.getStringPref(
|
||||
"browser.contentblocking.report.vpn_regions"
|
||||
);
|
||||
const language = Services.locale.appLocaleAsBCP47;
|
||||
|
||||
return (
|
||||
currentRegion != "cn" &&
|
||||
homeRegion != "cn" &&
|
||||
regionsWithVPN.includes(currentRegion) &&
|
||||
language.includes("en-")
|
||||
);
|
||||
}
|
||||
|
||||
async receiveMessage(aMessage) {
|
||||
let win = this.browsingContext.top.embedderElement.ownerGlobal;
|
||||
switch (aMessage.name) {
|
||||
|
@ -456,7 +430,7 @@ class AboutProtectionsParent extends JSWindowActorParent {
|
|||
return this.VPNSubStatus();
|
||||
|
||||
case "FetchShowVPNCard":
|
||||
return this.VPNShouldShow();
|
||||
return BrowserUtils.shouldShowVPNPromo();
|
||||
}
|
||||
|
||||
return undefined;
|
||||
|
|
|
@ -1496,11 +1496,6 @@ pref("browser.newtabpage.activity-stream.asrouter.providers.messaging-experiment
|
|||
pref("browser.newtabpage.activity-stream.asrouter.userprefs.cfr.addons", true);
|
||||
pref("browser.newtabpage.activity-stream.asrouter.userprefs.cfr.features", true);
|
||||
|
||||
// Default to allowing the ASRouter captive portal VPN promo messages to be
|
||||
// shown when specified, but do so in a pref in case someone needs to override
|
||||
// it.
|
||||
pref("browser.newtabpage.activity-stream.asrouter.disable-captive-portal-vpn-promo", false);
|
||||
|
||||
// The pref that controls if ASRouter uses the remote fluent files.
|
||||
// It's enabled by default, but could be disabled to force ASRouter to use the local files.
|
||||
pref("browser.newtabpage.activity-stream.asrouter.useRemoteL10n", true);
|
||||
|
@ -1895,11 +1890,11 @@ pref("browser.vpn_promo.disallowed_regions", "ae,by,cn,cu,iq,ir,kp,om,ru,sd,sy,t
|
|||
|
||||
// Default to enabling VPN promo messages to be shown when specified and allowed
|
||||
pref("browser.vpn_promo.enabled", true);
|
||||
|
||||
// Enable the vpn card by default.
|
||||
pref("browser.contentblocking.report.vpn.enabled", true);
|
||||
// Only show vpn card to certain regions. Comma separated string of two letter ISO 3166-1 country codes.
|
||||
pref("browser.contentblocking.report.vpn_regions", "us,ca,nz,sg,my,gb,de,fr");
|
||||
// The most recent list of supported countries can be found at https://support.mozilla.org/en-US/kb/mozilla-vpn-countries-available-subscribe
|
||||
pref("browser.contentblocking.report.vpn_regions", "at,be,ca,ch,de,fr,ie,it,my,nl,nz,sg,es,gb,us"
|
||||
);
|
||||
|
||||
// Comma separated string of mozilla vpn supported platforms.
|
||||
pref("browser.contentblocking.report.vpn_platforms", "win,mac,linux");
|
||||
pref("browser.contentblocking.report.hide_vpn_banner", false);
|
||||
|
|
|
@ -4,9 +4,6 @@
|
|||
"use strict";
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { XPCOMUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
const PROVIDER_PREF_BRANCH =
|
||||
"browser.newtabpage.activity-stream.asrouter.providers.";
|
||||
|
@ -52,12 +49,6 @@ class _ASRouterPreferences {
|
|||
constructor() {
|
||||
Object.assign(this, DEFAULT_STATE);
|
||||
this._callbacks = new Set();
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
"disableCaptivePortalVPNPromo",
|
||||
"browser.newtabpage.activity-stream.asrouter.disable-captive-portal-vpn-promo",
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
_transformPersonalizedCfrScores(value) {
|
||||
|
|
|
@ -9,11 +9,10 @@ const { XPCOMUtils } = ChromeUtils.import(
|
|||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
|
||||
Region: "resource://gre/modules/Region.jsm",
|
||||
EveryWindow: "resource:///modules/EveryWindow.jsm",
|
||||
AboutReaderParent: "resource:///actors/AboutReaderParent.jsm",
|
||||
ASRouterPreferences: "resource://activity-stream/lib/ASRouterPreferences.jsm",
|
||||
BrowserUtils: "resource://gre/modules/BrowserUtils.jsm",
|
||||
EveryWindow: "resource:///modules/EveryWindow.jsm",
|
||||
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
|
||||
});
|
||||
|
||||
const FEW_MINUTES = 15 * 60 * 1000; // 15 mins
|
||||
|
@ -595,25 +594,8 @@ this.ASRouterTriggerListeners = new Map([
|
|||
_initialized: false,
|
||||
_triggerHandler: null,
|
||||
|
||||
// XXX For the moment, the captive-portal-login trigger is assumed to be
|
||||
// for the VPN promo, and we check to make sure that hasn't been
|
||||
// disabled by pref for a region (or maybe partner or OS distro?).
|
||||
///
|
||||
// Ultimately, we'd like to unstaple the VPN promo checks from here,
|
||||
// perhaps even doing them entirely using both ASRouter message targeting
|
||||
// and experimenter/rollout targeting. This work is being tracked in
|
||||
// bug 1731176.
|
||||
_shouldShowCaptivePortalVPNPromo() {
|
||||
const disablePromoPref =
|
||||
ASRouterPreferences.disableCaptivePortalVPNPromo;
|
||||
const homeRegion = Region.home || "";
|
||||
const currentRegion = Region.current || "";
|
||||
|
||||
return (
|
||||
!disablePromoPref &&
|
||||
homeRegion.toLowerCase() !== "cn" &&
|
||||
currentRegion.toLowerCase() !== "cn"
|
||||
);
|
||||
return BrowserUtils.shouldShowVPNPromo();
|
||||
},
|
||||
|
||||
init(triggerHandler) {
|
||||
|
|
|
@ -111,80 +111,6 @@ describe("ASRouterTriggerListeners", () => {
|
|||
});
|
||||
|
||||
describe("captivePortal", () => {
|
||||
describe("_shouldShowCaptivePortalVPNPromo", () => {
|
||||
it("should return true if disable pref is false && neither home nor current regions are cn", () => {
|
||||
regionFake._home = "us";
|
||||
regionFake._current = "ca";
|
||||
sandbox
|
||||
.stub(ASRouterPreferences, "disableCaptivePortalVPNPromo")
|
||||
.get(() => false);
|
||||
|
||||
assert.isTrue(
|
||||
captivePortalLoginListener._shouldShowCaptivePortalVPNPromo()
|
||||
);
|
||||
});
|
||||
|
||||
it("should return false if disable pref is false and only the home region is 'cn'", () => {
|
||||
regionFake._home = "cn";
|
||||
regionFake._current = "us";
|
||||
sandbox
|
||||
.stub(ASRouterPreferences, "disableCaptivePortalVPNPromo")
|
||||
.get(() => false);
|
||||
|
||||
assert.isFalse(
|
||||
captivePortalLoginListener._shouldShowCaptivePortalVPNPromo()
|
||||
);
|
||||
});
|
||||
|
||||
it("should return false if disable pref is false and only the current region is 'cn'", () => {
|
||||
regionFake._home = "us";
|
||||
regionFake._current = "cn";
|
||||
sandbox
|
||||
.stub(ASRouterPreferences, "disableCaptivePortalVPNPromo")
|
||||
.get(() => false);
|
||||
|
||||
assert.isFalse(
|
||||
captivePortalLoginListener._shouldShowCaptivePortalVPNPromo()
|
||||
);
|
||||
});
|
||||
|
||||
it("should return false if the disable pref is false and a region check is cn", () => {
|
||||
regionFake._home = "us";
|
||||
regionFake._current = "cn";
|
||||
sandbox
|
||||
.stub(ASRouterPreferences, "disableCaptivePortalVPNPromo")
|
||||
.get(() => false);
|
||||
|
||||
assert.isFalse(
|
||||
captivePortalLoginListener._shouldShowCaptivePortalVPNPromo()
|
||||
);
|
||||
});
|
||||
|
||||
it("should return false if the disable pref is true and no regions are cn", () => {
|
||||
regionFake._home = "us";
|
||||
regionFake._current = "ca";
|
||||
sandbox
|
||||
.stub(ASRouterPreferences, "disableCaptivePortalVPNPromo")
|
||||
.get(() => true);
|
||||
|
||||
assert.isFalse(
|
||||
captivePortalLoginListener._shouldShowCaptivePortalVPNPromo()
|
||||
);
|
||||
});
|
||||
|
||||
it("should return false if the disable pref is true and a region is cn", () => {
|
||||
regionFake._home = "us";
|
||||
regionFake._current = "cn";
|
||||
sandbox
|
||||
.stub(ASRouterPreferences, "disableCaptivePortalVPNPromo")
|
||||
.get(() => true);
|
||||
|
||||
assert.isFalse(
|
||||
captivePortalLoginListener._shouldShowCaptivePortalVPNPromo()
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("observe", () => {
|
||||
it("should not call the trigger handler if _shouldShowCaptivePortalVPNPromo returns false", () => {
|
||||
sandbox
|
||||
|
|
|
@ -3,11 +3,21 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { EnterprisePolicyTesting } = ChromeUtils.import(
|
||||
"resource://testing-common/EnterprisePolicyTesting.jsm"
|
||||
);
|
||||
|
||||
let { TelemetryTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/TelemetryTestUtils.jsm"
|
||||
);
|
||||
|
||||
async function clearPolicies() {
|
||||
// Ensure no active policies are set
|
||||
await EnterprisePolicyTesting.setupPolicyEngineWithJson("");
|
||||
}
|
||||
|
||||
add_task(async function testDefaultUIWithoutTemplatePref() {
|
||||
await clearPolicies();
|
||||
await openPreferencesViaOpenPreferencesAPI("paneGeneral", {
|
||||
leaveOpen: true,
|
||||
});
|
||||
|
@ -129,6 +139,7 @@ add_task(async function test_aboutpreferences_event_telemetry() {
|
|||
});
|
||||
|
||||
add_task(async function test_aboutpreferences_simple_template() {
|
||||
await clearPolicies();
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.preferences.moreFromMozilla", true],
|
||||
|
@ -157,6 +168,7 @@ add_task(async function test_aboutpreferences_simple_template() {
|
|||
});
|
||||
|
||||
add_task(async function test_aboutpreferences_advanced_template() {
|
||||
await clearPolicies();
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.preferences.moreFromMozilla", true],
|
||||
|
@ -193,6 +205,7 @@ add_task(async function test_aboutpreferences_advanced_template() {
|
|||
});
|
||||
|
||||
add_task(async function test_aboutpreferences_clickBtnVPN() {
|
||||
await clearPolicies();
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.preferences.moreFromMozilla", true],
|
||||
|
@ -306,6 +319,7 @@ add_task(async function test_aboutpreferences_clickBtnMobile() {
|
|||
});
|
||||
|
||||
add_task(async function test_aboutpreferences_search() {
|
||||
await clearPolicies();
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.preferences.moreFromMozilla", true],
|
||||
|
|
|
@ -3,10 +3,14 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { EnterprisePolicyTesting } = ChromeUtils.import(
|
||||
"resource://testing-common/EnterprisePolicyTesting.jsm"
|
||||
);
|
||||
|
||||
let { Region } = ChromeUtils.import("resource://gre/modules/Region.jsm");
|
||||
|
||||
const initialHomeRegion = Region._home;
|
||||
const intialCurrentRegion = Region._current;
|
||||
const initialCurrentRegion = Region._current;
|
||||
|
||||
// Helper to run tests for specific regions
|
||||
async function setupRegions(home, current) {
|
||||
|
@ -19,7 +23,30 @@ function setLocale(language) {
|
|||
Services.locale.requestedLocales = [language];
|
||||
}
|
||||
|
||||
async function clearPolicies() {
|
||||
// Ensure no active policies are set
|
||||
await EnterprisePolicyTesting.setupPolicyEngineWithJson("");
|
||||
}
|
||||
|
||||
async function getPromoCards() {
|
||||
await openPreferencesViaOpenPreferencesAPI("paneMoreFromMozilla", {
|
||||
leaveOpen: true,
|
||||
});
|
||||
|
||||
let doc = gBrowser.contentDocument;
|
||||
let vpnPromoCard = doc.getElementById("mozilla-vpn");
|
||||
let mobileCard = doc.getElementById("firefox-mobile");
|
||||
let rallyPromoCard = doc.getElementById("mozilla-rally");
|
||||
|
||||
return {
|
||||
vpnPromoCard,
|
||||
mobileCard,
|
||||
rallyPromoCard,
|
||||
};
|
||||
}
|
||||
|
||||
add_task(async function test_VPN_promo_enabled() {
|
||||
await clearPolicies();
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.preferences.moreFromMozilla", true],
|
||||
|
@ -27,13 +54,8 @@ add_task(async function test_VPN_promo_enabled() {
|
|||
],
|
||||
});
|
||||
|
||||
await openPreferencesViaOpenPreferencesAPI("paneMoreFromMozilla", {
|
||||
leaveOpen: true,
|
||||
});
|
||||
let { vpnPromoCard, mobileCard } = await getPromoCards();
|
||||
|
||||
let doc = gBrowser.contentDocument;
|
||||
let vpnPromoCard = doc.getElementById("mozilla-vpn");
|
||||
let mobileCard = doc.getElementById("firefox-mobile");
|
||||
ok(vpnPromoCard, "The VPN promo is visible");
|
||||
ok(mobileCard, "The Mobile promo is visible");
|
||||
|
||||
|
@ -41,17 +63,13 @@ add_task(async function test_VPN_promo_enabled() {
|
|||
});
|
||||
|
||||
add_task(async function test_VPN_promo_disabled() {
|
||||
await clearPolicies();
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.vpn_promo.enabled", false]],
|
||||
});
|
||||
|
||||
await openPreferencesViaOpenPreferencesAPI("paneMoreFromMozilla", {
|
||||
leaveOpen: true,
|
||||
});
|
||||
let { vpnPromoCard, mobileCard } = await getPromoCards();
|
||||
|
||||
let doc = gBrowser.contentDocument;
|
||||
let vpnPromoCard = doc.getElementById("mozilla-vpn");
|
||||
let mobileCard = doc.getElementById("firefox-mobile");
|
||||
ok(!vpnPromoCard, "The VPN promo is not visible");
|
||||
ok(mobileCard, "The Mobile promo is visible");
|
||||
|
||||
|
@ -60,6 +78,7 @@ add_task(async function test_VPN_promo_disabled() {
|
|||
});
|
||||
|
||||
add_task(async function test_VPN_promo_in_disallowed_home_region() {
|
||||
await clearPolicies();
|
||||
const disallowedRegion = "SY";
|
||||
|
||||
setupRegions(disallowedRegion);
|
||||
|
@ -69,21 +88,17 @@ add_task(async function test_VPN_promo_in_disallowed_home_region() {
|
|||
set: [["browser.vpn_promo.enabled", true]],
|
||||
});
|
||||
|
||||
await openPreferencesViaOpenPreferencesAPI("paneMoreFromMozilla", {
|
||||
leaveOpen: true,
|
||||
});
|
||||
let { vpnPromoCard, mobileCard } = await getPromoCards();
|
||||
|
||||
let doc = gBrowser.contentDocument;
|
||||
let vpnPromoCard = doc.getElementById("mozilla-vpn");
|
||||
let mobileCard = doc.getElementById("firefox-mobile");
|
||||
ok(!vpnPromoCard, "The VPN promo is not visible");
|
||||
ok(mobileCard, "The Mobile promo is visible");
|
||||
|
||||
setupRegions(initialHomeRegion, intialCurrentRegion); // revert changes to regions
|
||||
setupRegions(initialHomeRegion, initialCurrentRegion); // revert changes to regions
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
});
|
||||
|
||||
add_task(async function test_VPN_promo_in_illegal_home_region() {
|
||||
await clearPolicies();
|
||||
const illegalRegion = "CN";
|
||||
|
||||
setupRegions(illegalRegion);
|
||||
|
@ -93,21 +108,17 @@ add_task(async function test_VPN_promo_in_illegal_home_region() {
|
|||
set: [["browser.vpn_promo.disallowedRegions", "SY, CU"]],
|
||||
});
|
||||
|
||||
await openPreferencesViaOpenPreferencesAPI("paneMoreFromMozilla", {
|
||||
leaveOpen: true,
|
||||
});
|
||||
let { vpnPromoCard, mobileCard } = await getPromoCards();
|
||||
|
||||
let doc = gBrowser.contentDocument;
|
||||
let vpnPromoCard = doc.getElementById("mozilla-vpn");
|
||||
let mobileCard = doc.getElementById("firefox-mobile");
|
||||
ok(!vpnPromoCard, "The VPN promo is not visible");
|
||||
ok(mobileCard, "The Mobile promo is visible");
|
||||
|
||||
setupRegions(initialHomeRegion, intialCurrentRegion); // revert changes to regions
|
||||
setupRegions(initialHomeRegion, initialCurrentRegion); // revert changes to regions
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
});
|
||||
|
||||
add_task(async function test_VPN_promo_in_disallowed_current_region() {
|
||||
await clearPolicies();
|
||||
const allowedRegion = "US";
|
||||
const disallowedRegion = "SY";
|
||||
|
||||
|
@ -118,21 +129,17 @@ add_task(async function test_VPN_promo_in_disallowed_current_region() {
|
|||
set: [["browser.vpn_promo.enabled", true]],
|
||||
});
|
||||
|
||||
await openPreferencesViaOpenPreferencesAPI("paneMoreFromMozilla", {
|
||||
leaveOpen: true,
|
||||
});
|
||||
let { vpnPromoCard, mobileCard } = await getPromoCards();
|
||||
|
||||
let doc = gBrowser.contentDocument;
|
||||
let vpnPromoCard = doc.getElementById("mozilla-vpn");
|
||||
let mobileCard = doc.getElementById("firefox-mobile");
|
||||
ok(!vpnPromoCard, "The VPN promo is not visible");
|
||||
ok(mobileCard, "The Mobile promo is visible");
|
||||
|
||||
setupRegions(initialHomeRegion, intialCurrentRegion); // revert changes to regions
|
||||
setupRegions(initialHomeRegion, initialCurrentRegion); // revert changes to regions
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
});
|
||||
|
||||
add_task(async function test_VPN_promo_in_illegal_current_region() {
|
||||
await clearPolicies();
|
||||
const allowedRegion = "US";
|
||||
const illegalRegion = "CN";
|
||||
|
||||
|
@ -143,17 +150,12 @@ add_task(async function test_VPN_promo_in_illegal_current_region() {
|
|||
set: [["browser.vpn_promo.disallowedRegions", "SY, CU"]],
|
||||
});
|
||||
|
||||
await openPreferencesViaOpenPreferencesAPI("paneMoreFromMozilla", {
|
||||
leaveOpen: true,
|
||||
});
|
||||
let { vpnPromoCard, mobileCard } = await getPromoCards();
|
||||
|
||||
let doc = gBrowser.contentDocument;
|
||||
let vpnPromoCard = doc.getElementById("mozilla-vpn");
|
||||
let mobileCard = doc.getElementById("firefox-mobile");
|
||||
ok(!vpnPromoCard, "The VPN promo is not visible");
|
||||
ok(mobileCard, "The Mobile promo is visible");
|
||||
|
||||
setupRegions(initialHomeRegion, intialCurrentRegion); // revert changes to regions
|
||||
setupRegions(initialHomeRegion, initialCurrentRegion); // revert changes to regions
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
});
|
||||
|
||||
|
@ -162,17 +164,12 @@ add_task(
|
|||
// Only show the Rally promo when US is the region and English is the langauge
|
||||
setupRegions("US");
|
||||
|
||||
await openPreferencesViaOpenPreferencesAPI("paneMoreFromMozilla", {
|
||||
leaveOpen: true,
|
||||
});
|
||||
let { rallyPromoCard, mobileCard } = await getPromoCards();
|
||||
|
||||
let doc = gBrowser.contentDocument;
|
||||
let rallyPromoCard = doc.getElementById("mozilla-rally");
|
||||
let mobileCard = doc.getElementById("firefox-mobile");
|
||||
ok(rallyPromoCard, "The Rally promo is visible");
|
||||
ok(mobileCard, "The Mobile promo is visible");
|
||||
|
||||
setupRegions(initialHomeRegion, intialCurrentRegion); // revert changes to regions
|
||||
setupRegions(initialHomeRegion, initialCurrentRegion); // revert changes to regions
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
}
|
||||
);
|
||||
|
@ -180,34 +177,24 @@ add_task(
|
|||
add_task(async function test_rally_promo_with_unapproved_home_region() {
|
||||
setupRegions("IS");
|
||||
|
||||
await openPreferencesViaOpenPreferencesAPI("paneMoreFromMozilla", {
|
||||
leaveOpen: true,
|
||||
});
|
||||
let { rallyPromoCard, mobileCard } = await getPromoCards();
|
||||
|
||||
let doc = gBrowser.contentDocument;
|
||||
let rallyPromoCard = doc.getElementById("mozilla-rally");
|
||||
let mobileCard = doc.getElementById("firefox-mobile");
|
||||
ok(!rallyPromoCard, "The Rally promo is not visible");
|
||||
ok(mobileCard, "The Mobile promo is visible");
|
||||
|
||||
setupRegions(initialHomeRegion, intialCurrentRegion); // revert changes to regions
|
||||
setupRegions(initialHomeRegion, initialCurrentRegion); // revert changes to regions
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
});
|
||||
|
||||
add_task(async function test_rally_promo_with_unapproved_current_region() {
|
||||
setupRegions("US", "IS");
|
||||
|
||||
await openPreferencesViaOpenPreferencesAPI("paneMoreFromMozilla", {
|
||||
leaveOpen: true,
|
||||
});
|
||||
let { rallyPromoCard, mobileCard } = await getPromoCards();
|
||||
|
||||
let doc = gBrowser.contentDocument;
|
||||
let rallyPromoCard = doc.getElementById("mozilla-rally");
|
||||
let mobileCard = doc.getElementById("firefox-mobile");
|
||||
ok(!rallyPromoCard, "The Rally promo is not visible");
|
||||
ok(mobileCard, "The Mobile promo is visible");
|
||||
|
||||
setupRegions(initialHomeRegion, intialCurrentRegion); // revert changes to regions
|
||||
setupRegions(initialHomeRegion, initialCurrentRegion); // revert changes to regions
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
});
|
||||
|
||||
|
@ -217,17 +204,12 @@ add_task(async function test_rally_promo_with_unapproved_language() {
|
|||
const initialLanguage = Services.locale.appLocaleAsBCP47;
|
||||
setLocale("ko-KR");
|
||||
|
||||
await openPreferencesViaOpenPreferencesAPI("paneMoreFromMozilla", {
|
||||
leaveOpen: true,
|
||||
});
|
||||
let { rallyPromoCard, mobileCard } = await getPromoCards();
|
||||
|
||||
let doc = gBrowser.contentDocument;
|
||||
let rallyPromoCard = doc.getElementById("mozilla-rally");
|
||||
let mobileCard = doc.getElementById("firefox-mobile");
|
||||
ok(!rallyPromoCard, "The Rally promo is not visible");
|
||||
ok(mobileCard, "The Mobile promo is visible");
|
||||
|
||||
setupRegions(initialHomeRegion, intialCurrentRegion); // revert changes to regions
|
||||
setupRegions(initialHomeRegion, initialCurrentRegion); // revert changes to regions
|
||||
// revert changes to language
|
||||
setLocale(initialLanguage);
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
|
@ -311,3 +293,58 @@ add_task(
|
|||
setLocale(initialLocale); // revert changes to language
|
||||
}
|
||||
);
|
||||
|
||||
add_task(
|
||||
async function test_VPN_promo_in_unsupported_current_region_with_supported_home_region() {
|
||||
await clearPolicies();
|
||||
const supportedRegion = "US";
|
||||
const unsupportedRegion = "LY";
|
||||
|
||||
setupRegions(supportedRegion, unsupportedRegion);
|
||||
|
||||
let { vpnPromoCard, mobileCard } = await getPromoCards();
|
||||
|
||||
ok(vpnPromoCard, "The VPN promo is visible");
|
||||
ok(mobileCard, "The Mobile promo is visible");
|
||||
|
||||
setupRegions(initialHomeRegion, initialCurrentRegion); // revert changes to regions
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
}
|
||||
);
|
||||
|
||||
add_task(
|
||||
async function test_VPN_promo_in_supported_current_region_with_unsupported_home_region() {
|
||||
await clearPolicies();
|
||||
const supportedRegion = "US";
|
||||
const unsupportedRegion = "LY";
|
||||
|
||||
setupRegions(unsupportedRegion, supportedRegion);
|
||||
|
||||
let { vpnPromoCard, mobileCard } = await getPromoCards();
|
||||
|
||||
ok(vpnPromoCard, "The VPN promo is visible");
|
||||
ok(mobileCard, "The Mobile promo is visible");
|
||||
|
||||
setupRegions(initialHomeRegion, initialCurrentRegion); // revert changes to regions
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
}
|
||||
);
|
||||
|
||||
add_task(async function test_VPN_promo_with_active_enterprise_policy() {
|
||||
// set up an arbitrary enterprise policy
|
||||
await EnterprisePolicyTesting.setupPolicyEngineWithJson({
|
||||
policies: {
|
||||
EnableTrackingProtection: {
|
||||
Value: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
let { vpnPromoCard, mobileCard } = await getPromoCards();
|
||||
ok(!vpnPromoCard, "The VPN promo is not visible");
|
||||
ok(mobileCard, "The Mobile promo is visible");
|
||||
|
||||
setupRegions(initialHomeRegion, initialCurrentRegion); // revert changes to regions
|
||||
await clearPolicies();
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
});
|
||||
|
|
|
@ -482,10 +482,7 @@ document.addEventListener("DOMContentLoaded", e => {
|
|||
const proxyUI = document.querySelector(".proxy-card");
|
||||
proxyUI.dataset.enabled = proxyEnabled;
|
||||
|
||||
const VPNEnabled = RPMGetBoolPref(
|
||||
"browser.contentblocking.report.vpn.enabled",
|
||||
true
|
||||
);
|
||||
const VPNEnabled = RPMGetBoolPref("browser.vpn_promo.enabled", true);
|
||||
if (VPNEnabled) {
|
||||
const vpnCard = new VPNCard(document);
|
||||
vpnCard.init();
|
||||
|
|
|
@ -62,21 +62,6 @@ export default class VPNCard {
|
|||
return;
|
||||
}
|
||||
const vpnCard = this.doc.querySelector(".vpn-card");
|
||||
let availablePlatforms = RPMGetStringPref(
|
||||
"browser.contentblocking.report.vpn_platforms"
|
||||
);
|
||||
|
||||
let hasSupportedPlatform = false;
|
||||
for (let platform of availablePlatforms.split(",")) {
|
||||
if (navigator.platform.toLowerCase().includes(platform)) {
|
||||
hasSupportedPlatform = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasSupportedPlatform) {
|
||||
return;
|
||||
}
|
||||
|
||||
// add 'subscribed' class if user is subscribed to vpn
|
||||
RPMSendQuery("FetchVPNSubStatus", {}).then(async hasVPN => {
|
||||
|
@ -102,7 +87,7 @@ export default class VPNCard {
|
|||
showVPNBanner() {
|
||||
if (
|
||||
RPMGetBoolPref("browser.contentblocking.report.hide_vpn_banner", false) ||
|
||||
!RPMGetBoolPref("browser.contentblocking.report.vpn.enabled", false)
|
||||
!RPMGetBoolPref("browser.vpn_promo.enabled", false)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ add_task(async function setup() {
|
|||
set: [
|
||||
["browser.contentblocking.report.monitor.enabled", false],
|
||||
["browser.contentblocking.report.lockwise.enabled", false],
|
||||
["browser.contentblocking.report.vpn.enabled", false],
|
||||
["browser.vpn_promo.enabled", false],
|
||||
],
|
||||
});
|
||||
});
|
||||
|
|
|
@ -33,7 +33,7 @@ add_task(async function setup() {
|
|||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.contentblocking.database.enabled", true],
|
||||
["browser.contentblocking.report.vpn.enabled", false],
|
||||
["browser.vpn_promo.enabled", false],
|
||||
],
|
||||
});
|
||||
});
|
||||
|
|
|
@ -46,8 +46,12 @@ requestLongerTimeout(2);
|
|||
add_task(async function setup() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.vpn_promo.enabled", true],
|
||||
["browser.contentblocking.report.vpn_regions", "us,ca,nz,sg,my,gb"],
|
||||
["browser.contentblocking.report.vpn_platforms", "win"],
|
||||
[
|
||||
"browser.vpn_promo.disallowed_regions",
|
||||
"ae,by,cn,cu,iq,ir,kp,om,ru,sd,sy,tm,tr,ua",
|
||||
],
|
||||
|
||||
// Change the endpoints to prevent non-local network connections when landing on the page.
|
||||
["browser.contentblocking.report.monitor.url", ""],
|
||||
|
@ -83,7 +87,7 @@ add_task(async function checkTelemetryLoadEvents() {
|
|||
["browser.contentblocking.report.monitor.enabled", false],
|
||||
["browser.contentblocking.report.lockwise.enabled", false],
|
||||
["browser.contentblocking.report.proxy.enabled", false],
|
||||
["browser.contentblocking.report.vpn.enabled", false],
|
||||
["browser.vpn_promo.enabled", false],
|
||||
],
|
||||
});
|
||||
await addArbitraryTimeout();
|
||||
|
@ -180,7 +184,7 @@ add_task(async function checkTelemetryClickEvents() {
|
|||
["browser.contentblocking.report.monitor.enabled", true],
|
||||
["browser.contentblocking.report.lockwise.enabled", true],
|
||||
["browser.contentblocking.report.proxy.enabled", true],
|
||||
["browser.contentblocking.report.vpn.enabled", false],
|
||||
["browser.vpn_promo.enabled", false],
|
||||
],
|
||||
});
|
||||
await addArbitraryTimeout();
|
||||
|
@ -787,7 +791,7 @@ add_task(async function checkTelemetryLoadEventForEntrypoint() {
|
|||
["browser.contentblocking.report.monitor.enabled", false],
|
||||
["browser.contentblocking.report.lockwise.enabled", false],
|
||||
["browser.contentblocking.report.proxy.enabled", false],
|
||||
["browser.contentblocking.report.vpn.enabled", false],
|
||||
["browser.vpn_promo.enabled", false],
|
||||
],
|
||||
});
|
||||
await addArbitraryTimeout();
|
||||
|
@ -892,13 +896,16 @@ add_task(async function checkTelemetryClickEventsVPN() {
|
|||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false, "us"));
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.vpn_promo.enabled", true],
|
||||
[
|
||||
"browser.vpn_promo.disallowed_regions",
|
||||
"ae,by,cn,cu,iq,ir,kp,om,ru,sd,sy,tm,tr,ua",
|
||||
],
|
||||
["browser.contentblocking.report.vpn_regions", "us,ca,nz,sg,my,gb"],
|
||||
["browser.contentblocking.database.enabled", false],
|
||||
["browser.contentblocking.report.monitor.enabled", false],
|
||||
["browser.contentblocking.report.lockwise.enabled", false],
|
||||
["browser.contentblocking.report.proxy.enabled", false],
|
||||
["browser.contentblocking.report.vpn.enabled", true],
|
||||
["browser.contentblocking.report.vpn_regions", "us,ca,nz,sg,my,gb,cn"],
|
||||
["browser.contentblocking.report.vpn_platforms", "win"],
|
||||
["browser.contentblocking.report.hide_vpn_banner", true],
|
||||
["browser.contentblocking.report.vpn-android.url", ""],
|
||||
["browser.contentblocking.report.vpn-ios.url", ""],
|
||||
|
@ -1020,13 +1027,16 @@ add_task(async function checkTelemetryEventsVPNBanner() {
|
|||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false, "us"));
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.vpn_promo.enabled", true],
|
||||
["browser.contentblocking.report.vpn_regions", "us,ca,nz,sg,my,gb"],
|
||||
[
|
||||
"browser.vpn_promo.disallowed_regions",
|
||||
"ae,by,cn,cu,iq,ir,kp,om,ru,sd,sy,tm,tr,ua",
|
||||
],
|
||||
["browser.contentblocking.database.enabled", false],
|
||||
["browser.contentblocking.report.monitor.enabled", false],
|
||||
["browser.contentblocking.report.lockwise.enabled", false],
|
||||
["browser.contentblocking.report.proxy.enabled", false],
|
||||
["browser.contentblocking.report.vpn.enabled", true],
|
||||
["browser.contentblocking.report.vpn_regions", "us,ca,nz,sg,my,gb"],
|
||||
["browser.contentblocking.report.vpn_platforms", "win"],
|
||||
["browser.contentblocking.report.hide_vpn_banner", false],
|
||||
["browser.contentblocking.report.vpn-promo.url", ""],
|
||||
],
|
||||
|
|
|
@ -8,82 +8,10 @@ const { AboutProtectionsParent } = ChromeUtils.import(
|
|||
"resource:///actors/AboutProtectionsParent.jsm"
|
||||
);
|
||||
|
||||
add_task(async function setup() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.contentblocking.report.monitor.enabled", false],
|
||||
["browser.contentblocking.report.lockwise.enabled", false],
|
||||
["browser.contentblocking.report.vpn.enabled", true],
|
||||
],
|
||||
});
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false, "us"));
|
||||
const avLocales = Services.locale.availableLocales;
|
||||
let { Region } = ChromeUtils.import("resource://gre/modules/Region.jsm");
|
||||
|
||||
registerCleanupFunction(() => {
|
||||
Services.locale.availableLocales = avLocales;
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function testVPNCardVisibility() {
|
||||
if (Services.sysinfo.getProperty("name") != "Windows_NT") {
|
||||
ok(true, "User is on an unsupported platform, the vpn card will not show");
|
||||
return;
|
||||
}
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false, "my"));
|
||||
await promiseSetHomeRegion("my");
|
||||
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab({
|
||||
url: "about:protections",
|
||||
gBrowser,
|
||||
});
|
||||
|
||||
info("Enable showing the VPN card");
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.contentblocking.report.vpn.enabled", true],
|
||||
["browser.contentblocking.report.vpn_regions", "us,ca,nz,sg,my,gb"],
|
||||
["browser.contentblocking.report.vpn_platforms", "win"],
|
||||
],
|
||||
});
|
||||
|
||||
info("Check that vpn card is hidden if user's language is not en*");
|
||||
Services.locale.availableLocales = ["ko-KR", "ar"];
|
||||
Services.locale.requestedLocales = ["ko-KR"];
|
||||
await reloadTab(tab);
|
||||
await checkVPNCardVisibility(tab, true);
|
||||
|
||||
info("Check that vpn card is shown if user's language is en*");
|
||||
// Set language back to en-US
|
||||
Services.locale.availableLocales = ["en-US"];
|
||||
Services.locale.requestedLocales = ["en-US"];
|
||||
await reloadTab(tab);
|
||||
await checkVPNCardVisibility(tab, false);
|
||||
|
||||
info(
|
||||
"Check that vpn card is hidden if user's location is not on the regions list."
|
||||
);
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false, "ls"));
|
||||
await reloadTab(tab);
|
||||
await checkVPNCardVisibility(tab, true);
|
||||
|
||||
info(
|
||||
"Check that vpn card shows a different version if user has subscribed to Mozilla vpn."
|
||||
);
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(true, "us"));
|
||||
await reloadTab(tab);
|
||||
await checkVPNCardVisibility(tab, false, true);
|
||||
|
||||
info(
|
||||
"VPN card should be hidden when vpn not enabled, though all other conditions are true"
|
||||
);
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.contentblocking.report.vpn.enabled", false]],
|
||||
});
|
||||
await reloadTab(tab);
|
||||
await checkVPNCardVisibility(tab, true);
|
||||
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
const initialHomeRegion = Region._home;
|
||||
const initialCurrentRegion = Region._current;
|
||||
|
||||
async function checkVPNCardVisibility(tab, shouldBeHidden, subscribed = false) {
|
||||
await SpecialPowers.spawn(
|
||||
|
@ -106,12 +34,115 @@ async function checkVPNCardVisibility(tab, shouldBeHidden, subscribed = false) {
|
|||
);
|
||||
}
|
||||
|
||||
async function checkVPNPromoBannerVisibility(tab, shouldBeHidden) {
|
||||
await SpecialPowers.spawn(
|
||||
tab.linkedBrowser,
|
||||
[{ _shouldBeHidden: shouldBeHidden }],
|
||||
async function({ _shouldBeHidden }) {
|
||||
await ContentTaskUtils.waitForCondition(() => {
|
||||
const vpnBanner = content.document.querySelector(".vpn-banner");
|
||||
return ContentTaskUtils.is_hidden(vpnBanner) === _shouldBeHidden;
|
||||
});
|
||||
|
||||
const visibilityState = _shouldBeHidden ? "hidden" : "shown";
|
||||
ok(true, `VPN banner is ${visibilityState}.`);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async function setCurrentRegion(region) {
|
||||
Region._setCurrentRegion(region);
|
||||
}
|
||||
|
||||
async function setHomeRegion(region) {
|
||||
// _setHomeRegion sets a char pref to the value of region. A non-string value will result in an error, so default to an empty string when region is falsey.
|
||||
Region._setHomeRegion(region || "");
|
||||
}
|
||||
|
||||
async function revertRegions() {
|
||||
setCurrentRegion(initialCurrentRegion);
|
||||
setHomeRegion(initialHomeRegion);
|
||||
}
|
||||
|
||||
add_task(async function setup() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.contentblocking.report.monitor.enabled", false],
|
||||
["browser.contentblocking.report.lockwise.enabled", false],
|
||||
["browser.vpn_promo.enabled", true],
|
||||
],
|
||||
});
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false));
|
||||
setCurrentRegion("us");
|
||||
const avLocales = Services.locale.availableLocales;
|
||||
|
||||
registerCleanupFunction(() => {
|
||||
Services.locale.availableLocales = avLocales;
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function testVPNCardVisibility() {
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false));
|
||||
await promiseSetHomeRegion("us");
|
||||
setCurrentRegion("us");
|
||||
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab({
|
||||
url: "about:protections",
|
||||
gBrowser,
|
||||
});
|
||||
|
||||
info("Enable showing the VPN card");
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.vpn_promo.enabled", true],
|
||||
["browser.contentblocking.report.vpn_regions", "us,ca,nz,sg,my,gb"],
|
||||
[
|
||||
"browser.vpn_promo.disallowed_regions",
|
||||
"ae,by,cn,cu,iq,ir,kp,om,ru,sd,sy,tm,tr,ua",
|
||||
],
|
||||
],
|
||||
});
|
||||
|
||||
info(
|
||||
"Check that vpn card is hidden if neither the user's home nor current location is on the regions list."
|
||||
);
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false));
|
||||
setCurrentRegion("ls");
|
||||
await promiseSetHomeRegion("ls");
|
||||
await reloadTab(tab);
|
||||
await checkVPNCardVisibility(tab, true);
|
||||
|
||||
info(
|
||||
"Check that vpn card is hidden if user's location is in the list of disallowed regions."
|
||||
);
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false));
|
||||
setCurrentRegion("sy");
|
||||
await reloadTab(tab);
|
||||
await checkVPNCardVisibility(tab, true);
|
||||
|
||||
info(
|
||||
"Check that vpn card shows a different version if user has subscribed to Mozilla vpn."
|
||||
);
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(true));
|
||||
setCurrentRegion("us");
|
||||
await reloadTab(tab);
|
||||
await checkVPNCardVisibility(tab, false, true);
|
||||
|
||||
info(
|
||||
"VPN card should be hidden when vpn not enabled, though all other conditions are true"
|
||||
);
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.vpn_promo.enabled", false]],
|
||||
});
|
||||
await reloadTab(tab);
|
||||
await checkVPNCardVisibility(tab, true);
|
||||
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
revertRegions();
|
||||
});
|
||||
|
||||
add_task(async function testVPNPromoBanner() {
|
||||
if (Services.sysinfo.getProperty("name") != "Windows_NT") {
|
||||
ok(true, "User is on an unsupported platform, the vpn card will not show");
|
||||
return;
|
||||
}
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false, "us"));
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false));
|
||||
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab({
|
||||
url: "about:protections",
|
||||
|
@ -121,28 +152,18 @@ add_task(async function testVPNPromoBanner() {
|
|||
info("Enable showing the VPN card and banner");
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.contentblocking.report.vpn.enabled", true],
|
||||
["browser.vpn_promo.enabled", true],
|
||||
["browser.contentblocking.report.vpn_regions", "us,ca,nz,sg,my,gb"],
|
||||
["browser.contentblocking.report.vpn_platforms", "win"],
|
||||
[
|
||||
"browser.vpn_promo.disallowed_regions",
|
||||
"ae,by,cn,cu,iq,ir,kp,om,ru,sd,sy,tm,tr,ua",
|
||||
],
|
||||
["browser.contentblocking.report.hide_vpn_banner", false],
|
||||
],
|
||||
});
|
||||
|
||||
info("Check that vpn banner is hidden if user's language is not en*");
|
||||
Services.locale.availableLocales = ["de"];
|
||||
Services.locale.requestedLocales = ["de"];
|
||||
await reloadTab(tab);
|
||||
await checkVPNPromoBannerVisibility(tab, true);
|
||||
|
||||
// VPN Banner flips this pref each time it shows, flip back between each instruction.
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.contentblocking.report.hide_vpn_banner", false]],
|
||||
});
|
||||
|
||||
info("Check that vpn banner is shown if user's language is en*");
|
||||
// Set language back to en-US
|
||||
Services.locale.availableLocales = ["en-US"];
|
||||
Services.locale.requestedLocales = ["en-US"];
|
||||
info("Check that vpn banner is shown if user's region is supported");
|
||||
setCurrentRegion("us");
|
||||
await reloadTab(tab);
|
||||
await checkVPNPromoBannerVisibility(tab, false);
|
||||
|
||||
|
@ -166,7 +187,17 @@ add_task(async function testVPNPromoBanner() {
|
|||
info(
|
||||
"Check that VPN banner is hidden if user's location is not on the regions list."
|
||||
);
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false, "ls"));
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false));
|
||||
setCurrentRegion("ls");
|
||||
await setHomeRegion("ls'");
|
||||
await reloadTab(tab);
|
||||
await checkVPNPromoBannerVisibility(tab, true);
|
||||
|
||||
info(
|
||||
"Check that VPN banner is hidden if user's location is in the disallowed regions list."
|
||||
);
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false));
|
||||
setCurrentRegion("sy");
|
||||
await reloadTab(tab);
|
||||
await checkVPNPromoBannerVisibility(tab, true);
|
||||
|
||||
|
@ -175,7 +206,7 @@ add_task(async function testVPNPromoBanner() {
|
|||
);
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.contentblocking.report.vpn.enabled", false],
|
||||
["browser.vpn_promo.enabled", false],
|
||||
["browser.contentblocking.report.hide_vpn_banner", false],
|
||||
],
|
||||
});
|
||||
|
@ -184,43 +215,25 @@ add_task(async function testVPNPromoBanner() {
|
|||
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.contentblocking.report.vpn.enabled", true],
|
||||
["browser.vpn_promo.enabled", true],
|
||||
["browser.contentblocking.report.hide_vpn_banner", false],
|
||||
],
|
||||
});
|
||||
|
||||
info("If user is subscribed to VPN already the promo banner should not show");
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(true, "us"));
|
||||
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(true));
|
||||
setCurrentRegion("us");
|
||||
await reloadTab(tab);
|
||||
await checkVPNPromoBannerVisibility(tab, true);
|
||||
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
revertRegions();
|
||||
});
|
||||
|
||||
async function checkVPNPromoBannerVisibility(tab, shouldBeHidden) {
|
||||
await SpecialPowers.spawn(
|
||||
tab.linkedBrowser,
|
||||
[{ _shouldBeHidden: shouldBeHidden }],
|
||||
async function({ _shouldBeHidden }) {
|
||||
await ContentTaskUtils.waitForCondition(() => {
|
||||
const vpnBanner = content.document.querySelector(".vpn-banner");
|
||||
return ContentTaskUtils.is_hidden(vpnBanner) === _shouldBeHidden;
|
||||
});
|
||||
|
||||
const visibilityState = _shouldBeHidden ? "hidden" : "shown";
|
||||
ok(true, `VPN banner is ${visibilityState}.`);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Expect the vpn card and banner to not show as we are expressly excluding China. Even when cn is in the supported region pref.
|
||||
add_task(async function testVPNDoesNotShowChina() {
|
||||
if (Services.sysinfo.getProperty("name") != "Windows_NT") {
|
||||
ok(true, "User is on an unsupported platform, the vpn card will not show");
|
||||
return;
|
||||
}
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false, "us"));
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false));
|
||||
setCurrentRegion("us");
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab({
|
||||
url: "about:protections",
|
||||
gBrowser,
|
||||
|
@ -229,9 +242,12 @@ add_task(async function testVPNDoesNotShowChina() {
|
|||
info("Enable showing the VPN card and banners");
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.contentblocking.report.vpn.enabled", true],
|
||||
["browser.vpn_promo.enabled", true],
|
||||
["browser.contentblocking.report.vpn_regions", "us,ca,nz,sg,my,gb,cn"],
|
||||
["browser.contentblocking.report.vpn_platforms", "win"],
|
||||
[
|
||||
"browser.vpn_promo.disallowed_regions",
|
||||
"ae,by,cn,cu,iq,ir,kp,om,ru,sd,sy,tm,tr,ua",
|
||||
],
|
||||
["browser.contentblocking.report.hide_vpn_banner", false],
|
||||
],
|
||||
});
|
||||
|
@ -251,12 +267,14 @@ add_task(async function testVPNDoesNotShowChina() {
|
|||
});
|
||||
|
||||
info("home region is US, but current location is China");
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false));
|
||||
await promiseSetHomeRegion("US");
|
||||
AboutProtectionsParent.setTestOverride(getVPNOverrides(false, "cn"));
|
||||
setCurrentRegion("CN");
|
||||
await reloadTab(tab);
|
||||
await checkVPNPromoBannerVisibility(tab, true);
|
||||
await reloadTab(tab);
|
||||
await checkVPNCardVisibility(tab, true);
|
||||
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
revertRegions();
|
||||
});
|
||||
|
|
|
@ -86,14 +86,11 @@ registerCleanupFunction(function head_cleanup() {
|
|||
Services.logins.removeAllUserFacingLogins();
|
||||
});
|
||||
|
||||
// Used to replace AboutProtectionsParent.VPNSubStatus and Region.current
|
||||
const getVPNOverrides = (hasSubscription = false, location = "us") => {
|
||||
// Used to replace AboutProtectionsParent.VPNSubStatus
|
||||
const getVPNOverrides = (hasSubscription = false) => {
|
||||
return {
|
||||
vpnOverrides: () => {
|
||||
return {
|
||||
hasSubscription,
|
||||
location,
|
||||
};
|
||||
return hasSubscription;
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
|
@ -20,6 +20,15 @@ ChromeUtils.defineModuleGetter(
|
|||
"resource://gre/modules/Region.jsm"
|
||||
);
|
||||
|
||||
function stringPrefToSet(prefVal) {
|
||||
return new Set(
|
||||
prefVal
|
||||
.toLowerCase()
|
||||
.split(/\s*,\s*/g) // split on commas, ignoring whitespace
|
||||
.filter(v => !!v) // discard any falsey values
|
||||
);
|
||||
}
|
||||
|
||||
var BrowserUtils = {
|
||||
/**
|
||||
* Return or create a principal with the content of one, and the originAttributes
|
||||
|
@ -305,20 +314,31 @@ var BrowserUtils = {
|
|||
|
||||
// Returns true if user should see VPN promos
|
||||
shouldShowVPNPromo() {
|
||||
const enablePromoPref = Services.prefs.getBoolPref(
|
||||
"browser.vpn_promo.enabled"
|
||||
const vpnPromoEnabled = Services.prefs.getBoolPref(
|
||||
"browser.vpn_promo.enabled",
|
||||
true
|
||||
);
|
||||
const homeRegion = Region.home || "";
|
||||
const currentRegion = Region.current || "";
|
||||
let avoidAdsCountries = BrowserUtils.vpnDisallowedRegions;
|
||||
const supportedRegions = BrowserUtils.vpnSupportedRegions;
|
||||
const inSupportedRegion =
|
||||
supportedRegions.has(currentRegion.toLowerCase()) ||
|
||||
supportedRegions.has(homeRegion.toLowerCase());
|
||||
const avoidAdsCountries = BrowserUtils.vpnDisallowedRegions;
|
||||
// Extra check for countries where VPNs are illegal and compliance is strongly enforced
|
||||
let vpnIllegalCountries = ["cn", "kp", "tm"];
|
||||
const vpnIllegalCountries = ["cn", "kp", "tm"];
|
||||
vpnIllegalCountries.forEach(country => avoidAdsCountries.add(country));
|
||||
// Don't show promo if there's an active enterprise policy
|
||||
const noActivePolicy =
|
||||
!Services.policies ||
|
||||
Services.policies.status !== Services.policies.ACTIVE;
|
||||
|
||||
return (
|
||||
enablePromoPref &&
|
||||
vpnPromoEnabled &&
|
||||
!avoidAdsCountries.has(homeRegion.toLowerCase()) &&
|
||||
!avoidAdsCountries.has(currentRegion.toLowerCase())
|
||||
!avoidAdsCountries.has(currentRegion.toLowerCase()) &&
|
||||
inSupportedRegion &&
|
||||
noActivePolicy
|
||||
);
|
||||
},
|
||||
|
||||
|
@ -340,17 +360,20 @@ XPCOMUtils.defineLazyPreferenceGetter(
|
|||
false
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
BrowserUtils,
|
||||
"vpnSupportedRegions",
|
||||
"browser.contentblocking.report.vpn_regions",
|
||||
"us,ca,nz,sg,my,gb,de,fr",
|
||||
null,
|
||||
stringPrefToSet
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
BrowserUtils,
|
||||
"vpnDisallowedRegions",
|
||||
"browser.vpn_promo.disallowed_regions",
|
||||
"ae,by,cn,cu,iq,ir,kp,om,ru,sd,sy,tm,tr,ua",
|
||||
null,
|
||||
prefVal =>
|
||||
new Set(
|
||||
prefVal
|
||||
.toLowerCase()
|
||||
.split(/\s*,\s*/g) // split on commas, ignoring whitespace
|
||||
.filter(v => !!v) // discard any falsey values
|
||||
)
|
||||
stringPrefToSet
|
||||
);
|
||||
|
|
|
@ -173,7 +173,7 @@ let RemotePageAccessManager = {
|
|||
"privacy.trackingprotection.socialtracking.enabled",
|
||||
"browser.contentblocking.report.show_mobile_app",
|
||||
"browser.contentblocking.report.hide_vpn_banner",
|
||||
"browser.contentblocking.report.vpn.enabled",
|
||||
"browser.vpn_promo.enabled",
|
||||
],
|
||||
RPMGetStringPref: [
|
||||
"browser.contentblocking.category",
|
||||
|
@ -189,7 +189,6 @@ let RemotePageAccessManager = {
|
|||
"browser.contentblocking.report.vpn-promo.url",
|
||||
"browser.contentblocking.report.vpn-android.url",
|
||||
"browser.contentblocking.report.vpn-ios.url",
|
||||
"browser.contentblocking.report.vpn_platforms",
|
||||
],
|
||||
RPMGetIntPref: ["network.cookie.cookieBehavior"],
|
||||
RPMGetFormatURLPref: [
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
const { BrowserUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/BrowserUtils.jsm"
|
||||
);
|
||||
|
||||
const { Region } = ChromeUtils.import("resource://gre/modules/Region.jsm");
|
||||
|
||||
const initialHomeRegion = Region._home;
|
||||
const initialCurrentRegion = Region._current;
|
||||
|
||||
// Helper to run tests for specific regions
|
||||
function setupRegions(home, current) {
|
||||
Region._setHomeRegion(home || "");
|
||||
Region._setCurrentRegion(current || "");
|
||||
}
|
||||
|
||||
add_task(async function test_shouldShowVPNPromo() {
|
||||
function setPromoEnabled(enabled) {
|
||||
Services.prefs.setBoolPref("browser.vpn_promo.enabled", enabled);
|
||||
}
|
||||
|
||||
const allowedRegion = "US";
|
||||
const disallowedRegion = "SY";
|
||||
const illegalRegion = "CN";
|
||||
const unsupportedRegion = "LY";
|
||||
|
||||
// Show promo when enabled in allowed regions
|
||||
setupRegions(allowedRegion, allowedRegion);
|
||||
Assert.ok(BrowserUtils.shouldShowVPNPromo());
|
||||
|
||||
// Don't show when not enabled
|
||||
setPromoEnabled(false);
|
||||
Assert.ok(!BrowserUtils.shouldShowVPNPromo());
|
||||
|
||||
// Don't show in disallowed home regions, even when enabled
|
||||
setPromoEnabled(true);
|
||||
setupRegions(disallowedRegion);
|
||||
Assert.ok(!BrowserUtils.shouldShowVPNPromo());
|
||||
|
||||
// Don't show in illegal home regions, even when enabled
|
||||
setupRegions(illegalRegion);
|
||||
Assert.ok(!BrowserUtils.shouldShowVPNPromo());
|
||||
|
||||
// Don't show in disallowed current regions, even when enabled
|
||||
setupRegions(allowedRegion, disallowedRegion);
|
||||
Assert.ok(!BrowserUtils.shouldShowVPNPromo());
|
||||
|
||||
// Don't show in illegal current regions, even when enabled
|
||||
setupRegions(allowedRegion, illegalRegion);
|
||||
Assert.ok(!BrowserUtils.shouldShowVPNPromo());
|
||||
|
||||
// Show if home region is supported, even if current region is not supported (but isn't disallowed or illegal)
|
||||
setupRegions(allowedRegion, unsupportedRegion);
|
||||
Assert.ok(BrowserUtils.shouldShowVPNPromo());
|
||||
|
||||
// Show VPN if current region is supported, even if home region is unsupported (but isn't disallowed or illegal)
|
||||
setupRegions(unsupportedRegion, allowedRegion); // revert changes to regions
|
||||
Assert.ok(BrowserUtils.shouldShowVPNPromo());
|
||||
|
||||
setupRegions(initialHomeRegion, initialCurrentRegion); // revert changes to regions
|
||||
});
|
||||
|
||||
add_task(async function test_shouldShowRallyPromo() {
|
||||
const initialLanguage = Services.locale.appLocaleAsBCP47;
|
||||
const allowedRegion = "US";
|
||||
const disallowedRegion = "CN";
|
||||
const allowedLanguage = "en-US";
|
||||
const disallowedLanguage = "fr";
|
||||
|
||||
function setLanguage(language) {
|
||||
Services.locale.availableLocales = [language];
|
||||
Services.locale.requestedLocales = [language];
|
||||
}
|
||||
|
||||
// Show promo when region is US and language is en-US
|
||||
setupRegions(allowedRegion, allowedRegion);
|
||||
setLanguage(allowedLanguage);
|
||||
Assert.ok(BrowserUtils.shouldShowRallyPromo());
|
||||
|
||||
// Don't show when home region is not US
|
||||
setupRegions(disallowedRegion);
|
||||
Assert.ok(!BrowserUtils.shouldShowRallyPromo());
|
||||
|
||||
// Don't show when langauge is not en-US, even if region is US
|
||||
setLanguage(disallowedLanguage);
|
||||
setupRegions(allowedRegion);
|
||||
Assert.ok(!BrowserUtils.shouldShowRallyPromo());
|
||||
|
||||
// Don't show when home region is not US, even if language is en-US
|
||||
setupRegions(disallowedRegion);
|
||||
Assert.ok(!BrowserUtils.shouldShowRallyPromo());
|
||||
|
||||
// Don't show when current region is not US, even if home region is US and langague is en-US
|
||||
setupRegions(allowedRegion, disallowedRegion);
|
||||
Assert.ok(!BrowserUtils.shouldShowRallyPromo());
|
||||
|
||||
setupRegions(initialHomeRegion, initialCurrentRegion); // revert changes to regions
|
||||
setLanguage(initialLanguage); // revert changes to language
|
||||
});
|
|
@ -13,6 +13,7 @@ support-files =
|
|||
regions/world-buffered.geojson
|
||||
|
||||
[test_BinarySearch.js]
|
||||
[test_BrowserUtils.js]
|
||||
[test_CanonicalJSON.js]
|
||||
[test_Color.js]
|
||||
[test_CreditCard.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче