зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1599116 - WNPanel messages need detailed access to TP blocked resources r=k88hudson
Differential Revision: https://phabricator.services.mozilla.com/D54550 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
12f01bf037
Коммит
5fd08f939a
|
@ -19,6 +19,14 @@ XPCOMUtils.defineLazyServiceGetter(
|
|||
"nsITrackingDBService"
|
||||
);
|
||||
|
||||
const idToTextMap = new Map([
|
||||
[Ci.nsITrackingDBService.TRACKERS_ID, "tracker"],
|
||||
[Ci.nsITrackingDBService.TRACKING_COOKIES_ID, "cookie"],
|
||||
[Ci.nsITrackingDBService.CRYPTOMINERS_ID, "cryptominer"],
|
||||
[Ci.nsITrackingDBService.FINGERPRINTERS_ID, "fingerprinter"],
|
||||
[Ci.nsITrackingDBService.SOCIAL_ID, "social"],
|
||||
]);
|
||||
|
||||
const WHATSNEW_ENABLED_PREF = "browser.messaging-system.whatsNewPanel.enabled";
|
||||
const PROTECTIONS_PANEL_INFOMSG_PREF =
|
||||
"browser.protections_panel.infoMessage.seen";
|
||||
|
@ -391,21 +399,28 @@ class _ToolbarPanelHub {
|
|||
dateTo
|
||||
);
|
||||
// Count all events in the past 6 weeks
|
||||
// Returns an object with:
|
||||
// `blockedCount` total number of blocked resources
|
||||
// {tracker|cookie|social...} breakdown by event type as defined by `idToTextMap`
|
||||
const totalEvents = eventsByDate.reduce(
|
||||
(acc, day) => acc + day.getResultByName("count"),
|
||||
0
|
||||
(acc, day) => {
|
||||
const type = day.getResultByName("type");
|
||||
const count = day.getResultByName("count");
|
||||
acc[idToTextMap.get(type)] = (acc[idToTextMap.get(type)] || 0) + count;
|
||||
acc.blockedCount += count;
|
||||
return acc;
|
||||
},
|
||||
{ blockedCount: 0 }
|
||||
);
|
||||
return {
|
||||
// Keys need to match variable names used in asrouter.ftl
|
||||
// `earliestDate` will be either 6 weeks ago or when tracking recording
|
||||
// started. Whichever is more recent.
|
||||
earliestDate: new Date(
|
||||
Math.max(
|
||||
new Date(await TrackingDBService.getEarliestRecordedDate()),
|
||||
dateFrom
|
||||
)
|
||||
).getTime(),
|
||||
blockedCount: totalEvents.toLocaleString(),
|
||||
earliestDate: Math.max(
|
||||
new Date(await TrackingDBService.getEarliestRecordedDate()),
|
||||
dateFrom
|
||||
),
|
||||
...totalEvents,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -405,9 +405,15 @@ describe("ToolbarPanelHub", () => {
|
|||
m => m.template === "whatsnew_panel_message"
|
||||
);
|
||||
getMessagesStub.returns(messages);
|
||||
const ev1 = sandbox.stub();
|
||||
ev1.withArgs("type").returns(2); // cookie
|
||||
ev1.withArgs("count").returns(4);
|
||||
const ev2 = sandbox.stub();
|
||||
ev2.withArgs("type").returns(2); // cookie
|
||||
ev2.withArgs("count").returns(3);
|
||||
getEventsByDateRangeStub.returns([
|
||||
{ getResultByName: sandbox.stub().returns(2) },
|
||||
{ getResultByName: sandbox.stub().returns(3) },
|
||||
{ getResultByName: ev1 },
|
||||
{ getResultByName: ev2 },
|
||||
]);
|
||||
|
||||
await instance.renderMessages(fakeWindow, fakeDocument, "container-id");
|
||||
|
@ -416,8 +422,39 @@ describe("ToolbarPanelHub", () => {
|
|||
{
|
||||
id: sinon.match.string,
|
||||
args: {
|
||||
blockedCount: "5",
|
||||
blockedCount: 7,
|
||||
earliestDate: getEarliestRecordedDateStub(),
|
||||
cookie: 7,
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
it("should correctly compute event counts per type", async () => {
|
||||
const messages = (await PanelTestProvider.getMessages()).filter(
|
||||
m => m.template === "whatsnew_panel_message"
|
||||
);
|
||||
getMessagesStub.returns(messages);
|
||||
const ev1 = sandbox.stub();
|
||||
ev1.withArgs("type").returns(1); // tracker
|
||||
ev1.withArgs("count").returns(4);
|
||||
const ev2 = sandbox.stub();
|
||||
ev2.withArgs("type").returns(4); // fingerprinter
|
||||
ev2.withArgs("count").returns(3);
|
||||
getEventsByDateRangeStub.returns([
|
||||
{ getResultByName: ev1 },
|
||||
{ getResultByName: ev2 },
|
||||
]);
|
||||
|
||||
await instance.renderMessages(fakeWindow, fakeDocument, "container-id");
|
||||
|
||||
assert.calledWithExactly(global.RemoteL10n.l10n.formatMessages, [
|
||||
{
|
||||
id: sinon.match.string,
|
||||
args: {
|
||||
blockedCount: 7,
|
||||
earliestDate: getEarliestRecordedDateStub(),
|
||||
tracker: 4,
|
||||
fingerprinter: 3,
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
|
|
@ -131,6 +131,13 @@ const TEST_GLOBAL = {
|
|||
nsITimer: { TYPE_ONE_SHOT: 1 },
|
||||
nsIWebProgressListener: { LOCATION_CHANGE_SAME_DOCUMENT: 1 },
|
||||
nsIDOMWindow: Object,
|
||||
nsITrackingDBService: {
|
||||
TRACKERS_ID: 1,
|
||||
TRACKING_COOKIES_ID: 2,
|
||||
CRYPTOMINERS_ID: 3,
|
||||
FINGERPRINTERS_ID: 4,
|
||||
SOCIAL_ID: 5,
|
||||
},
|
||||
},
|
||||
Cu: {
|
||||
importGlobalProperties() {},
|
||||
|
|
Загрузка…
Ссылка в новой задаче