Bug 1628094 - Address-bar-navigated reason not logged in telemetry on opening about:welcome manually via url r=mconley

Differential Revision: https://phabricator.services.mozilla.com/D70418

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Punam Dahiya 2020-04-15 05:06:10 +00:00
parent 5e373d876a
commit 4f914d1314
3 changed files with 48 additions and 12 deletions

View File

@ -25,6 +25,30 @@ XPCOMUtils.defineLazyGetter(this, "log", () => {
class AboutWelcomeChild extends JSWindowActorChild {
actorCreated() {
this.exportFunctions();
this.initWebProgressListener();
}
initWebProgressListener() {
const webProgress = this.manager.browsingContext.top.docShell
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebProgress);
const listener = {
QueryInterface: ChromeUtils.generateQI([
Ci.nsIWebProgressListener,
Ci.nsISupportsWeakReference,
]),
};
listener.onLocationChange = (aWebProgress, aRequest, aLocation, aFlags) => {
log.debug(`onLocationChange handled: ${aWebProgress.DOMWindow}`);
this.AWSendToParent("LOCATION_CHANGED");
};
webProgress.addProgressListener(
listener,
Ci.nsIWebProgress.NOTIFY_LOCATION
);
}
/**

View File

@ -42,7 +42,13 @@ const AWTerminate = {
class AboutWelcomeObserver {
constructor() {
Services.obs.addObserver(this, "quit-application");
this.win = Services.focus.activeWindow;
if (!this.win) {
return;
}
this.terminateReason = AWTerminate.UNKNOWN;
this.onWindowClose = () => {
@ -55,8 +61,6 @@ class AboutWelcomeObserver {
this.win.addEventListener("TabClose", this.onTabClose, { once: true });
this.win.addEventListener("unload", this.onWindowClose, { once: true });
this.win.gBrowser.addTabsProgressListener(this);
Services.obs.addObserver(this, "quit-application");
}
observe(aSubject, aTopic, aData) {
@ -67,10 +71,6 @@ class AboutWelcomeObserver {
}
}
onLocationChange() {
this.terminateReason = AWTerminate.ADDRESS_BAR_NAVIGATED;
}
// Added for testing
get AWTerminate() {
return AWTerminate;
@ -78,10 +78,13 @@ class AboutWelcomeObserver {
stop() {
log.debug(`Terminate reason is ${this.terminateReason}`);
Services.obs.removeObserver(this, "quit-application");
if (!this.win) {
return;
}
this.win.removeEventListener("TabClose", this.onTabClose);
this.win.removeEventListener("unload", this.onWindowClose);
this.win.gBrowser.removeTabsProgressListener(this);
Services.obs.removeObserver(this, "quit-application");
this.win = null;
}
}
@ -141,6 +144,10 @@ class AboutWelcomeParent extends JSWindowActorParent {
case "AWPage:TELEMETRY_EVENT":
Telemetry.sendTelemetry(data);
break;
case "AWPage:LOCATION_CHANGED":
this.AboutWelcomeObserver.terminateReason =
AWTerminate.ADDRESS_BAR_NAVIGATED;
break;
default:
log.debug(`Unexpected event ${type} was not handled.`);
}

View File

@ -54,10 +54,15 @@ add_task(async function test_About_Welcome_Tab_Close() {
*/
add_task(async function test_About_Welcome_Location_Change() {
await openAboutWelcomeTab();
let currentWindow =
gBrowser.selectedBrowser.browsingContext.currentWindowGlobal;
let AWP = new AboutWelcomeParent();
Assert.ok(AWP.AboutWelcomeObserver, "AboutWelcomeObserver is not null");
let aboutWelcomeActor = await currentWindow.getActor("AboutWelcome");
Assert.ok(
aboutWelcomeActor.AboutWelcomeObserver,
"AboutWelcomeObserver is not null"
);
await BrowserTestUtils.loadURI(
gBrowser.selectedBrowser,
"http://example.com/#foo"
@ -68,8 +73,8 @@ add_task(async function test_About_Welcome_Location_Change() {
);
Assert.equal(
AWP.AboutWelcomeObserver.terminateReason,
AWP.AboutWelcomeObserver.AWTerminate.ADDRESS_BAR_NAVIGATED,
aboutWelcomeActor.AboutWelcomeObserver.terminateReason,
aboutWelcomeActor.AboutWelcomeObserver.AWTerminate.ADDRESS_BAR_NAVIGATED,
"Terminated due to location uri changed"
);
});