зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1484251 - Part 4 - Test updates for new content blocking telemetry. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D6896 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
260c7f5bf4
Коммит
13a2e264e0
|
@ -8,6 +8,15 @@ const REMOVE_DIALOG_URL = "chrome://browser/content/preferences/siteDataRemoveSe
|
|||
ChromeUtils.defineModuleGetter(this, "SiteDataTestUtils",
|
||||
"resource://testing-common/SiteDataTestUtils.jsm");
|
||||
|
||||
add_task(async function setup() {
|
||||
let oldCanRecord = Services.telemetry.canRecordExtended;
|
||||
Services.telemetry.canRecordExtended = true;
|
||||
|
||||
registerCleanupFunction(() => {
|
||||
Services.telemetry.canRecordExtended = oldCanRecord;
|
||||
});
|
||||
});
|
||||
|
||||
async function testClearing(testQuota, testCookies) {
|
||||
// Add some test quota storage.
|
||||
if (testQuota) {
|
||||
|
@ -53,6 +62,8 @@ async function testClearing(testQuota, testCookies) {
|
|||
]);
|
||||
}
|
||||
|
||||
Services.telemetry.clearEvents();
|
||||
|
||||
// Click the "Clear data" button.
|
||||
siteDataUpdated = TestUtils.topicObserved("sitedatamanager:sites-updated");
|
||||
let hideEvent = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popuphidden");
|
||||
|
@ -61,6 +72,11 @@ async function testClearing(testQuota, testCookies) {
|
|||
await hideEvent;
|
||||
await removeDialogPromise;
|
||||
|
||||
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] == "clear_sitedata");
|
||||
is(buttonEvents.length, 1, "recorded telemetry for the button click");
|
||||
|
||||
await siteDataUpdated;
|
||||
|
||||
// Check that cookies were deleted.
|
||||
|
|
|
@ -31,6 +31,14 @@ async function waitAndAssertPreferencesShown() {
|
|||
|
||||
add_task(async function setup() {
|
||||
await UrlClassifierTestUtils.addTestTrackers();
|
||||
let oldCanRecord = Services.telemetry.canRecordExtended;
|
||||
Services.telemetry.canRecordExtended = true;
|
||||
|
||||
registerCleanupFunction(() => {
|
||||
Services.telemetry.canRecordExtended = oldCanRecord;
|
||||
});
|
||||
|
||||
Services.telemetry.clearEvents();
|
||||
});
|
||||
|
||||
// Tests that pressing the preferences icon in the identity popup
|
||||
|
@ -48,6 +56,11 @@ add_task(async function testOpenPreferencesFromPrefsButton() {
|
|||
let shown = waitAndAssertPreferencesShown();
|
||||
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] == "cb_prefs_button");
|
||||
is(clickEvents.length, 1, "recorded telemetry for the click");
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -76,6 +89,11 @@ add_task(async function testOpenPreferencesFromAddBlockingButtons() {
|
|||
let shown = waitAndAssertPreferencesShown();
|
||||
button.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"));
|
||||
is(clickEvents.length, 1, "recorded telemetry for the click");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -22,6 +22,13 @@ add_task(async function setup() {
|
|||
[CB_UI_PREF, true],
|
||||
]});
|
||||
await UrlClassifierTestUtils.addTestTrackers();
|
||||
|
||||
let oldCanRecord = Services.telemetry.canRecordExtended;
|
||||
Services.telemetry.canRecordExtended = true;
|
||||
|
||||
registerCleanupFunction(() => {
|
||||
Services.telemetry.canRecordExtended = oldCanRecord;
|
||||
});
|
||||
});
|
||||
|
||||
function openIdentityPopup() {
|
||||
|
@ -126,6 +133,8 @@ add_task(async function testReportBreakageCancel() {
|
|||
await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function() {
|
||||
await openIdentityPopup();
|
||||
|
||||
Services.telemetry.clearEvents();
|
||||
|
||||
let reportBreakageButton = document.getElementById("identity-popup-content-blocking-report-breakage");
|
||||
ok(BrowserTestUtils.is_visible(reportBreakageButton), "report breakage button is visible");
|
||||
let reportBreakageView = document.getElementById("identity-popup-breakageReportView");
|
||||
|
@ -133,6 +142,11 @@ add_task(async function testReportBreakageCancel() {
|
|||
reportBreakageButton.click();
|
||||
await viewShown;
|
||||
|
||||
let events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN).parent;
|
||||
let clickEvents = events.filter(
|
||||
e => e[1] == "security.ui.identitypopup" && e[2] == "click" && e[3] == "report_breakage");
|
||||
is(clickEvents.length, 1, "recorded telemetry for the click");
|
||||
|
||||
ok(true, "Report breakage view was shown");
|
||||
|
||||
let mainView = document.getElementById("identity-popup-mainView");
|
||||
|
|
|
@ -11,8 +11,6 @@ const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/
|
|||
*/
|
||||
var oldCanRecord = Services.telemetry.canRecordExtended;
|
||||
Services.telemetry.canRecordExtended = true;
|
||||
Services.prefs.setBoolPref(PREF, false);
|
||||
Services.telemetry.getHistogramById("TRACKING_PROTECTION_ENABLED").clear();
|
||||
registerCleanupFunction(function() {
|
||||
UrlClassifierTestUtils.cleanupTestTrackers();
|
||||
Services.telemetry.canRecordExtended = oldCanRecord;
|
||||
|
@ -23,26 +21,10 @@ function getShieldHistogram() {
|
|||
return Services.telemetry.getHistogramById("TRACKING_PROTECTION_SHIELD");
|
||||
}
|
||||
|
||||
function getEnabledHistogram() {
|
||||
return Services.telemetry.getHistogramById("TRACKING_PROTECTION_ENABLED");
|
||||
}
|
||||
|
||||
function getEventsHistogram() {
|
||||
return Services.telemetry.getHistogramById("TRACKING_PROTECTION_EVENTS");
|
||||
}
|
||||
|
||||
function getShieldCounts() {
|
||||
return getShieldHistogram().snapshot().counts;
|
||||
}
|
||||
|
||||
function getEnabledCounts() {
|
||||
return getEnabledHistogram().snapshot().counts;
|
||||
}
|
||||
|
||||
function getEventCounts() {
|
||||
return getEventsHistogram().snapshot().counts;
|
||||
}
|
||||
|
||||
add_task(async function setup() {
|
||||
await UrlClassifierTestUtils.addTestTrackers();
|
||||
|
||||
|
@ -50,94 +32,105 @@ add_task(async function setup() {
|
|||
ok(TrackingProtection, "TP is attached to the browser window");
|
||||
ok(!TrackingProtection.enabled, "TP is not enabled");
|
||||
|
||||
// Open a window with TP disabled to make sure 'enabled' is logged correctly.
|
||||
let newWin = await BrowserTestUtils.openNewBrowserWindow({});
|
||||
newWin.close();
|
||||
let enabledCounts =
|
||||
Services.telemetry.getHistogramById("TRACKING_PROTECTION_ENABLED").snapshot().counts;
|
||||
is(enabledCounts[0], 1, "TP was not enabled on start up");
|
||||
|
||||
is(getEnabledCounts()[0], 1, "TP was disabled once on start up");
|
||||
is(getEnabledCounts()[1], 0, "TP was not enabled on start up");
|
||||
let scalars = Services.telemetry.snapshotScalars(
|
||||
Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTOUT, false).parent;
|
||||
|
||||
// Enable TP so the next browser to open will log 'enabled'
|
||||
Services.prefs.setBoolPref(PREF, true);
|
||||
is(scalars["contentblocking.enabled"], true, "CB was enabled at startup");
|
||||
is(scalars["contentblocking.fastblock_enabled"], true, "FB was enabled at startup");
|
||||
is(scalars["contentblocking.exceptions"], 0, "no CB exceptions at startup");
|
||||
});
|
||||
|
||||
|
||||
add_task(async function testNewWindow() {
|
||||
let newWin = await BrowserTestUtils.openNewBrowserWindow({});
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(newWin.gBrowser);
|
||||
let TrackingProtection = newWin.TrackingProtection;
|
||||
ok(TrackingProtection, "TP is attached to the browser window");
|
||||
|
||||
is(getEnabledCounts()[0], 1, "TP was disabled once on start up");
|
||||
is(getEnabledCounts()[1], 1, "TP was enabled once on start up");
|
||||
add_task(async function testShieldHistogram() {
|
||||
Services.prefs.setBoolPref(PREF, true);
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
|
||||
|
||||
// Reset these to make counting easier
|
||||
getEventsHistogram().clear();
|
||||
getShieldHistogram().clear();
|
||||
|
||||
await promiseTabLoadEvent(tab, BENIGN_PAGE);
|
||||
is(getEventCounts()[0], 1, "Total page loads");
|
||||
is(getEventCounts()[1], 0, "Disable actions");
|
||||
is(getEventCounts()[2], 0, "Enable actions");
|
||||
is(getShieldCounts()[0], 1, "Page loads without tracking");
|
||||
|
||||
await promiseTabLoadEvent(tab, TRACKING_PAGE);
|
||||
// Note that right now the events and shield histogram is not measuring what
|
||||
// Note that right now the shield histogram is not measuring what
|
||||
// you might think. Since onSecurityChange fires twice for a tracking page,
|
||||
// the total page loads count is double counting, and the shield count
|
||||
// (which is meant to measure times when the shield wasn't shown) fires even
|
||||
// when tracking elements exist on the page.
|
||||
todo_is(getEventCounts()[0], 2, "FIXME: TOTAL PAGE LOADS IS DOUBLE COUNTING");
|
||||
is(getEventCounts()[1], 0, "Disable actions");
|
||||
is(getEventCounts()[2], 0, "Enable actions");
|
||||
todo_is(getShieldCounts()[0], 1, "FIXME: TOTAL PAGE LOADS WITHOUT TRACKING IS DOUBLE COUNTING");
|
||||
|
||||
info("Disable TP for the page (which reloads the page)");
|
||||
let tabReloadPromise = promiseTabLoadEvent(tab);
|
||||
newWin.document.querySelector("#tracking-action-unblock").doCommand();
|
||||
document.querySelector("#tracking-action-unblock").doCommand();
|
||||
await tabReloadPromise;
|
||||
todo_is(getEventCounts()[0], 3, "FIXME: TOTAL PAGE LOADS IS DOUBLE COUNTING");
|
||||
is(getEventCounts()[1], 1, "Disable actions");
|
||||
is(getEventCounts()[2], 0, "Enable actions");
|
||||
todo_is(getShieldCounts()[0], 1, "FIXME: TOTAL PAGE LOADS WITHOUT TRACKING IS DOUBLE COUNTING");
|
||||
|
||||
info("Re-enable TP for the page (which reloads the page)");
|
||||
tabReloadPromise = promiseTabLoadEvent(tab);
|
||||
newWin.document.querySelector("#tracking-action-block").doCommand();
|
||||
document.querySelector("#tracking-action-block").doCommand();
|
||||
await tabReloadPromise;
|
||||
todo_is(getEventCounts()[0], 4, "FIXME: TOTAL PAGE LOADS IS DOUBLE COUNTING");
|
||||
is(getEventCounts()[1], 1, "Disable actions");
|
||||
is(getEventCounts()[2], 1, "Enable actions");
|
||||
todo_is(getShieldCounts()[0], 1, "FIXME: TOTAL PAGE LOADS WITHOUT TRACKING IS DOUBLE COUNTING");
|
||||
|
||||
newWin.close();
|
||||
gBrowser.removeCurrentTab();
|
||||
|
||||
// Reset these to make counting easier for the next test
|
||||
getEventsHistogram().clear();
|
||||
getShieldHistogram().clear();
|
||||
getEnabledHistogram().clear();
|
||||
});
|
||||
|
||||
add_task(async function testPrivateBrowsing() {
|
||||
let privateWin = await BrowserTestUtils.openNewBrowserWindow({private: true});
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(privateWin.gBrowser);
|
||||
let TrackingProtection = privateWin.TrackingProtection;
|
||||
ok(TrackingProtection, "TP is attached to the browser window");
|
||||
add_task(async function testIdentityPopupEvents() {
|
||||
Services.prefs.setBoolPref(PREF, true);
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
|
||||
|
||||
// Do a bunch of actions and make sure that no telemetry data is gathered
|
||||
await promiseTabLoadEvent(tab, BENIGN_PAGE);
|
||||
|
||||
Services.telemetry.clearEvents();
|
||||
|
||||
let { gIdentityHandler } = gBrowser.ownerGlobal;
|
||||
let promisePanelOpen = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown");
|
||||
gIdentityHandler._identityBox.click();
|
||||
await promisePanelOpen;
|
||||
|
||||
let events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true).parent;
|
||||
let openEvents = events.filter(
|
||||
e => e[1] == "security.ui.identitypopup" && e[2] == "open" && e[3] == "identity_popup");
|
||||
is(openEvents.length, 1, "recorded telemetry for opening the identity popup");
|
||||
is(openEvents[0][4], "shield-hidden", "recorded the shield as hidden");
|
||||
|
||||
await promiseTabLoadEvent(tab, TRACKING_PAGE);
|
||||
|
||||
promisePanelOpen = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown");
|
||||
gIdentityHandler._identityBox.click();
|
||||
await promisePanelOpen;
|
||||
|
||||
events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true).parent;
|
||||
openEvents = events.filter(
|
||||
e => e[1] == "security.ui.identitypopup" && e[2] == "open" && e[3] == "identity_popup");
|
||||
is(openEvents.length, 1, "recorded telemetry for opening the identity popup");
|
||||
is(openEvents[0][4], "shield-showing", "recorded the shield as showing");
|
||||
|
||||
info("Disable TP for the page (which reloads the page)");
|
||||
let tabReloadPromise = promiseTabLoadEvent(tab);
|
||||
privateWin.document.querySelector("#tracking-action-unblock").doCommand();
|
||||
document.querySelector("#tracking-action-unblock").doCommand();
|
||||
await tabReloadPromise;
|
||||
|
||||
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] == "unblock");
|
||||
is(clickEvents.length, 1, "recorded telemetry for the click");
|
||||
|
||||
info("Re-enable TP for the page (which reloads the page)");
|
||||
tabReloadPromise = promiseTabLoadEvent(tab);
|
||||
privateWin.document.querySelector("#tracking-action-block").doCommand();
|
||||
document.querySelector("#tracking-action-block").doCommand();
|
||||
await tabReloadPromise;
|
||||
|
||||
// Sum up all the counts to make sure that nothing got logged
|
||||
is(getEnabledCounts().reduce((p, c) => p + c), 0, "Telemetry logging off in PB mode");
|
||||
is(getEventCounts().reduce((p, c) => p + c), 0, "Telemetry logging off in PB mode");
|
||||
is(getShieldCounts().reduce((p, c) => p + c), 0, "Telemetry logging off in PB mode");
|
||||
events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true).parent;
|
||||
clickEvents = events.filter(
|
||||
e => e[1] == "security.ui.identitypopup" && e[2] == "click" && e[3] == "block");
|
||||
is(clickEvents.length, 1, "recorded telemetry for the click");
|
||||
|
||||
privateWin.close();
|
||||
gBrowser.removeCurrentTab();
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче