Backed out changeset 260a3d2ed070 (bug 1747149) for causing android xpc failures in test_BrowserUtils.

This commit is contained in:
smolnar
2022-02-11 05:04:29 +02:00
parent daaa255d8f
commit 9f23ccb51e
19 changed files with 399 additions and 444 deletions

View File

@@ -482,7 +482,10 @@ document.addEventListener("DOMContentLoaded", e => {
const proxyUI = document.querySelector(".proxy-card");
proxyUI.dataset.enabled = proxyEnabled;
const VPNEnabled = RPMGetBoolPref("browser.vpn_promo.enabled", true);
const VPNEnabled = RPMGetBoolPref(
"browser.contentblocking.report.vpn.enabled",
true
);
if (VPNEnabled) {
const vpnCard = new VPNCard(document);
vpnCard.init();

View File

@@ -62,6 +62,21 @@ 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 => {
@@ -87,7 +102,7 @@ export default class VPNCard {
showVPNBanner() {
if (
RPMGetBoolPref("browser.contentblocking.report.hide_vpn_banner", false) ||
!RPMGetBoolPref("browser.vpn_promo.enabled", false)
!RPMGetBoolPref("browser.contentblocking.report.vpn.enabled", false)
) {
return;
}

View File

@@ -13,7 +13,7 @@ add_task(async function setup() {
set: [
["browser.contentblocking.report.monitor.enabled", false],
["browser.contentblocking.report.lockwise.enabled", false],
["browser.vpn_promo.enabled", false],
["browser.contentblocking.report.vpn.enabled", false],
],
});
});

View File

@@ -33,7 +33,7 @@ add_task(async function setup() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.contentblocking.database.enabled", true],
["browser.vpn_promo.enabled", false],
["browser.contentblocking.report.vpn.enabled", false],
],
});
});

View File

@@ -46,12 +46,8 @@ 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.vpn_promo.disallowed_regions",
"ae,by,cn,cu,iq,ir,kp,om,ru,sd,sy,tm,tr,ua",
],
["browser.contentblocking.report.vpn_platforms", "win"],
// Change the endpoints to prevent non-local network connections when landing on the page.
["browser.contentblocking.report.monitor.url", ""],
@@ -87,7 +83,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.vpn_promo.enabled", false],
["browser.contentblocking.report.vpn.enabled", false],
],
});
await addArbitraryTimeout();
@@ -184,7 +180,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.vpn_promo.enabled", false],
["browser.contentblocking.report.vpn.enabled", false],
],
});
await addArbitraryTimeout();
@@ -791,7 +787,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.vpn_promo.enabled", false],
["browser.contentblocking.report.vpn.enabled", false],
],
});
await addArbitraryTimeout();
@@ -896,16 +892,13 @@ 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", ""],
@@ -1027,16 +1020,13 @@ 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", ""],
],

View File

@@ -8,10 +8,82 @@ const { AboutProtectionsParent } = ChromeUtils.import(
"resource:///actors/AboutProtectionsParent.jsm"
);
let { Region } = ChromeUtils.import("resource://gre/modules/Region.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;
const initialHomeRegion = Region._home;
const initialCurrentRegion = Region._current;
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);
});
async function checkVPNCardVisibility(tab, shouldBeHidden, subscribed = false) {
await SpecialPowers.spawn(
@@ -34,115 +106,12 @@ 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() {
AboutProtectionsParent.setTestOverride(getVPNOverrides(false));
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"));
let tab = await BrowserTestUtils.openNewForegroundTab({
url: "about:protections",
@@ -152,18 +121,28 @@ add_task(async function testVPNPromoBanner() {
info("Enable showing the VPN card and banner");
await SpecialPowers.pushPrefEnv({
set: [
["browser.vpn_promo.enabled", true],
["browser.contentblocking.report.vpn.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.report.vpn_platforms", "win"],
["browser.contentblocking.report.hide_vpn_banner", false],
],
});
info("Check that vpn banner is shown if user's region is supported");
setCurrentRegion("us");
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"];
await reloadTab(tab);
await checkVPNPromoBannerVisibility(tab, false);
@@ -187,17 +166,7 @@ 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));
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");
AboutProtectionsParent.setTestOverride(getVPNOverrides(false, "ls"));
await reloadTab(tab);
await checkVPNPromoBannerVisibility(tab, true);
@@ -206,7 +175,7 @@ add_task(async function testVPNPromoBanner() {
);
await SpecialPowers.pushPrefEnv({
set: [
["browser.vpn_promo.enabled", false],
["browser.contentblocking.report.vpn.enabled", false],
["browser.contentblocking.report.hide_vpn_banner", false],
],
});
@@ -215,25 +184,43 @@ add_task(async function testVPNPromoBanner() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.vpn_promo.enabled", true],
["browser.contentblocking.report.vpn.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));
setCurrentRegion("us");
AboutProtectionsParent.setTestOverride(getVPNOverrides(true, "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() {
AboutProtectionsParent.setTestOverride(getVPNOverrides(false));
setCurrentRegion("us");
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"));
let tab = await BrowserTestUtils.openNewForegroundTab({
url: "about:protections",
gBrowser,
@@ -242,12 +229,9 @@ add_task(async function testVPNDoesNotShowChina() {
info("Enable showing the VPN card and banners");
await SpecialPowers.pushPrefEnv({
set: [
["browser.vpn_promo.enabled", true],
["browser.contentblocking.report.vpn.enabled", true],
["browser.contentblocking.report.vpn_regions", "us,ca,nz,sg,my,gb,cn"],
[
"browser.vpn_promo.disallowed_regions",
"ae,by,cn,cu,iq,ir,kp,om,ru,sd,sy,tm,tr,ua",
],
["browser.contentblocking.report.vpn_platforms", "win"],
["browser.contentblocking.report.hide_vpn_banner", false],
],
});
@@ -267,14 +251,12 @@ add_task(async function testVPNDoesNotShowChina() {
});
info("home region is US, but current location is China");
AboutProtectionsParent.setTestOverride(getVPNOverrides(false));
await promiseSetHomeRegion("US");
setCurrentRegion("CN");
AboutProtectionsParent.setTestOverride(getVPNOverrides(false, "cn"));
await reloadTab(tab);
await checkVPNPromoBannerVisibility(tab, true);
await reloadTab(tab);
await checkVPNCardVisibility(tab, true);
await BrowserTestUtils.removeTab(tab);
revertRegions();
});

View File

@@ -86,11 +86,14 @@ registerCleanupFunction(function head_cleanup() {
Services.logins.removeAllUserFacingLogins();
});
// Used to replace AboutProtectionsParent.VPNSubStatus
const getVPNOverrides = (hasSubscription = false) => {
// Used to replace AboutProtectionsParent.VPNSubStatus and Region.current
const getVPNOverrides = (hasSubscription = false, location = "us") => {
return {
vpnOverrides: () => {
return hasSubscription;
return {
hasSubscription,
location,
};
},
};
};