зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1766592 - [Experiment] The "Focus Promo" experiment message is wrongly displayed on the fist opened tab after it was dismissed r=pdahiya
Differential Revision: https://phabricator.services.mozilla.com/D145015
This commit is contained in:
Родитель
9fcc2426e8
Коммит
f5f23cdb0a
|
@ -6,6 +6,9 @@
|
|||
|
||||
var EXPORTED_SYMBOLS = ["AboutPrivateBrowsingParent"];
|
||||
|
||||
const { ASRouter } = ChromeUtils.import(
|
||||
"resource://activity-stream/lib/ASRouter.jsm"
|
||||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { BrowserUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/BrowserUtils.jsm"
|
||||
|
@ -171,6 +174,10 @@ class AboutPrivateBrowsingParent extends JSWindowActorParent {
|
|||
}
|
||||
case "SpecialMessageActionDispatch": {
|
||||
SpecialMessageActions.handleAction(aMessage.data, browser);
|
||||
break;
|
||||
}
|
||||
case "IsPromoBlocked": {
|
||||
return !ASRouter.isUnblockedMessage(aMessage.data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -188,9 +188,9 @@ async function renderPromo({
|
|||
}
|
||||
|
||||
/**
|
||||
* For every PB newtab loaded a second is pre-rendered in the background.
|
||||
* 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.
|
||||
* If visible, record. Otherwise, listen for visibility change and record later.
|
||||
*/
|
||||
function recordOnceVisible(message) {
|
||||
const recordImpression = () => {
|
||||
|
@ -217,6 +217,24 @@ function recordOnceVisible(message) {
|
|||
}
|
||||
}
|
||||
|
||||
// The PB newtab may be pre-rendered. Once the tab is visible, check to make sure the message wasn't blocked after the initial render. If it was, remove the promo.
|
||||
async function handlePromoOnPreload(message) {
|
||||
async function removePromoIfBlocked() {
|
||||
if (document.visibilityState === "visible") {
|
||||
let blocked = await RPMSendQuery("IsPromoBlocked", message);
|
||||
if (blocked) {
|
||||
const container = document.querySelector(".promo");
|
||||
container.remove();
|
||||
}
|
||||
}
|
||||
document.removeEventListener("visibilitychange", removePromoIfBlocked);
|
||||
}
|
||||
// Only add the listener to pre-rendered tabs that aren't visible
|
||||
if (document.visibilityState !== "visible") {
|
||||
document.addEventListener("visibilitychange", removePromoIfBlocked);
|
||||
}
|
||||
}
|
||||
|
||||
async function setupFeatureConfig() {
|
||||
let config = null;
|
||||
let message = null;
|
||||
|
@ -239,6 +257,7 @@ async function setupFeatureConfig() {
|
|||
let hasRendered = await renderPromo(config);
|
||||
if (hasRendered && message) {
|
||||
recordOnceVisible(message);
|
||||
await handlePromoOnPreload(message);
|
||||
}
|
||||
// For tests
|
||||
document.documentElement.setAttribute("PrivateBrowsingRenderComplete", true);
|
||||
|
|
|
@ -39,3 +39,31 @@ add_task(async function test_default_promo() {
|
|||
await BrowserTestUtils.closeWindow(win3);
|
||||
await BrowserTestUtils.closeWindow(win4);
|
||||
});
|
||||
|
||||
add_task(async function test_remove_promo_from_prerendered_tab_if_blocked() {
|
||||
ASRouter.resetMessageState();
|
||||
|
||||
const { win, tab: tab1 } = await openTabAndWaitForRender();
|
||||
|
||||
await SpecialPowers.spawn(tab1, [], async function() {
|
||||
const promoContainer = content.document.querySelector(".promo"); // container which is present if promo message is not blocked
|
||||
ok(promoContainer, "Focus promo is shown in a new tab");
|
||||
content.document.getElementById("dismiss-btn").click();
|
||||
});
|
||||
|
||||
win.BrowserOpenTab();
|
||||
await BrowserTestUtils.switchTab(win.gBrowser, win.gBrowser.tabs[1]);
|
||||
await SimpleTest.promiseFocus(gBrowser.selectedBrowser);
|
||||
const tab2 = win.gBrowser.selectedBrowser;
|
||||
|
||||
await SpecialPowers.spawn(tab2, [], async function() {
|
||||
const promoContainer = content.document.querySelector(".promo"); // container which is not present if promo message is blocked
|
||||
ok(
|
||||
!promoContainer,
|
||||
"Focus promo is not shown in a new tab after being dismissed in another tab"
|
||||
);
|
||||
});
|
||||
|
||||
await ASRouter.unblockAll();
|
||||
await BrowserTestUtils.closeWindow(win);
|
||||
});
|
||||
|
|
|
@ -129,6 +129,7 @@ let RemotePageAccessManager = {
|
|||
"SearchHandoff",
|
||||
],
|
||||
RPMSendQuery: [
|
||||
"IsPromoBlocked",
|
||||
"ShouldShowSearch",
|
||||
"ShouldShowSearchBanner",
|
||||
"ShouldShowPromo",
|
||||
|
|
Загрузка…
Ссылка в новой задаче