--- a/browser/modules/test/browser/browser_UsageTelemetry_urlbar.js
+++ b/browser/modules/test/browser/browser_UsageTelemetry_urlbar.js
@@ -47,33 +47,63 @@ let searchInAwesomebar = async function(
Ci.nsIAutoCompleteController.STATUS_COMPLETE_NO_MATCH);
};
/**
* Click one of the entries in the urlbar suggestion popup.
*
* @param {String} entryName
* The name of the elemet to click on.
+ * @param {Number} button [optional]
+ * which button to click.
*/
-function clickURLBarSuggestion(entryName) {
+function clickURLBarSuggestion(entryName, button = 1) {
// The entry in the suggestion list should follow the format:
// "<search term> <engine name> Search"
const expectedSuggestionName = entryName + " " + SUGGESTION_ENGINE_NAME + " Search";
return BrowserTestUtils.waitForCondition(() => {
for (let child of gURLBar.popup.richlistbox.children) {
if (child.label === expectedSuggestionName) {
// This entry is the search suggestion we're looking for.
- child.click();
+ if (button == 1)
+ child.click();
+ else if (button == 2) {
+ EventUtils.synthesizeMouseAtCenter(child, {type: "mousedown", button: 2});
+ }
return true;
}
}
return false;
}, "Waiting for the expected suggestion to appear");
}
+/**
+ * Create an engine to generate search suggestions and add it as default
+ * for this test.
+ */
+async function withNewSearchEngine(taskFn) {
+ const url = getRootDirectory(gTestPath) + "usageTelemetrySearchSuggestions.xml";
+ let suggestionEngine = await new Promise((resolve, reject) => {
+ Services.search.addEngine(url, null, "", false, {
+ onSuccess(engine) { resolve(engine); },
+ onError() { reject(); }
+ });
+ });
+
+ let previousEngine = Services.search.currentEngine;
+ Services.search.currentEngine = suggestionEngine;
+
+ try {
+ await taskFn(suggestionEngine);
+ } finally {
+ Services.search.currentEngine = previousEngine;
+ Services.search.removeEngine(suggestionEngine);
+ }
+}
+
add_task(async function setup() {
// Create a new search engine.
Services.search.addEngineWithDetails("MozSearch", "", "mozalias", "", "GET",
"http://example.com/?q={searchTerms}");
// Make it the default search engine.
let engine = Services.search.getEngineByName("MozSearch");
let originalEngine = Services.search.currentEngine;
@@ -115,17 +145,16 @@ add_task(async function setup() {
Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, suggestionsEnabled);
Services.prefs.clearUserPref(ONEOFF_URLBAR_PREF);
await PlacesUtils.history.clear();
Services.telemetry.setEventRecordingEnabled("navigation", false);
});
});
add_task(async function test_simpleQuery() {
- // Let's reset the counts.
Services.telemetry.clearScalars();
Services.telemetry.clearEvents();
let resultIndexHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_INDEX");
let resultTypeHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_TYPE");
let resultIndexByTypeHist = getAndClearKeyedHistogram("FX_URLBAR_SELECTED_RESULT_INDEX_BY_TYPE");
let resultMethodHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_METHOD");
let search_hist = getAndClearKeyedHistogram("SEARCH_COUNTS");
@@ -170,17 +199,16 @@ add_task(async function test_simpleQuery
checkHistogramResults(resultMethods,
URLBAR_SELECTED_RESULT_METHODS.enter,
"FX_URLBAR_SELECTED_RESULT_METHOD");
BrowserTestUtils.removeTab(tab);
});
add_task(async function test_searchAlias() {
- // Let's reset the counts.
Services.telemetry.clearScalars();
Services.telemetry.clearEvents();
let resultIndexHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_INDEX");
let resultTypeHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_TYPE");
let resultIndexByTypeHist = getAndClearKeyedHistogram("FX_URLBAR_SELECTED_RESULT_INDEX_BY_TYPE");
let resultMethodHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_METHOD");
let search_hist = getAndClearKeyedHistogram("SEARCH_COUNTS");
@@ -227,17 +255,16 @@ add_task(async function test_searchAlias
"FX_URLBAR_SELECTED_RESULT_METHOD");
BrowserTestUtils.removeTab(tab);
});
// Performs a search using the first result, a one-off button, and the Return
// (Enter) key.
add_task(async function test_oneOff_enter() {
- // Let's reset the counts.
Services.telemetry.clearScalars();
Services.telemetry.clearEvents();
let resultIndexHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_INDEX");
let resultTypeHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_TYPE");
let resultIndexByTypeHist = getAndClearKeyedHistogram("FX_URLBAR_SELECTED_RESULT_INDEX_BY_TYPE");
let resultMethodHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_METHOD");
let search_hist = getAndClearKeyedHistogram("SEARCH_COUNTS");
@@ -288,61 +315,45 @@ add_task(async function test_oneOff_ente
BrowserTestUtils.removeTab(tab);
});
// Performs a search using the second result, a one-off button, and the Return
// (Enter) key. This only tests the FX_URLBAR_SELECTED_RESULT_METHOD histogram
// since test_oneOff_enter covers everything else.
add_task(async function test_oneOff_enterSelection() {
- // Let's reset the counts.
Services.telemetry.clearScalars();
-
let resultMethodHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_METHOD");
- // Create an engine to generate search suggestions and add it as default
- // for this test.
- const url = getRootDirectory(gTestPath) + "usageTelemetrySearchSuggestions.xml";
- let suggestionEngine = await new Promise((resolve, reject) => {
- Services.search.addEngine(url, null, "", false, {
- onSuccess(engine) { resolve(engine); },
- onError() { reject(); }
- });
- });
+ await withNewSearchEngine(async function() {
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
- let previousEngine = Services.search.currentEngine;
- Services.search.currentEngine = suggestionEngine;
-
- let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
+ info("Type a query. Suggestions should be generated by the test engine.");
+ let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ await searchInAwesomebar("query");
- info("Type a query. Suggestions should be generated by the test engine.");
- let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
- await searchInAwesomebar("query");
+ info("Select the second result, press Alt+Down to take us to the first one-off engine.");
+ EventUtils.synthesizeKey("KEY_ArrowDown");
+ EventUtils.synthesizeKey("KEY_ArrowDown", {altKey: true});
+ EventUtils.synthesizeKey("KEY_Enter");
+ await p;
- info("Select the second result, press Alt+Down to take us to the first one-off engine.");
- EventUtils.synthesizeKey("KEY_ArrowDown");
- EventUtils.synthesizeKey("KEY_ArrowDown", {altKey: true});
- EventUtils.synthesizeKey("KEY_Enter");
- await p;
+ let resultMethods = resultMethodHist.snapshot();
+ checkHistogramResults(resultMethods,
+ URLBAR_SELECTED_RESULT_METHODS.arrowEnterSelection,
+ "FX_URLBAR_SELECTED_RESULT_METHOD");
- let resultMethods = resultMethodHist.snapshot();
- checkHistogramResults(resultMethods,
- URLBAR_SELECTED_RESULT_METHODS.arrowEnterSelection,
- "FX_URLBAR_SELECTED_RESULT_METHOD");
-
- Services.search.currentEngine = previousEngine;
- Services.search.removeEngine(suggestionEngine);
- BrowserTestUtils.removeTab(tab);
+ BrowserTestUtils.removeTab(tab);
+ });
});
// Performs a search using a click on a one-off button. This only tests the
// FX_URLBAR_SELECTED_RESULT_METHOD histogram since test_oneOff_enter covers
// everything else.
add_task(async function test_oneOff_click() {
- // Let's reset the counts.
Services.telemetry.clearScalars();
let resultMethodHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_METHOD");
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
info("Type a query.");
let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
@@ -356,202 +367,168 @@ add_task(async function test_oneOff_clic
URLBAR_SELECTED_RESULT_METHODS.click,
"FX_URLBAR_SELECTED_RESULT_METHOD");
BrowserTestUtils.removeTab(tab);
});
// Clicks the first suggestion offered by the test search engine.
add_task(async function test_suggestion_click() {
- // Let's reset the counts.
Services.telemetry.clearScalars();
Services.telemetry.clearEvents();
let resultIndexHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_INDEX");
let resultTypeHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_TYPE");
let resultIndexByTypeHist = getAndClearKeyedHistogram("FX_URLBAR_SELECTED_RESULT_INDEX_BY_TYPE");
let resultMethodHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_METHOD");
let search_hist = getAndClearKeyedHistogram("SEARCH_COUNTS");
- // Create an engine to generate search suggestions and add it as default
- // for this test.
- const url = getRootDirectory(gTestPath) + "usageTelemetrySearchSuggestions.xml";
- let suggestionEngine = await new Promise((resolve, reject) => {
- Services.search.addEngine(url, null, "", false, {
- onSuccess(engine) { resolve(engine); },
- onError() { reject(); }
- });
- });
+ await withNewSearchEngine(async function(engine) {
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
- let previousEngine = Services.search.currentEngine;
- Services.search.currentEngine = suggestionEngine;
+ info("Type a query. Suggestions should be generated by the test engine.");
+ let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ await searchInAwesomebar("query");
+ info("Clicking the urlbar suggestion.");
+ await clickURLBarSuggestion("queryfoo");
+ await p;
- let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
+ // Check if the scalars contain the expected values.
+ const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);
+ checkKeyedScalar(scalars, SCALAR_URLBAR, "search_suggestion", 1);
+ Assert.equal(Object.keys(scalars[SCALAR_URLBAR]).length, 1,
+ "This search must only increment one entry in the scalar.");
- info("Type a query. Suggestions should be generated by the test engine.");
- let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
- await searchInAwesomebar("query");
- info("Clicking the urlbar suggestion.");
- await clickURLBarSuggestion("queryfoo");
- await p;
-
- // Check if the scalars contain the expected values.
- const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);
- checkKeyedScalar(scalars, SCALAR_URLBAR, "search_suggestion", 1);
- 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.
+ let searchEngineId = "other-" + engine.name;
+ checkKeyedHistogram(search_hist, searchEngineId + ".urlbar", 1);
- // Make sure SEARCH_COUNTS contains identical values.
- let searchEngineId = "other-" + suggestionEngine.name;
- checkKeyedHistogram(search_hist, searchEngineId + ".urlbar", 1);
+ // Also check events.
+ let events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
+ events = (events.parent || []).filter(e => e[1] == "navigation" && e[2] == "search");
+ checkEvents(events, [["navigation", "search", "urlbar", "suggestion", {engine: searchEngineId}]]);
- // Also check events.
- let events = Services.telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
- events = (events.parent || []).filter(e => e[1] == "navigation" && e[2] == "search");
- checkEvents(events, [["navigation", "search", "urlbar", "suggestion", {engine: searchEngineId}]]);
-
- // Check the histograms as well.
- let resultIndexes = resultIndexHist.snapshot();
- checkHistogramResults(resultIndexes, 3, "FX_URLBAR_SELECTED_RESULT_INDEX");
+ // Check the histograms as well.
+ let resultIndexes = resultIndexHist.snapshot();
+ checkHistogramResults(resultIndexes, 3, "FX_URLBAR_SELECTED_RESULT_INDEX");
- let resultTypes = resultTypeHist.snapshot();
- checkHistogramResults(resultTypes,
- URLBAR_SELECTED_RESULT_TYPES.searchsuggestion,
- "FX_URLBAR_SELECTED_RESULT_TYPE");
+ let resultTypes = resultTypeHist.snapshot();
+ checkHistogramResults(resultTypes,
+ URLBAR_SELECTED_RESULT_TYPES.searchsuggestion,
+ "FX_URLBAR_SELECTED_RESULT_TYPE");
- let resultIndexByType = resultIndexByTypeHist.snapshot("searchsuggestion");
- checkHistogramResults(resultIndexByType,
- 3,
- "FX_URLBAR_SELECTED_RESULT_INDEX_BY_TYPE");
+ let resultIndexByType = resultIndexByTypeHist.snapshot("searchsuggestion");
+ checkHistogramResults(resultIndexByType,
+ 3,
+ "FX_URLBAR_SELECTED_RESULT_INDEX_BY_TYPE");
- let resultMethods = resultMethodHist.snapshot();
- checkHistogramResults(resultMethods,
- URLBAR_SELECTED_RESULT_METHODS.click,
- "FX_URLBAR_SELECTED_RESULT_METHOD");
+ let resultMethods = resultMethodHist.snapshot();
+ checkHistogramResults(resultMethods,
+ URLBAR_SELECTED_RESULT_METHODS.click,
+ "FX_URLBAR_SELECTED_RESULT_METHOD");
- Services.search.currentEngine = previousEngine;
- Services.search.removeEngine(suggestionEngine);
- BrowserTestUtils.removeTab(tab);
+ BrowserTestUtils.removeTab(tab);
+ });
});
// Selects and presses the Return (Enter) key on the first suggestion offered by
// the test search engine. This only tests the FX_URLBAR_SELECTED_RESULT_METHOD
// histogram since test_suggestion_click covers everything else.
add_task(async function test_suggestion_arrowEnterSelection() {
- // Let's reset the counts.
Services.telemetry.clearScalars();
-
let resultMethodHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_METHOD");
- // Create an engine to generate search suggestions and add it as default
- // for this test.
- const url = getRootDirectory(gTestPath) + "usageTelemetrySearchSuggestions.xml";
- let suggestionEngine = await new Promise((resolve, reject) => {
- Services.search.addEngine(url, null, "", false, {
- onSuccess(engine) { resolve(engine); },
- onError() { reject(); }
- });
- });
-
- let previousEngine = Services.search.currentEngine;
- Services.search.currentEngine = suggestionEngine;
-
- let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
+ await withNewSearchEngine(async function() {
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
- info("Type a query. Suggestions should be generated by the test engine.");
- let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
- await searchInAwesomebar("query");
- info("Select the second result and press Return.");
- EventUtils.synthesizeKey("KEY_ArrowDown");
- EventUtils.synthesizeKey("KEY_Enter");
- await p;
+ info("Type a query. Suggestions should be generated by the test engine.");
+ let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ await searchInAwesomebar("query");
+ info("Select the second result and press Return.");
+ EventUtils.synthesizeKey("KEY_ArrowDown");
+ EventUtils.synthesizeKey("KEY_Enter");
+ await p;
- let resultMethods = resultMethodHist.snapshot();
- checkHistogramResults(resultMethods,
- URLBAR_SELECTED_RESULT_METHODS.arrowEnterSelection,
- "FX_URLBAR_SELECTED_RESULT_METHOD");
+ let resultMethods = resultMethodHist.snapshot();
+ checkHistogramResults(resultMethods,
+ URLBAR_SELECTED_RESULT_METHODS.arrowEnterSelection,
+ "FX_URLBAR_SELECTED_RESULT_METHOD");
- Services.search.currentEngine = previousEngine;
- Services.search.removeEngine(suggestionEngine);
- BrowserTestUtils.removeTab(tab);
+ BrowserTestUtils.removeTab(tab);
+ });
});
// Selects through tab and presses the Return (Enter) key on the first
// suggestion offered by the test search engine.
add_task(async function test_suggestion_tabEnterSelection() {
- // Let's reset the counts.
Services.telemetry.clearScalars();
-
let resultMethodHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_METHOD");
- // Create an engine to generate search suggestions and add it as default
- // for this test.
- const url = getRootDirectory(gTestPath) + "usageTelemetrySearchSuggestions.xml";
- let suggestionEngine = await new Promise((resolve, reject) => {
- Services.search.addEngine(url, null, "", false, {
- onSuccess(engine) { resolve(engine); },
- onError() { reject(); }
- });
- });
-
- let previousEngine = Services.search.currentEngine;
- Services.search.currentEngine = suggestionEngine;
-
- let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
+ await withNewSearchEngine(async function() {
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
- info("Type a query. Suggestions should be generated by the test engine.");
- let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
- await searchInAwesomebar("query");
- info("Select the second result and press Return.");
- EventUtils.synthesizeKey("KEY_Tab");
- EventUtils.synthesizeKey("KEY_Enter");
- await p;
+ info("Type a query. Suggestions should be generated by the test engine.");
+ let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ await searchInAwesomebar("query");
+ info("Select the second result and press Return.");
+ EventUtils.synthesizeKey("KEY_Tab");
+ EventUtils.synthesizeKey("KEY_Enter");
+ await p;
- let resultMethods = resultMethodHist.snapshot();
- checkHistogramResults(resultMethods,
- URLBAR_SELECTED_RESULT_METHODS.tabEnterSelection,
- "FX_URLBAR_SELECTED_RESULT_METHOD");
+ let resultMethods = resultMethodHist.snapshot();
+ checkHistogramResults(resultMethods,
+ URLBAR_SELECTED_RESULT_METHODS.tabEnterSelection,
+ "FX_URLBAR_SELECTED_RESULT_METHOD");
- Services.search.currentEngine = previousEngine;
- Services.search.removeEngine(suggestionEngine);
- BrowserTestUtils.removeTab(tab);
+ BrowserTestUtils.removeTab(tab);
+ });
});
// Selects through code and presses the Return (Enter) key on the first
// suggestion offered by the test search engine.
add_task(async function test_suggestion_enterSelection() {
- // Let's reset the counts.
Services.telemetry.clearScalars();
-
let resultMethodHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_METHOD");
- // Create an engine to generate search suggestions and add it as default
- // for this test.
- const url = getRootDirectory(gTestPath) + "usageTelemetrySearchSuggestions.xml";
- let suggestionEngine = await new Promise((resolve, reject) => {
- Services.search.addEngine(url, null, "", false, {
- onSuccess(engine) { resolve(engine); },
- onError() { reject(); }
- });
+ await withNewSearchEngine(async function() {
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
+
+ info("Type a query. Suggestions should be generated by the test engine.");
+ let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ await searchInAwesomebar("query");
+ info("Select the second result and press Return.");
+ gURLBar.popup.selectedIndex = 1;
+ EventUtils.synthesizeKey("KEY_Enter");
+ await p;
+
+ let resultMethods = resultMethodHist.snapshot();
+ checkHistogramResults(resultMethods,
+ URLBAR_SELECTED_RESULT_METHODS.enterSelection,
+ "FX_URLBAR_SELECTED_RESULT_METHOD");
+
+ BrowserTestUtils.removeTab(tab);
});
-
- let previousEngine = Services.search.currentEngine;
- Services.search.currentEngine = suggestionEngine;
-
- let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
+});
- info("Type a query. Suggestions should be generated by the test engine.");
- let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
- await searchInAwesomebar("query");
- info("Select the second result and press Return.");
- gURLBar.popup.selectedIndex = 1;
- EventUtils.synthesizeKey("KEY_Enter");
- await p;
+// Selects through mouse right button and press the Return (Enter) key.
+add_task(async function test_suggestion_rightclick() {
+ Services.telemetry.clearScalars();
+ let resultMethodHist = getAndClearHistogram("FX_URLBAR_SELECTED_RESULT_METHOD");
+
+ await withNewSearchEngine(async function() {
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
- let resultMethods = resultMethodHist.snapshot();
- checkHistogramResults(resultMethods,
- URLBAR_SELECTED_RESULT_METHODS.enterSelection,
- "FX_URLBAR_SELECTED_RESULT_METHOD");
+ info("Type a query. Suggestions should be generated by the test engine.");
+ let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ await searchInAwesomebar("query");
+ info("Right click the the second result and then press Return.");
+ await clickURLBarSuggestion("queryfoo", 2);
+ EventUtils.synthesizeKey("KEY_Enter");
+ await p;
- Services.search.currentEngine = previousEngine;
- Services.search.removeEngine(suggestionEngine);
- BrowserTestUtils.removeTab(tab);
+ let resultMethods = resultMethodHist.snapshot();
+ checkHistogramResults(resultMethods,
+ URLBAR_SELECTED_RESULT_METHODS.rightClickEnter,
+ "FX_URLBAR_SELECTED_RESULT_METHOD");
+
+ BrowserTestUtils.removeTab(tab);
+ });
});