Bug 1819081 - Add telemetry to bookmarks sidebar and library r=mak

* Add histograms for cumulative searches and utilize scalars added in bug 1815906
* Add test coverage

Differential Revision: https://phabricator.services.mozilla.com/D172596
This commit is contained in:
Sarah Clements 2023-03-20 17:46:15 +00:00
parent 28387809e8
commit cfd4bcb67c
9 changed files with 319 additions and 18 deletions

View file

@ -26,6 +26,7 @@ XPCOMUtils.defineLazyScriptGetter(
"chrome://browser/content/places/controller.js"
);
/* End Shared Places Import */
var gCumulativeSearches = 0;
function init() {
let uidensity = window.top.document.documentElement.getAttribute("uidensity");
@ -43,10 +44,35 @@ function searchBookmarks(aSearchString) {
// eslint-disable-next-line no-self-assign
tree.place = tree.place;
} else {
Services.telemetry.keyedScalarAdd("sidebar.search", "bookmarks", 1);
gCumulativeSearches++;
tree.applyFilter(aSearchString, PlacesUtils.bookmarks.userContentRoots);
}
}
function updateTelemetry(urlsOpened = []) {
let searchesHistogram = Services.telemetry.getHistogramById(
"PLACES_BOOKMARKS_SEARCHBAR_CUMULATIVE_SEARCHES"
);
searchesHistogram.add(gCumulativeSearches);
clearCumulativeCounter();
Services.telemetry.keyedScalarAdd(
"sidebar.link",
"bookmarks",
urlsOpened.length
);
}
function clearCumulativeCounter() {
gCumulativeSearches = 0;
}
function unloadBookmarksSidebar() {
clearCumulativeCounter();
PlacesUIUtils.setMouseoverURL("", window);
}
window.addEventListener("SidebarFocused", () =>
document.getElementById("search-box").focus()
);

View file

@ -16,7 +16,7 @@
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="init();"
onunload="PlacesUIUtils.setMouseoverURL('', window);"
onunload="unloadBookmarksSidebar();"
data-l10n-id="bookmarks-sidebar-content">
<script src="chrome://browser/content/places/bookmarksSidebar.js"/>

View file

@ -34,8 +34,6 @@ var gCumulativeSearches = 0;
var gCumulativeFilterCount = 0;
function HistorySidebarInit() {
Services.telemetry.keyedScalarAdd("sidebar.opened", "history", 1);
let uidensity = window.top.document.documentElement.getAttribute("uidensity");
if (uidensity) {
document.documentElement.setAttribute("uidensity", uidensity);

View file

@ -183,6 +183,8 @@ var PlacesOrganizer = {
this._places.selectNode(historyNode.getChild(0));
}
Services.telemetry.keyedScalarAdd("library.opened", "history", 1);
} else {
Services.telemetry.keyedScalarAdd("library.opened", "bookmarks", 1);
}
// clear the back-stack
@ -825,13 +827,8 @@ var PlacesSearchBox = {
return document.getElementById("searchFilter");
},
_cumulativeLibraryHistorySearchCount: 0,
get cumulativeSearchCount() {
return this._cumulativeLibraryHistorySearchCount;
},
set cumulativeSearchCount(cumulativeSearches) {
this._cumulativeLibraryHistorySearchCount = cumulativeSearches;
},
cumulativeHistorySearches: 0,
cumulativeBookmarkSearches: 0,
/**
* Folders to include when searching.
@ -873,6 +870,8 @@ var PlacesSearchBox = {
switch (PlacesSearchBox.filterCollection) {
case "bookmarks":
currentView.applyFilter(filterString, this.folders);
Services.telemetry.keyedScalarAdd("library.search", "bookmarks", 1);
this.cumulativeBookmarkSearches++;
break;
case "history": {
let currentOptions = PO.getCurrentOptions();
@ -893,7 +892,7 @@ var PlacesSearchBox = {
currentView.applyFilter(filterString, null, true);
TelemetryStopwatch.finish(HISTORY_LIBRARY_SEARCH_TELEMETRY);
Services.telemetry.keyedScalarAdd("library.search", "history", 1);
this._cumulativeLibraryHistorySearchCount++;
this.cumulativeHistorySearches++;
}
break;
}
@ -998,7 +997,19 @@ function updateTelemetry(urlsOpened) {
link => !link.isBookmark && !PlacesUtils.nodeIsBookmark(link)
);
if (!historyLinks.length) {
// TODO (Bug 1819081)
let searchesHistogram = Services.telemetry.getHistogramById(
"PLACES_LIBRARY_CUMULATIVE_BOOKMARK_SEARCHES"
);
searchesHistogram.add(PlacesSearchBox.cumulativeBookmarkSearches);
// Clear cumulative search counter
PlacesSearchBox.cumulativeBookmarkSearches = 0;
Services.telemetry.keyedScalarAdd(
"library.link",
"bookmarks",
urlsOpened.length
);
return;
}
@ -1006,10 +1017,10 @@ function updateTelemetry(urlsOpened) {
let searchesHistogram = Services.telemetry.getHistogramById(
"PLACES_LIBRARY_CUMULATIVE_HISTORY_SEARCHES"
);
searchesHistogram.add(PlacesSearchBox.cumulativeSearchCount);
searchesHistogram.add(PlacesSearchBox.cumulativeHistorySearches);
// Clear cumulative search counter
PlacesSearchBox.cumulativeSearchCount = 0;
PlacesSearchBox.cumulativeHistorySearches = 0;
Services.telemetry.keyedScalarAdd(
"library.link",

View file

@ -95,7 +95,6 @@ skip-if = verify && debug && os == 'win'
[browser_library_delete_bookmarks_in_tags.js]
[browser_library_delete_tags.js]
[browser_library_downloads.js]
[browser_library_history_telemetry.js]
[browser_library_left_pane_middleclick.js]
[browser_library_left_pane_select_hierarchy.js]
[browser_library_middleclick.js]
@ -107,6 +106,7 @@ skip-if = verify && debug && os == 'win'
[browser_library_open_leak.js]
[browser_library_panel_leak.js]
[browser_library_search.js]
[browser_library_telemetry.js]
[browser_library_tree_leak.js]
[browser_library_views_liveupdate.js]
[browser_library_warnOnOpen.js]
@ -117,6 +117,7 @@ skip-if = verify && debug && os == 'win'
[browser_paste_resets_cut_highlights.js]
[browser_remove_bookmarks.js]
[browser_sidebar_history_telemetry.js]
[browser_sidebar_bookmarks_telemetry.js]
[browser_sidebar_open_bookmarks.js]
[browser_sidebarpanels_click.js]
[browser_sort_in_library.js]

View file

@ -49,8 +49,16 @@ async function searchHistory(gLibrary, searchTerm) {
);
}
function searchBookmarks(gLibrary, searchTerm) {
let searchBox = gLibrary.document.getElementById("searchFilter");
searchBox.value = searchTerm;
gLibrary.PlacesSearchBox.search(searchBox.value);
}
add_setup(async function() {
await PlacesUtils.history.clear();
await PlacesUtils.bookmarks.eraseEverything();
// Add some visited pages to history
let time = Date.now();
let places = [];
@ -63,8 +71,22 @@ add_setup(async function() {
}
await PlacesTestUtils.addVisits(places);
await PlacesUtils.bookmarks.insertTree({
guid: PlacesUtils.bookmarks.unfiledGuid,
children: [
{
title: "Mozilla",
url: "https://www.mozilla.org/",
},
{
title: "Example",
url: "https://sidebar.mozilla.org/",
},
],
});
await registerCleanupFunction(async () => {
await PlacesUtils.history.clear();
await PlacesUtils.bookmarks.eraseEverything();
});
});
@ -305,3 +327,87 @@ add_task(async function test_library_history_telemetry() {
BrowserTestUtils.removeTab(gBrowser.selectedTab);
}
});
add_task(async function test_library_bookmarks_telemetry() {
Services.telemetry.clearScalars();
let cumulativeSearchesHistogram = TelemetryTestUtils.getAndClearHistogram(
"PLACES_LIBRARY_CUMULATIVE_BOOKMARK_SEARCHES"
);
let library = await promiseLibrary("AllBookmarks");
TelemetryTestUtils.assertKeyedScalar(
TelemetryTestUtils.getProcessScalars("parent", true, true),
"library.opened",
"bookmarks",
1
);
searchBookmarks(library, "mozilla");
// reset
searchBookmarks(library, "");
// search again
searchBookmarks(library, "moz");
TelemetryTestUtils.assertKeyedScalar(
TelemetryTestUtils.getProcessScalars("parent", true, true),
"library.search",
"bookmarks",
2
);
let firstNode = library.ContentTree.view.view.nodeForTreeIndex(0);
library.ContentTree.view.selectNode(firstNode);
synthesizeClickOnSelectedTreeCell(library.ContentTree.view, {
clickCount: 2,
});
TelemetryTestUtils.assertKeyedScalar(
TelemetryTestUtils.getProcessScalars("parent", true, true),
"library.link",
"bookmarks",
1
);
TelemetryTestUtils.assertHistogram(cumulativeSearchesHistogram, 2, 1);
cumulativeSearchesHistogram = TelemetryTestUtils.getAndClearHistogram(
"PLACES_LIBRARY_CUMULATIVE_BOOKMARK_SEARCHES"
);
// do another search to make sure everything has been cleared
searchBookmarks(library, "moz");
TelemetryTestUtils.assertKeyedScalar(
TelemetryTestUtils.getProcessScalars("parent", true, true),
"library.search",
"bookmarks",
1
);
firstNode = library.ContentTree.view.view.nodeForTreeIndex(0);
library.ContentTree.view.selectNode(firstNode);
synthesizeClickOnSelectedTreeCell(library.ContentTree.view, {
clickCount: 2,
});
TelemetryTestUtils.assertKeyedScalar(
TelemetryTestUtils.getProcessScalars("parent", true, true),
"library.link",
"bookmarks",
1
);
TelemetryTestUtils.assertHistogram(cumulativeSearchesHistogram, 1, 1);
cumulativeSearchesHistogram.clear();
await promiseLibraryClosed(library);
while (gBrowser.tabs.length > 1) {
BrowserTestUtils.removeTab(gBrowser.selectedTab);
}
});

View file

@ -0,0 +1,137 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { TelemetryTestUtils } = ChromeUtils.import(
"resource://testing-common/TelemetryTestUtils.jsm"
);
let bookmarks;
add_setup(async function() {
await PlacesUtils.bookmarks.eraseEverything();
bookmarks = await PlacesUtils.bookmarks.insertTree({
guid: PlacesUtils.bookmarks.unfiledGuid,
children: [
{
title: "Mozilla",
url: "https://www.mozilla.org/",
},
{
title: "Example",
url: "https://sidebar.mozilla.org/",
},
],
});
registerCleanupFunction(async () => {
await PlacesUtils.bookmarks.eraseEverything();
});
});
add_task(async function test_open_multiple_bookmarks() {
await withSidebarTree("bookmarks", async tree => {
tree.selectItems([PlacesUtils.bookmarks.virtualUnfiledGuid]);
is(
tree.selectedNode.title,
"Other Bookmarks",
"The Other bookmarks folder is selected"
);
// open all bookmarks in this folder (which is two)
synthesizeClickOnSelectedTreeCell(tree, { button: 1 });
// expand the "Other bookmarks" folder
synthesizeClickOnSelectedTreeCell(tree, { button: 0 });
tree.selectItems([bookmarks[0].guid]);
is(tree.selectedNode.title, "Mozilla", "The first bookmark is selected");
synthesizeClickOnSelectedTreeCell(tree, { button: 0 });
TelemetryTestUtils.assertKeyedScalar(
TelemetryTestUtils.getProcessScalars("parent", true),
"sidebar.link",
"bookmarks",
3
);
let newWinOpened = BrowserTestUtils.waitForNewWindow();
// open a bookmark in new window via context menu
synthesizeClickOnSelectedTreeCell(tree, {
button: 2,
type: "contextmenu",
});
let openNewWindowOption = document.getElementById(
"placesContext_open:newwindow"
);
openNewWindowOption.click();
let newWin = await newWinOpened;
// total bookmarks opened
TelemetryTestUtils.assertKeyedScalar(
TelemetryTestUtils.getProcessScalars("parent", true, true),
"sidebar.link",
"bookmarks",
4
);
Services.telemetry.clearScalars();
BrowserTestUtils.closeWindow(newWin);
while (gBrowser.tabs.length > 1) {
BrowserTestUtils.removeTab(gBrowser.selectedTab);
}
});
});
add_task(async function test_bookmarks_search() {
let cumulativeSearchesHistogram = TelemetryTestUtils.getAndClearHistogram(
"PLACES_BOOKMARKS_SEARCHBAR_CUMULATIVE_SEARCHES"
);
cumulativeSearchesHistogram.clear();
await withSidebarTree("bookmarks", async tree => {
// Search the tree.
let searchBox = tree.ownerDocument.getElementById("search-box");
searchBox.value = "example";
searchBox.doCommand();
searchBox.value = "";
searchBox.doCommand();
info("Search was reset");
// Perform a second search.
searchBox.value = "mozilla";
searchBox.doCommand();
info("Second search was performed");
// Select the first link and click on it.
tree.selectNode(tree.view.nodeForTreeIndex(0));
synthesizeClickOnSelectedTreeCell(tree, { button: 0 });
info("First link was selected and then clicked on");
TelemetryTestUtils.assertKeyedScalar(
TelemetryTestUtils.getProcessScalars("parent", true, true),
"sidebar.link",
"bookmarks",
1
);
});
TelemetryTestUtils.assertHistogram(cumulativeSearchesHistogram, 2, 1);
info("Cumulative search probe is recorded");
cumulativeSearchesHistogram.clear();
Services.telemetry.clearScalars();
while (gBrowser.tabs.length > 1) {
BrowserTestUtils.removeTab(gBrowser.selectedTab);
}
});

View file

@ -7244,6 +7244,17 @@
"n_values": 20,
"description": "Cumulative no. of History-specific searches performed before selecting a History link in Library."
},
"PLACES_LIBRARY_CUMULATIVE_BOOKMARK_SEARCHES": {
"record_in_processes": ["main"],
"products": ["firefox"],
"expires_in_version": "never",
"alert_emails": ["firefox-view-engineers@mozilla.com"],
"releaseChannelCollection": "opt-out",
"bug_numbers": [1819081],
"kind": "enumerated",
"n_values": 20,
"description": "Cumulative no. of Bookmark-specific searches performed before selecting a bookmark link in Library."
},
"PLACES_IDLE_FRECENCY_DECAY_TIME_MS": {
"record_in_processes": ["main", "content"],
"products": ["firefox", "fennec", "thunderbird"],
@ -16059,6 +16070,17 @@
"n_values": 20,
"description": "Cumulative no. of search filters applied performed before selecting a link."
},
"PLACES_BOOKMARKS_SEARCHBAR_CUMULATIVE_SEARCHES": {
"record_in_processes": ["main"],
"products": ["firefox"],
"expires_in_version": "never",
"alert_emails": ["firefox-view-engineers@mozilla.com"],
"releaseChannelCollection": "opt-out",
"bug_numbers": [1819081],
"kind": "enumerated",
"n_values": 20,
"description": "Cumulative no. bookmark of searches performed before selecting a link."
},
"NOTIFY_OBSERVERS_LATENCY_MS": {
"record_in_processes": ["main", "content", "gpu"],
"products": ["firefox", "fennec"],

View file

@ -2258,7 +2258,7 @@ library:
bug_numbers:
- 1815906
description: >
The number of history items opened from the Library window
The number of history or bookmark items opened from the Library window
expires: never
kind: uint
keyed: true
@ -2273,7 +2273,7 @@ library:
bug_numbers:
- 1815906
description: >
The number of times the Library window was opened
The number of times the Library window was opened, keyed by 'history' or 'bookmarks'
expires: never
kind: uint
keyed: true
@ -2288,7 +2288,7 @@ library:
bug_numbers:
- 1815906
description: >
The number of history-specific searches made from the Library window
The number of history-specific or bookmark-specific searches made from the Library window
expires: never
kind: uint
keyed: true