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

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

Issue 2489443002: Move all components/offline_pages/ files into component/offline_pages/core (Closed)
Patch Set: more rebase Created 4 years, 1 month 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/remove_requests_task_unittest.cc
diff --git a/components/offline_pages/background/remove_requests_task_unittest.cc b/components/offline_pages/background/remove_requests_task_unittest.cc
deleted file mode 100644
index f83ed8ac89a6c7761068cf6f6a2f6790d55e7e01..0000000000000000000000000000000000000000
--- a/components/offline_pages/background/remove_requests_task_unittest.cc
+++ /dev/null
@@ -1,176 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// 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/remove_requests_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/request_queue_in_memory_store.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace offline_pages {
-namespace {
-const int64_t kRequestId1 = 42;
-const int64_t kRequestId2 = 43;
-const int64_t kRequestId3 = 44;
-const GURL kUrl1("http://example.com");
-const GURL kUrl2("http://another-example.com");
-const ClientId kClientId1("bookmark", "1234");
-const ClientId kClientId2("async", "5678");
-} // namespace
-
-class RemoveRequestsTaskTest : public testing::Test {
- public:
- RemoveRequestsTaskTest();
- ~RemoveRequestsTaskTest() override;
-
- void PumpLoop();
-
- void AddRequestsToStore(RequestQueueStore* store);
-
- void AddRequestDone(ItemActionStatus status);
-
- void RemoveRequestsCallback(std::unique_ptr<UpdateRequestsResult> result);
-
- UpdateRequestsResult* last_result() const { return result_.get(); }
-
- private:
- std::unique_ptr<UpdateRequestsResult> result_;
- scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
- base::ThreadTaskRunnerHandle task_runner_handle_;
-};
-
-RemoveRequestsTaskTest::RemoveRequestsTaskTest()
- : task_runner_(new base::TestSimpleTaskRunner),
- task_runner_handle_(task_runner_) {}
-
-RemoveRequestsTaskTest::~RemoveRequestsTaskTest() {}
-
-void RemoveRequestsTaskTest::PumpLoop() {
- task_runner_->RunUntilIdle();
-}
-
-void RemoveRequestsTaskTest::AddRequestsToStore(RequestQueueStore* store) {
- base::Time creation_time = base::Time::Now();
- SavePageRequest request_1(kRequestId1, kUrl1, kClientId1, creation_time,
- true);
- store->AddRequest(request_1,
- base::Bind(&RemoveRequestsTaskTest::AddRequestDone,
- base::Unretained(this)));
- SavePageRequest request_2(kRequestId2, kUrl2, kClientId2, creation_time,
- true);
- store->AddRequest(request_2,
- base::Bind(&RemoveRequestsTaskTest::AddRequestDone,
- base::Unretained(this)));
- PumpLoop();
-}
-
-void RemoveRequestsTaskTest::AddRequestDone(ItemActionStatus status) {
- ASSERT_EQ(ItemActionStatus::SUCCESS, status);
-}
-
-void RemoveRequestsTaskTest::RemoveRequestsCallback(
- std::unique_ptr<UpdateRequestsResult> result) {
- result_ = std::move(result);
-}
-
-TEST_F(RemoveRequestsTaskTest, RemoveWhenStoreEmpty) {
- RequestQueueInMemoryStore store;
- std::vector<int64_t> request_ids{kRequestId1};
- RemoveRequestsTask task(
- &store, request_ids,
- base::Bind(&RemoveRequestsTaskTest::RemoveRequestsCallback,
- base::Unretained(this)));
- task.Run();
- PumpLoop();
- ASSERT_TRUE(last_result());
- EXPECT_EQ(1UL, last_result()->item_statuses.size());
- EXPECT_EQ(kRequestId1, last_result()->item_statuses.at(0).first);
- EXPECT_EQ(ItemActionStatus::NOT_FOUND,
- last_result()->item_statuses.at(0).second);
- EXPECT_EQ(0UL, last_result()->updated_items.size());
-}
-
-TEST_F(RemoveRequestsTaskTest, RemoveSingleItem) {
- RequestQueueInMemoryStore store;
- AddRequestsToStore(&store);
- std::vector<int64_t> request_ids{kRequestId1};
- RemoveRequestsTask task(
- &store, request_ids,
- base::Bind(&RemoveRequestsTaskTest::RemoveRequestsCallback,
- base::Unretained(this)));
- task.Run();
- PumpLoop();
- ASSERT_TRUE(last_result());
- EXPECT_EQ(1UL, last_result()->item_statuses.size());
- EXPECT_EQ(kRequestId1, last_result()->item_statuses.at(0).first);
- EXPECT_EQ(ItemActionStatus::SUCCESS,
- last_result()->item_statuses.at(0).second);
- EXPECT_EQ(1UL, last_result()->updated_items.size());
- EXPECT_EQ(kRequestId1, last_result()->updated_items.at(0).request_id());
-}
-
-TEST_F(RemoveRequestsTaskTest, RemoveMultipleItems) {
- RequestQueueInMemoryStore store;
- AddRequestsToStore(&store);
- std::vector<int64_t> request_ids{kRequestId1, kRequestId2};
- RemoveRequestsTask task(
- &store, request_ids,
- base::Bind(&RemoveRequestsTaskTest::RemoveRequestsCallback,
- base::Unretained(this)));
- task.Run();
- PumpLoop();
- ASSERT_TRUE(last_result());
- EXPECT_EQ(2UL, last_result()->item_statuses.size());
- EXPECT_EQ(kRequestId1, last_result()->item_statuses.at(0).first);
- EXPECT_EQ(ItemActionStatus::SUCCESS,
- last_result()->item_statuses.at(0).second);
- EXPECT_EQ(kRequestId2, last_result()->item_statuses.at(1).first);
- EXPECT_EQ(ItemActionStatus::SUCCESS,
- last_result()->item_statuses.at(1).second);
- EXPECT_EQ(2UL, last_result()->updated_items.size());
- EXPECT_EQ(kRequestId1, last_result()->updated_items.at(0).request_id());
- EXPECT_EQ(kRequestId2, last_result()->updated_items.at(1).request_id());
-}
-
-TEST_F(RemoveRequestsTaskTest, DeleteWithEmptyIdList) {
- RequestQueueInMemoryStore store;
- std::vector<int64_t> request_ids;
- RemoveRequestsTask task(
- &store, request_ids,
- base::Bind(&RemoveRequestsTaskTest::RemoveRequestsCallback,
- base::Unretained(this)));
- task.Run();
- PumpLoop();
- ASSERT_TRUE(last_result());
- EXPECT_EQ(0UL, last_result()->item_statuses.size());
- EXPECT_EQ(0UL, last_result()->updated_items.size());
-}
-
-TEST_F(RemoveRequestsTaskTest, RemoveMissingItem) {
- RequestQueueInMemoryStore store;
- AddRequestsToStore(&store);
- std::vector<int64_t> request_ids{kRequestId1, kRequestId3};
- RemoveRequestsTask task(
- &store, request_ids,
- base::Bind(&RemoveRequestsTaskTest::RemoveRequestsCallback,
- base::Unretained(this)));
- task.Run();
- PumpLoop();
- ASSERT_TRUE(last_result());
- EXPECT_EQ(2UL, last_result()->item_statuses.size());
- EXPECT_EQ(kRequestId1, last_result()->item_statuses.at(0).first);
- EXPECT_EQ(ItemActionStatus::SUCCESS,
- last_result()->item_statuses.at(0).second);
- EXPECT_EQ(kRequestId3, last_result()->item_statuses.at(1).first);
- EXPECT_EQ(ItemActionStatus::NOT_FOUND,
- last_result()->item_statuses.at(1).second);
- EXPECT_EQ(1UL, last_result()->updated_items.size());
- EXPECT_EQ(kRequestId1, last_result()->updated_items.at(0).request_id());
-}
-
-} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698