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

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

Issue 352913002: Port HistoryService::ScheduleDBTask to CancelableTaskTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 1509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 DISALLOW_COPY_AND_ASSIGN(HistoryDBTaskImpl); 1520 DISALLOW_COPY_AND_ASSIGN(HistoryDBTaskImpl);
1521 }; 1521 };
1522 1522
1523 // static 1523 // static
1524 const int HistoryDBTaskImpl::kWantInvokeCount = 2; 1524 const int HistoryDBTaskImpl::kWantInvokeCount = 2;
1525 1525
1526 } // namespace 1526 } // namespace
1527 1527
1528 TEST_F(HistoryTest, HistoryDBTask) { 1528 TEST_F(HistoryTest, HistoryDBTask) {
1529 ASSERT_TRUE(history_service_.get()); 1529 ASSERT_TRUE(history_service_.get());
1530 CancelableRequestConsumerT<int, 0> request_consumer; 1530 base::CancelableTaskTracker task_tracker;
1531 scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl()); 1531 scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl());
1532 history_service_->ScheduleDBTask(task.get(), &request_consumer); 1532 history_service_->ScheduleDBTask(task.get(), &task_tracker);
1533 // Run the message loop. When HistoryDBTaskImpl::DoneRunOnMainThread runs, 1533 // Run the message loop. When HistoryDBTaskImpl::DoneRunOnMainThread runs,
1534 // it will stop the message loop. If the test hangs here, it means 1534 // it will stop the message loop. If the test hangs here, it means
1535 // DoneRunOnMainThread isn't being invoked correctly. 1535 // DoneRunOnMainThread isn't being invoked correctly.
1536 base::MessageLoop::current()->Run(); 1536 base::MessageLoop::current()->Run();
1537 CleanupHistoryService(); 1537 CleanupHistoryService();
1538 // WARNING: history has now been deleted. 1538 // WARNING: history has now been deleted.
1539 history_service_.reset(); 1539 history_service_.reset();
1540 ASSERT_EQ(HistoryDBTaskImpl::kWantInvokeCount, task->invoke_count); 1540 ASSERT_EQ(HistoryDBTaskImpl::kWantInvokeCount, task->invoke_count);
1541 ASSERT_TRUE(task->done_invoked); 1541 ASSERT_TRUE(task->done_invoked);
1542 } 1542 }
1543 1543
1544 TEST_F(HistoryTest, HistoryDBTaskCanceled) { 1544 TEST_F(HistoryTest, HistoryDBTaskCanceled) {
1545 ASSERT_TRUE(history_service_.get()); 1545 ASSERT_TRUE(history_service_.get());
1546 CancelableRequestConsumerT<int, 0> request_consumer; 1546 base::CancelableTaskTracker task_tracker;
1547 scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl()); 1547 scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl());
1548 history_service_->ScheduleDBTask(task.get(), &request_consumer); 1548 history_service_->ScheduleDBTask(task.get(), &task_tracker);
1549 request_consumer.CancelAllRequests(); 1549 task_tracker.TryCancelAll();
1550 CleanupHistoryService(); 1550 CleanupHistoryService();
1551 // WARNING: history has now been deleted. 1551 // WARNING: history has now been deleted.
1552 history_service_.reset(); 1552 history_service_.reset();
1553 ASSERT_FALSE(task->done_invoked); 1553 ASSERT_FALSE(task->done_invoked);
1554 } 1554 }
1555 1555
1556 // Create a local delete directive and process it while sync is 1556 // Create a local delete directive and process it while sync is
1557 // online, and then when offline. The delete directive should be sent to sync, 1557 // online, and then when offline. The delete directive should be sent to sync,
1558 // no error should be returned for the first time, and an error should be 1558 // no error should be returned for the first time, and an error should be
1559 // returned for the second time. 1559 // returned for the second time.
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 std::vector<PageUsageData*> results; 1856 std::vector<PageUsageData*> results;
1857 db_->QuerySegmentUsage(segment_time, 10, &results); 1857 db_->QuerySegmentUsage(segment_time, 10, &results);
1858 ASSERT_EQ(1u, results.size()); 1858 ASSERT_EQ(1u, results.size());
1859 EXPECT_EQ(url, results[0]->GetURL()); 1859 EXPECT_EQ(url, results[0]->GetURL());
1860 EXPECT_EQ(segment_id, results[0]->GetID()); 1860 EXPECT_EQ(segment_id, results[0]->GetID());
1861 EXPECT_EQ(title, results[0]->GetTitle()); 1861 EXPECT_EQ(title, results[0]->GetTitle());
1862 STLDeleteElements(&results); 1862 STLDeleteElements(&results);
1863 } 1863 }
1864 1864
1865 } // namespace history 1865 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698