mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-09 21:00:42 +02:00
Bug 840177 - Part 4: Record search bar searches in Firefox Health Report; r=gavin
This commit is contained in:
parent
7006c8b7b3
commit
35ba4532c5
3 changed files with 98 additions and 0 deletions
|
|
@ -455,6 +455,7 @@
|
||||||
<body><![CDATA[
|
<body><![CDATA[
|
||||||
// null parameter below specifies HTML response for search
|
// null parameter below specifies HTML response for search
|
||||||
var submission = this.currentEngine.getSubmission(aData);
|
var submission = this.currentEngine.getSubmission(aData);
|
||||||
|
BrowserSearch.recordSearchInHealthReport(this.currentEngine.name, "searchbar");
|
||||||
openUILinkIn(submission.uri.spec, aWhere, null, submission.postData);
|
openUILinkIn(submission.uri.spec, aWhere, null, submission.postData);
|
||||||
]]></body>
|
]]></body>
|
||||||
</method>
|
</method>
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ MOCHITEST_BROWSER_FILES = \
|
||||||
browser_405664.js \
|
browser_405664.js \
|
||||||
browser_addEngine.js \
|
browser_addEngine.js \
|
||||||
browser_contextmenu.js \
|
browser_contextmenu.js \
|
||||||
|
browser_healthreport.js \
|
||||||
browser_private_search_perwindowpb.js \
|
browser_private_search_perwindowpb.js \
|
||||||
testEngine.xml \
|
testEngine.xml \
|
||||||
testEngine_mozsearch.xml \
|
testEngine_mozsearch.xml \
|
||||||
|
|
|
||||||
96
browser/components/search/test/browser_healthreport.js
Normal file
96
browser/components/search/test/browser_healthreport.js
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
function test() {
|
||||||
|
waitForExplicitFinish();
|
||||||
|
|
||||||
|
if (!("@mozilla.org/datareporting/service;1" in Components.classes)) {
|
||||||
|
// We need a test or else we'll be marked as failure.
|
||||||
|
ok(true, "Firefox Health Report is not enabled.");
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function testFHR() {
|
||||||
|
let reporter = Components.classes["@mozilla.org/datareporting/service;1"]
|
||||||
|
.getService()
|
||||||
|
.wrappedJSObject
|
||||||
|
.healthReporter;
|
||||||
|
ok(reporter, "Health Reporter available.");
|
||||||
|
reporter.onInit().then(function onInit() {
|
||||||
|
let provider = reporter.getProvider("org.mozilla.searches");
|
||||||
|
let m = provider.getMeasurement("counts", 1);
|
||||||
|
|
||||||
|
m.getValues().then(function onData(data) {
|
||||||
|
let now = new Date();
|
||||||
|
let oldCount = 0;
|
||||||
|
|
||||||
|
// Foo engine goes into "other" bucket.
|
||||||
|
let field = "other.searchbar";
|
||||||
|
|
||||||
|
if (data.days.hasDay(now)) {
|
||||||
|
let day = data.days.getDay(now);
|
||||||
|
if (day.has(field)) {
|
||||||
|
oldCount = day.get(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now perform a search and ensure the count is incremented.
|
||||||
|
let tab = gBrowser.addTab();
|
||||||
|
gBrowser.selectedTab = tab;
|
||||||
|
let searchBar = BrowserSearch.searchBar;
|
||||||
|
|
||||||
|
searchBar.value = "firefox health report";
|
||||||
|
searchBar.focus();
|
||||||
|
|
||||||
|
function afterSearch() {
|
||||||
|
searchBar.value = "";
|
||||||
|
gBrowser.removeTab(tab);
|
||||||
|
|
||||||
|
m.getValues().then(function onData(data) {
|
||||||
|
ok(data.days.hasDay(now), "Have data for today.");
|
||||||
|
let day = data.days.getDay(now);
|
||||||
|
|
||||||
|
is(day.get(field), oldCount + 1, "Performing a search increments FHR count by 1.");
|
||||||
|
|
||||||
|
let engine = Services.search.getEngineByName("Foo");
|
||||||
|
Services.search.removeEngine(engine);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
EventUtils.synthesizeKey("VK_RETURN", {});
|
||||||
|
executeSoon(afterSearch);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function observer(subject, topic, data) {
|
||||||
|
switch (data) {
|
||||||
|
case "engine-added":
|
||||||
|
let engine = Services.search.getEngineByName("Foo");
|
||||||
|
ok(engine, "Engine was added.");
|
||||||
|
Services.search.currentEngine = engine;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "engine-current":
|
||||||
|
is(Services.search.currentEngine.name, "Foo", "Current engine is Foo");
|
||||||
|
testFHR();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "engine-removed":
|
||||||
|
Services.obs.removeObserver(observer, "browser-search-engine-modified");
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Services.obs.addObserver(observer, "browser-search-engine-modified", false);
|
||||||
|
Services.search.addEngine("http://mochi.test:8888/browser/browser/components/search/test/testEngine.xml",
|
||||||
|
Ci.nsISearchEngine.DATA_XML,
|
||||||
|
"data:image/x-icon,%00",
|
||||||
|
false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in a new issue