| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/offline_pages/downloads/download_notifying_observer.h" | 5 #include "components/offline_pages/downloads/download_notifying_observer.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "components/offline_pages/background/save_page_request.h" | 8 #include "components/offline_pages/background/save_page_request.h" |
| 9 #include "components/offline_pages/client_namespace_constants.h" | 9 #include "components/offline_pages/client_namespace_constants.h" |
| 10 #include "components/offline_pages/client_policy_controller.h" | 10 #include "components/offline_pages/client_policy_controller.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 DownloadNotifyingObserverTest::~DownloadNotifyingObserverTest() {} | 121 DownloadNotifyingObserverTest::~DownloadNotifyingObserverTest() {} |
| 122 | 122 |
| 123 void DownloadNotifyingObserverTest::SetUp() { | 123 void DownloadNotifyingObserverTest::SetUp() { |
| 124 std::unique_ptr<TestNotifier> notifier(new TestNotifier); | 124 std::unique_ptr<TestNotifier> notifier(new TestNotifier); |
| 125 policy_controller_.reset(new ClientPolicyController()); | 125 policy_controller_.reset(new ClientPolicyController()); |
| 126 notifier_ = notifier.get(); | 126 notifier_ = notifier.get(); |
| 127 observer_.reset(new DownloadNotifyingObserver(std::move(notifier), | 127 observer_.reset(new DownloadNotifyingObserver(std::move(notifier), |
| 128 policy_controller_.get())); | 128 policy_controller_.get())); |
| 129 } | 129 } |
| 130 | 130 |
| 131 TEST_F(DownloadNotifyingObserverTest, OnAdded) { | 131 TEST_F(DownloadNotifyingObserverTest, OnAddedAsAvailable) { |
| 132 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, | 132 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, |
| 133 kTestCreationTime, kTestUserRequested); | 133 kTestCreationTime, kTestUserRequested); |
| 134 request.set_request_state(SavePageRequest::RequestState::AVAILABLE); |
| 134 observer()->OnAdded(request); | 135 observer()->OnAdded(request); |
| 135 EXPECT_EQ(LastNotificationType::DOWNLOAD_PROGRESS, | 136 EXPECT_EQ(LastNotificationType::DOWNLOAD_INTERRUPTED, |
| 136 notifier()->last_notification_type()); | 137 notifier()->last_notification_type()); |
| 137 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); | 138 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); |
| 138 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); | 139 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); |
| 139 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); | 140 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); |
| 140 } | 141 } |
| 141 | 142 |
| 143 TEST_F(DownloadNotifyingObserverTest, OnAddedAsOffling) { |
| 144 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, |
| 145 kTestCreationTime, kTestUserRequested); |
| 146 request.set_request_state(SavePageRequest::RequestState::OFFLINING); |
| 147 observer()->OnAdded(request); |
| 148 EXPECT_EQ(LastNotificationType::DOWNLOAD_PROGRESS, |
| 149 notifier()->last_notification_type()); |
| 150 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); |
| 151 } |
| 152 |
| 153 TEST_F(DownloadNotifyingObserverTest, OnAddedAsPaused) { |
| 154 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, |
| 155 kTestCreationTime, kTestUserRequested); |
| 156 request.set_request_state(SavePageRequest::RequestState::PAUSED); |
| 157 observer()->OnAdded(request); |
| 158 EXPECT_EQ(LastNotificationType::DOWNLOAD_PAUSED, |
| 159 notifier()->last_notification_type()); |
| 160 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); |
| 161 } |
| 162 |
| 142 TEST_F(DownloadNotifyingObserverTest, OnChangedToPaused) { | 163 TEST_F(DownloadNotifyingObserverTest, OnChangedToPaused) { |
| 143 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, | 164 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, |
| 144 kTestCreationTime, kTestUserRequested); | 165 kTestCreationTime, kTestUserRequested); |
| 145 request.set_request_state(SavePageRequest::RequestState::PAUSED); | 166 request.set_request_state(SavePageRequest::RequestState::PAUSED); |
| 146 observer()->OnChanged(request); | 167 observer()->OnChanged(request); |
| 147 EXPECT_EQ(LastNotificationType::DOWNLOAD_PAUSED, | 168 EXPECT_EQ(LastNotificationType::DOWNLOAD_PAUSED, |
| 148 notifier()->last_notification_type()); | 169 notifier()->last_notification_type()); |
| 149 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); | 170 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); |
| 150 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); | 171 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); |
| 151 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); | 172 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); |
| 152 } | 173 } |
| 153 | 174 |
| 154 TEST_F(DownloadNotifyingObserverTest, OnChangedToAvailable) { | 175 TEST_F(DownloadNotifyingObserverTest, OnChangedToAvailable) { |
| 155 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, | 176 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, |
| 156 kTestCreationTime, kTestUserRequested); | 177 kTestCreationTime, kTestUserRequested); |
| 157 request.set_request_state(SavePageRequest::RequestState::AVAILABLE); | 178 request.set_request_state(SavePageRequest::RequestState::AVAILABLE); |
| 158 observer()->OnChanged(request); | 179 observer()->OnChanged(request); |
| 180 EXPECT_EQ(LastNotificationType::DOWNLOAD_INTERRUPTED, |
| 181 notifier()->last_notification_type()); |
| 182 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); |
| 183 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); |
| 184 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); |
| 185 } |
| 186 |
| 187 TEST_F(DownloadNotifyingObserverTest, OnChangedToOfflining) { |
| 188 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, |
| 189 kTestCreationTime, kTestUserRequested); |
| 190 request.set_request_state(SavePageRequest::RequestState::OFFLINING); |
| 191 observer()->OnChanged(request); |
| 159 EXPECT_EQ(LastNotificationType::DOWNLOAD_PROGRESS, | 192 EXPECT_EQ(LastNotificationType::DOWNLOAD_PROGRESS, |
| 160 notifier()->last_notification_type()); | 193 notifier()->last_notification_type()); |
| 161 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); | 194 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); |
| 162 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); | 195 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); |
| 163 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); | 196 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); |
| 164 } | 197 } |
| 165 | 198 |
| 166 TEST_F(DownloadNotifyingObserverTest, OnCompletedSuccess) { | 199 TEST_F(DownloadNotifyingObserverTest, OnCompletedSuccess) { |
| 167 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, | 200 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, |
| 168 kTestCreationTime, kTestUserRequested); | 201 kTestCreationTime, kTestUserRequested); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 for (auto name_space : name_spaces) { | 275 for (auto name_space : name_spaces) { |
| 243 ClientId invisible_client_id(name_space, kTestGuid); | 276 ClientId invisible_client_id(name_space, kTestGuid); |
| 244 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), invisible_client_id, | 277 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), invisible_client_id, |
| 245 kTestCreationTime, kTestUserRequested); | 278 kTestCreationTime, kTestUserRequested); |
| 246 observer()->OnAdded(request); | 279 observer()->OnAdded(request); |
| 247 EXPECT_EQ(LastNotificationType::NONE, notifier()->last_notification_type()); | 280 EXPECT_EQ(LastNotificationType::NONE, notifier()->last_notification_type()); |
| 248 } | 281 } |
| 249 } | 282 } |
| 250 | 283 |
| 251 } // namespace offline_pages | 284 } // namespace offline_pages |
| OLD | NEW |