Home | History | Annotate | Download | only in prerender
      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.
      4 
      5 #include "chrome/browser/prerender/prerender_util.h"
      6 #include "testing/gtest/include/gtest/gtest.h"
      7 
      8 namespace prerender {
      9 
     10 class PrerenderUtilTest : public testing::Test {
     11  public:
     12   PrerenderUtilTest() {
     13   }
     14 };
     15 
     16 // Ensure that extracting a urlencoded URL in the url= query string component
     17 // works.
     18 TEST_F(PrerenderUtilTest, ExtractURLInQueryStringTest) {
     19   GURL result;
     20   EXPECT_TRUE(MaybeGetQueryStringBasedAliasURL(
     21       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"),
     22       &result));
     23   ASSERT_EQ(GURL("http://www.abercrombie.com/webapp/wcs/stores/servlet/StoreLocator?catalogId=&storeId=10051&langId=-1").spec(), result.spec());
     24   EXPECT_FALSE(MaybeGetQueryStringBasedAliasURL(
     25       GURL("http://www.google.com/url?sadf=test&blah=blahblahblah"), &result));
     26   EXPECT_FALSE(MaybeGetQueryStringBasedAliasURL(
     27       GURL("http://www.google.com/?url=INVALIDurlsAREsoMUCHfun.com"), &result));
     28   EXPECT_TRUE(MaybeGetQueryStringBasedAliasURL(
     29       GURL("http://www.google.com/?url=http://validURLSareGREAT.com"),
     30       &result));
     31   ASSERT_EQ(GURL("http://validURLSareGREAT.com").spec(), result.spec());
     32 }
     33 
     34 // Ensure that extracting an experiment in the lpe= query string component
     35 // works.
     36 TEST_F(PrerenderUtilTest, ExtractExperimentInQueryStringTest) {
     37   EXPECT_EQ(GetQueryStringBasedExperiment(
     38       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);
     39   EXPECT_EQ(GetQueryStringBasedExperiment(
     40       GURL("http://www.google.com/test.php?a=b")), kNoExperiment);
     41   EXPECT_EQ(GetQueryStringBasedExperiment(
     42       GURL("http://www.google.com/test.php?lpe=5")), 5);
     43   EXPECT_EQ(GetQueryStringBasedExperiment(
     44       GURL("http://www.google.com/test.php?lpe=50")), kNoExperiment);
     45   EXPECT_EQ(GetQueryStringBasedExperiment(
     46       GURL("http://www.google.com/test.php?lpe=0")), kNoExperiment);
     47   EXPECT_EQ(GetQueryStringBasedExperiment(
     48       GURL("http://www.google.com/test.php?lpe=10")), kNoExperiment);
     49 }
     50 
     51 // Ensure that we detect Google search result URLs correctly.
     52 TEST_F(PrerenderUtilTest, DetectGoogleSearchREsultURLTest) {
     53   EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/#asdf")));
     54   EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/")));
     55   EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/?a=b")));
     56   EXPECT_TRUE(IsGoogleSearchResultURL(
     57       GURL("http://www.google.com/search?q=hi")));
     58   EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/search")));
     59   EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/webhp")));
     60   EXPECT_TRUE(IsGoogleSearchResultURL(
     61       GURL("http://www.google.com/webhp?a=b#123")));
     62   EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://www.google.com/imgres")));
     63   EXPECT_FALSE(IsGoogleSearchResultURL(
     64       GURL("http://www.google.com/imgres?q=hi")));
     65   EXPECT_FALSE(IsGoogleSearchResultURL(
     66       GURL("http://www.google.com/imgres?q=hi#123")));
     67   EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://google.com/search")));
     68   EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://WWW.GooGLE.CoM/search")));
     69   EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://WWW.GooGLE.CoM/SeArcH")));
     70   EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.co.uk/search")));
     71   EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://google.co.uk/search")));
     72   EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://www.chromium.org/search")));
     73 }
     74 
     75 }  // namespace prerender
     76