Bug 1318333 - Fix SEARCH_COUNTS not counting one-off searches. r=mak

MozReview-Commit-ID: 2HTJBzbpUK2

--HG--
extra : rebase_source : 2583dbba6373b342be8d6c3b037ae03924822776
This commit is contained in:
Alessio Placitelli 2016-11-21 04:56:00 -05:00
Родитель d1cae84099
Коммит 112871ebe3
6 изменённых файлов: 76 добавлений и 2 удалений

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

@ -270,14 +270,17 @@ let BrowserUsageTelemetry = {
*/
recordSearch(engine, source, details = {}) {
const isOneOff = !!details.isOneOff;
const countId = getSearchEngineId(engine) + "." + source;
if (isOneOff) {
if (!KNOWN_ONEOFF_SOURCES.includes(source)) {
// Silently drop the error if this bogus call
// came from 'urlbar' or 'searchbar'. They're
// calling |recordSearch| twice from two different
// code paths.
// code paths because they want to record the search
// in SEARCH_COUNTS.
if (['urlbar', 'searchbar'].includes(source)) {
Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS").add(countId);
return;
}
throw new Error("Unknown source for one-off search: " + source);
@ -286,7 +289,6 @@ let BrowserUsageTelemetry = {
if (!KNOWN_SEARCH_SOURCES.includes(source)) {
throw new Error("Unknown source for search: " + source);
}
let countId = getSearchEngineId(engine) + "." + source;
Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS").add(countId);
}

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

@ -23,6 +23,11 @@ add_task(function* setup() {
let engineOneOff = Services.search.getEngineByName("MozSearch2");
Services.search.moveEngine(engineOneOff, 0);
yield SpecialPowers.pushPrefEnv({"set": [
["dom.select_events.enabled", true], // We want select events to be fired.
["toolkit.telemetry.enabled", true] // And Extended Telemetry to be enabled.
]});
// Make sure to restore the engine once we're done.
registerCleanupFunction(function* () {
Services.search.currentEngine = originalEngine;
@ -34,6 +39,7 @@ add_task(function* setup() {
add_task(function* test_context_menu() {
// Let's reset the counts.
Services.telemetry.clearScalars();
let search_hist = getSearchCountsHistogram();
// Open a new tab with a page containing some text.
let tab =
@ -65,6 +71,9 @@ add_task(function* test_context_menu() {
Assert.equal(Object.keys(scalars[SCALAR_CONTEXT_MENU]).length, 1,
"This search must only increment one entry in the scalar.");
// Make sure SEARCH_COUNTS contains identical values.
checkKeyedHistogram(search_hist, 'other-MozSearch.contextmenu', 1);
contextMenu.hidePopup();
yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
yield BrowserTestUtils.removeTab(tab);
@ -73,6 +82,7 @@ add_task(function* test_context_menu() {
add_task(function* test_about_newtab() {
// Let's reset the counts.
Services.telemetry.clearScalars();
let search_hist = getSearchCountsHistogram();
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:newtab", false);
yield ContentTask.spawn(tab.linkedBrowser, null, function* () {
@ -92,5 +102,8 @@ add_task(function* test_about_newtab() {
Assert.equal(Object.keys(scalars[SCALAR_ABOUT_NEWTAB]).length, 1,
"This search must only increment one entry in the scalar.");
// Make sure SEARCH_COUNTS contains identical values.
checkKeyedHistogram(search_hist, 'other-MozSearch.newtab', 1);
yield BrowserTestUtils.removeTab(tab);
});

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

@ -27,6 +27,9 @@ add_task(function* setup() {
let engineOneOff = Services.search.getEngineByName("MozSearch2");
Services.search.moveEngine(engineOneOff, 0);
// Enable Extended Telemetry.
yield SpecialPowers.pushPrefEnv({"set": [["toolkit.telemetry.enabled", true]]});
// Make sure to restore the engine once we're done.
registerCleanupFunction(function* () {
Services.search.currentEngine = originalEngine;
@ -38,6 +41,7 @@ add_task(function* setup() {
add_task(function* test_abouthome_simpleQuery() {
// Let's reset the counts.
Services.telemetry.clearScalars();
let search_hist = getSearchCountsHistogram();
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser);
@ -67,5 +71,8 @@ add_task(function* test_abouthome_simpleQuery() {
Assert.equal(Object.keys(scalars[SCALAR_ABOUT_HOME]).length, 1,
"This search must only increment one entry in the scalar.");
// Make sure SEARCH_COUNTS contains identical values.
checkKeyedHistogram(search_hist, 'other-MozSearch.abouthome', 1);
yield BrowserTestUtils.removeTab(tab);
});

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

@ -67,6 +67,9 @@ add_task(function* setup() {
let engineOneOff = Services.search.getEngineByName("MozSearch2");
Services.search.moveEngine(engineOneOff, 0);
// Enable Extended Telemetry.
yield SpecialPowers.pushPrefEnv({"set": [["toolkit.telemetry.enabled", true]]});
// Make sure to restore the engine once we're done.
registerCleanupFunction(function* () {
Services.search.currentEngine = originalEngine;
@ -78,6 +81,7 @@ add_task(function* setup() {
add_task(function* test_plainQuery() {
// Let's reset the counts.
Services.telemetry.clearScalars();
let search_hist = getSearchCountsHistogram();
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
@ -94,12 +98,16 @@ add_task(function* test_plainQuery() {
Assert.equal(Object.keys(scalars[SCALAR_SEARCHBAR]).length, 1,
"This search must only increment one entry in the scalar.");
// Make sure SEARCH_COUNTS contains identical values.
checkKeyedHistogram(search_hist, 'other-MozSearch.searchbar', 1);
yield BrowserTestUtils.removeTab(tab);
});
add_task(function* test_oneOff() {
// Let's reset the counts.
Services.telemetry.clearScalars();
let search_hist = getSearchCountsHistogram();
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
@ -119,12 +127,16 @@ add_task(function* test_oneOff() {
Assert.equal(Object.keys(scalars[SCALAR_SEARCHBAR]).length, 1,
"This search must only increment one entry in the scalar.");
// Make sure SEARCH_COUNTS contains identical values.
checkKeyedHistogram(search_hist, 'other-MozSearch2.searchbar', 1);
yield BrowserTestUtils.removeTab(tab);
});
add_task(function* test_suggestion() {
// Let's reset the counts.
Services.telemetry.clearScalars();
let search_hist = getSearchCountsHistogram();
// Create an engine to generate search suggestions and add it as default
// for this test.
@ -155,6 +167,9 @@ add_task(function* test_suggestion() {
Assert.equal(Object.keys(scalars[SCALAR_SEARCHBAR]).length, 1,
"This search must only increment one entry in the scalar.");
// Make sure SEARCH_COUNTS contains identical values.
checkKeyedHistogram(search_hist, 'other-' + suggestionEngine.name + '.searchbar', 1);
Services.search.currentEngine = previousEngine;
Services.search.removeEngine(suggestionEngine);
yield BrowserTestUtils.removeTab(tab);

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

@ -59,6 +59,9 @@ add_task(function* setup() {
// Enable the urlbar one-off buttons.
Services.prefs.setBoolPref(ONEOFF_URLBAR_PREF, true);
// Enable Extended Telemetry.
yield SpecialPowers.pushPrefEnv({"set": [["toolkit.telemetry.enabled", true]]});
// Make sure to restore the engine once we're done.
registerCleanupFunction(function* () {
Services.search.currentEngine = originalEngine;
@ -71,6 +74,7 @@ add_task(function* setup() {
add_task(function* test_simpleQuery() {
// Let's reset the counts.
Services.telemetry.clearScalars();
let search_hist = getSearchCountsHistogram();
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
@ -87,12 +91,16 @@ add_task(function* test_simpleQuery() {
Assert.equal(Object.keys(scalars[SCALAR_URLBAR]).length, 1,
"This search must only increment one entry in the scalar.");
// Make sure SEARCH_COUNTS contains identical values.
checkKeyedHistogram(search_hist, 'other-MozSearch.urlbar', 1);
yield BrowserTestUtils.removeTab(tab);
});
add_task(function* test_searchAlias() {
// Let's reset the counts.
Services.telemetry.clearScalars();
let search_hist = getSearchCountsHistogram();
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
@ -109,12 +117,16 @@ add_task(function* test_searchAlias() {
Assert.equal(Object.keys(scalars[SCALAR_URLBAR]).length, 1,
"This search must only increment one entry in the scalar.");
// Make sure SEARCH_COUNTS contains identical values.
checkKeyedHistogram(search_hist, 'other-MozSearch.urlbar', 1);
yield BrowserTestUtils.removeTab(tab);
});
add_task(function* test_oneOff() {
// Let's reset the counts.
Services.telemetry.clearScalars();
let search_hist = getSearchCountsHistogram();
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
@ -134,12 +146,16 @@ add_task(function* test_oneOff() {
Assert.equal(Object.keys(scalars[SCALAR_URLBAR]).length, 1,
"This search must only increment one entry in the scalar.");
// Make sure SEARCH_COUNTS contains identical values.
checkKeyedHistogram(search_hist, 'other-MozSearch.urlbar', 1);
yield BrowserTestUtils.removeTab(tab);
});
add_task(function* test_suggestion() {
// Let's reset the counts.
Services.telemetry.clearScalars();
let search_hist = getSearchCountsHistogram();
// Create an engine to generate search suggestions and add it as default
// for this test.
@ -170,6 +186,9 @@ add_task(function* test_suggestion() {
Assert.equal(Object.keys(scalars[SCALAR_URLBAR]).length, 1,
"This search must only increment one entry in the scalar.");
// Make sure SEARCH_COUNTS contains identical values.
checkKeyedHistogram(search_hist, 'other-' + suggestionEngine.name + '.urlbar', 1);
Services.search.currentEngine = previousEngine;
Services.search.removeEngine(suggestionEngine);
yield BrowserTestUtils.removeTab(tab);

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

@ -77,3 +77,21 @@ let typeInSearchField = Task.async(function* (browser, text, fieldName) {
searchInput.value = contentText;
});
});
/**
* Clear and get the SEARCH_COUNTS histogram.
*/
function getSearchCountsHistogram() {
let search_hist = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS");
search_hist.clear();
return search_hist;
}
/**
* Check that the keyed histogram contains the right value.
*/
function checkKeyedHistogram(h, key, expectedValue) {
const snapshot = h.snapshot();
Assert.ok(key in snapshot, `The histogram must contain ${key}.`);
Assert.equal(snapshot[key].sum, expectedValue, `The key ${key} must contain ${expectedValue}.`);
}