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

Unified Diff: components/offline_pages/background/mark_attempt_aborted_task_unittest.cc

Issue 2438503003: [Offline pages] Add MarkAttemptAbortedTask to Request Queue (Closed)
Patch Set: Addressing feedback -- adding comments and documentation Created 4 years, 2 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
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 67%
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..fc35d208cbfff684b8ede852ccb2ea9069bf4a37 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,24 @@ 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(
+ // First mark attempt started.
+ MarkAttemptStartedTask start_request_task(
+ &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 +120,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();

Powered by Google App Engine
This is Rietveld 408576698