OLD | NEW |
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 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1523 DISALLOW_COPY_AND_ASSIGN(HistoryDBTaskImpl); | 1523 DISALLOW_COPY_AND_ASSIGN(HistoryDBTaskImpl); |
1524 }; | 1524 }; |
1525 | 1525 |
1526 // static | 1526 // static |
1527 const int HistoryDBTaskImpl::kWantInvokeCount = 2; | 1527 const int HistoryDBTaskImpl::kWantInvokeCount = 2; |
1528 | 1528 |
1529 } // namespace | 1529 } // namespace |
1530 | 1530 |
1531 TEST_F(HistoryTest, HistoryDBTask) { | 1531 TEST_F(HistoryTest, HistoryDBTask) { |
1532 ASSERT_TRUE(history_service_.get()); | 1532 ASSERT_TRUE(history_service_.get()); |
1533 CancelableRequestConsumerT<int, 0> request_consumer; | 1533 base::CancelableTaskTracker task_tracker; |
1534 scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl()); | 1534 scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl()); |
1535 history_service_->ScheduleDBTask(task.get(), &request_consumer); | 1535 history_service_->ScheduleDBTask(task.get(), &task_tracker); |
1536 // Run the message loop. When HistoryDBTaskImpl::DoneRunOnMainThread runs, | 1536 // Run the message loop. When HistoryDBTaskImpl::DoneRunOnMainThread runs, |
1537 // 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 |
1538 // DoneRunOnMainThread isn't being invoked correctly. | 1538 // DoneRunOnMainThread isn't being invoked correctly. |
1539 base::MessageLoop::current()->Run(); | 1539 base::MessageLoop::current()->Run(); |
1540 CleanupHistoryService(); | 1540 CleanupHistoryService(); |
1541 // WARNING: history has now been deleted. | 1541 // WARNING: history has now been deleted. |
1542 history_service_.reset(); | 1542 history_service_.reset(); |
1543 ASSERT_EQ(HistoryDBTaskImpl::kWantInvokeCount, task->invoke_count); | 1543 ASSERT_EQ(HistoryDBTaskImpl::kWantInvokeCount, task->invoke_count); |
1544 ASSERT_TRUE(task->done_invoked); | 1544 ASSERT_TRUE(task->done_invoked); |
1545 } | 1545 } |
1546 | 1546 |
1547 TEST_F(HistoryTest, HistoryDBTaskCanceled) { | 1547 TEST_F(HistoryTest, HistoryDBTaskCanceled) { |
1548 ASSERT_TRUE(history_service_.get()); | 1548 ASSERT_TRUE(history_service_.get()); |
1549 CancelableRequestConsumerT<int, 0> request_consumer; | 1549 base::CancelableTaskTracker task_tracker; |
1550 scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl()); | 1550 scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl()); |
1551 history_service_->ScheduleDBTask(task.get(), &request_consumer); | 1551 history_service_->ScheduleDBTask(task.get(), &task_tracker); |
1552 request_consumer.CancelAllRequests(); | 1552 task_tracker.TryCancelAll(); |
1553 CleanupHistoryService(); | 1553 CleanupHistoryService(); |
1554 // WARNING: history has now been deleted. | 1554 // WARNING: history has now been deleted. |
1555 history_service_.reset(); | 1555 history_service_.reset(); |
1556 ASSERT_FALSE(task->done_invoked); | 1556 ASSERT_FALSE(task->done_invoked); |
1557 } | 1557 } |
1558 | 1558 |
1559 // Create a local delete directive and process it while sync is | 1559 // Create a local delete directive and process it while sync is |
1560 // 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, |
1561 // 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 |
1562 // returned for the second time. | 1562 // returned for the second time. |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 std::vector<PageUsageData*> results; | 1859 std::vector<PageUsageData*> results; |
1860 db_->QuerySegmentUsage(segment_time, 10, &results); | 1860 db_->QuerySegmentUsage(segment_time, 10, &results); |
1861 ASSERT_EQ(1u, results.size()); | 1861 ASSERT_EQ(1u, results.size()); |
1862 EXPECT_EQ(url, results[0]->GetURL()); | 1862 EXPECT_EQ(url, results[0]->GetURL()); |
1863 EXPECT_EQ(segment_id, results[0]->GetID()); | 1863 EXPECT_EQ(segment_id, results[0]->GetID()); |
1864 EXPECT_EQ(title, results[0]->GetTitle()); | 1864 EXPECT_EQ(title, results[0]->GetTitle()); |
1865 STLDeleteElements(&results); | 1865 STLDeleteElements(&results); |
1866 } | 1866 } |
1867 | 1867 |
1868 } // namespace history | 1868 } // namespace history |
OLD | NEW |