mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
Bug 840177 - Part 5: Add observer notification for keyword searches; r=gavin
The intent is for this to be captured by Firefox Health Report.
This commit is contained in:
parent
c0a743349c
commit
c97c97b484
@ -383,6 +383,20 @@ NS_IMETHODIMP nsDefaultURIFixup::KeywordToURI(const nsACString& aKeyword,
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
// This notification is meant for Firefox Health Report so it
|
||||
// can increment counts from the search engine. The assumption
|
||||
// here is that this keyword/submission will eventually result
|
||||
// in a search. Since we only generate a URI here, there is the
|
||||
// possibility we'll increment the counter without actually
|
||||
// incurring a search. A robust solution would involve currying
|
||||
// the search engine's name through various function calls.
|
||||
nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
|
||||
if (obsSvc) {
|
||||
nsAutoString name;
|
||||
defaultEngine->GetName(name);
|
||||
obsSvc->NotifyObservers(nullptr, "keyword-search", name.get());
|
||||
}
|
||||
|
||||
return submission->GetUri(aURI);
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ MOCHITEST_BROWSER_FILES = \
|
||||
file_bug234628-11.html \
|
||||
file_bug234628-11-child.xhtml \
|
||||
file_bug234628-11-child.xhtml^headers^ \
|
||||
browser_search_notification.js \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
29
docshell/test/browser/browser_search_notification.js
Normal file
29
docshell/test/browser/browser_search_notification.js
Normal file
@ -0,0 +1,29 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
let tab = gBrowser.addTab();
|
||||
gBrowser.selectedTab = tab;
|
||||
|
||||
function observer(subject, topic, data) {
|
||||
Services.obs.removeObserver(observer, "keyword-search");
|
||||
is(topic, "keyword-search", "Got keyword-search notification");
|
||||
|
||||
let engine = Services.search.originalDefaultEngine;
|
||||
ok(engine, "Have default search engine.");
|
||||
is(engine.name, data, "Notification data is engine name.");
|
||||
|
||||
executeSoon(function cleanup() {
|
||||
gBrowser.removeTab(tab);
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
Services.obs.addObserver(observer, "keyword-search", false);
|
||||
|
||||
gURLBar.value = "firefox health report";
|
||||
gURLBar.handleCommand();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user