Commit 2d02bea2 authored by tburkard@chromium.org's avatar tburkard@chromium.org

Tighten conditions for when a URL is a search result, and move

it to a different class.
R=ziga, dominich
Review URL: http://codereview.chromium.org/7812011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98895 0039d316-1c4b-4281-b951-d872f2087c98
parent 5a47f866
......@@ -9,7 +9,6 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/string_util.h"
#include "base/time.h"
#include "base/values.h"
#include "base/utf_string_conversions.h"
......@@ -298,11 +297,8 @@ bool PrerenderManager::AddPrerender(
const GURL& referrer) {
DCHECK(CalledOnValidThread());
if (origin == ORIGIN_LINK_REL_PRERENDER &&
StartsWithASCII(referrer.host(), std::string("www.google."), true) &&
!StartsWithASCII(referrer.path(), std::string("/imgres"), true)) {
if (origin == ORIGIN_LINK_REL_PRERENDER && IsGoogleSearchResultURL(referrer))
origin = ORIGIN_GWS_PRERENDER;
}
histograms_->RecordPrerender(origin, url_arg);
......
......@@ -5,6 +5,7 @@
#include "chrome/browser/prerender/prerender_util.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "googleurl/src/url_canon.h"
#include "googleurl/src/url_parse.h"
#include "googleurl/src/url_util.h"
......@@ -61,4 +62,13 @@ uint8 GetQueryStringBasedExperiment(const GURL& url) {
return kNoExperiment;
}
bool IsGoogleSearchResultURL(const GURL& url) {
if (!StartsWithASCII(url.host(), std::string("www.google."), true))
return false;
return (url.path().empty() ||
StartsWithASCII(url.path(), std::string("/search"), true) ||
(url.path() == "/") ||
StartsWithASCII(url.path(), std::string("/webhp"), true));
}
} // namespace prerender
......@@ -24,6 +24,9 @@ bool MaybeGetQueryStringBasedAliasURL(const GURL& url, GURL* alias_url);
// is not an integer in the range 1 to 9.
uint8 GetQueryStringBasedExperiment(const GURL& url);
// Indicates whether the URL provided could be a Google search result page.
bool IsGoogleSearchResultURL(const GURL& url);
} // namespace prerender
#endif // CHROME_BROWSER_PRERENDER_PRERENDER_UTIL_H_
......@@ -34,7 +34,6 @@ TEST_F(PrerenderUtilTest, ExtractURLInQueryStringTest) {
// Ensure that extracting an experiment in the lpe= query string component
// works.
TEST_F(PrerenderUtilTest, ExtractExperimentInQueryStringTest) {
GURL result;
EXPECT_EQ(GetQueryStringBasedExperiment(
GURL("http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBcQFjAA&url=http%3A%2F%2Fwww.abercrombie.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FStoreLocator%3FcatalogId%3D%26storeId%3D10051%26langId%3D-1&rct=j&q=allinurl%3A%26&ei=KLyUTYGSEdTWiAKUmLCdCQ&usg=AFQjCNF8nJ2MpBFfr1ijO39_f22bcKyccw&sig2=2ymyGpO0unJwU1d4kdCUjQ&lpe=4&asdf=test")), 4);
EXPECT_EQ(GetQueryStringBasedExperiment(
......@@ -49,4 +48,28 @@ TEST_F(PrerenderUtilTest, ExtractExperimentInQueryStringTest) {
GURL("http://www.google.com/test.php?lpe=10")), kNoExperiment);
}
// Ensure that we detect Google search result URLs correctly.
TEST_F(PrerenderUtilTest, DetectGoogleSearchREsultURLTest) {
EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/#asdf")));
EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/")));
EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/?a=b")));
EXPECT_TRUE(IsGoogleSearchResultURL(
GURL("http://www.google.com/search?q=hi")));
EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/search")));
EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/webhp")));
EXPECT_TRUE(IsGoogleSearchResultURL(
GURL("http://www.google.com/webhp?a=b#123")));
EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://www.google.com/imgres")));
EXPECT_FALSE(IsGoogleSearchResultURL(
GURL("http://www.google.com/imgres?q=hi")));
EXPECT_FALSE(IsGoogleSearchResultURL(
GURL("http://www.google.com/imgres?q=hi#123")));
EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://google.com/search")));
EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://WWW.GooGLE.CoM/search")));
EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://WWW.GooGLE.CoM/SeArcH")));
EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.co.uk/search")));
EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://google.co.uk/search")));
EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://www.chromium.org/search")));
}
} // namespace prerender
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