Commit 1e1f7378 authored by rogerta@chromium.org's avatar rogerta@chromium.org

Add more flexible handling of what is considered a google home page.

BUG=http:b/5609053
TEST=See unit tests for valid and invalid URLs.

Review URL: http://codereview.chromium.org/8728004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112726 0039d316-1c4b-4281-b951-d872f2087c98
parent a8946f90
......@@ -1739,8 +1739,7 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
PrefService* pref_service = profile_->GetPrefs();
if (pref_service) {
std::string homepage = pref_service->GetString(prefs::kHomePage);
google_search_homepage =
homepage == GoogleURLTracker::kDefaultGoogleHomepage;
google_search_homepage = google_util::IsGoogleHomePageUrl(homepage);
}
RLZTracker::InitRlzDelayed(is_first_run_, master_prefs_->ping_delay,
......
......@@ -128,6 +128,43 @@ bool GetReactivationBrand(std::string* brand) {
#endif
bool IsGoogleHomePageUrl(const std::string& url) {
GURL original_url(url);
if (!original_url.is_valid())
return false;
// Make sure the scheme is valid.
if (!original_url.SchemeIs("http") && !original_url.SchemeIs("https"))
return false;
// Make sure port is default for the respective scheme.
if (!original_url.port().empty())
return false;
// Accept only valid TLD.
size_t tld_length = net::RegistryControlledDomainService::GetRegistryLength(
original_url, false);
if (tld_length == 0 || tld_length == std::string::npos)
return false;
// We only accept "www.google." in front of the TLD.
std::string host = original_url.host();
host = host.substr(0, host.length() - tld_length);
if (!LowerCaseEqualsASCII(host, "www.google.") &&
!LowerCaseEqualsASCII(host, "google."))
return false;
// Make sure the path is a known home page path.
std::string path(original_url.path());
if (!LowerCaseEqualsASCII(path, "/") &&
!LowerCaseEqualsASCII(path, "/webhp") &&
!StartsWithASCII(path, "/ig", false)) {
return false;
}
return true;
}
bool IsOrganic(const std::string& brand) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kOrganicInstall))
......
......@@ -38,6 +38,9 @@ bool GetBrand(std::string* brand);
// install. Returns false if the information is not available.
bool GetReactivationBrand(std::string* brand);
// True if |url| represents a valid Google home page URL.
bool IsGoogleHomePageUrl(const std::string& url);
// True if a build is strictly organic, according to its brand code.
bool IsOrganic(const std::string& brand);
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/google/google_url_tracker.h"
#include "chrome/browser/google/google_util.h"
#include "testing/gtest/include/gtest/gtest.h"
using google_util::IsGoogleHomePageUrl;
TEST(GoogleUtilTest, GoodHomePagesNonSecure) {
// Valid home page hosts.
EXPECT_TRUE(IsGoogleHomePageUrl(GoogleURLTracker::kDefaultGoogleHomepage));
EXPECT_TRUE(IsGoogleHomePageUrl("http://google.com"));
EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com"));
EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.ca"));
EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.co.uk"));
EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com:80/"));
// Only the paths /, /webhp, and /ig.* are valid. Query parameters are
// ignored.
EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/"));
EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/webhp"));
EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/webhp?rlz=TEST"));
EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig"));
EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig/foo"));
EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig?rlz=TEST"));
EXPECT_TRUE(IsGoogleHomePageUrl("http://www.google.com/ig/foo?rlz=TEST"));
}
TEST(GoogleUtilTest, GoodHomePagesSecure) {
// Valid home page hosts.
EXPECT_TRUE(IsGoogleHomePageUrl("https://google.com"));
EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com"));
EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.ca"));
EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.co.uk"));
EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com:443/"));
// Only the paths /, /webhp, and /ig.* are valid. Query parameters are
// ignored.
EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/"));
EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/webhp"));
EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/webhp?rlz=TEST"));
EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/ig"));
EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/ig/foo"));
EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/ig?rlz=TEST"));
EXPECT_TRUE(IsGoogleHomePageUrl("https://www.google.com/ig/foo?rlz=TEST"));
}
TEST(GoogleUtilTest, BadHomePages) {
EXPECT_FALSE(IsGoogleHomePageUrl(""));
// If specified, only the "www" subdomain is OK.
EXPECT_FALSE(IsGoogleHomePageUrl("http://maps.google.com"));
EXPECT_FALSE(IsGoogleHomePageUrl("http://foo.google.com"));
// No non-standard port numbers.
EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com:1234"));
EXPECT_FALSE(IsGoogleHomePageUrl("https://www.google.com:5678"));
// Invalid TLDs.
EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.abc"));
EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com.abc"));
EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.abc.com"));
EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.ab.cd"));
EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.uk.qq"));
// Must be http or https.
EXPECT_FALSE(IsGoogleHomePageUrl("ftp://www.google.com"));
EXPECT_FALSE(IsGoogleHomePageUrl("file://does/not/exist"));
EXPECT_FALSE(IsGoogleHomePageUrl("bad://www.google.com"));
EXPECT_FALSE(IsGoogleHomePageUrl("www.google.com"));
// Only the paths /, /webhp, and /ig.* are valid.
EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/abc"));
EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/webhpabc"));
EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/webhp/abc"));
EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/abcig"));
EXPECT_FALSE(IsGoogleHomePageUrl("http://www.google.com/webhp/ig"));
}
......@@ -1426,6 +1426,7 @@
'browser/global_keyboard_shortcuts_mac_unittest.mm',
'browser/google/google_update_settings_unittest.cc',
'browser/google/google_url_tracker_unittest.cc',
'browser/google/google_util_unittest.cc',
'browser/history/expire_history_backend_unittest.cc',
'browser/history/history_backend_unittest.cc',
'browser/history/history_querying_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment