OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/test/mock_time_provider.h" | 10 #include "base/test/mock_time_provider.h" |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 }; | 835 }; |
836 | 836 |
837 ChangeModelToLoadState(); | 837 ChangeModelToLoadState(); |
838 AddKeywordWithDate("x", false, "http://x/foo?q={searchTerms}", | 838 AddKeywordWithDate("x", false, "http://x/foo?q={searchTerms}", |
839 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name", false, Time(), | 839 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name", false, Time(), |
840 Time()); | 840 Time()); |
841 | 841 |
842 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 842 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
843 history::URLVisitedDetails details; | 843 history::URLVisitedDetails details; |
844 details.row = history::URLRow(GURL(data[i].url)); | 844 details.row = history::URLRow(GURL(data[i].url)); |
845 details.transition = 0; | 845 details.transition = content::PageTransitionFromInt(0); |
846 model()->UpdateKeywordSearchTermsForURL(details); | 846 model()->UpdateKeywordSearchTermsForURL(details); |
847 EXPECT_EQ(data[i].term, GetAndClearSearchTerm()); | 847 EXPECT_EQ(data[i].term, GetAndClearSearchTerm()); |
848 } | 848 } |
849 } | 849 } |
850 | 850 |
851 TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) { | 851 TEST_F(TemplateURLServiceTest, DontUpdateKeywordSearchForNonReplaceable) { |
852 struct TestData { | 852 struct TestData { |
853 const std::string url; | 853 const std::string url; |
854 } data[] = { | 854 } data[] = { |
855 { "http://foo/" }, | 855 { "http://foo/" }, |
856 { "http://x/bar?q=xx" }, | 856 { "http://x/bar?q=xx" }, |
857 { "http://x/foo?y=xx" }, | 857 { "http://x/foo?y=xx" }, |
858 }; | 858 }; |
859 | 859 |
860 ChangeModelToLoadState(); | 860 ChangeModelToLoadState(); |
861 AddKeywordWithDate("x", false, "http://x/foo", "http://sugg1", | 861 AddKeywordWithDate("x", false, "http://x/foo", "http://sugg1", |
862 "http://icon1", "UTF-8;UTF-16", "name", false, Time(), Time()); | 862 "http://icon1", "UTF-8;UTF-16", "name", false, Time(), Time()); |
863 | 863 |
864 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 864 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
865 history::URLVisitedDetails details; | 865 history::URLVisitedDetails details; |
866 details.row = history::URLRow(GURL(data[i].url)); | 866 details.row = history::URLRow(GURL(data[i].url)); |
867 details.transition = 0; | 867 details.transition = content::PageTransitionFromInt(0); |
868 model()->UpdateKeywordSearchTermsForURL(details); | 868 model()->UpdateKeywordSearchTermsForURL(details); |
869 ASSERT_EQ(string16(), GetAndClearSearchTerm()); | 869 ASSERT_EQ(string16(), GetAndClearSearchTerm()); |
870 } | 870 } |
871 } | 871 } |
872 | 872 |
873 TEST_F(TemplateURLServiceTest, ChangeGoogleBaseValue) { | 873 TEST_F(TemplateURLServiceTest, ChangeGoogleBaseValue) { |
874 // NOTE: Do not do a VerifyLoad() here as it will load the prepopulate data, | 874 // NOTE: Do not do a VerifyLoad() here as it will load the prepopulate data, |
875 // which also has a {google:baseURL} keyword in it, which will confuse this | 875 // which also has a {google:baseURL} keyword in it, which will confuse this |
876 // test. | 876 // test. |
877 ChangeModelToLoadState(); | 877 ChangeModelToLoadState(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 "keyword", false, "http://foo.com/foo?query={searchTerms}", | 926 "keyword", false, "http://foo.com/foo?query={searchTerms}", |
927 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "keyword", | 927 "http://sugg1", "http://icon1", "UTF-8;UTF-16", "keyword", |
928 true, base::Time::Now(), base::Time::Now()); | 928 true, base::Time::Now(), base::Time::Now()); |
929 | 929 |
930 // Add a visit that matches the url of the keyword. | 930 // Add a visit that matches the url of the keyword. |
931 HistoryService* history = | 931 HistoryService* history = |
932 profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 932 profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
933 history->AddPage( | 933 history->AddPage( |
934 GURL(t_url->url()->ReplaceSearchTerms(*t_url, ASCIIToUTF16("blah"), 0, | 934 GURL(t_url->url()->ReplaceSearchTerms(*t_url, ASCIIToUTF16("blah"), 0, |
935 string16())), | 935 string16())), |
936 NULL, 0, GURL(), PageTransition::KEYWORD, history::RedirectList(), | 936 NULL, 0, GURL(), content::PAGE_TRANSITION_KEYWORD, |
937 history::SOURCE_BROWSED, false); | 937 history::RedirectList(), history::SOURCE_BROWSED, false); |
938 | 938 |
939 // Wait for history to finish processing the request. | 939 // Wait for history to finish processing the request. |
940 profile()->BlockUntilHistoryProcessesPendingRequests(); | 940 profile()->BlockUntilHistoryProcessesPendingRequests(); |
941 | 941 |
942 // Query history for the generated url. | 942 // Query history for the generated url. |
943 CancelableRequestConsumer consumer; | 943 CancelableRequestConsumer consumer; |
944 QueryHistoryCallbackImpl callback; | 944 QueryHistoryCallbackImpl callback; |
945 history->QueryURL(GURL("http://keyword"), true, &consumer, | 945 history->QueryURL(GURL("http://keyword"), true, &consumer, |
946 base::Bind(&QueryHistoryCallbackImpl::Callback, | 946 base::Bind(&QueryHistoryCallbackImpl::Callback, |
947 base::Unretained(&callback))); | 947 base::Unretained(&callback))); |
948 | 948 |
949 // Wait for the request to be processed. | 949 // Wait for the request to be processed. |
950 profile()->BlockUntilHistoryProcessesPendingRequests(); | 950 profile()->BlockUntilHistoryProcessesPendingRequests(); |
951 | 951 |
952 // And make sure the url and visit were added. | 952 // And make sure the url and visit were added. |
953 EXPECT_TRUE(callback.success); | 953 EXPECT_TRUE(callback.success); |
954 EXPECT_NE(0, callback.row.id()); | 954 EXPECT_NE(0, callback.row.id()); |
955 ASSERT_EQ(1U, callback.visits.size()); | 955 ASSERT_EQ(1U, callback.visits.size()); |
956 EXPECT_EQ(PageTransition::KEYWORD_GENERATED, | 956 EXPECT_EQ(content::PAGE_TRANSITION_KEYWORD_GENERATED, |
957 PageTransition::StripQualifier(callback.visits[0].transition)); | 957 content::PageTransitionStripQualifier(callback.visits[0].transition)); |
958 } | 958 } |
959 | 959 |
960 // Make sure that the load routine deletes prepopulated engines that no longer | 960 // Make sure that the load routine deletes prepopulated engines that no longer |
961 // exist in the prepopulate data. | 961 // exist in the prepopulate data. |
962 TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) { | 962 TEST_F(TemplateURLServiceTest, LoadDeletesUnusedProvider) { |
963 // Create a preloaded template url. Add it to a loaded model and wait for the | 963 // Create a preloaded template url. Add it to a loaded model and wait for the |
964 // saves to finish. | 964 // saves to finish. |
965 TemplateURL* t_url = CreatePreloadedTemplateURL(); | 965 TemplateURL* t_url = CreatePreloadedTemplateURL(); |
966 ChangeModelToLoadState(); | 966 ChangeModelToLoadState(); |
967 model()->Add(t_url); | 967 model()->Add(t_url); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 model()->SetDefaultSearchProvider(t_url); | 1240 model()->SetDefaultSearchProvider(t_url); |
1241 EXPECT_EQ(t_url, model()->GetDefaultSearchProvider()); | 1241 EXPECT_EQ(t_url, model()->GetDefaultSearchProvider()); |
1242 | 1242 |
1243 // Now reset the model again but load it after setting the preferences. | 1243 // Now reset the model again but load it after setting the preferences. |
1244 ResetModel(false); | 1244 ResetModel(false); |
1245 SetManagedDefaultSearchPreferences(false, "", "", "", "", "", ""); | 1245 SetManagedDefaultSearchPreferences(false, "", "", "", "", "", ""); |
1246 VerifyLoad(); | 1246 VerifyLoad(); |
1247 EXPECT_TRUE(model()->is_default_search_managed()); | 1247 EXPECT_TRUE(model()->is_default_search_managed()); |
1248 EXPECT_TRUE(model()->GetDefaultSearchProvider() == NULL); | 1248 EXPECT_TRUE(model()->GetDefaultSearchProvider() == NULL); |
1249 } | 1249 } |
OLD | NEW |