зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1767511 - Many messaging-system/onboarding pings missing required event identifier r=Mardak
Differential Revision: https://phabricator.services.mozilla.com/D145615
This commit is contained in:
Родитель
c0cb7fd820
Коммит
5b655b243e
|
@ -4196,14 +4196,12 @@ BrowserGlue.prototype = {
|
|||
},
|
||||
|
||||
async _showUpgradeDialog() {
|
||||
const msg = await OnboardingMessageProvider.getUpgradeMessage();
|
||||
const data = await OnboardingMessageProvider.getUpgradeMessage();
|
||||
const win = BrowserWindowTracker.getTopWindow();
|
||||
const browser = win.gBrowser.selectedBrowser;
|
||||
const config = {
|
||||
type: "SHOW_SPOTLIGHT",
|
||||
data: {
|
||||
content: msg.content,
|
||||
},
|
||||
data,
|
||||
};
|
||||
SpecialMessageActions.handleAction(config, browser);
|
||||
},
|
||||
|
|
|
@ -15,10 +15,18 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
"resource://messaging-system/lib/SpecialMessageActions.jsm",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(
|
||||
this,
|
||||
"AWTelemetry",
|
||||
() => new AboutWelcomeTelemetry()
|
||||
);
|
||||
|
||||
const Spotlight = {
|
||||
sendUserEventTelemetry(event, message, dispatch) {
|
||||
const message_id =
|
||||
message.template === "multistage" ? message.content.id : message.id;
|
||||
const ping = {
|
||||
message_id: message.id,
|
||||
message_id,
|
||||
event,
|
||||
};
|
||||
dispatch({
|
||||
|
@ -27,6 +35,13 @@ const Spotlight = {
|
|||
});
|
||||
},
|
||||
|
||||
defaultDispatch(message) {
|
||||
if (message.type === "SPOTLIGHT_TELEMETRY") {
|
||||
const { message_id, event } = message.data;
|
||||
AWTelemetry.sendTelemetry({ message_id, event });
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Shows spotlight tab or window modal specific to the given browser
|
||||
* @param browser The browser for spotlight display
|
||||
|
@ -34,7 +49,7 @@ const Spotlight = {
|
|||
* @param dispatchCFRAction A function to dispatch resulting actions
|
||||
* @return boolean value capturing if spotlight was displayed
|
||||
*/
|
||||
async showSpotlightDialog(browser, message, dispatch) {
|
||||
async showSpotlightDialog(browser, message, dispatch = this.defaultDispatch) {
|
||||
const win = browser.ownerGlobal;
|
||||
if (win.gDialogBox.isOpen) {
|
||||
return false;
|
||||
|
@ -43,9 +58,7 @@ const Spotlight = {
|
|||
|
||||
const dispatchCFRAction =
|
||||
// This also blocks CFR impressions, which is fine for current use cases.
|
||||
message.content?.metrics === "block"
|
||||
? () => {}
|
||||
: dispatch ?? (msg => new AboutWelcomeTelemetry().sendTelemetry(msg));
|
||||
message.content?.metrics === "block" ? () => {} : dispatch;
|
||||
let params = { primaryBtn: false, secondaryBtn: false };
|
||||
|
||||
// There are two events named `IMPRESSION` the first one refers to telemetry
|
||||
|
|
|
@ -10,19 +10,31 @@ const { BrowserWindowTracker } = ChromeUtils.import(
|
|||
"resource:///modules/BrowserWindowTracker.jsm"
|
||||
);
|
||||
|
||||
const { AboutWelcomeTelemetry } = ChromeUtils.import(
|
||||
"resource://activity-stream/aboutwelcome/lib/AboutWelcomeTelemetry.jsm"
|
||||
);
|
||||
|
||||
async function waitForClick(selector, win) {
|
||||
await TestUtils.waitForCondition(() => win.document.querySelector(selector));
|
||||
win.document.querySelector(selector).click();
|
||||
}
|
||||
|
||||
async function showDialog(dialogOptions) {
|
||||
function waitForDialog(callback = win => win.close()) {
|
||||
return BrowserTestUtils.promiseAlertDialog(
|
||||
null,
|
||||
"chrome://browser/content/spotlight.html",
|
||||
{ callback, isSubDialog: true }
|
||||
);
|
||||
}
|
||||
|
||||
function showAndWaitForDialog(dialogOptions, callback) {
|
||||
const promise = waitForDialog(callback);
|
||||
Spotlight.showSpotlightDialog(
|
||||
dialogOptions.browser,
|
||||
dialogOptions.message,
|
||||
dialogOptions.dispatchStub
|
||||
);
|
||||
const [win] = await TestUtils.topicObserved("subdialog-loaded");
|
||||
return win;
|
||||
return promise;
|
||||
}
|
||||
|
||||
add_task(async function send_spotlight_as_page_in_telemetry() {
|
||||
|
@ -31,20 +43,69 @@ add_task(async function send_spotlight_as_page_in_telemetry() {
|
|||
);
|
||||
let dispatchStub = sinon.stub();
|
||||
let browser = BrowserWindowTracker.getTopWindow().gBrowser.selectedBrowser;
|
||||
let win = await showDialog({ message, browser, dispatchStub });
|
||||
let sandbox = sinon.createSandbox();
|
||||
|
||||
sandbox.stub(win, "AWSendEventTelemetry");
|
||||
await waitForClick("button.secondary", win);
|
||||
await showAndWaitForDialog({ message, browser, dispatchStub }, async win => {
|
||||
let stub = sandbox.stub(win, "AWSendEventTelemetry");
|
||||
await waitForClick("button.secondary", win);
|
||||
Assert.equal(
|
||||
stub.lastCall.args[0].event_context.page,
|
||||
"spotlight",
|
||||
"The value of event context page should be set to 'spotlight' in event telemetry"
|
||||
);
|
||||
win.close();
|
||||
});
|
||||
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
add_task(async function send_dismiss_event_telemetry() {
|
||||
const messageId = "PB_FOCUS_PROMO"; // a multistage spotlight promo with dismiss button
|
||||
let message = (await PanelTestProvider.getMessages()).find(
|
||||
m => m.id === messageId
|
||||
);
|
||||
let browser = BrowserWindowTracker.getTopWindow().gBrowser.selectedBrowser;
|
||||
let sandbox = sinon.createSandbox();
|
||||
let stub = sandbox.stub(AboutWelcomeTelemetry.prototype, "sendTelemetry");
|
||||
// send without a dispatch function so that default is used
|
||||
await showAndWaitForDialog({ message, browser }, async win => {
|
||||
await waitForClick("button.dismiss-button", win);
|
||||
win.close();
|
||||
});
|
||||
|
||||
Assert.equal(
|
||||
win.AWSendEventTelemetry.lastCall.args[0].event_context.page,
|
||||
"spotlight",
|
||||
"The value of event context page should be set to 'spotlight' in event telemetry"
|
||||
stub.lastCall.args[0].message_id,
|
||||
messageId,
|
||||
"A dismiss event is called with the correct message id"
|
||||
);
|
||||
|
||||
win.close();
|
||||
registerCleanupFunction(() => {
|
||||
sandbox.restore();
|
||||
});
|
||||
Assert.equal(
|
||||
stub.lastCall.args[0].event,
|
||||
"DISMISS",
|
||||
"A dismiss event is called with a top level event field with value 'DISMISS'"
|
||||
);
|
||||
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
add_task(
|
||||
async function do_not_send_impression_telemetry_from_default_dispatch() {
|
||||
// Don't send impression telemetry from the Spotlight default dispatch function
|
||||
let message = (await PanelTestProvider.getMessages()).find(
|
||||
m => m.id === "MULTISTAGE_SPOTLIGHT_MESSAGE"
|
||||
);
|
||||
let browser = BrowserWindowTracker.getTopWindow().gBrowser.selectedBrowser;
|
||||
let sandbox = sinon.createSandbox();
|
||||
let stub = sandbox.stub(AboutWelcomeTelemetry.prototype, "sendTelemetry");
|
||||
// send without a dispatch function so that default is used
|
||||
await showAndWaitForDialog({ message, browser });
|
||||
|
||||
Assert.equal(
|
||||
stub.calledOn(),
|
||||
false,
|
||||
"No extra impression event was sent for multistage Spotlight"
|
||||
);
|
||||
|
||||
sandbox.restore();
|
||||
}
|
||||
);
|
||||
|
|
Загрузка…
Ссылка в новой задаче