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..07e5f1a179cf6bcb3b5df3b73130c34838c532eb 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" |
Joao da Silva
2012/09/28 11:46:10
used?
beaudoin
2012/10/02 17:43:29
Done.
|
#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" |
Joao da Silva
2012/09/28 11:46:10
used?
beaudoin
2012/10/02 17:43:29
Done.
|
#include "testing/gtest/include/gtest/gtest.h" |
#if defined(ENABLE_RLZ) |
@@ -641,3 +643,116 @@ TEST_F(TemplateURLTest, ParseURLNestedParameter) { |
EXPECT_EQ(TemplateURLRef::SEARCH_TERMS, replacements[0].type); |
EXPECT_TRUE(valid); |
} |
+ |
+TEST_F(TemplateURLTest, GetURLNoInstantURL) { |
+ TemplateURLData data; |
+ data.SetURL("http://google.com/?q={searchTerms}"); |
+ data.suggestions_url = "http://google.com/suggest?q={searchTerms}"; |
+ data.alternate_urls.push_back("http://google.com/alt?q={searchTerms}"); |
+ data.alternate_urls.push_back("{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.alternate_urls.push_back("http://google.com/alt?q={searchTerms}"); |
+ data.alternate_urls.push_back("{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.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}"); |
+ data.alternate_urls.push_back("http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar"); |
Joao da Silva
2012/09/28 11:46:10
nit: line length
beaudoin
2012/10/02 17:43:29
Done.
|
+ 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); |
+} |