Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/background_fetch/background_fetch_client_impl.h" | |
| 6 | |
| 7 #include "base/macros.h" | |
| 8 #include "base/threading/thread_task_runner_handle.h" | |
| 9 #include "chrome/browser/background_fetch/background_fetch_client_factory.h" | |
| 10 #include "chrome/test/base/testing_profile.h" | |
| 11 #include "components/offline_items_collection/core/offline_item.h" | |
| 12 #include "content/public/test/test_browser_thread_bundle.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 const char kRegistrationId[] = "1234:www.example.com:game_data"; | |
| 18 const char kNamespace[] = "BackgroundFetchNamespace"; | |
| 19 | |
| 20 class FakeBackgroundFetchDelegate | |
| 21 : public content::BackgroundFetchClient::Delegate { | |
| 22 public: | |
| 23 explicit FakeBackgroundFetchDelegate(const std::string& id) | |
| 24 : expected_id_(id) {} | |
| 25 | |
| 26 void CancelDownload(const std::string& registration_id) override { | |
| 27 ASSERT_EQ(registration_id, expected_id_); | |
| 28 } | |
| 29 | |
| 30 void PauseDownload(const std::string& registration_id) override { | |
| 31 ASSERT_EQ(registration_id, expected_id_); | |
| 32 } | |
| 33 | |
| 34 void ResumeDownload(const std::string& registration_id) override { | |
| 35 ASSERT_EQ(registration_id, expected_id_); | |
| 36 } | |
| 37 | |
| 38 private: | |
| 39 std::string expected_id_; | |
| 40 }; | |
| 41 | |
| 42 class BackgroundFetchTestingProfile : public TestingProfile { | |
| 43 public: | |
| 44 BackgroundFetchTestingProfile() {} | |
| 45 ~BackgroundFetchTestingProfile() override {} | |
| 46 | |
| 47 BackgroundFetchClientImpl* GetBackgroundFetchClient() override { | |
| 48 return BackgroundFetchClientFactory::GetForProfile(this); | |
| 49 } | |
| 50 | |
| 51 private: | |
| 52 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchTestingProfile); | |
| 53 }; | |
| 54 | |
| 55 } // namespace | |
| 56 | |
| 57 class BackgroundFetchClientTest : public ::testing::Test { | |
| 58 public: | |
| 59 BackgroundFetchClientTest() {} | |
| 60 ~BackgroundFetchClientTest() override {} | |
| 61 | |
| 62 private: | |
| 63 content::TestBrowserThreadBundle thread_bundle_; | |
| 64 | |
| 65 protected: | |
| 66 BackgroundFetchTestingProfile profile_; | |
| 67 }; | |
| 68 | |
| 69 TEST_F(BackgroundFetchClientTest, CancelDownloadTest) { | |
| 70 BackgroundFetchClientImpl* client = profile_.GetBackgroundFetchClient(); | |
| 71 FakeBackgroundFetchDelegate delegate(kRegistrationId); | |
| 72 client->SetDelegate(&delegate); | |
| 73 | |
| 74 offline_items_collection::ContentId id(kNamespace, kRegistrationId); | |
| 75 ASSERT_NO_FATAL_FAILURE(client->CancelDownload(id)); | |
| 76 } | |
| 77 | |
| 78 TEST_F(BackgroundFetchClientTest, PauseDownloadTest) { | |
| 79 BackgroundFetchClientImpl* client = profile_.GetBackgroundFetchClient(); | |
| 80 FakeBackgroundFetchDelegate delegate(kRegistrationId); | |
| 81 client->SetDelegate(&delegate); | |
| 82 | |
| 83 offline_items_collection::ContentId id(kNamespace, kRegistrationId); | |
| 84 ASSERT_NO_FATAL_FAILURE(client->PauseDownload(id)); | |
| 85 } | |
| 86 | |
| 87 TEST_F(BackgroundFetchClientTest, ResumeDownloadTest) { | |
| 88 BackgroundFetchClientImpl* client = profile_.GetBackgroundFetchClient(); | |
| 89 FakeBackgroundFetchDelegate delegate(kRegistrationId); | |
| 90 client->SetDelegate(&delegate); | |
| 91 | |
| 92 offline_items_collection::ContentId id(kNamespace, kRegistrationId); | |
| 93 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
| |
| 94 } | |
| OLD | NEW |