Backed out changeset edbc8f7e808f (bug 1748240) for bc failures on browser_privatebrowsing_about_nimbus.js. CLOSED TREE

This commit is contained in:
Cosmin Sabou 2022-02-01 05:40:15 +02:00
parent c4d027fbb0
commit c1424ed185
6 changed files with 47 additions and 263 deletions

View File

@ -51,30 +51,6 @@ const ONBOARDING_MESSAGES = () => [
},
targeting: "true",
},
{
id: "PB_NEWTAB_VPN_PROMO",
template: "pb_newtab",
content: {
promoEnabled: true,
infoEnabled: true,
infoIcon: "",
infoTitle: "",
infoBody: "fluent:about-private-browsing-info-description-private-window",
infoLinkText: "fluent:about-private-browsing-learn-more-link",
infoTitleEnabled: false,
promoLinkType: "button",
promoLinkText: "fluent:about-private-browsing-prominent-cta",
promoSectionStyle: "below-search",
promoHeader: "fluent:about-private-browsing-get-privacy",
promoTitle: "fluent:about-private-browsing-hide-activity-1",
promoTitleEnabled: true,
promoImageLarge: "chrome://browser/content/assets/moz-vpn.svg",
},
// Ensure this message is shown over others while frequency allows
priority: 2,
targeting: "region != 'CN' && !hasActiveEnterprisePolicies",
frequency: { lifetime: 3 },
},
];
const OnboardingMessageProvider = {

View File

@ -74,7 +74,6 @@
</div>
</div>
</div>
<button data-l10n-id="about-private-browsing-dismiss-button" id="dismiss-btn" class="promo-dismiss"></button>
</div>
</body>
</html>

View File

@ -31,7 +31,7 @@ async function translateElements(container, items) {
}
async function renderInfo({
infoEnabled = false,
infoEnabled,
infoTitle,
infoTitleEnabled,
infoBody,
@ -75,7 +75,6 @@ async function renderInfo({
}
async function renderPromo({
messageId = null,
promoEnabled = false,
promoTitle,
promoTitleEnabled,
@ -90,16 +89,22 @@ async function renderPromo({
const container = document.querySelector(".promo");
if (promoEnabled === false) {
container.remove();
return false;
return;
}
// Check the current geo and remove if we're in the wrong one.
RPMSendQuery("ShouldShowVPNPromo", {}).then(shouldShow => {
if (!shouldShow) {
container.remove();
}
});
const titleEl = document.getElementById("private-browsing-vpn-text");
let linkEl = document.getElementById("private-browsing-vpn-link");
const promoHeaderEl = document.getElementById("promo-header");
const infoContainerEl = document.querySelector(".info");
const promoImageLargeEl = document.querySelector(".promo-image-large img");
const promoImageSmallEl = document.querySelector(".promo-image-small img");
const dismissBtn = document.querySelector("#dismiss-btn");
// Setup the private browsing VPN link.
const vpnPromoUrl =
@ -117,19 +122,7 @@ async function renderPromo({
} else {
// If the link is undefined, remove the promo completely
container.remove();
return false;
}
const onDismissBtnClick = () => {
window.ASRouterMessage({
type: "BLOCK_MESSAGE_BY_ID",
data: { id: messageId },
});
container.remove();
};
if (dismissBtn && messageId) {
dismissBtn.addEventListener("click", onDismissBtnClick, { once: true });
return;
}
if (promoSectionStyle) {
@ -175,38 +168,10 @@ async function renderPromo({
// Only make promo section visible after adding content
// and translations to prevent layout shifting in page
container.classList.add("promo-visible");
return true;
}
/**
* For every PB newtab loaded a second is pre-rendered in the background.
* We need to guard against invalid impressions by checking visibility state.
* If visible record otherwise listen for visibility change and record later.
*/
function recordOnceVisible(message) {
const recordImpression = () => {
if (document.visibilityState === "visible") {
window.ASRouterMessage({
type: "IMPRESSION",
data: message,
});
document.removeEventListener("visibilitychange", recordImpression);
}
};
if (document.visibilityState === "visible") {
window.ASRouterMessage({
type: "IMPRESSION",
data: message,
});
} else {
document.addEventListener("visibilitychange", recordImpression);
}
}
async function setupFeatureConfig() {
let config = null;
let message = null;
try {
config = window.PrivateBrowsingFeatureConfig();
} catch (e) {}
@ -216,21 +181,13 @@ async function setupFeatureConfig() {
type: "PBNEWTAB_MESSAGE_REQUEST",
data: {},
});
message = response?.message;
config = message?.content;
config.messageId = message?.id;
config = response?.message?.content;
} catch (e) {}
}
await renderInfo(config);
// Check the current geo and don't render if we're in the wrong one.
const shouldShow = await RPMSendQuery("ShouldShowVPNPromo", {});
if (shouldShow) {
let hasRendered = await renderPromo(config);
if (hasRendered && message) {
recordOnceVisible(message);
}
}
await renderPromo(config);
// For tests
document.documentElement.setAttribute("PrivateBrowsingRenderComplete", true);
}

View File

@ -14,9 +14,6 @@ const { TelemetryTestUtils } = ChromeUtils.import(
const { PanelTestProvider } = ChromeUtils.import(
"resource://activity-stream/lib/PanelTestProvider.jsm"
);
const { ASRouter } = ChromeUtils.import(
"resource://activity-stream/lib/ASRouter.jsm"
);
/**
* These tests ensure that the experiment and remote default capabilities
@ -54,39 +51,6 @@ function waitForTelemetryEvent(category) {
}, "waiting for telemetry event");
}
async function setupMSExperimentWithMessage(message) {
let doExperimentCleanup = await ExperimentFakes.enrollWithFeatureConfig({
featureId: "pbNewtab",
enabled: true,
value: message,
});
Services.prefs.setStringPref(
"browser.newtabpage.activity-stream.asrouter.providers.messaging-experiments",
'{"id":"messaging-experiments","enabled":true,"type":"remote-experiments","messageGroups":["pbNewtab"],"updateCycleInMs":0}'
);
// Reload the provider
await ASRouter._updateMessageProviders();
// Wait to load the messages from the messaging-experiments provider
await ASRouter.loadMessagesFromAllProviders();
registerCleanupFunction(async () => {
// Reload the provider again at cleanup to remove the experiment message
await ASRouter._updateMessageProviders();
// Wait to load the messages from the messaging-experiments provider
await ASRouter.loadMessagesFromAllProviders();
Services.prefs.clearUserPref(
"browser.newtabpage.activity-stream.asrouter.providers.messaging-experiments"
);
});
Assert.ok(
ASRouter.state.messages.find(m => m.id.includes(message.id)),
"Experiment message found in ASRouter state"
);
return doExperimentCleanup;
}
add_task(async function test_experiment_plain_text() {
const defaultMessageContent = (await PanelTestProvider.getMessages()).find(
m => m.template === "pb_newtab"
@ -261,7 +225,6 @@ add_task(async function test_experiment_click_info_telemetry() {
featureId: "privatebrowsing",
enabled: true,
value: {
infoEnabled: true,
infoLinkUrl: "http://example.com",
},
});
@ -490,22 +453,42 @@ add_task(async function test_experiment_top_promo() {
add_task(async function test_experiment_messaging_system() {
const LOCALE = Services.locale.appLocaleAsBCP47;
let doExperimentCleanup = await setupMSExperimentWithMessage({
id: "PB_NEWTAB_MESSAGING_SYSTEM",
template: "pb_newtab",
content: {
promoEnabled: true,
infoEnabled: true,
infoBody: "fluent:about-private-browsing-info-title",
promoLinkText: "fluent:about-private-browsing-prominent-cta",
infoLinkUrl: "http://foo.example.com/%LOCALE%",
promoLinkUrl: "http://bar.example.com/%LOCALE%",
let doExperimentCleanup = await ExperimentFakes.enrollWithFeatureConfig({
featureId: "pbNewtab",
enabled: true,
value: {
id: "PB_NEWTAB_MESSAGING_SYSTEM",
template: "pb_newtab",
content: {
promoEnabled: true,
infoEnabled: true,
infoBody: "fluent:about-private-browsing-info-title",
promoLinkText: "fluent:about-private-browsing-prominent-cta",
infoLinkUrl: "http://foo.example.com/%LOCALE%",
promoLinkUrl: "http://bar.example.com/%LOCALE%",
},
// Priority ensures this message is picked over the one in
// OnboardingMessageProvider
priority: 5,
targeting: "true",
},
// Priority ensures this message is picked over the one in
// OnboardingMessageProvider
priority: 5,
targeting: "true",
});
Services.prefs.setStringPref(
"browser.newtabpage.activity-stream.asrouter.providers.messaging-experiments",
'{"id":"messaging-experiments","enabled":true,"type":"remote-experiments","messageGroups":["pbNewtab"],"updateCycleInMs":0}'
);
const { ASRouter } = ChromeUtils.import(
"resource://activity-stream/lib/ASRouter.jsm"
);
// Reload the provider
await ASRouter._updateMessageProviders();
// Wait to load the messages from the messaging-experiments provider
await ASRouter.loadMessagesFromAllProviders();
Assert.ok(
ASRouter.state.messages.find(m => m.id === "PB_NEWTAB_MESSAGING_SYSTEM"),
"Experiment message found in ASRouter state"
);
Services.telemetry.clearEvents();
@ -555,112 +538,3 @@ add_task(async function test_experiment_messaging_system() {
await BrowserTestUtils.closeWindow(win);
await doExperimentCleanup();
});
add_task(async function test_experiment_messaging_system_impressions() {
const LOCALE = Services.locale.appLocaleAsBCP47;
let doExperimentCleanup = await setupMSExperimentWithMessage({
id: `PB_NEWTAB_MESSAGING_SYSTEM_${Math.random()}`,
template: "pb_newtab",
content: {
promoEnabled: true,
infoEnabled: true,
infoBody: "fluent:about-private-browsing-info-title",
promoLinkText: "fluent:about-private-browsing-prominent-cta",
infoLinkUrl: "http://foo.example.com/%LOCALE%",
promoLinkUrl: "http://bar.example.com/%LOCALE%",
},
frequency: {
lifetime: 2,
},
// Priority ensures this message is picked over the one in
// OnboardingMessageProvider
priority: 5,
targeting: "true",
});
let { win: win1, tab: tab1 } = await openTabAndWaitForRender();
await SpecialPowers.spawn(tab1, [LOCALE], async function(locale) {
is(
content.document.querySelector(".promo a").getAttribute("href"),
"http://bar.example.com/" + locale,
"should format the promoLinkUrl url"
);
});
let { win: win2, tab: tab2 } = await openTabAndWaitForRender();
await SpecialPowers.spawn(tab2, [LOCALE], async function(locale) {
is(
content.document.querySelector(".promo a").getAttribute("href"),
"http://bar.example.com/" + locale,
"should format the promoLinkUrl url"
);
});
let { win: win3, tab: tab3 } = await openTabAndWaitForRender();
await SpecialPowers.spawn(tab3, [], async function() {
is(
content.document
.querySelector(".promo a")
.getAttribute("href")
?.includes("example.com"),
false,
"should no longer render the experiment message after 2 impressions"
);
});
await BrowserTestUtils.closeWindow(win1);
await BrowserTestUtils.closeWindow(win2);
await BrowserTestUtils.closeWindow(win3);
await doExperimentCleanup();
});
add_task(async function test_experiment_messaging_system_dismiss() {
const LOCALE = Services.locale.appLocaleAsBCP47;
let doExperimentCleanup = await setupMSExperimentWithMessage({
id: `PB_NEWTAB_MESSAGING_SYSTEM_${Math.random()}`,
template: "pb_newtab",
content: {
promoEnabled: true,
infoEnabled: true,
infoBody: "fluent:about-private-browsing-info-title",
promoLinkText: "fluent:about-private-browsing-prominent-cta",
infoLinkUrl: "http://foo.example.com/%LOCALE%",
promoLinkUrl: "http://bar.example.com/%LOCALE%",
},
// Priority ensures this message is picked over the one in
// OnboardingMessageProvider
priority: 5,
targeting: "true",
});
let { win: win1, tab: tab1 } = await openTabAndWaitForRender();
await SpecialPowers.spawn(tab1, [LOCALE], async function(locale) {
is(
content.document.querySelector(".promo a").getAttribute("href"),
"http://bar.example.com/" + locale,
"should format the promoLinkUrl url"
);
content.document.querySelector("#dismiss-btn").click();
});
let { win: win2, tab: tab2 } = await openTabAndWaitForRender();
await SpecialPowers.spawn(tab2, [], async function() {
is(
content.document
.querySelector(".promo a")
.getAttribute("href")
?.includes("example.com"),
false,
"should no longer render the experiment message after blocking"
);
});
await BrowserTestUtils.closeWindow(win1);
await BrowserTestUtils.closeWindow(win2);
await doExperimentCleanup();
});

View File

@ -40,6 +40,3 @@ about-private-browsing-search-banner-description = {
}
about-private-browsing-search-banner-close-button =
.aria-label = Close
about-private-browsing-dismiss-button =
.title = Dismiss

View File

@ -4,7 +4,6 @@
@import url("chrome://global/skin/in-content/info-pages.css");
@media not (prefers-contrast) {
html.private {
--in-content-page-color: white;
--in-content-text-color: white;
@ -16,7 +15,6 @@ html.private {
--in-content-button-background-hover: rgba(12,12,13,.1);
--in-content-button-background-active: rgba(12,12,13,.15);
}
}
/**
* When the showBanner class is applied, the banner is displayed at the top
@ -334,23 +332,6 @@ p {
display: flex;
}
.promo-dismiss {
padding: 10px;
min-width: 16px;
min-height: 16px;
display: inline flow-root;
background: url("chrome://global/skin/icons/close.svg") center no-repeat;
cursor: pointer;
-moz-context-properties: fill;
fill: currentColor;
}
@media not (prefers-contrast) {
.promo-dismiss {
opacity: 0.5;
}
}
.promo-content {
width: 100%;
}