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

Unified Diff: chrome/browser/history/history_unittest.cc

Issue 387923002: Make HistoryDBTask not refcounted, and ensure it's destroyed on its origin thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert unnecessary changes Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/history/history_service.cc ('k') | chrome/browser/history/in_memory_url_index.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/history/history_unittest.cc
diff --git a/chrome/browser/history/history_unittest.cc b/chrome/browser/history/history_unittest.cc
index 5c242665171687bdfb09bc456a2b69b5b5767fa8..a5b37139b01d95631deb24726b0f083b7976ec98 100644
--- a/chrome/browser/history/history_unittest.cc
+++ b/chrome/browser/history/history_unittest.cc
@@ -1502,20 +1502,21 @@ class HistoryDBTaskImpl : public HistoryDBTask {
public:
static const int kWantInvokeCount;
- HistoryDBTaskImpl() : invoke_count(0), done_invoked(false) {}
+ HistoryDBTaskImpl(int* invoke_count, bool* done_invoked)
+ : invoke_count_(invoke_count), done_invoked_(done_invoked) {}
virtual bool RunOnDBThread(HistoryBackend* backend,
HistoryDatabase* db) OVERRIDE {
- return (++invoke_count == kWantInvokeCount);
+ return (++*invoke_count_ == kWantInvokeCount);
}
virtual void DoneRunOnMainThread() OVERRIDE {
- done_invoked = true;
+ *done_invoked_ = true;
base::MessageLoop::current()->Quit();
}
- int invoke_count;
- bool done_invoked;
+ int* invoke_count_;
+ bool* done_invoked_;
private:
virtual ~HistoryDBTaskImpl() {}
@@ -1531,8 +1532,12 @@ const int HistoryDBTaskImpl::kWantInvokeCount = 2;
TEST_F(HistoryTest, HistoryDBTask) {
ASSERT_TRUE(history_service_.get());
base::CancelableTaskTracker task_tracker;
- scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl());
- history_service_->ScheduleDBTask(task.get(), &task_tracker);
+ int invoke_count = 0;
+ bool done_invoked = false;
+ history_service_->ScheduleDBTask(
+ scoped_ptr<history::HistoryDBTask>(
+ new HistoryDBTaskImpl(&invoke_count, &done_invoked)),
+ &task_tracker);
// Run the message loop. When HistoryDBTaskImpl::DoneRunOnMainThread runs,
// it will stop the message loop. If the test hangs here, it means
// DoneRunOnMainThread isn't being invoked correctly.
@@ -1540,20 +1545,24 @@ TEST_F(HistoryTest, HistoryDBTask) {
CleanupHistoryService();
// WARNING: history has now been deleted.
history_service_.reset();
- ASSERT_EQ(HistoryDBTaskImpl::kWantInvokeCount, task->invoke_count);
- ASSERT_TRUE(task->done_invoked);
+ ASSERT_EQ(HistoryDBTaskImpl::kWantInvokeCount, invoke_count);
+ ASSERT_TRUE(done_invoked);
}
TEST_F(HistoryTest, HistoryDBTaskCanceled) {
ASSERT_TRUE(history_service_.get());
base::CancelableTaskTracker task_tracker;
- scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl());
- history_service_->ScheduleDBTask(task.get(), &task_tracker);
+ int invoke_count = 0;
+ bool done_invoked = false;
+ history_service_->ScheduleDBTask(
+ scoped_ptr<history::HistoryDBTask>(
+ new HistoryDBTaskImpl(&invoke_count, &done_invoked)),
+ &task_tracker);
task_tracker.TryCancelAll();
CleanupHistoryService();
// WARNING: history has now been deleted.
history_service_.reset();
- ASSERT_FALSE(task->done_invoked);
+ ASSERT_FALSE(done_invoked);
}
// Create a local delete directive and process it while sync is
« no previous file with comments | « chrome/browser/history/history_service.cc ('k') | chrome/browser/history/in_memory_url_index.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698