Bug 1522256 - Add telemetry events for new content blocking UI items. r=ewright

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Johann Hofmann 2019-01-25 16:07:40 +00:00
parent 2d29717b84
commit 7b94b61d51
6 changed files with 140 additions and 42 deletions

View File

@ -11,11 +11,15 @@ const CONTAINER_PAGE = "http://not-tracking.example.com/browser/browser/base/con
const TPC_PREF = "network.cookie.cookieBehavior";
add_task(async function setup() {
let oldCanRecord = Services.telemetry.canRecordExtended;
Services.telemetry.canRecordExtended = true;
// Avoid the content blocking tour interfering with our tests by popping up.
await SpecialPowers.pushPrefEnv({set: [[ContentBlocking.prefIntroCount, ContentBlocking.MAX_INTROS]]});
await UrlClassifierTestUtils.addTestTrackers();
registerCleanupFunction(() => {
Services.telemetry.canRecordExtended = oldCanRecord;
UrlClassifierTestUtils.cleanupTestTrackers();
});
});
@ -38,6 +42,8 @@ async function assertSitesListed(trackersBlocked, thirdPartyBlocked, firstPartyB
await openIdentityPopup();
Services.telemetry.clearEvents();
let categoryItem =
document.getElementById("identity-popup-content-blocking-category-cookies");
ok(BrowserTestUtils.is_visible(categoryItem), "TP category item is visible");
@ -48,6 +54,11 @@ async function assertSitesListed(trackersBlocked, thirdPartyBlocked, firstPartyB
ok(true, "Cookies view was shown");
let events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN).parent;
let buttonEvents = events.filter(
e => e[1] == "security.ui.identitypopup" && e[2] == "click" && e[3] == "cookies_subview_btn");
is(buttonEvents.length, 1, "recorded telemetry for the button click");
let listHeaders = cookiesView.querySelectorAll(".identity-popup-cookiesView-list-header");
is(listHeaders.length, 3, "We have 3 list headers");

View File

@ -7,17 +7,17 @@ const TP_PREF = "privacy.trackingprotection.enabled";
const TPC_PREF = "network.cookie.cookieBehavior";
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
async function waitAndAssertPreferencesShown() {
async function waitAndAssertPreferencesShown(_spotlight) {
await BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popuphidden");
await TestUtils.waitForCondition(() => gBrowser.currentURI.spec == "about:preferences#privacy",
"Should open about:preferences.");
await ContentTask.spawn(gBrowser.selectedBrowser, {}, async function() {
await ContentTask.spawn(gBrowser.selectedBrowser, {spotlight: _spotlight}, async function({spotlight}) {
let doc = content.document;
let section = await ContentTaskUtils.waitForCondition(
() => doc.querySelector(".spotlight"), "The spotlight should appear.");
is(section.getAttribute("data-subcategory"), "trackingprotection",
"The trackingprotection section is spotlighted.");
is(section.getAttribute("data-subcategory"), spotlight,
"The correct section is spotlighted.");
});
BrowserTestUtils.removeTab(gBrowser.selectedTab);
@ -30,14 +30,13 @@ add_task(async function setup() {
registerCleanupFunction(() => {
Services.telemetry.canRecordExtended = oldCanRecord;
UrlClassifierTestUtils.cleanupTestTrackers();
});
Services.telemetry.clearEvents();
});
// Tests that pressing the preferences icon in the identity popup
// Tests that pressing the content blocking preferences icon in the identity popup
// links to about:preferences
add_task(async function testOpenPreferencesFromPrefsButton() {
add_task(async function testOpenPreferencesFromCBPrefsButton() {
await BrowserTestUtils.withNewTab("https://example.com", async function() {
let promisePanelOpen = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown");
gIdentityHandler._identityBox.click();
@ -45,9 +44,11 @@ add_task(async function testOpenPreferencesFromPrefsButton() {
let preferencesButton = document.getElementById("tracking-protection-preferences-button");
ok(!BrowserTestUtils.is_hidden(preferencesButton), "The enable tracking protection button is shown.");
ok(BrowserTestUtils.is_visible(preferencesButton), "The preferences button is shown.");
let shown = waitAndAssertPreferencesShown();
Services.telemetry.clearEvents();
let shown = waitAndAssertPreferencesShown("trackingprotection");
preferencesButton.click();
await shown;
@ -58,35 +59,105 @@ add_task(async function testOpenPreferencesFromPrefsButton() {
});
});
// Tests that clicking the contentblocking category items "add blocking" labels
// Tests that pressing the permissions preferences icon in the identity popup
// links to about:preferences
add_task(async function testOpenPreferencesFromAddBlockingButtons() {
SpecialPowers.pushPrefEnv({set: [
[TP_PREF, false],
[TPC_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT],
]});
await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function() {
let addBlockingButtons = document.querySelectorAll(".identity-popup-content-blocking-category-add-blocking");
for (let button of addBlockingButtons) {
add_task(async function testOpenPreferencesFromPermissionsPrefsButton() {
await BrowserTestUtils.withNewTab("https://example.com", async function() {
let promisePanelOpen = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown");
gIdentityHandler._identityBox.click();
await promisePanelOpen;
ok(BrowserTestUtils.is_visible(button), "Button is shown.");
let shown = waitAndAssertPreferencesShown();
button.click();
let preferencesButton = document.getElementById("identity-popup-permission-preferences-button");
ok(BrowserTestUtils.is_visible(preferencesButton), "The preferences button is shown.");
Services.telemetry.clearEvents();
let shown = waitAndAssertPreferencesShown("permissions");
preferencesButton.click();
await shown;
let events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true).parent;
let clickEvents = events.filter(
e => e[1] == "security.ui.identitypopup" && e[2] == "click" && e[3].endsWith("_add_blocking"));
e => e[1] == "security.ui.identitypopup" && e[2] == "click" && e[3] == "permission_prefs_btn");
is(clickEvents.length, 1, "recorded telemetry for the click");
}
});
});
// Tests that pressing the preferences button in the trackers subview
// links to about:preferences
add_task(async function testOpenPreferencesFromTrackersSubview() {
Services.prefs.setBoolPref(TP_PREF, true);
add_task(async function cleanup() {
UrlClassifierTestUtils.cleanupTestTrackers();
await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function() {
let promisePanelOpen = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown");
gIdentityHandler._identityBox.click();
await promisePanelOpen;
let categoryItem =
document.getElementById("identity-popup-content-blocking-category-tracking-protection");
ok(BrowserTestUtils.is_visible(categoryItem), "TP category item is visible");
let trackersView = document.getElementById("identity-popup-trackersView");
let viewShown = BrowserTestUtils.waitForEvent(trackersView, "ViewShown");
categoryItem.click();
await viewShown;
ok(true, "Trackers view was shown");
let preferencesButton = document.getElementById("identity-popup-trackersView-settings-button");
ok(BrowserTestUtils.is_visible(preferencesButton), "The preferences button is shown.");
Services.telemetry.clearEvents();
let shown = waitAndAssertPreferencesShown("trackingprotection");
preferencesButton.click();
await shown;
let events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true).parent;
let clickEvents = events.filter(
e => e[1] == "security.ui.identitypopup" && e[2] == "click" && e[3] == "trackers_prefs_btn");
is(clickEvents.length, 1, "recorded telemetry for the click");
});
Services.prefs.clearUserPref(TP_PREF);
});
// Tests that pressing the preferences button in the cookies subview
// links to about:preferences
add_task(async function testOpenPreferencesFromCookiesSubview() {
Services.prefs.setIntPref(TPC_PREF, Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER);
await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function() {
let promisePanelOpen = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown");
gIdentityHandler._identityBox.click();
await promisePanelOpen;
let categoryItem =
document.getElementById("identity-popup-content-blocking-category-cookies");
ok(BrowserTestUtils.is_visible(categoryItem), "TP category item is visible");
let cookiesView = document.getElementById("identity-popup-cookiesView");
let viewShown = BrowserTestUtils.waitForEvent(cookiesView, "ViewShown");
categoryItem.click();
await viewShown;
ok(true, "Cookies view was shown");
let preferencesButton = document.getElementById("identity-popup-cookiesView-settings-button");
ok(BrowserTestUtils.is_visible(preferencesButton), "The preferences button is shown.");
Services.telemetry.clearEvents();
let shown = waitAndAssertPreferencesShown("trackingprotection");
preferencesButton.click();
await shown;
let events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true).parent;
let clickEvents = events.filter(
e => e[1] == "security.ui.identitypopup" && e[2] == "click" && e[3] == "cookies_prefs_btn");
is(clickEvents.length, 1, "recorded telemetry for the click");
});
Services.prefs.clearUserPref(TPC_PREF);
});

View File

@ -9,11 +9,15 @@ const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/
const TP_PREF = "privacy.trackingprotection.enabled";
add_task(async function setup() {
let oldCanRecord = Services.telemetry.canRecordExtended;
Services.telemetry.canRecordExtended = true;
// Avoid the content blocking tour interfering with our tests by popping up.
await SpecialPowers.pushPrefEnv({set: [[ContentBlocking.prefIntroCount, ContentBlocking.MAX_INTROS]]});
await UrlClassifierTestUtils.addTestTrackers();
registerCleanupFunction(() => {
Services.telemetry.canRecordExtended = oldCanRecord;
UrlClassifierTestUtils.cleanupTestTrackers();
});
});
@ -22,6 +26,8 @@ async function assertSitesListed(blocked) {
await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function(browser) {
await openIdentityPopup();
Services.telemetry.clearEvents();
let categoryItem =
document.getElementById("identity-popup-content-blocking-category-tracking-protection");
ok(BrowserTestUtils.is_visible(categoryItem), "TP category item is visible");
@ -32,6 +38,11 @@ async function assertSitesListed(blocked) {
ok(true, "Trackers view was shown");
let events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN).parent;
let buttonEvents = events.filter(
e => e[1] == "security.ui.identitypopup" && e[2] == "click" && e[3] == "trackers_subview_btn");
is(buttonEvents.length, 1, "recorded telemetry for the button click");
let listItems = trackersView.querySelectorAll(".identity-popup-content-blocking-list-item");
is(listItems.length, 1, "We have 1 tracker in the list");

View File

@ -50,7 +50,7 @@
<button id="identity-popup-security-expander"
class="identity-popup-expander"
when-connection="not-secure secure secure-ev secure-cert-user-overridden"
oncommand="gIdentityHandler.showSecuritySubView();"/>
oncommand="gIdentityHandler.showSecuritySubView(); gIdentityHandler.recordClick('security_subview_btn');"/>
</hbox>
<!-- Tracking Protection Section -->
@ -75,14 +75,14 @@
<vbox id="identity-popup-content-blocking-category-list">
<toolbarbutton id="identity-popup-content-blocking-category-tracking-protection"
onclick="ContentBlocking.showTrackersSubview()"
onclick="ContentBlocking.showTrackersSubview(); gIdentityHandler.recordClick('trackers_subview_btn');"
class="identity-popup-content-blocking-category" align="center">
<image class="identity-popup-content-blocking-category-icon tracking-protection-icon"/>
<label flex="1" class="identity-popup-content-blocking-category-label">&contentBlocking.trackingProtection3.label;</label>
<label flex="1" id="identity-popup-content-blocking-tracking-protection-state-label" class="identity-popup-content-blocking-category-state-label"/>
</toolbarbutton>
<toolbarbutton id="identity-popup-content-blocking-category-cookies"
onclick="ContentBlocking.showCookiesSubview()"
onclick="ContentBlocking.showCookiesSubview(); gIdentityHandler.recordClick('cookies_subview_btn');"
class="identity-popup-content-blocking-category" align="center">
<image class="identity-popup-content-blocking-category-icon thirdpartycookies-icon"/>
<label flex="1" id="identity-popup-content-blocking-category-label-default"
@ -126,7 +126,7 @@
<toolbarbutton id="identity-popup-permission-preferences-button"
class="identity-popup-preferences-button subviewbutton"
tooltiptext="&identity.permissionsPreferences.tooltip;"
oncommand="gIdentityHandler.openPermissionPreferences();" />
oncommand="gIdentityHandler.openPermissionPreferences(); gIdentityHandler.recordClick('permission_prefs_btn');" />
</hbox>
<vbox id="identity-popup-permission-list"/>
<description id="identity-popup-permission-reload-hint">&identity.permissionsReloadHint;</description>
@ -250,7 +250,7 @@
<button id="identity-popup-trackersView-settings-button"
label="&contentBlocking.manageSettings.label;"
accesskey="&contentBlocking.manageSettings.accesskey;"
oncommand="ContentBlocking.openPreferences();"/>
oncommand="ContentBlocking.openPreferences(); gIdentityHandler.recordClick('trackers_prefs_btn');"/>
</vbox>
</panelview>
@ -265,7 +265,7 @@
<button id="identity-popup-cookiesView-settings-button"
label="&contentBlocking.manageSettings.label;"
accesskey="&contentBlocking.manageSettings.accesskey;"
oncommand="ContentBlocking.openPreferences();"/>
oncommand="ContentBlocking.openPreferences(); gIdentityHandler.recordClick('cookies_prefs_btn');"/>
</vbox>
</panelview>

View File

@ -174,7 +174,6 @@
#identity-popup-content-blocking-report-breakage,
.identity-popup-content-blocking-category-label,
.identity-popup-content-blocking-category-state-label,
.identity-popup-content-blocking-category-add-blocking,
.identity-popup-permission-label,
.identity-popup-permission-state-label,
.identity-popup-security-content > description,
@ -676,7 +675,6 @@ description#identity-popup-content-verifier,
}
.identity-popup-content-blocking-category-state-label,
.identity-popup-content-blocking-category-add-blocking,
.identity-popup-permission-state-label {
margin-inline-end: 5px;
text-align: end;

View File

@ -610,6 +610,7 @@ security.ui.identitypopup:
objects: ["identity_popup"]
bug_numbers:
- 1484251
- 1522256
description: >
How many times the control center was opened.
Keyed by the state of the content blocking shield, where the shield-showing key indicates
@ -631,11 +632,17 @@ security.ui.identitypopup:
click:
objects: [
"cb_prefs_button",
"permission_prefs_btn",
"clear_sitedata",
"unblock",
"unblock_private",
"block",
"report_breakage"
"report_breakage",
"security_subview_btn",
"trackers_subview_btn",
"cookies_subview_btn",
"trackers_prefs_btn",
"cookies_prefs_btn"
]
bug_numbers:
- 1484251