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

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

Issue 314293005: Change HistoryService::QueryURL to use CancelableTaskTracker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments 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
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 21 matching lines...) Expand all
32 #include "base/files/file_path.h" 32 #include "base/files/file_path.h"
33 #include "base/files/scoped_temp_dir.h" 33 #include "base/files/scoped_temp_dir.h"
34 #include "base/logging.h" 34 #include "base/logging.h"
35 #include "base/memory/scoped_ptr.h" 35 #include "base/memory/scoped_ptr.h"
36 #include "base/memory/scoped_vector.h" 36 #include "base/memory/scoped_vector.h"
37 #include "base/message_loop/message_loop.h" 37 #include "base/message_loop/message_loop.h"
38 #include "base/path_service.h" 38 #include "base/path_service.h"
39 #include "base/strings/string_util.h" 39 #include "base/strings/string_util.h"
40 #include "base/strings/stringprintf.h" 40 #include "base/strings/stringprintf.h"
41 #include "base/strings/utf_string_conversions.h" 41 #include "base/strings/utf_string_conversions.h"
42 #include "base/task/cancelable_task_tracker.h"
42 #include "base/threading/platform_thread.h" 43 #include "base/threading/platform_thread.h"
43 #include "base/time/time.h" 44 #include "base/time/time.h"
44 #include "chrome/browser/history/download_row.h" 45 #include "chrome/browser/history/download_row.h"
45 #include "chrome/browser/history/history_backend.h" 46 #include "chrome/browser/history/history_backend.h"
46 #include "chrome/browser/history/history_database.h" 47 #include "chrome/browser/history/history_database.h"
47 #include "chrome/browser/history/history_db_task.h" 48 #include "chrome/browser/history/history_db_task.h"
48 #include "chrome/browser/history/history_notifications.h" 49 #include "chrome/browser/history/history_notifications.h"
49 #include "chrome/browser/history/history_service.h" 50 #include "chrome/browser/history/history_service.h"
50 #include "chrome/browser/history/history_unittest_base.h" 51 #include "chrome/browser/history/history_unittest_base.h"
51 #include "chrome/browser/history/in_memory_database.h" 52 #include "chrome/browser/history/in_memory_database.h"
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 // moving to the next test. Note: if this never terminates, somebody is 973 // moving to the next test. Note: if this never terminates, somebody is
973 // probably leaking a reference to the history backend, so it never calls 974 // probably leaking a reference to the history backend, so it never calls
974 // our destroy task. 975 // our destroy task.
975 base::MessageLoop::current()->Run(); 976 base::MessageLoop::current()->Run();
976 } 977 }
977 978
978 // Fills the query_url_row_ and query_url_visits_ structures with the 979 // Fills the query_url_row_ and query_url_visits_ structures with the
979 // information about the given URL and returns true. If the URL was not 980 // information about the given URL and returns true. If the URL was not
980 // found, this will return false and those structures will not be changed. 981 // found, this will return false and those structures will not be changed.
981 bool QueryURL(HistoryService* history, const GURL& url) { 982 bool QueryURL(HistoryService* history, const GURL& url) {
982 history_service_->QueryURL(url, true, &consumer_, 983 history_service_->QueryURL(
983 base::Bind(&HistoryTest::SaveURLAndQuit, 984 url,
984 base::Unretained(this))); 985 true,
986 base::Bind(&HistoryTest::SaveURLAndQuit, base::Unretained(this)),
987 &tracker_);
985 base::MessageLoop::current()->Run(); // Will be exited in SaveURLAndQuit. 988 base::MessageLoop::current()->Run(); // Will be exited in SaveURLAndQuit.
986 return query_url_success_; 989 return query_url_success_;
987 } 990 }
988 991
989 // Callback for HistoryService::QueryURL. 992 // Callback for HistoryService::QueryURL.
990 void SaveURLAndQuit(HistoryService::Handle handle, 993 void SaveURLAndQuit(bool success,
991 bool success, 994 const URLRow& url_row,
992 const URLRow* url_row, 995 const VisitVector& visits) {
993 VisitVector* visit_vector) {
994 query_url_success_ = success; 996 query_url_success_ = success;
995 if (query_url_success_) { 997 if (query_url_success_) {
996 query_url_row_ = *url_row; 998 query_url_row_ = url_row;
997 query_url_visits_.swap(*visit_vector); 999 query_url_visits_ = visits;
998 } else { 1000 } else {
999 query_url_row_ = URLRow(); 1001 query_url_row_ = URLRow();
1000 query_url_visits_.clear(); 1002 query_url_visits_.clear();
1001 } 1003 }
1002 base::MessageLoop::current()->Quit(); 1004 base::MessageLoop::current()->Quit();
1003 } 1005 }
1004 1006
1005 // Fills in saved_redirects_ with the redirect information for the given URL, 1007 // Fills in saved_redirects_ with the redirect information for the given URL,
1006 // returning true on success. False means the URL was not found. 1008 // returning true on success. False means the URL was not found.
1007 bool QueryRedirectsFrom(HistoryService* history, const GURL& url) { 1009 bool QueryRedirectsFrom(HistoryService* history, const GURL& url) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 // clear this before issuing a thumbnail request. 1049 // clear this before issuing a thumbnail request.
1048 bool got_thumbnail_callback_; 1050 bool got_thumbnail_callback_;
1049 std::vector<unsigned char> thumbnail_data_; 1051 std::vector<unsigned char> thumbnail_data_;
1050 1052
1051 // Set by the redirect callback when we get data. You should be sure to 1053 // Set by the redirect callback when we get data. You should be sure to
1052 // clear this before issuing a redirect request. 1054 // clear this before issuing a redirect request.
1053 history::RedirectList saved_redirects_; 1055 history::RedirectList saved_redirects_;
1054 bool redirect_query_success_; 1056 bool redirect_query_success_;
1055 1057
1056 // For history requests. 1058 // For history requests.
1059 base::CancelableTaskTracker tracker_;
1057 CancelableRequestConsumer consumer_; 1060 CancelableRequestConsumer consumer_;
1058 1061
1059 // For saving URL info after a call to QueryURL 1062 // For saving URL info after a call to QueryURL
1060 bool query_url_success_; 1063 bool query_url_success_;
1061 URLRow query_url_row_; 1064 URLRow query_url_row_;
1062 VisitVector query_url_visits_; 1065 VisitVector query_url_visits_;
1063 }; 1066 };
1064 1067
1065 TEST_F(HistoryTest, AddPage) { 1068 TEST_F(HistoryTest, AddPage) {
1066 ASSERT_TRUE(history_service_.get()); 1069 ASSERT_TRUE(history_service_.get());
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 std::vector<PageUsageData*> results; 1871 std::vector<PageUsageData*> results;
1869 db_->QuerySegmentUsage(segment_time, 10, &results); 1872 db_->QuerySegmentUsage(segment_time, 10, &results);
1870 ASSERT_EQ(1u, results.size()); 1873 ASSERT_EQ(1u, results.size());
1871 EXPECT_EQ(url, results[0]->GetURL()); 1874 EXPECT_EQ(url, results[0]->GetURL());
1872 EXPECT_EQ(segment_id, results[0]->GetID()); 1875 EXPECT_EQ(segment_id, results[0]->GetID());
1873 EXPECT_EQ(title, results[0]->GetTitle()); 1876 EXPECT_EQ(title, results[0]->GetTitle());
1874 STLDeleteElements(&results); 1877 STLDeleteElements(&results);
1875 } 1878 }
1876 1879
1877 } // namespace history 1880 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698