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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 EXPECT_EQ("http://instant", default_turl->instant_url()); | 915 EXPECT_EQ("http://instant", default_turl->instant_url()); |
916 EXPECT_EQ(id, default_turl->id()); | 916 EXPECT_EQ(id, default_turl->id()); |
917 | 917 |
918 // Now do a load and make sure the default search provider really takes. | 918 // Now do a load and make sure the default search provider really takes. |
919 test_util_.VerifyLoad(); | 919 test_util_.VerifyLoad(); |
920 | 920 |
921 ASSERT_TRUE(model()->GetDefaultSearchProvider()); | 921 ASSERT_TRUE(model()->GetDefaultSearchProvider()); |
922 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); | 922 AssertEquals(*cloned_url, *model()->GetDefaultSearchProvider()); |
923 } | 923 } |
924 | 924 |
| 925 TEST_F(TemplateURLServiceTest, ResetNonExtensionURLs) { |
| 926 test_util_.VerifyLoad(); |
| 927 |
| 928 TemplateURL* new_provider = AddKeywordWithDate( |
| 929 "short_name", "keyword", "http://test.com/search?t={searchTerms}", |
| 930 std::string(), std::string(), std::string(), |
| 931 true, "UTF-8", Time(), Time()); |
| 932 model()->SetDefaultSearchProvider(new_provider); |
| 933 AddKeywordWithDate( |
| 934 "extension1", "ext_keyword", |
| 935 std::string(extensions::kExtensionScheme) + "://test1", std::string(), |
| 936 std::string(), std::string(), false, "UTF-8", Time(), Time()); |
| 937 TemplateURL* default_provider = model()->GetDefaultSearchProvider(); |
| 938 EXPECT_NE(SEARCH_ENGINE_GOOGLE, |
| 939 TemplateURLPrepopulateData::GetEngineType(default_provider->url())); |
| 940 |
| 941 // Non-extension URLs should go away. Default search engine is Google again. |
| 942 model()->ResetNonExtensionURLs(); |
| 943 default_provider = model()->GetDefaultSearchProvider(); |
| 944 ASSERT_TRUE(default_provider); |
| 945 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, |
| 946 TemplateURLPrepopulateData::GetEngineType(default_provider->url())); |
| 947 EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext_keyword"))); |
| 948 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
| 949 |
| 950 // Reload URLs. Result should be the same except that extension keywords |
| 951 // aren't persisted. |
| 952 test_util_.ResetModel(true); |
| 953 default_provider = model()->GetDefaultSearchProvider(); |
| 954 ASSERT_TRUE(default_provider); |
| 955 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, |
| 956 TemplateURLPrepopulateData::GetEngineType(default_provider->url())); |
| 957 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext_keyword"))); |
| 958 EXPECT_FALSE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword"))); |
| 959 } |
| 960 |
| 961 TEST_F(TemplateURLServiceTest, ResetURLsWithManagedDefault) { |
| 962 // Set a managed preference that establishes a default search provider. |
| 963 const char kName[] = "test1"; |
| 964 const char kKeyword[] = "test.com"; |
| 965 const char kSearchURL[] = "http://test.com/search?t={searchTerms}"; |
| 966 const char kIconURL[] = "http://test.com/icon.jpg"; |
| 967 const char kEncodings[] = "UTF-16;UTF-32"; |
| 968 const char kAlternateURL[] = "http://test.com/search#t={searchTerms}"; |
| 969 const char kSearchTermsReplacementKey[] = "espv"; |
| 970 test_util_.SetManagedDefaultSearchPreferences(true, kName, kKeyword, |
| 971 kSearchURL, std::string(), |
| 972 kIconURL, kEncodings, |
| 973 kAlternateURL, |
| 974 kSearchTermsReplacementKey); |
| 975 test_util_.VerifyLoad(); |
| 976 // Verify that the default manager we are getting is the managed one. |
| 977 TemplateURLData data; |
| 978 data.short_name = ASCIIToUTF16(kName); |
| 979 data.SetKeyword(ASCIIToUTF16(kKeyword)); |
| 980 data.SetURL(kSearchURL); |
| 981 data.favicon_url = GURL(kIconURL); |
| 982 data.show_in_default_list = true; |
| 983 base::SplitString(kEncodings, ';', &data.input_encodings); |
| 984 data.alternate_urls.push_back(kAlternateURL); |
| 985 data.search_terms_replacement_key = kSearchTermsReplacementKey; |
| 986 Profile* profile = test_util_.profile(); |
| 987 scoped_ptr<TemplateURL> expected_managed_default(new TemplateURL(profile, |
| 988 data)); |
| 989 EXPECT_TRUE(model()->is_default_search_managed()); |
| 990 const TemplateURL* actual_managed_default = |
| 991 model()->GetDefaultSearchProvider(); |
| 992 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
| 993 |
| 994 // The following call has no effect on the managed search engine. |
| 995 model()->ResetNonExtensionURLs(); |
| 996 |
| 997 EXPECT_TRUE(model()->is_default_search_managed()); |
| 998 actual_managed_default = model()->GetDefaultSearchProvider(); |
| 999 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
| 1000 } |
| 1001 |
925 TEST_F(TemplateURLServiceTest, UpdateKeywordSearchTermsForURL) { | 1002 TEST_F(TemplateURLServiceTest, UpdateKeywordSearchTermsForURL) { |
926 struct TestData { | 1003 struct TestData { |
927 const std::string url; | 1004 const std::string url; |
928 const string16 term; | 1005 const string16 term; |
929 } data[] = { | 1006 } data[] = { |
930 { "http://foo/", string16() }, | 1007 { "http://foo/", string16() }, |
931 { "http://foo/foo?q=xx", string16() }, | 1008 { "http://foo/foo?q=xx", string16() }, |
932 { "http://x/bar?q=xx", string16() }, | 1009 { "http://x/bar?q=xx", string16() }, |
933 { "http://x/foo?y=xx", string16() }, | 1010 { "http://x/foo?y=xx", string16() }, |
934 { "http://x/foo?q=xx", ASCIIToUTF16("xx") }, | 1011 { "http://x/foo?q=xx", ASCIIToUTF16("xx") }, |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1498 EXPECT_EQ(8U, loaded_url->input_encodings().size()); | 1575 EXPECT_EQ(8U, loaded_url->input_encodings().size()); |
1499 | 1576 |
1500 // Reload the model to verify it was actually saved to the database and the | 1577 // Reload the model to verify it was actually saved to the database and the |
1501 // duplicate encodings were removed. | 1578 // duplicate encodings were removed. |
1502 test_util_.ResetModel(true); | 1579 test_util_.ResetModel(true); |
1503 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); | 1580 ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); |
1504 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); | 1581 loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); |
1505 ASSERT_FALSE(loaded_url == NULL); | 1582 ASSERT_FALSE(loaded_url == NULL); |
1506 EXPECT_EQ(4U, loaded_url->input_encodings().size()); | 1583 EXPECT_EQ(4U, loaded_url->input_encodings().size()); |
1507 } | 1584 } |
OLD | NEW |