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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 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 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 79
80 // Acts like a synchronous call to history's QueryHistory. 80 // Acts like a synchronous call to history's QueryHistory.
81 void QueryHistory(const std::string& text_query, 81 void QueryHistory(const std::string& text_query,
82 const QueryOptions& options, 82 const QueryOptions& options,
83 QueryResults* results) { 83 QueryResults* results) {
84 history_->QueryHistory( 84 history_->QueryHistory(
85 UTF8ToUTF16(text_query), options, &consumer_, 85 UTF8ToUTF16(text_query), options, &consumer_,
86 base::Bind(&HistoryQueryTest::QueryHistoryComplete, 86 base::Bind(&HistoryQueryTest::QueryHistoryComplete,
87 base::Unretained(this))); 87 base::Unretained(this)));
88 MessageLoop::current()->Run(); // Will go until ...Complete calls Quit. 88 // Will go until ...Complete calls Quit.
89 base::MessageLoop::current()->Run();
89 results->Swap(&last_query_results_); 90 results->Swap(&last_query_results_);
90 } 91 }
91 92
92 // Test paging through results, with a fixed number of results per page. 93 // Test paging through results, with a fixed number of results per page.
93 // Defined here so code can be shared for the FTS version and the non-FTS 94 // Defined here so code can be shared for the FTS version and the non-FTS
94 // version. 95 // version.
95 void TestPaging(const std::string& query_text, 96 void TestPaging(const std::string& query_text,
96 const int* expected_results, 97 const int* expected_results,
97 int results_length) { 98 int results_length) {
98 ASSERT_TRUE(history_.get()); 99 ASSERT_TRUE(history_.get());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 Time now = Time::Now().LocalMidnight(); 176 Time now = Time::Now().LocalMidnight();
176 for (size_t i = 0; i < arraysize(test_entries); i++) { 177 for (size_t i = 0; i < arraysize(test_entries); i++) {
177 test_entries[i].time = 178 test_entries[i].time =
178 now - (test_entries[i].days_ago * TimeDelta::FromDays(1)); 179 now - (test_entries[i].days_ago * TimeDelta::FromDays(1));
179 AddEntryToHistory(test_entries[i]); 180 AddEntryToHistory(test_entries[i]);
180 } 181 }
181 } 182 }
182 183
183 virtual void TearDown() { 184 virtual void TearDown() {
184 if (history_) { 185 if (history_) {
185 history_->SetOnBackendDestroyTask(MessageLoop::QuitClosure()); 186 history_->SetOnBackendDestroyTask(base::MessageLoop::QuitClosure());
186 history_->Cleanup(); 187 history_->Cleanup();
187 history_.reset(); 188 history_.reset();
188 MessageLoop::current()->Run(); // Wait for the other thread. 189 base::MessageLoop::current()->Run(); // Wait for the other thread.
189 } 190 }
190 } 191 }
191 192
192 void QueryHistoryComplete(HistoryService::Handle, QueryResults* results) { 193 void QueryHistoryComplete(HistoryService::Handle, QueryResults* results) {
193 results->Swap(&last_query_results_); 194 results->Swap(&last_query_results_);
194 MessageLoop::current()->Quit(); // Will return out to QueryHistory. 195 base::MessageLoop::current()->Quit(); // Will return out to QueryHistory.
195 } 196 }
196 197
197 base::ScopedTempDir temp_dir_; 198 base::ScopedTempDir temp_dir_;
198 199
199 MessageLoop message_loop_; 200 base::MessageLoop message_loop_;
200 201
201 base::FilePath history_dir_; 202 base::FilePath history_dir_;
202 203
203 CancelableRequestConsumer consumer_; 204 CancelableRequestConsumer consumer_;
204 205
205 // The QueryHistoryComplete callback will put the results here so QueryHistory 206 // The QueryHistoryComplete callback will put the results here so QueryHistory
206 // can return them. 207 // can return them.
207 QueryResults last_query_results_; 208 QueryResults last_query_results_;
208 209
209 DISALLOW_COPY_AND_ASSIGN(HistoryQueryTest); 210 DISALLOW_COPY_AND_ASSIGN(HistoryQueryTest);
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 474
474 TEST_F(HistoryQueryTest, FTSPaging) { 475 TEST_F(HistoryQueryTest, FTSPaging) {
475 // Since results are fetched 1 and 2 at a time, entry #0 and #6 will not 476 // Since results are fetched 1 and 2 at a time, entry #0 and #6 will not
476 // be de-duplicated. Entry #4 does not contain the text "title", so it 477 // be de-duplicated. Entry #4 does not contain the text "title", so it
477 // shouldn't appear. 478 // shouldn't appear.
478 int expected_results[] = { 2, 3, 1, 7, 6, 5 }; 479 int expected_results[] = { 2, 3, 1, 7, 6, 5 };
479 TestPaging("title", expected_results, arraysize(expected_results)); 480 TestPaging("title", expected_results, arraysize(expected_results));
480 } 481 }
481 482
482 } // namespace history 483 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_browsertest.cc ('k') | chrome/browser/history/history_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698