Backed out changeset a70c7ee4b579 (bug 1646151) for bc failures on browser_pioneer_ui.js . CLOSED TREE

This commit is contained in:
Narcis Beleuzu 2020-08-21 23:27:01 +03:00
parent 07133c01bc
commit 64a77102a0
2 changed files with 31 additions and 124 deletions

View File

@ -5,16 +5,19 @@
const { AddonManager } = ChromeUtils.import(
"resource://gre/modules/AddonManager.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
const { RemoteSettings } = ChromeUtils.import(
"resource://services-settings/remote-settings.js"
);
const { TelemetryController } = ChromeUtils.import(
"resource://gre/modules/TelemetryController.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyModuleGetters(this, {
FileUtils: "resource://gre/modules/FileUtils.jsm",
});
const PREF_PIONEER_ID = "toolkit.telemetry.pioneerId";
const PREF_PIONEER_NEW_STUDIES_AVAILABLE =
@ -52,15 +55,19 @@ function showEnrollmentStatus() {
async function toggleEnrolled(studyAddonId, cachedAddons) {
let addon;
let install;
let cachedAddon;
const cachedAddon = cachedAddons.find(a => a.addon_id == studyAddonId);
for (cachedAddon of cachedAddons) {
if (studyAddonId == cachedAddon.addon_id) {
break;
}
}
if (Cu.isInAutomation) {
let testAddons = Services.prefs.getStringPref(PREF_TEST_ADDONS, "[]");
testAddons = JSON.parse(testAddons);
install = {
install: () => {
let testAddons = Services.prefs.getStringPref(PREF_TEST_ADDONS, "[]");
testAddons = JSON.parse(testAddons);
testAddons.push(studyAddonId);
Services.prefs.setStringPref(
PREF_TEST_ADDONS,
@ -68,19 +75,12 @@ async function toggleEnrolled(studyAddonId, cachedAddons) {
);
},
};
let testAddons = Services.prefs.getStringPref(PREF_TEST_ADDONS, "[]");
testAddons = JSON.parse(testAddons);
for (const testAddon of testAddons) {
if (testAddon == studyAddonId) {
addon = {};
addon.install = () => {};
addon.uninstall = () => {
Services.prefs.setStringPref(
PREF_TEST_ADDONS,
JSON.stringify(testAddons.filter(a => a.id != testAddon.id))
);
Services.prefs.setStringPref(PREF_TEST_ADDONS, "[]");
};
}
}
@ -400,37 +400,17 @@ async function setup(cachedAddons) {
document
.getElementById("leave-pioneer-accept-dialog-button")
.addEventListener("click", async event => {
const completedStudies = Services.prefs.getStringPref(
PREF_PIONEER_COMPLETED_STUDIES,
"{}"
);
const studies = JSON.parse(completedStudies);
// Send a deletion ping for all studies the user has been a part of.
for (const studyAddonId in studies) {
await sendDeletionPing(studyAddonId);
}
for (const cachedAddon of cachedAddons) {
const addon = await AddonManager.getAddonByID(cachedAddon.addon_id);
if (addon) {
// The user has ended all studies by unenrolling from Pioneer, so send deletion ping for any active studies.
await sendDeletionPing(addon.id);
await addon.uninstall();
}
const study = document.getElementById(cachedAddon.addon_id);
if (study) {
await updateStudy(cachedAddon.addon_id);
}
}
Services.prefs.clearUserPref(PREF_PIONEER_ID);
Services.prefs.clearUserPref(PREF_PIONEER_COMPLETED_STUDIES);
for (const cachedAddon of cachedAddons) {
// Record any studies that have been marked as concluded on the server, in case they re-enroll.
// Record any studies that have been marked as concluded on the server.
if ("studyEnded" in cachedAddon && cachedAddon.studyEnded === true) {
const completedStudies = Services.prefs.getStringPref(
PREF_PIONEER_COMPLETED_STUDIES,
"{}"
);
const studies = JSON.parse(completedStudies);
studies[cachedAddon.addon_id] = STUDY_LEAVE_REASONS.STUDY_ENDED;
Services.prefs.setStringPref(
@ -438,6 +418,10 @@ async function setup(cachedAddons) {
JSON.stringify(studies)
);
}
const addon = await AddonManager.getAddonByID(cachedAddon.addon_id);
if (addon) {
await addon.uninstall();
}
const study = document.getElementById(cachedAddon.addon_id);
if (study) {
@ -585,36 +569,6 @@ document.addEventListener("DOMContentLoaded", async domEvent => {
await showAvailableStudies(cachedAddons);
});
async function sendDeletionPing(studyAddonId) {
const type = "pioneer-study";
const options = {
studyName: studyAddonId,
addPioneerId: true,
useEncryption: true,
// NOTE - while we're not actually sending useful data in this payload, the current Pioneer v2 Telemetry
// pipeline requires that pings are shaped this way so they are routed to the correct environment.
//
// At the moment, the public key used here isn't important but we do need to use *something*.
encryptionKeyId: "debug",
publicKey: {
crv: "P-256",
kty: "EC",
x: "XLkI3NaY3-AF2nRMspC63BT1u0Y3moXYSfss7VuQ0mk",
y: "SB0KnIW-pqk85OIEYZenoNkEyOOp5GeWQhS1KeRtEUE",
},
schemaName: "deletion-request",
schemaVersion: 1,
schemaNamespace: "pioneer-debug",
};
const payload = {
encryptedData: "",
};
await TelemetryController.submitExternalPing(type, payload, options);
}
/**
* Prevent tab/shift-tab from leaving the modal dialog.
* FIXME - this should be removed once bug 1322939 is fixed.

View File

@ -10,14 +10,6 @@ ChromeUtils.defineModuleGetter(
"resource://testing-common/ajv-4.1.1.js"
);
const { TelemetryArchive } = ChromeUtils.import(
"resource://gre/modules/TelemetryArchive.jsm"
);
const { TelemetryStorage } = ChromeUtils.import(
"resource://gre/modules/TelemetryStorage.jsm"
);
const PREF_PIONEER_ID = "toolkit.telemetry.pioneerId";
const PREF_PIONEER_NEW_STUDIES_AVAILABLE =
"toolkit.telemetry.pioneer-new-studies-available";
@ -416,10 +408,6 @@ add_task(async function testAboutPage() {
"After leaving study, join button is disabled."
);
console.debug(
Services.prefs.getStringPref(PREF_TEST_ADDONS, null),
cachedAddon
);
ok(
Services.prefs.getStringPref(PREF_TEST_ADDONS, null) == "[]",
"Correct add-on was uninstalled"
@ -450,29 +438,12 @@ add_task(async function testAboutPage() {
const acceptUnenrollmentDialogButton = content.document.getElementById(
"leave-pioneer-accept-dialog-button"
);
acceptUnenrollmentDialogButton.click();
// Wait for deletion ping, uninstalls, and UI updates...
const pioneerUnenrolled = await new Promise((resolve, reject) => {
Services.prefs.addObserver(PREF_PIONEER_ID, function observer(
subject,
topic,
data
) {
try {
const prefValue = Services.prefs.getStringPref(
PREF_PIONEER_ID,
null
);
Services.prefs.removeObserver(PREF_PIONEER_ID, observer);
resolve(prefValue);
} catch (ex) {
Services.prefs.removeObserver(PREF_PIONEER_ID, observer);
reject(ex);
}
});
});
const pioneerUnenrolled = Services.prefs.getStringPref(
PREF_PIONEER_ID,
null
);
ok(
!pioneerUnenrolled,
@ -506,24 +477,6 @@ add_task(async function testAboutPage() {
}
}
);
// Wait for any pending pings to settle.
await TelemetryStorage.testClearPendingPings();
let pings = await TelemetryArchive.promiseArchivedPingList();
console.debug(pings);
ok(
pings.length === 2,
"The expected number of archived telemetry pings are present."
);
ok(
pings[0].type === "pioneer-study",
"Deletion request telemetry ping was sent."
);
ok(
pings[1].type === "pioneer-study",
"Deletion request telemetry ping was sent."
);
});
add_task(async function testPioneerBadge() {