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/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/task/cancelable_task_tracker.h" | |
15 #include "base/test/mock_time_provider.h" | 14 #include "base/test/mock_time_provider.h" |
16 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
17 #include "base/time/time.h" | 16 #include "base/time/time.h" |
18 #include "chrome/browser/history/history_notifications.h" | 17 #include "chrome/browser/history/history_notifications.h" |
19 #include "chrome/browser/history/history_service.h" | 18 #include "chrome/browser/history/history_service.h" |
20 #include "chrome/browser/history/history_service_factory.h" | 19 #include "chrome/browser/history/history_service_factory.h" |
21 #include "chrome/browser/search_engines/search_host_to_urls_map.h" | 20 #include "chrome/browser/search_engines/search_host_to_urls_map.h" |
22 #include "chrome/browser/search_engines/search_terms_data.h" | 21 #include "chrome/browser/search_engines/search_terms_data.h" |
23 #include "chrome/browser/search_engines/template_url.h" | 22 #include "chrome/browser/search_engines/template_url.h" |
24 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 23 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 std::string TestSearchTermsData::GoogleBaseURLValue() const { | 61 std::string TestSearchTermsData::GoogleBaseURLValue() const { |
63 return google_base_url_; | 62 return google_base_url_; |
64 } | 63 } |
65 | 64 |
66 | 65 |
67 // QueryHistoryCallbackImpl --------------------------------------------------- | 66 // QueryHistoryCallbackImpl --------------------------------------------------- |
68 | 67 |
69 struct QueryHistoryCallbackImpl { | 68 struct QueryHistoryCallbackImpl { |
70 QueryHistoryCallbackImpl() : success(false) {} | 69 QueryHistoryCallbackImpl() : success(false) {} |
71 | 70 |
72 void Callback(bool success, | 71 void Callback(HistoryService::Handle handle, |
73 const history::URLRow& row, | 72 bool success, |
74 const history::VisitVector& visits) { | 73 const history::URLRow* row, |
| 74 history::VisitVector* visits) { |
75 this->success = success; | 75 this->success = success; |
76 if (success) { | 76 if (row) |
77 this->row = row; | 77 this->row = *row; |
78 this->visits = visits; | 78 if (visits) |
79 } | 79 this->visits = *visits; |
80 } | 80 } |
81 | 81 |
82 bool success; | 82 bool success; |
83 history::URLRow row; | 83 history::URLRow row; |
84 history::VisitVector visits; | 84 history::VisitVector visits; |
85 }; | 85 }; |
86 | 86 |
87 TemplateURL* CreateKeywordWithDate( | 87 TemplateURL* CreateKeywordWithDate( |
88 TemplateURLService* model, | 88 TemplateURLService* model, |
89 const std::string& short_name, | 89 const std::string& short_name, |
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 history->AddPage( | 1064 history->AddPage( |
1065 GURL(t_url->url_ref().ReplaceSearchTerms( | 1065 GURL(t_url->url_ref().ReplaceSearchTerms( |
1066 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("blah")))), | 1066 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("blah")))), |
1067 base::Time::Now(), NULL, 0, GURL(), history::RedirectList(), | 1067 base::Time::Now(), NULL, 0, GURL(), history::RedirectList(), |
1068 content::PAGE_TRANSITION_KEYWORD, history::SOURCE_BROWSED, false); | 1068 content::PAGE_TRANSITION_KEYWORD, history::SOURCE_BROWSED, false); |
1069 | 1069 |
1070 // Wait for history to finish processing the request. | 1070 // Wait for history to finish processing the request. |
1071 test_util_.profile()->BlockUntilHistoryProcessesPendingRequests(); | 1071 test_util_.profile()->BlockUntilHistoryProcessesPendingRequests(); |
1072 | 1072 |
1073 // Query history for the generated url. | 1073 // Query history for the generated url. |
1074 base::CancelableTaskTracker tracker; | 1074 CancelableRequestConsumer consumer; |
1075 QueryHistoryCallbackImpl callback; | 1075 QueryHistoryCallbackImpl callback; |
1076 history->QueryURL(GURL("http://keyword"), | 1076 history->QueryURL(GURL("http://keyword"), true, &consumer, |
1077 true, | 1077 base::Bind(&QueryHistoryCallbackImpl::Callback, |
1078 base::Bind(&QueryHistoryCallbackImpl::Callback, | 1078 base::Unretained(&callback))); |
1079 base::Unretained(&callback)), | |
1080 &tracker); | |
1081 | 1079 |
1082 // Wait for the request to be processed. | 1080 // Wait for the request to be processed. |
1083 test_util_.profile()->BlockUntilHistoryProcessesPendingRequests(); | 1081 test_util_.profile()->BlockUntilHistoryProcessesPendingRequests(); |
1084 | 1082 |
1085 // And make sure the url and visit were added. | 1083 // And make sure the url and visit were added. |
1086 EXPECT_TRUE(callback.success); | 1084 EXPECT_TRUE(callback.success); |
1087 EXPECT_NE(0, callback.row.id()); | 1085 EXPECT_NE(0, callback.row.id()); |
1088 ASSERT_EQ(1U, callback.visits.size()); | 1086 ASSERT_EQ(1U, callback.visits.size()); |
1089 EXPECT_EQ(content::PAGE_TRANSITION_KEYWORD_GENERATED, | 1087 EXPECT_EQ(content::PAGE_TRANSITION_KEYWORD_GENERATED, |
1090 content::PageTransitionStripQualifier(callback.visits[0].transition)); | 1088 content::PageTransitionStripQualifier(callback.visits[0].transition)); |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 scoped_ptr<AssociatedExtensionInfo> extension_info( | 1558 scoped_ptr<AssociatedExtensionInfo> extension_info( |
1561 new AssociatedExtensionInfo); | 1559 new AssociatedExtensionInfo); |
1562 extension_info->wants_to_be_default_engine = true; | 1560 extension_info->wants_to_be_default_engine = true; |
1563 extension_info->extension_id = "ext1"; | 1561 extension_info->extension_id = "ext1"; |
1564 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); | 1562 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); |
1565 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1563 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
1566 EXPECT_TRUE(model()->is_default_search_managed()); | 1564 EXPECT_TRUE(model()->is_default_search_managed()); |
1567 actual_managed_default = model()->GetDefaultSearchProvider(); | 1565 actual_managed_default = model()->GetDefaultSearchProvider(); |
1568 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1566 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
1569 } | 1567 } |
OLD | NEW |