Bug 1102416: make Yahoo the default search plugin for en-US in American time zones, r=dolske, a=me

This commit is contained in:
Gavin Sharp 2014-11-23 20:38:22 -08:00
parent 646d0168f5
commit ce93d8354d
6 changed files with 114 additions and 10 deletions

View File

@ -404,6 +404,11 @@ pref("browser.search.order.1", "chrome://browser-region/locale/re
pref("browser.search.order.2", "chrome://browser-region/locale/region.properties");
pref("browser.search.order.3", "chrome://browser-region/locale/region.properties");
pref("browser.search.defaultenginename.US", "chrome://browser-region/locale/region.properties");
pref("browser.search.order.US.1", "chrome://browser-region/locale/region.properties");
pref("browser.search.order.US.2", "chrome://browser-region/locale/region.properties");
pref("browser.search.order.US.3", "chrome://browser-region/locale/region.properties");
// search bar results always open in a new tab
pref("browser.search.openintab", false);

View File

@ -53,8 +53,9 @@ function test() {
ok(data.days.hasDay(now), "Have data for today.");
let day = data.days.getDay(now);
// Will need to be changed if Google isn't the default search engine.
let field = "google.contextmenu";
// Will need to be changed if Yahoo isn't the default search engine.
let defaultProviderID = "yahoo";
let field = defaultProviderID + ".contextmenu";
ok(day.has(field), "Have search recorded for context menu.");
// If any other mochitests perform a context menu search, this will fail.

View File

@ -27,8 +27,10 @@ add_task(function* test_healthreport_search_recording() {
let now = new Date();
let oldCount = 0;
// This will to be need changed if default search engine is not Google.
let field = "google.urlbar";
// This will to be need changed if default search engine is not Yahoo.
let defaultEngineID = "yahoo";
let field = defaultEngineID + ".urlbar";
if (data.days.hasDay(now)) {
let day = data.days.getDay(now);
@ -71,7 +73,7 @@ add_task(function* test_healthreport_search_recording() {
ok(data.days.hasDay(now), "Have engines data when Telemetry is enabled.");
day = data.days.getDay(now);
ok(day.has("default"), "We have default engine data.");
is(day.get("default"), "google", "The default engine is reported properly.");
is(day.get("default"), defaultEngineID, "The default engine is reported properly.");
// Restore.
Services.prefs.setBoolPref("toolkit.telemetry.enabled", oldTelemetry);

View File

@ -10,6 +10,15 @@ browser.search.order.1=Google
browser.search.order.2=Yahoo
browser.search.order.3=Bing
# Hack for "NA market" only default changes
# These override the equivalents above when the client detects that it is in
# North America
browser.search.defaultenginename.US=Yahoo
browser.search.order.US.1=Yahoo
browser.search.order.US.2=Google
browser.search.order.US.3=Bing
# This is the default set of web based feed handlers shown in the reader
# selection UI
browser.contentHandlers.types.0.title=My Yahoo!

View File

@ -401,6 +401,39 @@ loadListener.prototype = {
onStatus: function (aRequest, aContext, aStatus, aStatusArg) {}
}
// Hacky method that tries to determine if this user is in a US geography, and
// using an en-US build.
function getIsUS() {
// If we've set the pref before, just return that result.
let cachePref = "browser.search.isUS";
try {
return Services.prefs.getBoolPref(cachePref);
} catch(e) {}
if (getLocale() != "en-US") {
Services.prefs.setBoolPref(cachePref, false);
return false;
}
// Timezone assumptions! We assume that if the system clock's timezone is
// between Newfoundland and Hawaii, that the user is in North America.
// This includes all of South America as well, but we have relatively few
// en-US users there, so that's OK.
// 150 minutes = 2.5 hours (UTC-2.5), which is
// Newfoundland Daylight Time (http://www.timeanddate.com/time/zones/ndt)
// 600 minutes = 10 hours (UTC-10), which is
// Hawaii-Aleutian Standard Time (http://www.timeanddate.com/time/zones/hast)
let UTCOffset = (new Date()).getTimezoneOffset();
let isNA = UTCOffset >= 150 && UTCOffset <= 600;
Services.prefs.setBoolPref(cachePref, isNA);
return isNA;
}
/**
* Used to verify a given DOM node's localName and namespaceURI.
@ -2999,8 +3032,16 @@ SearchService.prototype = {
let defaultPrefB = Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF);
let nsIPLS = Ci.nsIPrefLocalizedString;
let defaultEngine;
let defPref;
if (getIsUS()) {
defPref = "defaultenginename.US";
} else {
defPref = "defaultenginename";
}
try {
defaultEngine = defaultPrefB.getComplexValue("defaultenginename", nsIPLS).data;
defaultEngine = defaultPrefB.getComplexValue(defPref, nsIPLS).data;
} catch (ex) {
// If the default pref is invalid (e.g. an add-on set it to a bogus value)
// getEngineByName will just return null, which is the best we can do.
@ -3780,7 +3821,11 @@ SearchService.prototype = {
catch (e) { }
while (true) {
engineName = getLocalizedPref(BROWSER_SEARCH_PREF + "order." + (++i));
prefName = BROWSER_SEARCH_PREF + "order.";
if (getIsUS()) {
prefName += "US.";
}
engineName = getLocalizedPref(prefName + (++i));
if (!engineName)
break;
@ -3942,7 +3987,12 @@ SearchService.prototype = {
// Now look through the "browser.search.order" branch.
for (var j = 1; ; j++) {
engineName = getLocalizedPref(BROWSER_SEARCH_PREF + "order." + j);
var prefName = BROWSER_SEARCH_PREF + "order.";
if (getIsUS()) {
prefName += "US.";
}
prefName += j;
engineName = getLocalizedPref(prefName);
if (!engineName)
break;

View File

@ -8,9 +8,43 @@ const kSelectedEnginePref = "browser.search.selectedEngine";
const kTestEngineName = "Test search engine";
// These two functions (getLocale and getIsUS) are copied from nsSearchService.js
function getLocale() {
let LOCALE_PREF = "general.useragent.locale";
return Services.prefs.getCharPref(LOCALE_PREF);
}
function getIsUS() {
if (getLocale() != "en-US") {
return false;
}
// Timezone assumptions! We assume that if the system clock's timezone is
// between Newfoundland and Hawaii, that the user is in North America.
// This includes all of South America as well, but we have relatively few
// en-US users there, so that's OK.
// 150 minutes = 2.5 hours (UTC-2.5), which is
// Newfoundland Daylight Time (http://www.timeanddate.com/time/zones/ndt)
// 600 minutes = 10 hours (UTC-10), which is
// Hawaii-Aleutian Standard Time (http://www.timeanddate.com/time/zones/hast)
let UTCOffset = (new Date()).getTimezoneOffset();
let isNA = UTCOffset >= 150 && UTCOffset <= 600;
return isNA;
}
function getDefaultEngineName() {
const nsIPLS = Ci.nsIPrefLocalizedString;
return Services.prefs.getComplexValue(kDefaultenginenamePref, nsIPLS).data;
// Copy the logic from nsSearchService
let pref = kDefaultenginenamePref;
if (getIsUS()) {
pref += ".US";
}
return Services.prefs.getComplexValue(pref, nsIPLS).data;
}
function waitForNotification(aExpectedData) {
@ -94,7 +128,10 @@ add_task(function* test_persistAcrossRestarts() {
// Cleanup (set the engine back to default).
Services.search.currentEngine = Services.search.defaultEngine;
do_check_eq(Services.search.currentEngine.name, getDefaultEngineName());
// This check is no longer valid with bug 1102416's patch - defaultEngine
// is not based on the same value as _originalDefaultEngine in non-Firefox
// users of the search service.
//do_check_eq(Services.search.currentEngine.name, getDefaultEngineName());
});
// An engine set without a valid hash should be ignored.