Chromium Code Reviews| Index: components/offline_pages/background/mark_attempt_aborted_task_unittest.cc |
| diff --git a/components/offline_pages/background/mark_attempt_started_task_unittest.cc b/components/offline_pages/background/mark_attempt_aborted_task_unittest.cc |
| similarity index 68% |
| copy from components/offline_pages/background/mark_attempt_started_task_unittest.cc |
| copy to components/offline_pages/background/mark_attempt_aborted_task_unittest.cc |
| index 3e770c872a05a393a9bbeee87eadcac9d02f4366..f0b1a2ae84a5e63e00201753cb1393932aa89d16 100644 |
| --- a/components/offline_pages/background/mark_attempt_started_task_unittest.cc |
| +++ b/components/offline_pages/background/mark_attempt_aborted_task_unittest.cc |
| @@ -2,13 +2,14 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "components/offline_pages/background/mark_attempt_started_task.h" |
| +#include "components/offline_pages/background/mark_attempt_aborted_task.h" |
| #include <memory> |
| #include "base/bind.h" |
| #include "base/test/test_simple_task_runner.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| +#include "components/offline_pages/background/mark_attempt_started_task.h" |
| #include "components/offline_pages/background/request_queue_in_memory_store.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -20,10 +21,10 @@ const GURL kUrl1("http://example.com"); |
| const ClientId kClientId1("download", "1234"); |
| } // namespace |
| -class MarkAttemptStartedTaskTest : public testing::Test { |
| +class MarkAttemptAbortedTaskTest : public testing::Test { |
| public: |
| - MarkAttemptStartedTaskTest(); |
| - ~MarkAttemptStartedTaskTest() override; |
| + MarkAttemptAbortedTaskTest(); |
| + ~MarkAttemptAbortedTaskTest() override; |
| void PumpLoop(); |
| @@ -34,6 +35,8 @@ class MarkAttemptStartedTaskTest : public testing::Test { |
| void ChangeRequestsStateCallback( |
| std::unique_ptr<UpdateRequestsResult> result); |
| + void ClearResults(); |
| + |
| UpdateRequestsResult* last_result() const { return result_.get(); } |
| private: |
| @@ -42,40 +45,44 @@ class MarkAttemptStartedTaskTest : public testing::Test { |
| base::ThreadTaskRunnerHandle task_runner_handle_; |
| }; |
| -MarkAttemptStartedTaskTest::MarkAttemptStartedTaskTest() |
| +MarkAttemptAbortedTaskTest::MarkAttemptAbortedTaskTest() |
| : task_runner_(new base::TestSimpleTaskRunner), |
| task_runner_handle_(task_runner_) {} |
| -MarkAttemptStartedTaskTest::~MarkAttemptStartedTaskTest() {} |
| +MarkAttemptAbortedTaskTest::~MarkAttemptAbortedTaskTest() {} |
| -void MarkAttemptStartedTaskTest::PumpLoop() { |
| +void MarkAttemptAbortedTaskTest::PumpLoop() { |
| task_runner_->RunUntilIdle(); |
| } |
| -void MarkAttemptStartedTaskTest::AddItemToStore(RequestQueueStore* store) { |
| +void MarkAttemptAbortedTaskTest::AddItemToStore(RequestQueueStore* store) { |
| base::Time creation_time = base::Time::Now(); |
| SavePageRequest request_1(kRequestId1, kUrl1, kClientId1, creation_time, |
| true); |
| store->AddRequest(request_1, |
| - base::Bind(&MarkAttemptStartedTaskTest::AddRequestDone, |
| + base::Bind(&MarkAttemptAbortedTaskTest::AddRequestDone, |
| base::Unretained(this))); |
| PumpLoop(); |
| } |
| -void MarkAttemptStartedTaskTest::AddRequestDone(ItemActionStatus status) { |
| +void MarkAttemptAbortedTaskTest::AddRequestDone(ItemActionStatus status) { |
| ASSERT_EQ(ItemActionStatus::SUCCESS, status); |
| } |
| -void MarkAttemptStartedTaskTest::ChangeRequestsStateCallback( |
| +void MarkAttemptAbortedTaskTest::ChangeRequestsStateCallback( |
| std::unique_ptr<UpdateRequestsResult> result) { |
| result_ = std::move(result); |
| } |
| -TEST_F(MarkAttemptStartedTaskTest, MarkAttemptStartedWhenStoreEmpty) { |
| +void MarkAttemptAbortedTaskTest::ClearResults() { |
| + result_.reset(nullptr); |
| +} |
| + |
| +TEST_F(MarkAttemptAbortedTaskTest, MarkAttemptAbortedWhenStoreEmpty) { |
| RequestQueueInMemoryStore store; |
| - MarkAttemptStartedTask task( |
| + MarkAttemptAbortedTask task( |
| &store, kRequestId1, |
| - base::Bind(&MarkAttemptStartedTaskTest::ChangeRequestsStateCallback, |
| + base::Bind(&MarkAttemptAbortedTaskTest::ChangeRequestsStateCallback, |
| base::Unretained(this))); |
| task.Run(); |
| PumpLoop(); |
| @@ -87,17 +94,23 @@ TEST_F(MarkAttemptStartedTaskTest, MarkAttemptStartedWhenStoreEmpty) { |
| EXPECT_EQ(0UL, last_result()->updated_items.size()); |
| } |
| -TEST_F(MarkAttemptStartedTaskTest, MarkAttemptStartedWhenExists) { |
| +TEST_F(MarkAttemptAbortedTaskTest, MarkAttemptAbortedWhenExists) { |
| RequestQueueInMemoryStore store; |
| AddItemToStore(&store); |
| - MarkAttemptStartedTask task( |
| + MarkAttemptStartedTask start_request_task( |
|
dougarnett
2016/10/19 21:23:10
// First mark the request as started.
fgorski
2016/10/20 16:56:34
Done.
|
| + &store, kRequestId1, |
| + base::Bind(&MarkAttemptAbortedTaskTest::ChangeRequestsStateCallback, |
| + base::Unretained(this))); |
| + start_request_task.Run(); |
| + PumpLoop(); |
| + ClearResults(); |
| + |
| + MarkAttemptAbortedTask task( |
| &store, kRequestId1, |
| - base::Bind(&MarkAttemptStartedTaskTest::ChangeRequestsStateCallback, |
| + base::Bind(&MarkAttemptAbortedTaskTest::ChangeRequestsStateCallback, |
| base::Unretained(this))); |
| - // Current time for verification. |
| - base::Time before_time = base::Time::Now(); |
| task.Run(); |
| PumpLoop(); |
| ASSERT_TRUE(last_result()); |
| @@ -106,21 +119,16 @@ TEST_F(MarkAttemptStartedTaskTest, MarkAttemptStartedWhenExists) { |
| EXPECT_EQ(ItemActionStatus::SUCCESS, |
| last_result()->item_statuses.at(0).second); |
| EXPECT_EQ(1UL, last_result()->updated_items.size()); |
| - EXPECT_LE(before_time, |
| - last_result()->updated_items.at(0).last_attempt_time()); |
| - EXPECT_GE(base::Time::Now(), |
| - last_result()->updated_items.at(0).last_attempt_time()); |
| - EXPECT_EQ(1, last_result()->updated_items.at(0).started_attempt_count()); |
| - EXPECT_EQ(SavePageRequest::RequestState::PRERENDERING, |
| + EXPECT_EQ(SavePageRequest::RequestState::AVAILABLE, |
| last_result()->updated_items.at(0).request_state()); |
| } |
| -TEST_F(MarkAttemptStartedTaskTest, MarkAttemptStartedWhenItemMissing) { |
| +TEST_F(MarkAttemptAbortedTaskTest, MarkAttemptAbortedWhenItemMissing) { |
| RequestQueueInMemoryStore store; |
| AddItemToStore(&store); |
| - MarkAttemptStartedTask task( |
| + MarkAttemptAbortedTask task( |
| &store, kRequestId2, |
| - base::Bind(&MarkAttemptStartedTaskTest::ChangeRequestsStateCallback, |
| + base::Bind(&MarkAttemptAbortedTaskTest::ChangeRequestsStateCallback, |
| base::Unretained(this))); |
| task.Run(); |
| PumpLoop(); |