Index: chrome/browser/search_engines/template_url_unittest.cc |
diff --git a/chrome/browser/search_engines/template_url_unittest.cc b/chrome/browser/search_engines/template_url_unittest.cc |
index 089c1a1dab00494425ae7a3afceb7df39a2337a2..4a8244ff62cccbec166d9100a366a466b9960a04 100644 |
--- a/chrome/browser/search_engines/template_url_unittest.cc |
+++ b/chrome/browser/search_engines/template_url_unittest.cc |
@@ -3,12 +3,14 @@ |
// found in the LICENSE file. |
#include "base/base_paths.h" |
+#include "base/command_line.h" |
#include "base/string_util.h" |
#include "base/utf_string_conversions.h" |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/rlz/rlz.h" |
#include "chrome/browser/search_engines/search_terms_data.h" |
#include "chrome/browser/search_engines/template_url.h" |
+#include "chrome/common/chrome_switches.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#if defined(ENABLE_RLZ) |
@@ -641,3 +643,170 @@ TEST_F(TemplateURLTest, ParseURLNestedParameter) { |
EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type); |
EXPECT_TRUE(valid); |
} |
+ |
+TEST_F(TemplateURLTest, DeserializeAndSetAlternateURLs) { |
+ TemplateURLData data; |
+ EXPECT_TRUE(data.alternate_urls().empty()); |
+ |
+ data.DeserializeAndSetAlternateURLs("http://google.com?q={searchTerms}," |
+ "{google:baseURL}/#q={searchTerms}"); |
+ EXPECT_EQ(2U, data.alternate_urls().size()); |
+ EXPECT_EQ("http://google.com?q={searchTerms}", data.alternate_urls()[0]); |
+ EXPECT_EQ("{google:baseURL}/#q={searchTerms}", data.alternate_urls()[1]); |
+} |
+ |
+ |
+TEST_F(TemplateURLTest, DeserializeAndSetEmptyAlternateURLs) { |
+ TemplateURLData data; |
+ EXPECT_TRUE(data.alternate_urls().empty()); |
+ |
+ data.DeserializeAndSetAlternateURLs(""); |
+ EXPECT_TRUE(data.alternate_urls().empty()); |
+} |
+ |
+TEST_F(TemplateURLTest, SerializeAlternateURLs) { |
+ TemplateURLData data; |
+ EXPECT_TRUE(data.alternate_urls().empty()); |
+ data.alternate_urls_.push_back("{google:baseURL}/#q={searchTerms}"); |
+ data.alternate_urls_.push_back("http://google.com?q={searchTerms}"); |
+ |
+ std::string result = data.SerializeAlternateURLs(); |
+ EXPECT_EQ("{google:baseURL}/#q={searchTerms}," |
+ "http://google.com?q={searchTerms}", result); |
+} |
+ |
+TEST_F(TemplateURLTest, SerializeEmptyAlternateURLs) { |
+ TemplateURLData data; |
+ EXPECT_TRUE(data.alternate_urls().empty()); |
+ |
+ std::string result = data.SerializeAlternateURLs(); |
+ EXPECT_EQ("", result); |
+} |
+ |
+TEST_F(TemplateURLTest, GetURL) { |
+ TemplateURLData data; |
+ data.SetURL("http://google.com/?q={searchTerms}"); |
+ data.suggestions_url = "http://google.com/suggest?q={searchTerms}"; |
+ data.instant_url = "http://google.com/instant#q={searchTerms}"; |
+ data.DeserializeAndSetAlternateURLs("http://google.com/alt?q={searchTerms}," |
+ "{google:baseURL}/alt/#q={searchTerms}"); |
+ TemplateURL url(NULL, data); |
+ ASSERT_EQ(3U, url.URLCount()); |
+ EXPECT_EQ("http://google.com/alt?q={searchTerms}", url.GetURL(0)); |
+ EXPECT_EQ("{google:baseURL}/alt/#q={searchTerms}", url.GetURL(1)); |
+ EXPECT_EQ("http://google.com/?q={searchTerms}", url.GetURL(2)); |
+} |
+ |
+TEST_F(TemplateURLTest, GetURLNoInstantURL) { |
+ TemplateURLData data; |
+ data.SetURL("http://google.com/?q={searchTerms}"); |
+ data.suggestions_url = "http://google.com/suggest?q={searchTerms}"; |
+ data.DeserializeAndSetAlternateURLs("http://google.com/alt?q={searchTerms}," |
+ "{google:baseURL}/alt/#q={searchTerms}"); |
+ TemplateURL url(NULL, data); |
+ ASSERT_EQ(3U, url.URLCount()); |
+ EXPECT_EQ("http://google.com/alt?q={searchTerms}", url.GetURL(0)); |
+ EXPECT_EQ("{google:baseURL}/alt/#q={searchTerms}", url.GetURL(1)); |
+ EXPECT_EQ("http://google.com/?q={searchTerms}", url.GetURL(2)); |
+} |
+ |
+TEST_F(TemplateURLTest, GetURLNoSuggestionsURL) { |
+ TemplateURLData data; |
+ data.SetURL("http://google.com/?q={searchTerms}"); |
+ data.instant_url = "http://google.com/instant#q={searchTerms}"; |
+ data.DeserializeAndSetAlternateURLs("http://google.com/alt?q={searchTerms}," |
+ "{google:baseURL}/alt/#q={searchTerms}"); |
+ TemplateURL url(NULL, data); |
+ ASSERT_EQ(3U, url.URLCount()); |
+ EXPECT_EQ("http://google.com/alt?q={searchTerms}", url.GetURL(0)); |
+ EXPECT_EQ("{google:baseURL}/alt/#q={searchTerms}", url.GetURL(1)); |
+ EXPECT_EQ("http://google.com/?q={searchTerms}", url.GetURL(2)); |
+} |
+ |
+TEST_F(TemplateURLTest, GetURLOnlyOneURL) { |
+ TemplateURLData data; |
+ data.SetURL("http://www.google.co.uk/"); |
+ TemplateURL url(NULL, data); |
+ ASSERT_EQ(1U, url.URLCount()); |
+ EXPECT_EQ("http://www.google.co.uk/", url.GetURL(0)); |
+} |
+ |
+TEST_F(TemplateURLTest, ExtractSearchTermsFromURL) { |
+ TemplateURLData data; |
+ data.SetURL("http://google.com/?q={searchTerms}"); |
+ data.instant_url = "http://google.com/instant#q={searchTerms}"; |
+ data.DeserializeAndSetAlternateURLs( |
+ "http://google.com/alt/#q={searchTerms}," |
+ "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar"); |
+ TemplateURL url(NULL, data); |
+ string16 result; |
+ |
+ EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( |
+ GURL("http://google.com/?q=something"), &result)); |
+ EXPECT_EQ(string16(), result); |
+ |
+ EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( |
+ GURL("http://google.com/?q=something#espv=1"), &result)); |
+ EXPECT_EQ(string16(), result); |
+ |
+ EXPECT_TRUE(url.ExtractSearchTermsFromInstantExtendedURL( |
+ GURL("http://google.com/?q=something&espv=1"), &result)); |
+ EXPECT_EQ(ASCIIToUTF16("something"), result); |
+ |
+ EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( |
+ GURL("http://google.ca/?q=something&espv=1"), &result)); |
+ EXPECT_EQ(string16(), result); |
+ |
+ EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( |
+ GURL("http://google.com/foo/?q=foo&espv=1"), &result)); |
+ EXPECT_EQ(string16(), result); |
+ |
+ EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( |
+ GURL("https://google.com/?q=foo&espv=1"), &result)); |
+ EXPECT_EQ(string16(), result); |
+ |
+ EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( |
+ GURL("http://google.com:8080/?q=foo&espv=1"), &result)); |
+ EXPECT_EQ(string16(), result); |
+ |
+ EXPECT_TRUE(url.ExtractSearchTermsFromInstantExtendedURL( |
+ GURL("http://google.com/?q=1+2+3&b=456&espv=1"), &result)); |
+ EXPECT_EQ(ASCIIToUTF16("1 2 3"), result); |
+ |
+ EXPECT_TRUE(url.ExtractSearchTermsFromInstantExtendedURL( |
+ GURL("http://google.com/alt/?espv=1&q=123#q=456"), &result)); |
+ EXPECT_EQ(ASCIIToUTF16("456"), result); |
+ |
+ EXPECT_TRUE(url.ExtractSearchTermsFromInstantExtendedURL( |
+ GURL("http://google.com/alt/?espv=1&a=012&q=123&b=456#f=789"), &result)); |
+ EXPECT_EQ(ASCIIToUTF16("123"), result); |
+ |
+ EXPECT_TRUE(url.ExtractSearchTermsFromInstantExtendedURL(GURL( |
+ "http://google.com/alt/?a=012&q=123&espv=1&b=456#j=abc&q=789&h=def9"), |
+ &result)); |
+ EXPECT_EQ(ASCIIToUTF16("789"), result); |
+ |
+ EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( |
+ GURL("http://google.com/alt/?espv=1&q="), &result)); |
+ EXPECT_EQ(string16(), result); |
+ |
+ EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( |
+ GURL("http://google.com/alt/?q=&espv=1"), &result)); |
+ EXPECT_EQ(string16(), result); |
+ |
+ EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( |
+ GURL("http://google.com/alt/?espv=1#q="), &result)); |
+ EXPECT_EQ(string16(), result); |
+ |
+ EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( |
+ GURL("http://google.com/alt/?espv=1&q=#q="), &result)); |
+ EXPECT_EQ(string16(), result); |
+ |
+ EXPECT_FALSE(url.ExtractSearchTermsFromInstantExtendedURL( |
+ GURL("http://google.com/alt/?espv=1&q=123#q="), &result)); |
+ EXPECT_EQ(string16(), result); |
+ |
+ EXPECT_TRUE(url.ExtractSearchTermsFromInstantExtendedURL( |
+ GURL("http://google.com/alt/?espv=1&q=#q=123"), &result)); |
+ EXPECT_EQ(ASCIIToUTF16("123"), result); |
+} |