Bug 1682821 - Fix content blocking milestone message test and trigger r=nanj

Differential Revision: https://phabricator.services.mozilla.com/D99891
This commit is contained in:
Andrei Oprea 2020-12-17 17:58:43 +00:00
Родитель af859fd8ec
Коммит 12602737b0
5 изменённых файлов: 15 добавлений и 83 удалений

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

@ -661,9 +661,8 @@ this.ASRouterTargeting = {
candidateMessageTrigger.params.includes(trigger.param.host)) ||
(candidateMessageTrigger.params &&
trigger.param.type &&
candidateMessageTrigger.params.filter(
t => (t & trigger.param.type) === t
).length) ||
candidateMessageTrigger.params.filter(t => t === trigger.param.type)
.length) ||
(candidateMessageTrigger.patterns &&
trigger.param.url &&
new MatchPatternSet(candidateMessageTrigger.patterns).matches(

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

@ -557,7 +557,7 @@ this.ASRouterTriggerListeners = new Map([
pageLoad: this._sessionPageLoad,
},
param: {
host: aSubject.wrappedJSObject.event,
type: aSubject.wrappedJSObject.event,
},
}
);

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

@ -931,7 +931,7 @@ const CFR_MESSAGES = [
],
},
},
targeting: "pageLoad >= 4",
targeting: "pageLoad >= 1",
frequency: {
lifetime: 7, // Length of privacy.contentBlocking.cfr-milestone.milestones pref
},

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

@ -616,69 +616,6 @@ add_task(
}
);
add_task(
async function test_cfr_tracking_protection_milestone_notification_show() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.contentblocking.cfr-milestone.milestone-achieved", 1000],
[
"browser.newtabpage.activity-stream.asrouter.providers.cfr",
`{"id":"cfr","enabled":true,"type":"local","localProvider":"CFRMessageProvider","updateCycleInMs":3600000}`,
],
],
});
// addRecommendation checks that scheme starts with http and host matches
let browser = gBrowser.selectedBrowser;
BrowserTestUtils.loadURI(browser, "http://example.com/");
await BrowserTestUtils.browserLoaded(browser, false, "http://example.com/");
const showPanel = BrowserTestUtils.waitForEvent(
PopupNotifications.panel,
"popupshown"
);
const response = await trigger_cfr_panel(browser, "example.com", {
action: { type: "OPEN_PROTECTION_REPORT" },
category: "cfrFeatures",
layout: "short_message",
skip_address_bar_notifier: true,
use_single_secondary_button: true,
heading_text: "Test Milestone Message",
template: "milestone_message",
});
Assert.ok(
response,
"Should return true if addRecommendation checks were successful"
);
await showPanel;
const notification = document.getElementById(
"contextual-feature-recommendation-notification"
);
// checkCFRSocialTrackingProtection(notification);
checkCFRTrackingProtectionMilestone(notification);
// Check there is a primary button and click it. It will trigger the callback.
Assert.ok(notification.button);
let hidePanel = BrowserTestUtils.waitForEvent(
PopupNotifications.panel,
"popuphidden"
);
let protectionsTabPromise = BrowserTestUtils.waitForNewTab(gBrowser);
document
.getElementById("contextual-feature-recommendation-notification")
.button.click();
let protectionsTab = await protectionsTabPromise;
await BrowserTestUtils.removeTab(protectionsTab);
await hidePanel;
}
);
add_task(
async function test_cfr_tracking_protection_milestone_notification_remove() {
await SpecialPowers.pushPrefEnv({
@ -701,25 +638,21 @@ add_task(
"popupshown"
);
const response = await trigger_cfr_panel(browser, "example.com", {
action: { type: "OPEN_PROTECTION_REPORT" },
category: "cfrFeatures",
layout: "short_message",
skip_address_bar_notifier: true,
use_single_secondary_button: true,
heading_text: "Test Milestone Message",
template: "milestone_message",
});
Assert.ok(
response,
"Should return true if addRecommendation checks were successful"
Services.obs.notifyObservers(
{
wrappedJSObject: {
event: "ContentBlockingMilestone",
},
},
"SiteProtection:ContentBlockingMilestone"
);
await showPanel;
const notification = document.getElementById(
"contextual-feature-recommendation-notification"
);
// checkCFRSocialTrackingProtection(notification);
checkCFRTrackingProtectionMilestone(notification);
Assert.ok(notification.secondaryButton);

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

@ -417,10 +417,10 @@ add_task(async function check_contentBlockingMilestone_listener() {
const triggerHandler = (target, trigger) => {
const {
id,
param: { host },
param: { type },
} = trigger;
is(id, "contentBlocking", "should match event name");
is(host, "ContentBlockingMilestone", "Should be the correct event type");
is(type, "ContentBlockingMilestone", "Should be the correct event type");
observerEvent += 1;
};
const contentBlockingListener = ASRouterTriggerListeners.get(