| 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 // 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 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 query_url_row_ = URLRow(); | 1066 query_url_row_ = URLRow(); |
| 1067 query_url_visits_.clear(); | 1067 query_url_visits_.clear(); |
| 1068 } | 1068 } |
| 1069 base::MessageLoop::current()->Quit(); | 1069 base::MessageLoop::current()->Quit(); |
| 1070 } | 1070 } |
| 1071 | 1071 |
| 1072 // Fills in saved_redirects_ with the redirect information for the given URL, | 1072 // Fills in saved_redirects_ with the redirect information for the given URL, |
| 1073 // returning true on success. False means the URL was not found. | 1073 // returning true on success. False means the URL was not found. |
| 1074 bool QueryRedirectsFrom(HistoryService* history, const GURL& url) { | 1074 bool QueryRedirectsFrom(HistoryService* history, const GURL& url) { |
| 1075 history_service_->QueryRedirectsFrom( | 1075 history_service_->QueryRedirectsFrom( |
| 1076 url, &consumer_, | 1076 url, |
| 1077 base::Bind(&HistoryTest::OnRedirectQueryComplete, | 1077 base::Bind(&HistoryTest::OnRedirectQueryComplete, |
| 1078 base::Unretained(this))); | 1078 base::Unretained(this)), |
| 1079 &tracker_); |
| 1079 base::MessageLoop::current()->Run(); // Will be exited in *QueryComplete. | 1080 base::MessageLoop::current()->Run(); // Will be exited in *QueryComplete. |
| 1080 return redirect_query_success_; | 1081 return redirect_query_success_; |
| 1081 } | 1082 } |
| 1082 | 1083 |
| 1083 // Callback for QueryRedirects. | 1084 // Callback for QueryRedirects. |
| 1084 void OnRedirectQueryComplete(HistoryService::Handle handle, | 1085 void OnRedirectQueryComplete(GURL url, |
| 1085 GURL url, | |
| 1086 bool success, | 1086 bool success, |
| 1087 history::RedirectList* redirects) { | 1087 const history::RedirectList* redirects) { |
| 1088 saved_redirects_.clear(); |
| 1088 redirect_query_success_ = success; | 1089 redirect_query_success_ = success; |
| 1089 if (redirect_query_success_) | 1090 if (redirect_query_success_) { |
| 1090 saved_redirects_.swap(*redirects); | 1091 saved_redirects_.insert( |
| 1091 else | 1092 saved_redirects_.end(), redirects->begin(), redirects->end()); |
| 1092 saved_redirects_.clear(); | 1093 } |
| 1093 base::MessageLoop::current()->Quit(); | 1094 base::MessageLoop::current()->Quit(); |
| 1094 } | 1095 } |
| 1095 | 1096 |
| 1096 base::ScopedTempDir temp_dir_; | 1097 base::ScopedTempDir temp_dir_; |
| 1097 | 1098 |
| 1098 base::MessageLoopForUI message_loop_; | 1099 base::MessageLoopForUI message_loop_; |
| 1099 | 1100 |
| 1100 // PageUsageData vector to test segments. | 1101 // PageUsageData vector to test segments. |
| 1101 ScopedVector<PageUsageData> page_usage_data_; | 1102 ScopedVector<PageUsageData> page_usage_data_; |
| 1102 | 1103 |
| (...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1937 std::vector<PageUsageData*> results; | 1938 std::vector<PageUsageData*> results; |
| 1938 db_->QuerySegmentUsage(segment_time, 10, &results); | 1939 db_->QuerySegmentUsage(segment_time, 10, &results); |
| 1939 ASSERT_EQ(1u, results.size()); | 1940 ASSERT_EQ(1u, results.size()); |
| 1940 EXPECT_EQ(url, results[0]->GetURL()); | 1941 EXPECT_EQ(url, results[0]->GetURL()); |
| 1941 EXPECT_EQ(segment_id, results[0]->GetID()); | 1942 EXPECT_EQ(segment_id, results[0]->GetID()); |
| 1942 EXPECT_EQ(title, results[0]->GetTitle()); | 1943 EXPECT_EQ(title, results[0]->GetTitle()); |
| 1943 STLDeleteElements(&results); | 1944 STLDeleteElements(&results); |
| 1944 } | 1945 } |
| 1945 | 1946 |
| 1946 } // namespace history | 1947 } // namespace history |
| OLD | NEW |