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); | |
Peter Beverloo
2017/03/31 11:54:06
What do you think about just calling the factory i
harkness
2017/04/03 12:47:22
Done.
| |
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_; | |
Peter Beverloo
2017/03/31 11:54:06
style: Protected before private. Just make both pr
harkness
2017/04/03 12:47:22
Done.
| |
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 client->SetDelegate(nullptr); | |
78 ASSERT_NO_FATAL_FAILURE(client->CancelDownload(id)); | |
79 } | |
80 | |
81 TEST_F(BackgroundFetchClientTest, PauseDownloadTest) { | |
82 BackgroundFetchClientImpl* client = profile_.GetBackgroundFetchClient(); | |
83 FakeBackgroundFetchDelegate delegate(kRegistrationId); | |
84 client->SetDelegate(&delegate); | |
85 | |
86 offline_items_collection::ContentId id(kNamespace, kRegistrationId); | |
87 ASSERT_NO_FATAL_FAILURE(client->PauseDownload(id)); | |
88 | |
89 client->SetDelegate(nullptr); | |
90 ASSERT_NO_FATAL_FAILURE(client->PauseDownload(id)); | |
91 } | |
92 | |
93 TEST_F(BackgroundFetchClientTest, ResumeDownloadTest) { | |
94 BackgroundFetchClientImpl* client = profile_.GetBackgroundFetchClient(); | |
95 FakeBackgroundFetchDelegate delegate(kRegistrationId); | |
96 client->SetDelegate(&delegate); | |
97 | |
98 offline_items_collection::ContentId id(kNamespace, kRegistrationId); | |
99 ASSERT_NO_FATAL_FAILURE(client->ResumeDownload(id)); | |
100 | |
101 client->SetDelegate(nullptr); | |
102 ASSERT_NO_FATAL_FAILURE(client->ResumeDownload(id)); | |
103 } | |
OLD | NEW |