Bug 1498940 - Reflect study opt-out in about:studies when Normandy is generally enabled. r=Gijs

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Michael Cooper 2018-10-29 17:50:51 +00:00
Родитель 968a7a4996
Коммит e74056eacb
3 изменённых файлов: 57 добавлений и 11 удалений

Просмотреть файл

@ -15,6 +15,7 @@ ChromeUtils.defineModuleGetter(this, "RecipeRunner", "resource://normandy/lib/Re
var EXPORTED_SYMBOLS = ["AboutPages"];
const SHIELD_LEARN_MORE_URL_PREF = "app.normandy.shieldLearnMoreUrl";
XPCOMUtils.defineLazyPreferenceGetter(this, "gOptOutStudiesEnabled", "app.shield.optoutstudies.enabled");
/**
@ -192,10 +193,9 @@ XPCOMUtils.defineLazyGetter(this.AboutPages, "aboutStudies", () => {
*/
sendStudiesEnabled(target) {
RecipeRunner.checkPrefs();
const studiesEnabled = RecipeRunner.enabled && gOptOutStudiesEnabled;
try {
target.messageManager.sendAsyncMessage("Shield:ReceiveStudiesEnabled", {
studiesEnabled: RecipeRunner.enabled,
});
target.messageManager.sendAsyncMessage("Shield:ReceiveStudiesEnabled", { studiesEnabled });
} catch (err) {
// The child process might be gone, so no need to throw here.
Cu.reportError(err);
@ -237,11 +237,6 @@ XPCOMUtils.defineLazyGetter(this.AboutPages, "aboutStudies", () => {
getShieldLearnMoreHref() {
return Services.urlFormatter.formatURLPref(SHIELD_LEARN_MORE_URL_PREF);
},
getStudiesEnabled() {
RecipeRunner.checkPrefs();
return RecipeRunner.enabled;
},
});
return aboutStudies;

Просмотреть файл

@ -158,7 +158,12 @@ var RecipeRunner = {
}
const apiUrl = Services.prefs.getCharPref(API_URL_PREF);
if (!apiUrl || !apiUrl.startsWith("https://")) {
if (!apiUrl) {
log.warn(`Disabling Shield because ${API_URL_PREF} is not set.`);
this.disable();
return;
}
if (!apiUrl.startsWith("https://")) {
log.warn(`Disabling Shield because ${API_URL_PREF} is not an HTTPS url: ${apiUrl}.`);
this.disable();
return;

Просмотреть файл

@ -237,7 +237,7 @@ decorate_task(
decorate_task(
AddonStudies.withStudies([]),
withAboutStudies,
async function testStudyListing(studies, browser) {
async function testStudyListingNoStudies(studies, browser) {
await ContentTask.spawn(browser, null, async () => {
const doc = content.document;
await ContentTaskUtils.waitForCondition(() => doc.querySelectorAll(".study-list-info").length);
@ -255,7 +255,22 @@ decorate_task(
// Test that the message shown when studies are disabled and studies exist
decorate_task(
withAboutStudies,
async function testStudyListing(browser) {
AddonStudies.withStudies([
addonStudyFactory({
name: "A Fake Add-on Study",
active: false,
description: "A fake description",
studyStartDate: new Date(2018, 0, 4),
}),
]),
PreferenceExperiments.withMockExperiments([
preferenceStudyFactory({
name: "B Fake Preference Study",
lastSeen: new Date(2018, 0, 5),
expired: true,
}),
]),
async function testStudyListingDisabled(browser, addonStudies, preferenceStudies) {
try {
RecipeRunner.disable();
@ -276,3 +291,34 @@ decorate_task(
}
);
// Test for bug 1498940 - detects studies disabled when only study opt-out is set
decorate_task(
withPrefEnv({
set: [
["datareporting.healthreport.uploadEnabled", true],
["app.normandy.api_url", "https://example.com"],
["app.shield.optoutstudies.enabled", false],
],
}),
withAboutStudies,
AddonStudies.withStudies([]),
PreferenceExperiments.withMockExperiments([]),
async function testStudyListingStudiesOptOut(browser) {
RecipeRunner.checkPrefs();
ok(
RecipeRunner.enabled,
"RecipeRunner should be enabled as a Precondition",
);
await ContentTask.spawn(browser, null, async () => {
const doc = content.document;
await ContentTaskUtils.waitForCondition(() => doc.querySelector(".info-box-content > span").textContent);
is(
doc.querySelector(".info-box-content > span").textContent,
"This is a list of studies that you have participated in. No new studies will run.",
"A message is shown when studies are disabled",
);
});
}
);