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" |
14 #include "base/test/mock_time_provider.h" | 15 #include "base/test/mock_time_provider.h" |
15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "chrome/browser/history/history_notifications.h" | 18 #include "chrome/browser/history/history_notifications.h" |
18 #include "chrome/browser/history/history_service.h" | 19 #include "chrome/browser/history/history_service.h" |
19 #include "chrome/browser/history/history_service_factory.h" | 20 #include "chrome/browser/history/history_service_factory.h" |
20 #include "chrome/browser/search_engines/search_host_to_urls_map.h" | 21 #include "chrome/browser/search_engines/search_host_to_urls_map.h" |
21 #include "chrome/browser/search_engines/search_terms_data.h" | 22 #include "chrome/browser/search_engines/search_terms_data.h" |
22 #include "chrome/browser/search_engines/template_url.h" | 23 #include "chrome/browser/search_engines/template_url.h" |
23 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 24 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 std::string TestSearchTermsData::GoogleBaseURLValue() const { | 62 std::string TestSearchTermsData::GoogleBaseURLValue() const { |
62 return google_base_url_; | 63 return google_base_url_; |
63 } | 64 } |
64 | 65 |
65 | 66 |
66 // QueryHistoryCallbackImpl --------------------------------------------------- | 67 // QueryHistoryCallbackImpl --------------------------------------------------- |
67 | 68 |
68 struct QueryHistoryCallbackImpl { | 69 struct QueryHistoryCallbackImpl { |
69 QueryHistoryCallbackImpl() : success(false) {} | 70 QueryHistoryCallbackImpl() : success(false) {} |
70 | 71 |
71 void Callback(HistoryService::Handle handle, | 72 void Callback(bool success, |
72 bool success, | 73 const history::URLRow& row, |
73 const history::URLRow* row, | 74 const history::VisitVector& visits) { |
74 history::VisitVector* visits) { | |
75 this->success = success; | 75 this->success = success; |
76 if (row) | 76 if (success) { |
77 this->row = *row; | 77 this->row = row; |
78 if (visits) | 78 this->visits = visits; |
79 this->visits = *visits; | 79 } |
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 CancelableRequestConsumer consumer; | 1074 base::CancelableTaskTracker tracker; |
1075 QueryHistoryCallbackImpl callback; | 1075 QueryHistoryCallbackImpl callback; |
1076 history->QueryURL(GURL("http://keyword"), true, &consumer, | 1076 history->QueryURL(GURL("http://keyword"), |
1077 base::Bind(&QueryHistoryCallbackImpl::Callback, | 1077 true, |
1078 base::Unretained(&callback))); | 1078 base::Bind(&QueryHistoryCallbackImpl::Callback, |
| 1079 base::Unretained(&callback)), |
| 1080 &tracker); |
1079 | 1081 |
1080 // Wait for the request to be processed. | 1082 // Wait for the request to be processed. |
1081 test_util_.profile()->BlockUntilHistoryProcessesPendingRequests(); | 1083 test_util_.profile()->BlockUntilHistoryProcessesPendingRequests(); |
1082 | 1084 |
1083 // And make sure the url and visit were added. | 1085 // And make sure the url and visit were added. |
1084 EXPECT_TRUE(callback.success); | 1086 EXPECT_TRUE(callback.success); |
1085 EXPECT_NE(0, callback.row.id()); | 1087 EXPECT_NE(0, callback.row.id()); |
1086 ASSERT_EQ(1U, callback.visits.size()); | 1088 ASSERT_EQ(1U, callback.visits.size()); |
1087 EXPECT_EQ(content::PAGE_TRANSITION_KEYWORD_GENERATED, | 1089 EXPECT_EQ(content::PAGE_TRANSITION_KEYWORD_GENERATED, |
1088 content::PageTransitionStripQualifier(callback.visits[0].transition)); | 1090 content::PageTransitionStripQualifier(callback.visits[0].transition)); |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 scoped_ptr<AssociatedExtensionInfo> extension_info( | 1560 scoped_ptr<AssociatedExtensionInfo> extension_info( |
1559 new AssociatedExtensionInfo); | 1561 new AssociatedExtensionInfo); |
1560 extension_info->wants_to_be_default_engine = true; | 1562 extension_info->wants_to_be_default_engine = true; |
1561 extension_info->extension_id = "ext1"; | 1563 extension_info->extension_id = "ext1"; |
1562 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); | 1564 model()->AddExtensionControlledTURL(ext_dse, extension_info.Pass()); |
1563 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); | 1565 EXPECT_EQ(ext_dse, model()->GetTemplateURLForKeyword(ASCIIToUTF16("ext1"))); |
1564 EXPECT_TRUE(model()->is_default_search_managed()); | 1566 EXPECT_TRUE(model()->is_default_search_managed()); |
1565 actual_managed_default = model()->GetDefaultSearchProvider(); | 1567 actual_managed_default = model()->GetDefaultSearchProvider(); |
1566 ExpectSimilar(expected_managed_default.get(), actual_managed_default); | 1568 ExpectSimilar(expected_managed_default.get(), actual_managed_default); |
1567 } | 1569 } |
OLD | NEW |