зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
d1cae84099
Коммит
112871ebe3
|
@ -270,14 +270,17 @@ let BrowserUsageTelemetry = {
|
||||||
*/
|
*/
|
||||||
recordSearch(engine, source, details = {}) {
|
recordSearch(engine, source, details = {}) {
|
||||||
const isOneOff = !!details.isOneOff;
|
const isOneOff = !!details.isOneOff;
|
||||||
|
const countId = getSearchEngineId(engine) + "." + source;
|
||||||
|
|
||||||
if (isOneOff) {
|
if (isOneOff) {
|
||||||
if (!KNOWN_ONEOFF_SOURCES.includes(source)) {
|
if (!KNOWN_ONEOFF_SOURCES.includes(source)) {
|
||||||
// Silently drop the error if this bogus call
|
// Silently drop the error if this bogus call
|
||||||
// came from 'urlbar' or 'searchbar'. They're
|
// came from 'urlbar' or 'searchbar'. They're
|
||||||
// calling |recordSearch| twice from two different
|
// 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)) {
|
if (['urlbar', 'searchbar'].includes(source)) {
|
||||||
|
Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS").add(countId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new Error("Unknown source for one-off search: " + source);
|
throw new Error("Unknown source for one-off search: " + source);
|
||||||
|
@ -286,7 +289,6 @@ let BrowserUsageTelemetry = {
|
||||||
if (!KNOWN_SEARCH_SOURCES.includes(source)) {
|
if (!KNOWN_SEARCH_SOURCES.includes(source)) {
|
||||||
throw new Error("Unknown source for search: " + source);
|
throw new Error("Unknown source for search: " + source);
|
||||||
}
|
}
|
||||||
let countId = getSearchEngineId(engine) + "." + source;
|
|
||||||
Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS").add(countId);
|
Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS").add(countId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,11 @@ add_task(function* setup() {
|
||||||
let engineOneOff = Services.search.getEngineByName("MozSearch2");
|
let engineOneOff = Services.search.getEngineByName("MozSearch2");
|
||||||
Services.search.moveEngine(engineOneOff, 0);
|
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.
|
// Make sure to restore the engine once we're done.
|
||||||
registerCleanupFunction(function* () {
|
registerCleanupFunction(function* () {
|
||||||
Services.search.currentEngine = originalEngine;
|
Services.search.currentEngine = originalEngine;
|
||||||
|
@ -34,6 +39,7 @@ add_task(function* setup() {
|
||||||
add_task(function* test_context_menu() {
|
add_task(function* test_context_menu() {
|
||||||
// Let's reset the counts.
|
// Let's reset the counts.
|
||||||
Services.telemetry.clearScalars();
|
Services.telemetry.clearScalars();
|
||||||
|
let search_hist = getSearchCountsHistogram();
|
||||||
|
|
||||||
// Open a new tab with a page containing some text.
|
// Open a new tab with a page containing some text.
|
||||||
let tab =
|
let tab =
|
||||||
|
@ -65,6 +71,9 @@ add_task(function* test_context_menu() {
|
||||||
Assert.equal(Object.keys(scalars[SCALAR_CONTEXT_MENU]).length, 1,
|
Assert.equal(Object.keys(scalars[SCALAR_CONTEXT_MENU]).length, 1,
|
||||||
"This search must only increment one entry in the scalar.");
|
"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();
|
contextMenu.hidePopup();
|
||||||
yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||||
yield BrowserTestUtils.removeTab(tab);
|
yield BrowserTestUtils.removeTab(tab);
|
||||||
|
@ -73,6 +82,7 @@ add_task(function* test_context_menu() {
|
||||||
add_task(function* test_about_newtab() {
|
add_task(function* test_about_newtab() {
|
||||||
// Let's reset the counts.
|
// Let's reset the counts.
|
||||||
Services.telemetry.clearScalars();
|
Services.telemetry.clearScalars();
|
||||||
|
let search_hist = getSearchCountsHistogram();
|
||||||
|
|
||||||
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:newtab", false);
|
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:newtab", false);
|
||||||
yield ContentTask.spawn(tab.linkedBrowser, null, function* () {
|
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,
|
Assert.equal(Object.keys(scalars[SCALAR_ABOUT_NEWTAB]).length, 1,
|
||||||
"This search must only increment one entry in the scalar.");
|
"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);
|
yield BrowserTestUtils.removeTab(tab);
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,6 +27,9 @@ add_task(function* setup() {
|
||||||
let engineOneOff = Services.search.getEngineByName("MozSearch2");
|
let engineOneOff = Services.search.getEngineByName("MozSearch2");
|
||||||
Services.search.moveEngine(engineOneOff, 0);
|
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.
|
// Make sure to restore the engine once we're done.
|
||||||
registerCleanupFunction(function* () {
|
registerCleanupFunction(function* () {
|
||||||
Services.search.currentEngine = originalEngine;
|
Services.search.currentEngine = originalEngine;
|
||||||
|
@ -38,6 +41,7 @@ add_task(function* setup() {
|
||||||
add_task(function* test_abouthome_simpleQuery() {
|
add_task(function* test_abouthome_simpleQuery() {
|
||||||
// Let's reset the counts.
|
// Let's reset the counts.
|
||||||
Services.telemetry.clearScalars();
|
Services.telemetry.clearScalars();
|
||||||
|
let search_hist = getSearchCountsHistogram();
|
||||||
|
|
||||||
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser);
|
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,
|
Assert.equal(Object.keys(scalars[SCALAR_ABOUT_HOME]).length, 1,
|
||||||
"This search must only increment one entry in the scalar.");
|
"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);
|
yield BrowserTestUtils.removeTab(tab);
|
||||||
});
|
});
|
||||||
|
|
|
@ -67,6 +67,9 @@ add_task(function* setup() {
|
||||||
let engineOneOff = Services.search.getEngineByName("MozSearch2");
|
let engineOneOff = Services.search.getEngineByName("MozSearch2");
|
||||||
Services.search.moveEngine(engineOneOff, 0);
|
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.
|
// Make sure to restore the engine once we're done.
|
||||||
registerCleanupFunction(function* () {
|
registerCleanupFunction(function* () {
|
||||||
Services.search.currentEngine = originalEngine;
|
Services.search.currentEngine = originalEngine;
|
||||||
|
@ -78,6 +81,7 @@ add_task(function* setup() {
|
||||||
add_task(function* test_plainQuery() {
|
add_task(function* test_plainQuery() {
|
||||||
// Let's reset the counts.
|
// Let's reset the counts.
|
||||||
Services.telemetry.clearScalars();
|
Services.telemetry.clearScalars();
|
||||||
|
let search_hist = getSearchCountsHistogram();
|
||||||
|
|
||||||
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
|
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,
|
Assert.equal(Object.keys(scalars[SCALAR_SEARCHBAR]).length, 1,
|
||||||
"This search must only increment one entry in the scalar.");
|
"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);
|
yield BrowserTestUtils.removeTab(tab);
|
||||||
});
|
});
|
||||||
|
|
||||||
add_task(function* test_oneOff() {
|
add_task(function* test_oneOff() {
|
||||||
// Let's reset the counts.
|
// Let's reset the counts.
|
||||||
Services.telemetry.clearScalars();
|
Services.telemetry.clearScalars();
|
||||||
|
let search_hist = getSearchCountsHistogram();
|
||||||
|
|
||||||
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
|
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,
|
Assert.equal(Object.keys(scalars[SCALAR_SEARCHBAR]).length, 1,
|
||||||
"This search must only increment one entry in the scalar.");
|
"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);
|
yield BrowserTestUtils.removeTab(tab);
|
||||||
});
|
});
|
||||||
|
|
||||||
add_task(function* test_suggestion() {
|
add_task(function* test_suggestion() {
|
||||||
// Let's reset the counts.
|
// Let's reset the counts.
|
||||||
Services.telemetry.clearScalars();
|
Services.telemetry.clearScalars();
|
||||||
|
let search_hist = getSearchCountsHistogram();
|
||||||
|
|
||||||
// Create an engine to generate search suggestions and add it as default
|
// Create an engine to generate search suggestions and add it as default
|
||||||
// for this test.
|
// for this test.
|
||||||
|
@ -155,6 +167,9 @@ add_task(function* test_suggestion() {
|
||||||
Assert.equal(Object.keys(scalars[SCALAR_SEARCHBAR]).length, 1,
|
Assert.equal(Object.keys(scalars[SCALAR_SEARCHBAR]).length, 1,
|
||||||
"This search must only increment one entry in the scalar.");
|
"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.currentEngine = previousEngine;
|
||||||
Services.search.removeEngine(suggestionEngine);
|
Services.search.removeEngine(suggestionEngine);
|
||||||
yield BrowserTestUtils.removeTab(tab);
|
yield BrowserTestUtils.removeTab(tab);
|
||||||
|
|
|
@ -59,6 +59,9 @@ add_task(function* setup() {
|
||||||
// Enable the urlbar one-off buttons.
|
// Enable the urlbar one-off buttons.
|
||||||
Services.prefs.setBoolPref(ONEOFF_URLBAR_PREF, true);
|
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.
|
// Make sure to restore the engine once we're done.
|
||||||
registerCleanupFunction(function* () {
|
registerCleanupFunction(function* () {
|
||||||
Services.search.currentEngine = originalEngine;
|
Services.search.currentEngine = originalEngine;
|
||||||
|
@ -71,6 +74,7 @@ add_task(function* setup() {
|
||||||
add_task(function* test_simpleQuery() {
|
add_task(function* test_simpleQuery() {
|
||||||
// Let's reset the counts.
|
// Let's reset the counts.
|
||||||
Services.telemetry.clearScalars();
|
Services.telemetry.clearScalars();
|
||||||
|
let search_hist = getSearchCountsHistogram();
|
||||||
|
|
||||||
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
|
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,
|
Assert.equal(Object.keys(scalars[SCALAR_URLBAR]).length, 1,
|
||||||
"This search must only increment one entry in the scalar.");
|
"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);
|
yield BrowserTestUtils.removeTab(tab);
|
||||||
});
|
});
|
||||||
|
|
||||||
add_task(function* test_searchAlias() {
|
add_task(function* test_searchAlias() {
|
||||||
// Let's reset the counts.
|
// Let's reset the counts.
|
||||||
Services.telemetry.clearScalars();
|
Services.telemetry.clearScalars();
|
||||||
|
let search_hist = getSearchCountsHistogram();
|
||||||
|
|
||||||
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
|
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,
|
Assert.equal(Object.keys(scalars[SCALAR_URLBAR]).length, 1,
|
||||||
"This search must only increment one entry in the scalar.");
|
"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);
|
yield BrowserTestUtils.removeTab(tab);
|
||||||
});
|
});
|
||||||
|
|
||||||
add_task(function* test_oneOff() {
|
add_task(function* test_oneOff() {
|
||||||
// Let's reset the counts.
|
// Let's reset the counts.
|
||||||
Services.telemetry.clearScalars();
|
Services.telemetry.clearScalars();
|
||||||
|
let search_hist = getSearchCountsHistogram();
|
||||||
|
|
||||||
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
|
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,
|
Assert.equal(Object.keys(scalars[SCALAR_URLBAR]).length, 1,
|
||||||
"This search must only increment one entry in the scalar.");
|
"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);
|
yield BrowserTestUtils.removeTab(tab);
|
||||||
});
|
});
|
||||||
|
|
||||||
add_task(function* test_suggestion() {
|
add_task(function* test_suggestion() {
|
||||||
// Let's reset the counts.
|
// Let's reset the counts.
|
||||||
Services.telemetry.clearScalars();
|
Services.telemetry.clearScalars();
|
||||||
|
let search_hist = getSearchCountsHistogram();
|
||||||
|
|
||||||
// Create an engine to generate search suggestions and add it as default
|
// Create an engine to generate search suggestions and add it as default
|
||||||
// for this test.
|
// for this test.
|
||||||
|
@ -170,6 +186,9 @@ add_task(function* test_suggestion() {
|
||||||
Assert.equal(Object.keys(scalars[SCALAR_URLBAR]).length, 1,
|
Assert.equal(Object.keys(scalars[SCALAR_URLBAR]).length, 1,
|
||||||
"This search must only increment one entry in the scalar.");
|
"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.currentEngine = previousEngine;
|
||||||
Services.search.removeEngine(suggestionEngine);
|
Services.search.removeEngine(suggestionEngine);
|
||||||
yield BrowserTestUtils.removeTab(tab);
|
yield BrowserTestUtils.removeTab(tab);
|
||||||
|
|
|
@ -77,3 +77,21 @@ let typeInSearchField = Task.async(function* (browser, text, fieldName) {
|
||||||
searchInput.value = contentText;
|
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}.`);
|
||||||
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче