Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: chrome/browser/history/history_unittest.cc

Issue 349153006: Port HistoryService::QueryRedirects{From,To} to CancelableTaskTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // History unit tests come in two flavors: 5 // History unit tests come in two flavors:
6 // 6 //
7 // 1. The more complicated style is that the unit test creates a full history 7 // 1. The more complicated style is that the unit test creates a full history
8 // service. This spawns a background thread for the history backend, and 8 // service. This spawns a background thread for the history backend, and
9 // all communication is asynchronous. This is useful for testing more 9 // all communication is asynchronous. This is useful for testing more
10 // complicated things or end-to-end behavior. 10 // complicated things or end-to-end behavior.
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 << "Error \"" << cur_reason.name << "\" not found in historical list." 970 << "Error \"" << cur_reason.name << "\" not found in historical list."
971 << std::endl 971 << std::endl
972 << "Please add it."; 972 << "Please add it.";
973 } 973 }
974 } 974 }
975 975
976 class HistoryTest : public testing::Test { 976 class HistoryTest : public testing::Test {
977 public: 977 public:
978 HistoryTest() 978 HistoryTest()
979 : got_thumbnail_callback_(false), 979 : got_thumbnail_callback_(false),
980 redirect_query_success_(false),
981 query_url_success_(false) { 980 query_url_success_(false) {
982 } 981 }
983 982
984 virtual ~HistoryTest() { 983 virtual ~HistoryTest() {
985 } 984 }
986 985
987 void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle, 986 void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle,
988 std::vector<PageUsageData*>* data) { 987 std::vector<PageUsageData*>* data) {
989 page_usage_data_.swap(*data); 988 page_usage_data_.swap(*data);
990 base::MessageLoop::current()->Quit(); 989 base::MessageLoop::current()->Quit();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 query_url_visits_ = visits; 1063 query_url_visits_ = visits;
1065 } else { 1064 } else {
1066 query_url_row_ = URLRow(); 1065 query_url_row_ = URLRow();
1067 query_url_visits_.clear(); 1066 query_url_visits_.clear();
1068 } 1067 }
1069 base::MessageLoop::current()->Quit(); 1068 base::MessageLoop::current()->Quit();
1070 } 1069 }
1071 1070
1072 // Fills in saved_redirects_ with the redirect information for the given URL, 1071 // Fills in saved_redirects_ with the redirect information for the given URL,
1073 // returning true on success. False means the URL was not found. 1072 // returning true on success. False means the URL was not found.
1074 bool QueryRedirectsFrom(HistoryService* history, const GURL& url) { 1073 void QueryRedirectsFrom(HistoryService* history, const GURL& url) {
1075 history_service_->QueryRedirectsFrom( 1074 history_service_->QueryRedirectsFrom(
1076 url, &consumer_, 1075 url,
1077 base::Bind(&HistoryTest::OnRedirectQueryComplete, 1076 base::Bind(&HistoryTest::OnRedirectQueryComplete,
1078 base::Unretained(this))); 1077 base::Unretained(this)),
1078 &tracker_);
1079 base::MessageLoop::current()->Run(); // Will be exited in *QueryComplete. 1079 base::MessageLoop::current()->Run(); // Will be exited in *QueryComplete.
1080 return redirect_query_success_;
1081 } 1080 }
1082 1081
1083 // Callback for QueryRedirects. 1082 // Callback for QueryRedirects.
1084 void OnRedirectQueryComplete(HistoryService::Handle handle, 1083 void OnRedirectQueryComplete(const history::RedirectList* redirects) {
1085 GURL url, 1084 saved_redirects_.clear();
1086 bool success, 1085 if (!redirects->empty()) {
1087 history::RedirectList* redirects) { 1086 saved_redirects_.insert(
1088 redirect_query_success_ = success; 1087 saved_redirects_.end(), redirects->begin(), redirects->end());
1089 if (redirect_query_success_) 1088 }
1090 saved_redirects_.swap(*redirects);
1091 else
1092 saved_redirects_.clear();
1093 base::MessageLoop::current()->Quit(); 1089 base::MessageLoop::current()->Quit();
1094 } 1090 }
1095 1091
1096 base::ScopedTempDir temp_dir_; 1092 base::ScopedTempDir temp_dir_;
1097 1093
1098 base::MessageLoopForUI message_loop_; 1094 base::MessageLoopForUI message_loop_;
1099 1095
1100 // PageUsageData vector to test segments. 1096 // PageUsageData vector to test segments.
1101 ScopedVector<PageUsageData> page_usage_data_; 1097 ScopedVector<PageUsageData> page_usage_data_;
1102 1098
1103 MostVisitedURLList most_visited_urls_; 1099 MostVisitedURLList most_visited_urls_;
1104 1100
1105 // When non-NULL, this will be deleted on tear down and we will block until 1101 // When non-NULL, this will be deleted on tear down and we will block until
1106 // the backend thread has completed. This allows tests for the history 1102 // the backend thread has completed. This allows tests for the history
1107 // service to use this feature, but other tests to ignore this. 1103 // service to use this feature, but other tests to ignore this.
1108 scoped_ptr<HistoryService> history_service_; 1104 scoped_ptr<HistoryService> history_service_;
1109 1105
1110 // names of the database files 1106 // names of the database files
1111 base::FilePath history_dir_; 1107 base::FilePath history_dir_;
1112 1108
1113 // Set by the thumbnail callback when we get data, you should be sure to 1109 // Set by the thumbnail callback when we get data, you should be sure to
1114 // clear this before issuing a thumbnail request. 1110 // clear this before issuing a thumbnail request.
1115 bool got_thumbnail_callback_; 1111 bool got_thumbnail_callback_;
1116 std::vector<unsigned char> thumbnail_data_; 1112 std::vector<unsigned char> thumbnail_data_;
1117 1113
1118 // Set by the redirect callback when we get data. You should be sure to 1114 // Set by the redirect callback when we get data. You should be sure to
1119 // clear this before issuing a redirect request. 1115 // clear this before issuing a redirect request.
1120 history::RedirectList saved_redirects_; 1116 history::RedirectList saved_redirects_;
1121 bool redirect_query_success_;
1122 1117
1123 // For history requests. 1118 // For history requests.
1124 base::CancelableTaskTracker tracker_; 1119 base::CancelableTaskTracker tracker_;
1125 CancelableRequestConsumer consumer_; 1120 CancelableRequestConsumer consumer_;
1126 1121
1127 // For saving URL info after a call to QueryURL 1122 // For saving URL info after a call to QueryURL
1128 bool query_url_success_; 1123 bool query_url_success_;
1129 URLRow query_url_row_; 1124 URLRow query_url_row_;
1130 VisitVector query_url_visits_; 1125 VisitVector query_url_visits_;
1131 }; 1126 };
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 std::vector<PageUsageData*> results; 1932 std::vector<PageUsageData*> results;
1938 db_->QuerySegmentUsage(segment_time, 10, &results); 1933 db_->QuerySegmentUsage(segment_time, 10, &results);
1939 ASSERT_EQ(1u, results.size()); 1934 ASSERT_EQ(1u, results.size());
1940 EXPECT_EQ(url, results[0]->GetURL()); 1935 EXPECT_EQ(url, results[0]->GetURL());
1941 EXPECT_EQ(segment_id, results[0]->GetID()); 1936 EXPECT_EQ(segment_id, results[0]->GetID());
1942 EXPECT_EQ(title, results[0]->GetTitle()); 1937 EXPECT_EQ(title, results[0]->GetTitle());
1943 STLDeleteElements(&results); 1938 STLDeleteElements(&results);
1944 } 1939 }
1945 1940
1946 } // namespace history 1941 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_service.cc ('k') | chrome/browser/history/redirect_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698