Chromium Code Reviews| Index: chrome/browser/background_fetch/background_fetch_client_impl_unittest.cc |
| diff --git a/chrome/browser/background_fetch/background_fetch_client_impl_unittest.cc b/chrome/browser/background_fetch/background_fetch_client_impl_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..900539319911544faf54fa784fa92f12b36b3023 |
| --- /dev/null |
| +++ b/chrome/browser/background_fetch/background_fetch_client_impl_unittest.cc |
| @@ -0,0 +1,94 @@ |
| +// Copyright 2017 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 "chrome/browser/background_fetch/background_fetch_client_impl.h" |
| + |
| +#include "base/macros.h" |
| +#include "base/threading/thread_task_runner_handle.h" |
| +#include "chrome/browser/background_fetch/background_fetch_client_factory.h" |
| +#include "chrome/test/base/testing_profile.h" |
| +#include "components/offline_items_collection/core/offline_item.h" |
| +#include "content/public/test/test_browser_thread_bundle.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace { |
| + |
| +const char kRegistrationId[] = "1234:www.example.com:game_data"; |
| +const char kNamespace[] = "BackgroundFetchNamespace"; |
| + |
| +class FakeBackgroundFetchDelegate |
| + : public content::BackgroundFetchClient::Delegate { |
| + public: |
| + explicit FakeBackgroundFetchDelegate(const std::string& id) |
| + : expected_id_(id) {} |
| + |
| + void CancelDownload(const std::string& registration_id) override { |
| + ASSERT_EQ(registration_id, expected_id_); |
| + } |
| + |
| + void PauseDownload(const std::string& registration_id) override { |
| + ASSERT_EQ(registration_id, expected_id_); |
| + } |
| + |
| + void ResumeDownload(const std::string& registration_id) override { |
| + ASSERT_EQ(registration_id, expected_id_); |
| + } |
| + |
| + private: |
| + std::string expected_id_; |
| +}; |
| + |
| +class BackgroundFetchTestingProfile : public TestingProfile { |
| + public: |
| + BackgroundFetchTestingProfile() {} |
| + ~BackgroundFetchTestingProfile() override {} |
| + |
| + BackgroundFetchClientImpl* GetBackgroundFetchClient() override { |
| + return BackgroundFetchClientFactory::GetForProfile(this); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(BackgroundFetchTestingProfile); |
| +}; |
| + |
| +} // namespace |
| + |
| +class BackgroundFetchClientTest : public ::testing::Test { |
| + public: |
| + BackgroundFetchClientTest() {} |
| + ~BackgroundFetchClientTest() override {} |
| + |
| + private: |
| + content::TestBrowserThreadBundle thread_bundle_; |
| + |
| + protected: |
| + BackgroundFetchTestingProfile profile_; |
| +}; |
| + |
| +TEST_F(BackgroundFetchClientTest, CancelDownloadTest) { |
| + BackgroundFetchClientImpl* client = profile_.GetBackgroundFetchClient(); |
| + FakeBackgroundFetchDelegate delegate(kRegistrationId); |
| + client->SetDelegate(&delegate); |
| + |
| + offline_items_collection::ContentId id(kNamespace, kRegistrationId); |
| + ASSERT_NO_FATAL_FAILURE(client->CancelDownload(id)); |
| +} |
| + |
| +TEST_F(BackgroundFetchClientTest, PauseDownloadTest) { |
| + BackgroundFetchClientImpl* client = profile_.GetBackgroundFetchClient(); |
| + FakeBackgroundFetchDelegate delegate(kRegistrationId); |
| + client->SetDelegate(&delegate); |
| + |
| + offline_items_collection::ContentId id(kNamespace, kRegistrationId); |
| + ASSERT_NO_FATAL_FAILURE(client->PauseDownload(id)); |
| +} |
| + |
| +TEST_F(BackgroundFetchClientTest, ResumeDownloadTest) { |
| + BackgroundFetchClientImpl* client = profile_.GetBackgroundFetchClient(); |
| + FakeBackgroundFetchDelegate delegate(kRegistrationId); |
| + client->SetDelegate(&delegate); |
| + |
| + offline_items_collection::ContentId id(kNamespace, kRegistrationId); |
| + ASSERT_NO_FATAL_FAILURE(client->ResumeDownload(id)); |
|
Peter Beverloo
2017/03/31 01:32:23
I've got two worries with these tests:
(1) Half
harkness
2017/03/31 10:11:43
I don't really see a problem with #1. I've cleaned
Peter Beverloo
2017/03/31 11:54:06
Well, we always need to gauge whether adding tests
harkness
2017/04/03 12:47:22
I think any additional complexity will be on the c
|
| +} |