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

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

Issue 416543006: Revert 284958 "Make HistoryDBTask not refcounted, and ensure it'..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 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 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 1495
1496 // A HistoryDBTask implementation. Each time RunOnDBThread is invoked 1496 // A HistoryDBTask implementation. Each time RunOnDBThread is invoked
1497 // invoke_count is increment. When invoked kWantInvokeCount times, true is 1497 // invoke_count is increment. When invoked kWantInvokeCount times, true is
1498 // returned from RunOnDBThread which should stop RunOnDBThread from being 1498 // returned from RunOnDBThread which should stop RunOnDBThread from being
1499 // invoked again. When DoneRunOnMainThread is invoked, done_invoked is set to 1499 // invoked again. When DoneRunOnMainThread is invoked, done_invoked is set to
1500 // true. 1500 // true.
1501 class HistoryDBTaskImpl : public HistoryDBTask { 1501 class HistoryDBTaskImpl : public HistoryDBTask {
1502 public: 1502 public:
1503 static const int kWantInvokeCount; 1503 static const int kWantInvokeCount;
1504 1504
1505 HistoryDBTaskImpl(int* invoke_count, bool* done_invoked) 1505 HistoryDBTaskImpl() : invoke_count(0), done_invoked(false) {}
1506 : invoke_count_(invoke_count), done_invoked_(done_invoked) {}
1507 1506
1508 virtual bool RunOnDBThread(HistoryBackend* backend, 1507 virtual bool RunOnDBThread(HistoryBackend* backend,
1509 HistoryDatabase* db) OVERRIDE { 1508 HistoryDatabase* db) OVERRIDE {
1510 return (++*invoke_count_ == kWantInvokeCount); 1509 return (++invoke_count == kWantInvokeCount);
1511 } 1510 }
1512 1511
1513 virtual void DoneRunOnMainThread() OVERRIDE { 1512 virtual void DoneRunOnMainThread() OVERRIDE {
1514 *done_invoked_ = true; 1513 done_invoked = true;
1515 base::MessageLoop::current()->Quit(); 1514 base::MessageLoop::current()->Quit();
1516 } 1515 }
1517 1516
1518 int* invoke_count_; 1517 int invoke_count;
1519 bool* done_invoked_; 1518 bool done_invoked;
1520 1519
1521 private: 1520 private:
1522 virtual ~HistoryDBTaskImpl() {} 1521 virtual ~HistoryDBTaskImpl() {}
1523 1522
1524 DISALLOW_COPY_AND_ASSIGN(HistoryDBTaskImpl); 1523 DISALLOW_COPY_AND_ASSIGN(HistoryDBTaskImpl);
1525 }; 1524 };
1526 1525
1527 // static 1526 // static
1528 const int HistoryDBTaskImpl::kWantInvokeCount = 2; 1527 const int HistoryDBTaskImpl::kWantInvokeCount = 2;
1529 1528
1530 } // namespace 1529 } // namespace
1531 1530
1532 TEST_F(HistoryTest, HistoryDBTask) { 1531 TEST_F(HistoryTest, HistoryDBTask) {
1533 ASSERT_TRUE(history_service_.get()); 1532 ASSERT_TRUE(history_service_.get());
1534 base::CancelableTaskTracker task_tracker; 1533 base::CancelableTaskTracker task_tracker;
1535 int invoke_count = 0; 1534 scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl());
1536 bool done_invoked = false; 1535 history_service_->ScheduleDBTask(task.get(), &task_tracker);
1537 history_service_->ScheduleDBTask(
1538 scoped_ptr<history::HistoryDBTask>(
1539 new HistoryDBTaskImpl(&invoke_count, &done_invoked)),
1540 &task_tracker);
1541 // Run the message loop. When HistoryDBTaskImpl::DoneRunOnMainThread runs, 1536 // Run the message loop. When HistoryDBTaskImpl::DoneRunOnMainThread runs,
1542 // it will stop the message loop. If the test hangs here, it means 1537 // it will stop the message loop. If the test hangs here, it means
1543 // DoneRunOnMainThread isn't being invoked correctly. 1538 // DoneRunOnMainThread isn't being invoked correctly.
1544 base::MessageLoop::current()->Run(); 1539 base::MessageLoop::current()->Run();
1545 CleanupHistoryService(); 1540 CleanupHistoryService();
1546 // WARNING: history has now been deleted. 1541 // WARNING: history has now been deleted.
1547 history_service_.reset(); 1542 history_service_.reset();
1548 ASSERT_EQ(HistoryDBTaskImpl::kWantInvokeCount, invoke_count); 1543 ASSERT_EQ(HistoryDBTaskImpl::kWantInvokeCount, task->invoke_count);
1549 ASSERT_TRUE(done_invoked); 1544 ASSERT_TRUE(task->done_invoked);
1550 } 1545 }
1551 1546
1552 TEST_F(HistoryTest, HistoryDBTaskCanceled) { 1547 TEST_F(HistoryTest, HistoryDBTaskCanceled) {
1553 ASSERT_TRUE(history_service_.get()); 1548 ASSERT_TRUE(history_service_.get());
1554 base::CancelableTaskTracker task_tracker; 1549 base::CancelableTaskTracker task_tracker;
1555 int invoke_count = 0; 1550 scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl());
1556 bool done_invoked = false; 1551 history_service_->ScheduleDBTask(task.get(), &task_tracker);
1557 history_service_->ScheduleDBTask(
1558 scoped_ptr<history::HistoryDBTask>(
1559 new HistoryDBTaskImpl(&invoke_count, &done_invoked)),
1560 &task_tracker);
1561 task_tracker.TryCancelAll(); 1552 task_tracker.TryCancelAll();
1562 CleanupHistoryService(); 1553 CleanupHistoryService();
1563 // WARNING: history has now been deleted. 1554 // WARNING: history has now been deleted.
1564 history_service_.reset(); 1555 history_service_.reset();
1565 ASSERT_FALSE(done_invoked); 1556 ASSERT_FALSE(task->done_invoked);
1566 } 1557 }
1567 1558
1568 // Create a local delete directive and process it while sync is 1559 // Create a local delete directive and process it while sync is
1569 // online, and then when offline. The delete directive should be sent to sync, 1560 // online, and then when offline. The delete directive should be sent to sync,
1570 // no error should be returned for the first time, and an error should be 1561 // no error should be returned for the first time, and an error should be
1571 // returned for the second time. 1562 // returned for the second time.
1572 TEST_F(HistoryTest, ProcessLocalDeleteDirectiveSyncOnline) { 1563 TEST_F(HistoryTest, ProcessLocalDeleteDirectiveSyncOnline) {
1573 ASSERT_TRUE(history_service_.get()); 1564 ASSERT_TRUE(history_service_.get());
1574 1565
1575 const GURL test_url("http://www.google.com/"); 1566 const GURL test_url("http://www.google.com/");
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 std::vector<PageUsageData*> results; 1859 std::vector<PageUsageData*> results;
1869 db_->QuerySegmentUsage(segment_time, 10, &results); 1860 db_->QuerySegmentUsage(segment_time, 10, &results);
1870 ASSERT_EQ(1u, results.size()); 1861 ASSERT_EQ(1u, results.size());
1871 EXPECT_EQ(url, results[0]->GetURL()); 1862 EXPECT_EQ(url, results[0]->GetURL());
1872 EXPECT_EQ(segment_id, results[0]->GetID()); 1863 EXPECT_EQ(segment_id, results[0]->GetID());
1873 EXPECT_EQ(title, results[0]->GetTitle()); 1864 EXPECT_EQ(title, results[0]->GetTitle());
1874 STLDeleteElements(&results); 1865 STLDeleteElements(&results);
1875 } 1866 }
1876 1867
1877 } // namespace history 1868 } // namespace history
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/history/history_service.cc ('k') | trunk/src/chrome/browser/history/in_memory_url_index.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698