| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/prerender/prerender_util.h" | 5 #include "chrome/browser/prerender/prerender_util.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "url/gurl.h" | 8 #include "url/gurl.h" |
| 9 | 9 |
| 10 namespace prerender { | 10 namespace prerender { |
| 11 | 11 |
| 12 // Ensure that extracting a urlencoded URL in the url= query string component | 12 // Ensure that we detect GWS origin URLs correctly. |
| 13 // works. | 13 TEST(PrerenderUtilTest, DetectGWSOriginURLTest) { |
| 14 TEST(PrerenderUtilTest, ExtractURLInQueryStringTest) { | 14 EXPECT_TRUE(IsGoogleOriginURL(GURL("http://www.google.com/#asdf"))); |
| 15 GURL result; | 15 EXPECT_TRUE(IsGoogleOriginURL(GURL("http://www.google.com/"))); |
| 16 EXPECT_TRUE(MaybeGetQueryStringBasedAliasURL( | 16 EXPECT_TRUE(IsGoogleOriginURL(GURL("https://www.google.com"))); |
| 17 GURL( | 17 EXPECT_TRUE(IsGoogleOriginURL(GURL("http://www.google.com/?a=b"))); |
| 18 "http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBcQFjAA&url=h" | 18 EXPECT_TRUE(IsGoogleOriginURL(GURL("http://www.google.com/search?q=hi"))); |
| 19 "ttp%3A%2F%2Fwww.abercrombie.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%" | 19 EXPECT_TRUE(IsGoogleOriginURL(GURL("http://google.com"))); |
| 20 "2FStoreLocator%3FcatalogId%3D%26storeId%3D10051%26langId%3D-1&rct=" | 20 EXPECT_TRUE(IsGoogleOriginURL(GURL("http://WWW.GooGLE.CoM"))); |
| 21 "j&q=allinurl%3A%26&ei=KLyUTYGSEdTWiAKUmLCdCQ&usg=AFQjCNF8nJ2MpBFfr" | 21 EXPECT_TRUE(IsGoogleOriginURL(GURL("http://www.google.co.uk"))); |
| 22 "1ijO39_f22bcKyccw&sig2=2ymyGpO0unJwU1d4kdCUjQ"), | 22 // Non-standard ports are allowed for integration tests with the embedded |
| 23 &result)); | 23 // server. |
| 24 ASSERT_EQ(GURL( | 24 EXPECT_TRUE(IsGoogleOriginURL(GURL("http://www.google.com:42/"))); |
| 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()); | |
| 36 } | |
| 37 | 25 |
| 38 // Ensure that we detect Google search result URLs correctly. | 26 EXPECT_FALSE(IsGoogleOriginURL(GURL("http://news.google.com"))); |
| 39 TEST(PrerenderUtilTest, DetectGoogleSearchREsultURLTest) { | 27 EXPECT_FALSE(IsGoogleOriginURL(GURL("http://www.chromium.org"))); |
| 40 EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/#asdf"))); | 28 EXPECT_FALSE(IsGoogleOriginURL(GURL("what://www.google.com"))); |
| 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"))); | |
| 60 } | 29 } |
| 61 | 30 |
| 62 } // namespace prerender | 31 } // namespace prerender |
| OLD | NEW |