Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / chrome / browser / prerender / prerender_util_unittest.cc
blob3e316cbb7def50d1b0f52be5f7b7d7db2a17d16a
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/prerender/prerender_util.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "url/gurl.h"
10 namespace prerender {
12 // Ensure that extracting a urlencoded URL in the url= query string component
13 // works.
14 TEST(PrerenderUtilTest, ExtractURLInQueryStringTest) {
15 GURL result;
16 EXPECT_TRUE(MaybeGetQueryStringBasedAliasURL(
17 GURL(
18 "http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBcQFjAA&url=h"
19 "ttp%3A%2F%2Fwww.abercrombie.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%"
20 "2FStoreLocator%3FcatalogId%3D%26storeId%3D10051%26langId%3D-1&rct="
21 "j&q=allinurl%3A%26&ei=KLyUTYGSEdTWiAKUmLCdCQ&usg=AFQjCNF8nJ2MpBFfr"
22 "1ijO39_f22bcKyccw&sig2=2ymyGpO0unJwU1d4kdCUjQ"),
23 &result));
24 ASSERT_EQ(GURL(
25 "http://www.abercrombie.com/webapp/wcs/stores/servlet/StoreLo"
26 "cator?catalogId=&storeId=10051&langId=-1").spec(),
27 result.spec());
28 EXPECT_FALSE(MaybeGetQueryStringBasedAliasURL(
29 GURL("http://www.google.com/url?sadf=test&blah=blahblahblah"), &result));
30 EXPECT_FALSE(MaybeGetQueryStringBasedAliasURL(
31 GURL("http://www.google.com/?url=INVALIDurlsAREsoMUCHfun.com"), &result));
32 EXPECT_TRUE(MaybeGetQueryStringBasedAliasURL(
33 GURL("http://www.google.com/?url=http://validURLSareGREAT.com"),
34 &result));
35 ASSERT_EQ(GURL("http://validURLSareGREAT.com").spec(), result.spec());
38 // Ensure that we detect Google search result URLs correctly.
39 TEST(PrerenderUtilTest, DetectGoogleSearchREsultURLTest) {
40 EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/#asdf")));
41 EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/")));
42 EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/?a=b")));
43 EXPECT_TRUE(IsGoogleSearchResultURL(
44 GURL("http://www.google.com/search?q=hi")));
45 EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/search")));
46 EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/webhp")));
47 EXPECT_TRUE(IsGoogleSearchResultURL(
48 GURL("http://www.google.com/webhp?a=b#123")));
49 EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://www.google.com/imgres")));
50 EXPECT_FALSE(IsGoogleSearchResultURL(
51 GURL("http://www.google.com/imgres?q=hi")));
52 EXPECT_FALSE(IsGoogleSearchResultURL(
53 GURL("http://www.google.com/imgres?q=hi#123")));
54 EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://google.com/search")));
55 EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://WWW.GooGLE.CoM/search")));
56 EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://WWW.GooGLE.CoM/SeArcH")));
57 EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.co.uk/search")));
58 EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://google.co.uk/search")));
59 EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://www.chromium.org/search")));
62 } // namespace prerender