Chromium Code Reviews| 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 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 data.SetURL("http://google.com/?q={searchTerms}"); | 751 data.SetURL("http://google.com/?q={searchTerms}"); |
| 752 data.instant_url = "http://google.com/instant#q={searchTerms}"; | 752 data.instant_url = "http://google.com/instant#q={searchTerms}"; |
| 753 data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}"); | 753 data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}"); |
| 754 data.alternate_urls.push_back( | 754 data.alternate_urls.push_back( |
| 755 "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar"); | 755 "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar"); |
| 756 TemplateURL url(NULL, data); | 756 TemplateURL url(NULL, data); |
| 757 string16 result; | 757 string16 result; |
| 758 | 758 |
| 759 EXPECT_TRUE(url.ExtractSearchTermsFromURL( | 759 EXPECT_TRUE(url.ExtractSearchTermsFromURL( |
| 760 GURL("http://google.com/?q=something"), &result)); | 760 GURL("http://google.com/?q=something"), &result)); |
| 761 | |
| 762 EXPECT_EQ(ASCIIToUTF16("something"), result); | |
| 763 | |
| 764 EXPECT_TRUE(url.ExtractSearchTermsFromURL( | |
| 765 GURL("http://google.com/?espv&q=something"), &result)); | |
| 766 EXPECT_EQ(ASCIIToUTF16("something"), result); | |
| 767 | |
| 768 EXPECT_TRUE(url.ExtractSearchTermsFromURL( | |
| 769 GURL("http://google.com/?espv=1&q=something"), &result)); | |
| 770 EXPECT_EQ(ASCIIToUTF16("something"), result); | |
| 771 | |
| 772 EXPECT_TRUE(url.ExtractSearchTermsFromURL( | |
| 773 GURL("http://google.com/?espv=0&q=something"), &result)); | |
| 774 EXPECT_EQ(ASCIIToUTF16("something"), result); | |
| 775 | |
| 776 EXPECT_TRUE(url.ExtractSearchTermsFromURL( | |
| 777 GURL("http://google.com/alt/#q=something"), &result)); | |
| 778 EXPECT_EQ(ASCIIToUTF16("something"), result); | |
| 779 | |
| 780 EXPECT_TRUE(url.ExtractSearchTermsFromURL( | |
| 781 GURL("http://google.com/alt/#espv&q=something"), &result)); | |
| 782 EXPECT_EQ(ASCIIToUTF16("something"), result); | |
| 783 | |
| 784 EXPECT_TRUE(url.ExtractSearchTermsFromURL( | |
| 785 GURL("http://google.com/alt/#espv=1&q=something"), &result)); | |
| 786 EXPECT_EQ(ASCIIToUTF16("something"), result); | |
| 787 | |
| 788 EXPECT_TRUE(url.ExtractSearchTermsFromURL( | |
| 789 GURL("http://google.com/alt/#espv=0&q=something"), &result)); | |
| 790 | |
| 761 EXPECT_EQ(ASCIIToUTF16("something"), result); | 791 EXPECT_EQ(ASCIIToUTF16("something"), result); |
| 762 | 792 |
| 763 EXPECT_FALSE(url.ExtractSearchTermsFromURL( | 793 EXPECT_FALSE(url.ExtractSearchTermsFromURL( |
| 764 GURL("http://google.ca/?q=something"), &result)); | 794 GURL("http://google.ca/?q=something"), &result)); |
| 765 EXPECT_EQ(string16(), result); | 795 EXPECT_EQ(string16(), result); |
| 766 | 796 |
| 767 EXPECT_FALSE(url.ExtractSearchTermsFromURL( | 797 EXPECT_FALSE(url.ExtractSearchTermsFromURL( |
| 768 GURL("http://google.com/foo/?q=foo"), &result)); | 798 GURL("http://google.com/foo/?q=foo"), &result)); |
| 769 EXPECT_EQ(string16(), result); | 799 EXPECT_EQ(string16(), result); |
| 770 | 800 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 805 EXPECT_EQ(string16(), result); | 835 EXPECT_EQ(string16(), result); |
| 806 | 836 |
| 807 EXPECT_FALSE(url.ExtractSearchTermsFromURL( | 837 EXPECT_FALSE(url.ExtractSearchTermsFromURL( |
| 808 GURL("http://google.com/alt/?q=123#q="), &result)); | 838 GURL("http://google.com/alt/?q=123#q="), &result)); |
| 809 EXPECT_EQ(string16(), result); | 839 EXPECT_EQ(string16(), result); |
| 810 | 840 |
| 811 EXPECT_TRUE(url.ExtractSearchTermsFromURL( | 841 EXPECT_TRUE(url.ExtractSearchTermsFromURL( |
| 812 GURL("http://google.com/alt/?q=#q=123"), &result)); | 842 GURL("http://google.com/alt/?q=#q=123"), &result)); |
| 813 EXPECT_EQ(ASCIIToUTF16("123"), result); | 843 EXPECT_EQ(ASCIIToUTF16("123"), result); |
| 814 } | 844 } |
| 845 | |
| 846 | |
|
Joao da Silva
2013/01/08 21:38:20
nit: single newline?
beaudoin
2013/01/08 21:46:51
Done.
| |
| 847 TEST_F(TemplateURLTest, HasSearchTermsReplacementKey) { | |
| 848 TemplateURLData data; | |
| 849 data.SetURL("http://google.com/?q={searchTerms}"); | |
| 850 data.instant_url = "http://google.com/instant#q={searchTerms}"; | |
| 851 data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}"); | |
| 852 data.alternate_urls.push_back( | |
| 853 "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar"); | |
| 854 data.search_terms_replacement_key = "espv"; | |
| 855 TemplateURL url(NULL, data); | |
| 856 | |
| 857 // Test with instant enabled required. | |
| 858 EXPECT_FALSE(url.HasSearchTermsReplacementKey( | |
| 859 GURL("http://google.com/"))); | |
| 860 | |
| 861 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 862 GURL("http://google.com/?espv"))); | |
| 863 | |
| 864 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 865 GURL("http://google.com/#espv"))); | |
| 866 | |
| 867 EXPECT_FALSE(url.HasSearchTermsReplacementKey( | |
| 868 GURL("http://google.com/?q=something"))); | |
| 869 | |
| 870 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 871 GURL("http://google.com/?q=something&espv"))); | |
| 872 | |
| 873 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 874 GURL("http://google.com/?q=something&espv=1"))); | |
| 875 | |
| 876 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 877 GURL("http://google.com/?q=something&espv=0"))); | |
| 878 | |
| 879 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 880 GURL("http://google.com/?espv&q=something"))); | |
| 881 | |
| 882 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 883 GURL("http://google.com/?espv=1&q=something"))); | |
| 884 | |
| 885 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 886 GURL("http://google.com/?espv=0&q=something"))); | |
| 887 | |
| 888 EXPECT_FALSE(url.HasSearchTermsReplacementKey( | |
| 889 GURL("http://google.com/alt/#q=something"))); | |
| 890 | |
| 891 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 892 GURL("http://google.com/alt/#q=something&espv"))); | |
| 893 | |
| 894 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 895 GURL("http://google.com/alt/#q=something&espv=1"))); | |
| 896 | |
| 897 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 898 GURL("http://google.com/alt/#q=something&espv=0"))); | |
| 899 | |
| 900 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 901 GURL("http://google.com/alt/#espv&q=something"))); | |
| 902 | |
| 903 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 904 GURL("http://google.com/alt/#espv=1&q=something"))); | |
| 905 | |
| 906 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 907 GURL("http://google.com/alt/#espv=0&q=something"))); | |
| 908 | |
| 909 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 910 GURL("http://google.com/?espv#q=something"))); | |
| 911 | |
| 912 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 913 GURL("http://google.com/?espv=1#q=something"))); | |
| 914 | |
| 915 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 916 GURL("http://google.com/?q=something#espv"))); | |
| 917 | |
| 918 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 919 GURL("http://google.com/?q=something#espv=1"))); | |
| 920 | |
| 921 // This does not ensure the domain matches. | |
| 922 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 923 GURL("http://bing.com/?espv"))); | |
| 924 | |
| 925 EXPECT_TRUE(url.HasSearchTermsReplacementKey( | |
| 926 GURL("http://bing.com/#espv"))); | |
| 927 } | |
| OLD | NEW |