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 "components/search_engines/template_url_service.h" | 5 #include "components/search_engines/template_url_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "base/task/cancelable_task_tracker.h" | 22 #include "base/task/cancelable_task_tracker.h" |
23 #include "base/test/simple_test_clock.h" | 23 #include "base/test/simple_test_clock.h" |
24 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
25 #include "base/time/time.h" | 25 #include "base/time/time.h" |
26 #include "chrome/browser/history/history_service_factory.h" | 26 #include "chrome/browser/history/history_service_factory.h" |
27 #include "chrome/browser/search_engines/template_url_service_test_util.h" | 27 #include "chrome/browser/search_engines/template_url_service_test_util.h" |
28 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
29 #include "components/history/core/browser/history_service.h" | 29 #include "components/history/core/browser/history_service.h" |
30 #include "components/search_engines/keyword_web_data_service.h" | 30 #include "components/search_engines/keyword_web_data_service.h" |
| 31 #include "components/search_engines/search_engines_pref_names.h" |
31 #include "components/search_engines/search_host_to_urls_map.h" | 32 #include "components/search_engines/search_host_to_urls_map.h" |
32 #include "components/search_engines/search_terms_data.h" | 33 #include "components/search_engines/search_terms_data.h" |
33 #include "components/search_engines/template_url.h" | 34 #include "components/search_engines/template_url.h" |
34 #include "components/search_engines/template_url_prepopulate_data.h" | 35 #include "components/search_engines/template_url_prepopulate_data.h" |
| 36 #include "components/sync_preferences/testing_pref_service_syncable.h" |
35 #include "content/public/test/test_browser_thread_bundle.h" | 37 #include "content/public/test/test_browser_thread_bundle.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
37 | 39 |
38 using base::ASCIIToUTF16; | 40 using base::ASCIIToUTF16; |
39 using base::Time; | 41 using base::Time; |
40 using base::TimeDelta; | 42 using base::TimeDelta; |
41 | 43 |
42 namespace { | 44 namespace { |
43 | 45 |
44 // A prepopulated ID to set for engines we want to show in the default list. | 46 // A prepopulated ID to set for engines we want to show in the default list. |
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 888 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
887 | 889 |
888 // The following call has no effect on the managed search engine. | 890 // The following call has no effect on the managed search engine. |
889 model()->RepairPrepopulatedSearchEngines(); | 891 model()->RepairPrepopulatedSearchEngines(); |
890 | 892 |
891 EXPECT_TRUE(model()->is_default_search_managed()); | 893 EXPECT_TRUE(model()->is_default_search_managed()); |
892 actual_managed_default = model()->GetDefaultSearchProvider(); | 894 actual_managed_default = model()->GetDefaultSearchProvider(); |
893 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 895 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
894 } | 896 } |
895 | 897 |
| 898 TEST_F(TemplateURLServiceTest, RepairPrepopulatedEnginesUpdatesSyncGuid) { |
| 899 test_util()->VerifyLoad(); |
| 900 |
| 901 // Expect no synced DSE guid until user selected something or sync come in. |
| 902 EXPECT_TRUE(test_util() |
| 903 ->profile() |
| 904 ->GetTestingPrefService() |
| 905 ->GetString(prefs::kSyncedDefaultSearchProviderGUID) |
| 906 .empty()); |
| 907 |
| 908 // Google engine must exist. |
| 909 TemplateURL* google = |
| 910 model()->GetTemplateURLForKeyword(ASCIIToUTF16("google.com")); |
| 911 ASSERT_TRUE(google); |
| 912 // Add third-party default search engine. |
| 913 TemplateURL* user_dse = AddKeywordWithDate( |
| 914 "user_dse", "user_dse.com", "http://www.user_dse.com/s?q={searchTerms}", |
| 915 std::string(), std::string(), std::string(), true, "UTF-8", Time(), |
| 916 Time(), Time()); |
| 917 model()->SetUserSelectedDefaultSearchProvider(user_dse); |
| 918 EXPECT_EQ(user_dse, model()->GetDefaultSearchProvider()); |
| 919 |
| 920 // Check that user DSE guid is stored in kSyncedDefaultSearchProviderGUID. |
| 921 EXPECT_EQ(user_dse->sync_guid(), |
| 922 test_util()->profile()->GetTestingPrefService()->GetString( |
| 923 prefs::kSyncedDefaultSearchProviderGUID)); |
| 924 |
| 925 model()->RepairPrepopulatedSearchEngines(); |
| 926 |
| 927 // Check that Google is default after repair. |
| 928 ASSERT_EQ(google, model()->GetDefaultSearchProvider()); |
| 929 // Check that google guid is stored in kSyncedDefaultSearchProviderGUID. |
| 930 const std::string dse_guid = |
| 931 test_util()->profile()->GetTestingPrefService()->GetString( |
| 932 prefs::kSyncedDefaultSearchProviderGUID); |
| 933 EXPECT_EQ(google->sync_guid(), dse_guid); |
| 934 EXPECT_EQ(google->keyword(), |
| 935 model()->GetTemplateURLForGUID(dse_guid)->keyword()); |
| 936 } |
| 937 |
896 TEST_F(TemplateURLServiceTest, UpdateKeywordSearchTermsForURL) { | 938 TEST_F(TemplateURLServiceTest, UpdateKeywordSearchTermsForURL) { |
897 struct TestData { | 939 struct TestData { |
898 const std::string url; | 940 const std::string url; |
899 const base::string16 term; | 941 const base::string16 term; |
900 } data[] = { | 942 } data[] = { |
901 { "http://foo/", base::string16() }, | 943 { "http://foo/", base::string16() }, |
902 { "http://foo/foo?q=xx", base::string16() }, | 944 { "http://foo/foo?q=xx", base::string16() }, |
903 { "http://x/bar?q=xx", base::string16() }, | 945 { "http://x/bar?q=xx", base::string16() }, |
904 { "http://x/foo?y=xx", base::string16() }, | 946 { "http://x/foo?y=xx", base::string16() }, |
905 { "http://x/foo?q=xx", ASCIIToUTF16("xx") }, | 947 { "http://x/foo?q=xx", ASCIIToUTF16("xx") }, |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1542 TemplateURL* update_url = | 1584 TemplateURL* update_url = |
1543 model()->GetTemplateURLForKeyword(ASCIIToUTF16("engine_keyword")); | 1585 model()->GetTemplateURLForKeyword(ASCIIToUTF16("engine_keyword")); |
1544 const base::Time update_last_modified = update_url->last_modified(); | 1586 const base::Time update_last_modified = update_url->last_modified(); |
1545 model()->SetUserSelectedDefaultSearchProvider(update_url); | 1587 model()->SetUserSelectedDefaultSearchProvider(update_url); |
1546 TemplateURL* reloaded_url = | 1588 TemplateURL* reloaded_url = |
1547 model()->GetTemplateURLForKeyword(ASCIIToUTF16("engine_keyword")); | 1589 model()->GetTemplateURLForKeyword(ASCIIToUTF16("engine_keyword")); |
1548 const base::Time reloaded_last_modified = reloaded_url->last_modified(); | 1590 const base::Time reloaded_last_modified = reloaded_url->last_modified(); |
1549 EXPECT_NE(original_last_modified, reloaded_last_modified); | 1591 EXPECT_NE(original_last_modified, reloaded_last_modified); |
1550 EXPECT_EQ(update_last_modified, reloaded_last_modified); | 1592 EXPECT_EQ(update_last_modified, reloaded_last_modified); |
1551 } | 1593 } |
OLD | NEW |