| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/base_paths.h" | 5 #include "base/base_paths.h" |
| 6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/rlz/rlz.h" | 9 #include "chrome/browser/rlz/rlz.h" |
| 10 #include "chrome/browser/search_engines/search_terms_data.h" | 10 #include "chrome/browser/search_engines/search_terms_data.h" |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 std::string expected_url = "http://bar/?"; | 532 std::string expected_url = "http://bar/?"; |
| 533 if (!rlz_string.empty()) | 533 if (!rlz_string.empty()) |
| 534 expected_url += "rlz=" + UTF16ToUTF8(rlz_string) + "&"; | 534 expected_url += "rlz=" + UTF16ToUTF8(rlz_string) + "&"; |
| 535 expected_url += "x"; | 535 expected_url += "x"; |
| 536 EXPECT_EQ(expected_url, result.spec()); | 536 EXPECT_EQ(expected_url, result.spec()); |
| 537 } | 537 } |
| 538 | 538 |
| 539 TEST_F(TemplateURLTest, HostAndSearchTermKey) { | 539 TEST_F(TemplateURLTest, HostAndSearchTermKey) { |
| 540 struct TestData { | 540 struct TestData { |
| 541 const std::string url; | 541 const std::string url; |
| 542 const std::string scheme; | |
| 543 const std::string host; | 542 const std::string host; |
| 544 const std::string path; | 543 const std::string path; |
| 545 const std::string search_term_key; | 544 const std::string search_term_key; |
| 546 } test_data[] = { | 545 } test_data[] = { |
| 547 { "http://blah/?foo=bar&q={searchTerms}&b=x", "http", "blah", "/", "q"}, | 546 { "http://blah/?foo=bar&q={searchTerms}&b=x", "blah", "/", "q"}, |
| 548 | 547 |
| 549 // No query key should result in empty values. | 548 // No query key should result in empty values. |
| 550 { "http://blah/{searchTerms}", "", "", "", ""}, | 549 { "http://blah/{searchTerms}", "", "", ""}, |
| 551 | 550 |
| 552 // No term should result in empty values. | 551 // No term should result in empty values. |
| 553 { "http://blah/", "", "", "", ""}, | 552 { "http://blah/", "", "", ""}, |
| 554 | 553 |
| 555 // Multiple terms should result in empty values. | 554 // Multiple terms should result in empty values. |
| 556 { "http://blah/?q={searchTerms}&x={searchTerms}", "", "", "", ""}, | 555 { "http://blah/?q={searchTerms}&x={searchTerms}", "", "", ""}, |
| 557 | 556 |
| 558 // Term in the host shouldn't match. | 557 // Term in the host shouldn't match. |
| 559 { "http://{searchTerms}", "", "", "", ""}, | 558 { "http://{searchTerms}", "", "", ""}, |
| 560 | 559 |
| 561 { "http://blah/?q={searchTerms}", "http", "blah", "/", "q"}, | 560 { "http://blah/?q={searchTerms}", "blah", "/", "q"}, |
| 562 { "https://blah/?q={searchTerms}", "https", "blah", "/", "q"}, | 561 { "https://blah/?q={searchTerms}", "blah", "/", "q"}, |
| 563 | 562 |
| 564 // Single term with extra chars in value should match. | 563 // Single term with extra chars in value should match. |
| 565 { "http://blah/?q=stock:{searchTerms}", "http", "blah", "/", "q"}, | 564 { "http://blah/?q=stock:{searchTerms}", "blah", "/", "q"}, |
| 566 }; | 565 }; |
| 567 | 566 |
| 568 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 567 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { |
| 569 TemplateURLData data; | 568 TemplateURLData data; |
| 570 data.SetURL(test_data[i].url); | 569 data.SetURL(test_data[i].url); |
| 571 TemplateURL url(NULL, data); | 570 TemplateURL url(NULL, data); |
| 572 EXPECT_EQ(test_data[i].scheme, url.url_ref().GetScheme()); | |
| 573 EXPECT_EQ(test_data[i].host, url.url_ref().GetHost()); | 571 EXPECT_EQ(test_data[i].host, url.url_ref().GetHost()); |
| 574 EXPECT_EQ(test_data[i].path, url.url_ref().GetPath()); | 572 EXPECT_EQ(test_data[i].path, url.url_ref().GetPath()); |
| 575 EXPECT_EQ(test_data[i].search_term_key, url.url_ref().GetSearchTermKey()); | 573 EXPECT_EQ(test_data[i].search_term_key, url.url_ref().GetSearchTermKey()); |
| 576 } | 574 } |
| 577 } | 575 } |
| 578 | 576 |
| 579 TEST_F(TemplateURLTest, GoogleBaseSuggestURL) { | 577 TEST_F(TemplateURLTest, GoogleBaseSuggestURL) { |
| 580 static const struct { | 578 static const struct { |
| 581 const char* const base_url; | 579 const char* const base_url; |
| 582 const char* const base_suggest_url; | 580 const char* const base_suggest_url; |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | 918 EXPECT_TRUE(url.HasSearchTermsReplacementKey( |
| 921 GURL("http://google.com/?q=something#espv=1"))); | 919 GURL("http://google.com/?q=something#espv=1"))); |
| 922 | 920 |
| 923 // This does not ensure the domain matches. | 921 // This does not ensure the domain matches. |
| 924 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | 922 EXPECT_TRUE(url.HasSearchTermsReplacementKey( |
| 925 GURL("http://bing.com/?espv"))); | 923 GURL("http://bing.com/?espv"))); |
| 926 | 924 |
| 927 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | 925 EXPECT_TRUE(url.HasSearchTermsReplacementKey( |
| 928 GURL("http://bing.com/#espv"))); | 926 GURL("http://bing.com/#espv"))); |
| 929 } | 927 } |
| 930 | |
| 931 TEST_F(TemplateURLTest, IsInstantURL) { | |
| 932 TemplateURLData data; | |
| 933 data.SetURL("http://google.com/?q={searchTerms}"); | |
| 934 data.instant_url = "http://google.com/instant#q={searchTerms}"; | |
| 935 data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}"); | |
| 936 data.alternate_urls.push_back( | |
| 937 "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar"); | |
| 938 data.search_terms_replacement_key = "espv"; | |
| 939 TemplateURL url(NULL, data); | |
| 940 | |
| 941 EXPECT_FALSE(url.IsInstantURL( | |
| 942 GURL("http://google.com/"))); | |
| 943 | |
| 944 EXPECT_TRUE(url.IsInstantURL( | |
| 945 GURL("http://google.com/?espv"))); | |
| 946 | |
| 947 EXPECT_TRUE(url.IsInstantURL( | |
| 948 GURL("http://google.com/#espv"))); | |
| 949 | |
| 950 EXPECT_FALSE(url.IsInstantURL( | |
| 951 GURL("http://google.com/?q=something"))); | |
| 952 | |
| 953 EXPECT_TRUE(url.IsInstantURL( | |
| 954 GURL("http://google.com/instant?q=something"))); | |
| 955 | |
| 956 EXPECT_TRUE(url.IsInstantURL( | |
| 957 GURL("http://google.com/instant?x=something"))); | |
| 958 | |
| 959 EXPECT_TRUE(url.IsInstantURL( | |
| 960 GURL("http://google.com/?q=something&espv"))); | |
| 961 | |
| 962 EXPECT_TRUE(url.IsInstantURL( | |
| 963 GURL("http://google.com/?q=something&espv=1"))); | |
| 964 | |
| 965 EXPECT_FALSE(url.IsInstantURL( | |
| 966 GURL("https://google.com/?q=something&espv=1"))); | |
| 967 | |
| 968 EXPECT_TRUE(url.IsInstantURL( | |
| 969 GURL("http://google.com/?q=something&espv=0"))); | |
| 970 | |
| 971 EXPECT_TRUE(url.IsInstantURL( | |
| 972 GURL("http://google.com/?espv&q=something"))); | |
| 973 | |
| 974 EXPECT_TRUE(url.IsInstantURL( | |
| 975 GURL("http://google.com/?espv=1&q=something"))); | |
| 976 | |
| 977 EXPECT_TRUE(url.IsInstantURL( | |
| 978 GURL("http://google.com/?espv=0&q=something"))); | |
| 979 | |
| 980 EXPECT_FALSE(url.IsInstantURL( | |
| 981 GURL("http://google.com/alt/#q=something"))); | |
| 982 | |
| 983 EXPECT_TRUE(url.IsInstantURL( | |
| 984 GURL("http://google.com/alt/#q=something&espv"))); | |
| 985 | |
| 986 EXPECT_TRUE(url.IsInstantURL( | |
| 987 GURL("http://google.com/alt/#q=something&espv=1"))); | |
| 988 | |
| 989 EXPECT_TRUE(url.IsInstantURL( | |
| 990 GURL("http://google.com/alt/#q=something&espv=0"))); | |
| 991 | |
| 992 EXPECT_TRUE(url.IsInstantURL( | |
| 993 GURL("http://google.com/alt/#espv&q=something"))); | |
| 994 | |
| 995 EXPECT_TRUE(url.IsInstantURL( | |
| 996 GURL("http://google.com/alt/#espv=1&q=something"))); | |
| 997 | |
| 998 EXPECT_TRUE(url.IsInstantURL( | |
| 999 GURL("http://google.com/alt/#espv=0&q=something"))); | |
| 1000 | |
| 1001 EXPECT_TRUE(url.IsInstantURL( | |
| 1002 GURL("http://google.com/?espv#q=something"))); | |
| 1003 | |
| 1004 EXPECT_TRUE(url.IsInstantURL( | |
| 1005 GURL("http://google.com/?espv=1#q=something"))); | |
| 1006 | |
| 1007 EXPECT_TRUE(url.IsInstantURL( | |
| 1008 GURL("http://google.com/?q=something#espv"))); | |
| 1009 | |
| 1010 EXPECT_TRUE(url.IsInstantURL( | |
| 1011 GURL("http://google.com/?q=something#espv=1"))); | |
| 1012 | |
| 1013 EXPECT_TRUE(url.IsInstantURL( | |
| 1014 GURL("http://google.com/instant#q=something&espv=1"))); | |
| 1015 | |
| 1016 EXPECT_FALSE(url.IsInstantURL( | |
| 1017 GURL("http://bing.com/?espv=1"))); | |
| 1018 | |
| 1019 EXPECT_FALSE(url.IsInstantURL( | |
| 1020 GURL("http://bing.com/#espv=1"))); | |
| 1021 } | |
| OLD | NEW |