mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 840177 - Part 3: Record context menu searches in Firefox Health Report; r=gavin, r=rnewman
This commit is contained in:
parent
5cf2c4dfff
commit
fc97fa1257
@ -235,8 +235,7 @@
|
||||
accesskey="&keywordfield.accesskey;"
|
||||
oncommand="AddKeywordForSearchField();"/>
|
||||
<menuitem id="context-searchselect"
|
||||
oncommand="BrowserSearch.loadSearch(getBrowserSelection(), true,
|
||||
'contextmenu');"/>
|
||||
oncommand="BrowserSearch.loadSearchFromContext(getBrowserSelection());"/>
|
||||
<menuseparator id="frame-sep"/>
|
||||
<menu id="frame" label="&thisFrameMenu.label;" accesskey="&thisFrameMenu.accesskey;">
|
||||
<menupopup>
|
||||
|
@ -3471,6 +3471,9 @@ const BrowserSearch = {
|
||||
* A string meant to indicate the context of the search request. This
|
||||
* allows the search service to provide a different nsISearchSubmission
|
||||
* depending on e.g. where the search is triggered in the UI.
|
||||
*
|
||||
* @return string Name of the search engine used to perform a search or null
|
||||
* if a search was not performed.
|
||||
*/
|
||||
loadSearch: function BrowserSearch_search(searchText, useNewTab, purpose) {
|
||||
var engine;
|
||||
@ -3488,8 +3491,9 @@ const BrowserSearch = {
|
||||
// with a text/html response type. This is unlikely (since
|
||||
// SearchService._addEngineToStore() should fail for such an engine),
|
||||
// but let's be on the safe side.
|
||||
if (!submission)
|
||||
return;
|
||||
if (!submission) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let inBackground = Services.prefs.getBoolPref("browser.search.context.loadInBackground");
|
||||
openLinkIn(submission.uri.spec,
|
||||
@ -3497,6 +3501,21 @@ const BrowserSearch = {
|
||||
{ postData: submission.postData,
|
||||
inBackground: inBackground,
|
||||
relatedToCurrent: true });
|
||||
|
||||
return engine.name;
|
||||
},
|
||||
|
||||
/**
|
||||
* Perform a search initiated from the context menu.
|
||||
*
|
||||
* This should only be called from the context menu. See
|
||||
* BrowserSearch.loadSearch for the preferred API.
|
||||
*/
|
||||
loadSearchFromContext: function (terms) {
|
||||
let engine = BrowserSearch.loadSearch(terms, true, "contextmenu");
|
||||
if (engine) {
|
||||
BrowserSearch.recordSearchInHealthReport(engine, "contextmenu");
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -3,6 +3,8 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
function tabAdded(event) {
|
||||
let tab = event.target;
|
||||
tabs.push(tab);
|
||||
@ -14,8 +16,8 @@ function test() {
|
||||
container.addEventListener("TabOpen", tabAdded, false);
|
||||
|
||||
gBrowser.addTab("about:blank");
|
||||
BrowserSearch.loadSearch("mozilla", true);
|
||||
BrowserSearch.loadSearch("firefox", true);
|
||||
BrowserSearch.loadSearchFromContext("mozilla");
|
||||
BrowserSearch.loadSearchFromContext("firefox");
|
||||
|
||||
is(tabs[0], gBrowser.tabs[3], "blank tab has been pushed to the end");
|
||||
is(tabs[1], gBrowser.tabs[1], "first search tab opens next to the current tab");
|
||||
@ -23,4 +25,39 @@ function test() {
|
||||
|
||||
container.removeEventListener("TabOpen", tabAdded, false);
|
||||
tabs.forEach(gBrowser.removeTab, gBrowser);
|
||||
|
||||
if (!"@mozilla.org/datareporting/service;1" in Components.classes) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
let reporter = Components.classes["@mozilla.org/datareporting/service;1"]
|
||||
.getService()
|
||||
.wrappedJSObject
|
||||
.healthReporter;
|
||||
|
||||
// reporter should always be available in automation.
|
||||
ok(reporter, "Health Reporter available.");
|
||||
reporter.onInit().then(function onInit() {
|
||||
let provider = reporter.getProvider("org.mozilla.searches");
|
||||
ok(provider, "Searches provider is available.");
|
||||
|
||||
let m = provider.getMeasurement("counts", 1);
|
||||
m.getValues().then(function onValues(data) {
|
||||
let now = new Date();
|
||||
ok(data.days.hasDay(now), "Have data for today.");
|
||||
let day = data.days.getDay(now);
|
||||
|
||||
// Will need changed if Google isn't the default search engine.
|
||||
let field = "google.contextmenu";
|
||||
ok(day.has(field), "Have search recorded for context menu.");
|
||||
|
||||
// If any other mochitests perform a context menu search, this will fail.
|
||||
// The solution will be to look up count at test start and ensure it is
|
||||
// incremented by two.
|
||||
is(day.get(field), 2, "2 searches recorded in FHR.");
|
||||
finish();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user