mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1646860 - Pioneer badge call-out on RemoteSettings update r=leplatrem
Differential Revision: https://phabricator.services.mozilla.com/D82255
This commit is contained in:
parent
de043a8da3
commit
f842fb26e8
@ -2152,6 +2152,52 @@ BrowserGlue.prototype = {
|
||||
_checkPioneerPref();
|
||||
},
|
||||
|
||||
_monitorPioneerStudies() {
|
||||
const STUDY_ADDON_COLLECTION_KEY = "pioneer-study-addons";
|
||||
const PREF_PIONEER_NEW_STUDIES_AVAILABLE =
|
||||
"toolkit.telemetry.pioneer-new-studies-available";
|
||||
|
||||
const _badgeIcon = async () => {
|
||||
for (let win of Services.wm.getEnumerator("navigator:browser")) {
|
||||
win.document
|
||||
.getElementById("pioneer-button")
|
||||
.querySelector(".toolbarbutton-badge")
|
||||
.classList.add("feature-callout");
|
||||
}
|
||||
};
|
||||
|
||||
const windowListener = {
|
||||
onOpenWindow(xulWindow) {
|
||||
const win = xulWindow.docShell.domWindow;
|
||||
win.addEventListener("load", () => {
|
||||
const pioneerButton = win.document.getElementById("pioneer-button");
|
||||
if (pioneerButton) {
|
||||
const badge = pioneerButton.querySelector(".toolbarbutton-badge");
|
||||
if (
|
||||
Services.prefs.getBoolPref(
|
||||
PREF_PIONEER_NEW_STUDIES_AVAILABLE,
|
||||
false
|
||||
)
|
||||
) {
|
||||
badge.classList.add("feature-callout");
|
||||
} else {
|
||||
badge.classList.remove("feature-callout");
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
onCloseWindow() {},
|
||||
};
|
||||
|
||||
Services.prefs.addObserver(PREF_PIONEER_NEW_STUDIES_AVAILABLE, _badgeIcon);
|
||||
|
||||
RemoteSettings(STUDY_ADDON_COLLECTION_KEY).on("sync", async event => {
|
||||
Services.prefs.setBoolPref(PREF_PIONEER_NEW_STUDIES_AVAILABLE, true);
|
||||
});
|
||||
|
||||
Services.wm.addListener(windowListener);
|
||||
},
|
||||
|
||||
_showNewInstallModal() {
|
||||
// Allow other observers of the same topic to run while we open the dialog.
|
||||
Services.tm.dispatchToMainThread(() => {
|
||||
@ -2243,6 +2289,7 @@ BrowserGlue.prototype = {
|
||||
this._monitorWebcompatReporterPref();
|
||||
this._monitorHTTPSOnlyPref();
|
||||
this._monitorPioneerPref();
|
||||
this._monitorPioneerStudies();
|
||||
|
||||
let pService = Cc["@mozilla.org/toolkit/profile-service;1"].getService(
|
||||
Ci.nsIToolkitProfileService
|
||||
|
@ -33,6 +33,8 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
});
|
||||
|
||||
const PREF_PIONEER_ID = "toolkit.telemetry.pioneerId";
|
||||
const PREF_PIONEER_NEW_STUDIES_AVAILABLE =
|
||||
"toolkit.telemetry.pioneer-new-studies-available";
|
||||
|
||||
/**
|
||||
* This is the Remote Settings key that we use to get the list of available studies.
|
||||
@ -260,9 +262,23 @@ async function setup(cachedAddons) {
|
||||
});
|
||||
}
|
||||
|
||||
function removeBadge() {
|
||||
Services.prefs.setBoolPref(PREF_PIONEER_NEW_STUDIES_AVAILABLE, false);
|
||||
|
||||
for (let win of Services.wm.getEnumerator("navigator:browser")) {
|
||||
const badge = win.document
|
||||
.getElementById("pioneer-button")
|
||||
.querySelector(".toolbarbutton-badge");
|
||||
badge.classList.remove("feature-callout");
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async domEvent => {
|
||||
showEnrollmentStatus();
|
||||
|
||||
document.addEventListener("focus", removeBadge);
|
||||
removeBadge();
|
||||
|
||||
let cachedAddons;
|
||||
if (Cu.isInAutomation) {
|
||||
let testCachedAddons = Services.prefs.getStringPref(
|
||||
|
@ -9,6 +9,8 @@
|
||||
"use strict";
|
||||
|
||||
const PREF_PIONEER_ID = "toolkit.telemetry.pioneerId";
|
||||
const PREF_PIONEER_NEW_STUDIES_AVAILABLE =
|
||||
"toolkit.telemetry.pioneer-new-studies-available";
|
||||
|
||||
const PREF_CACHED_ADDONS = "toolkit.pioneer.testCachedAddons";
|
||||
const PREF_TEST_ADDON_INSTALLED = "toolkit.pioneer.testAddonInstalled";
|
||||
@ -52,7 +54,12 @@ const CACHED_ADDONS = [
|
||||
},
|
||||
];
|
||||
|
||||
add_task(async function() {
|
||||
const waitForAnimationFrame = () =>
|
||||
new Promise(resolve => {
|
||||
content.window.requestAnimationFrame(resolve);
|
||||
});
|
||||
|
||||
add_task(async function testAboutPage() {
|
||||
const cachedAddons = JSON.stringify(CACHED_ADDONS);
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
@ -67,11 +74,6 @@ add_task(async function() {
|
||||
gBrowser,
|
||||
});
|
||||
|
||||
const waitForAnimationFrame = () =>
|
||||
new Promise(resolve => {
|
||||
content.window.requestAnimationFrame(resolve);
|
||||
});
|
||||
|
||||
const beforePref = Services.prefs.getStringPref(PREF_PIONEER_ID, null);
|
||||
ok(beforePref === null, "before enrollment, Pioneer pref is null.");
|
||||
|
||||
@ -137,3 +139,57 @@ add_task(async function() {
|
||||
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
add_task(async function testPioneerBadge() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [[PREF_PIONEER_NEW_STUDIES_AVAILABLE, true]],
|
||||
clear: [
|
||||
[PREF_PIONEER_NEW_STUDIES_AVAILABLE, false],
|
||||
[PREF_PIONEER_ID, ""],
|
||||
],
|
||||
});
|
||||
|
||||
let pioneerTab = await BrowserTestUtils.openNewForegroundTab({
|
||||
url: "about:pioneer",
|
||||
gBrowser,
|
||||
});
|
||||
|
||||
const enrollmentButton = content.document.getElementById("enrollment-button");
|
||||
enrollmentButton.click();
|
||||
|
||||
let blankTab = await BrowserTestUtils.openNewForegroundTab({
|
||||
url: "about:home",
|
||||
gBrowser,
|
||||
});
|
||||
|
||||
Services.prefs.setBoolPref(PREF_PIONEER_NEW_STUDIES_AVAILABLE, true);
|
||||
|
||||
const toolbarButton = document.getElementById("pioneer-button");
|
||||
const toolbarBadge = toolbarButton.querySelector(".toolbarbutton-badge");
|
||||
|
||||
ok(
|
||||
toolbarBadge.classList.contains("feature-callout"),
|
||||
"When pref is true, Pioneer toolbar button is called out in the current window."
|
||||
);
|
||||
|
||||
toolbarButton.click();
|
||||
|
||||
ok(
|
||||
!toolbarBadge.classList.contains("feature-callout"),
|
||||
"When about:pioneer toolbar button is pressed, call-out is removed."
|
||||
);
|
||||
|
||||
Services.prefs.setBoolPref(PREF_PIONEER_NEW_STUDIES_AVAILABLE, true);
|
||||
|
||||
const newWin = await BrowserTestUtils.openNewBrowserWindow();
|
||||
const newToolbarBadge = toolbarButton.querySelector(".toolbarbutton-badge");
|
||||
|
||||
ok(
|
||||
newToolbarBadge.classList.contains("feature-callout"),
|
||||
"When pref is true, Pioneer toolbar button is called out in a new window."
|
||||
);
|
||||
|
||||
await BrowserTestUtils.closeWindow(newWin);
|
||||
await BrowserTestUtils.removeTab(pioneerTab);
|
||||
await BrowserTestUtils.removeTab(blankTab);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user