| 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/downloads/offline_page_download_notifier.h" | 10 #include "components/offline_pages/downloads/offline_page_download_notifier.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 EXPECT_EQ(LastNotificationType::DOWNLOAD_PROGRESS, | 155 EXPECT_EQ(LastNotificationType::DOWNLOAD_PROGRESS, |
| 156 notifier()->last_notification_type()); | 156 notifier()->last_notification_type()); |
| 157 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); | 157 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); |
| 158 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); | 158 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); |
| 159 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); | 159 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); |
| 160 } | 160 } |
| 161 | 161 |
| 162 TEST_F(DownloadNotifyingObserverTest, OnCompletedSuccess) { | 162 TEST_F(DownloadNotifyingObserverTest, OnCompletedSuccess) { |
| 163 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, | 163 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, |
| 164 kTestCreationTime, kTestUserRequested); | 164 kTestCreationTime, kTestUserRequested); |
| 165 observer()->OnCompleted(request, RequestNotifier::SavePageStatus::SUCCESS); | 165 observer()->OnCompleted(request, |
| 166 RequestNotifier::BackgroundSavePageResult::SUCCESS); |
| 166 EXPECT_EQ(LastNotificationType::DOWNLOAD_SUCCESSFUL, | 167 EXPECT_EQ(LastNotificationType::DOWNLOAD_SUCCESSFUL, |
| 167 notifier()->last_notification_type()); | 168 notifier()->last_notification_type()); |
| 168 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); | 169 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); |
| 169 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); | 170 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); |
| 170 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); | 171 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); |
| 171 } | 172 } |
| 172 | 173 |
| 173 TEST_F(DownloadNotifyingObserverTest, OnCompletedCanceled) { | 174 TEST_F(DownloadNotifyingObserverTest, OnCompletedCanceled) { |
| 174 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, | 175 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, |
| 175 kTestCreationTime, kTestUserRequested); | 176 kTestCreationTime, kTestUserRequested); |
| 176 observer()->OnCompleted(request, RequestNotifier::SavePageStatus::REMOVED); | 177 observer()->OnCompleted(request, |
| 178 RequestNotifier::BackgroundSavePageResult::REMOVED); |
| 177 EXPECT_EQ(LastNotificationType::DOWNLOAD_CANCELED, | 179 EXPECT_EQ(LastNotificationType::DOWNLOAD_CANCELED, |
| 178 notifier()->last_notification_type()); | 180 notifier()->last_notification_type()); |
| 179 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); | 181 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); |
| 180 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); | 182 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); |
| 181 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); | 183 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); |
| 182 } | 184 } |
| 183 | 185 |
| 184 TEST_F(DownloadNotifyingObserverTest, OnCompletedFailure) { | 186 TEST_F(DownloadNotifyingObserverTest, OnCompletedFailure) { |
| 185 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, | 187 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, |
| 186 kTestCreationTime, kTestUserRequested); | 188 kTestCreationTime, kTestUserRequested); |
| 187 observer()->OnCompleted(request, | 189 observer()->OnCompleted( |
| 188 RequestNotifier::SavePageStatus::PRERENDER_FAILURE); | 190 request, RequestNotifier::BackgroundSavePageResult::PRERENDER_FAILURE); |
| 189 EXPECT_EQ(LastNotificationType::DOWNLOAD_FAILED, | 191 EXPECT_EQ(LastNotificationType::DOWNLOAD_FAILED, |
| 190 notifier()->last_notification_type()); | 192 notifier()->last_notification_type()); |
| 191 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); | 193 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); |
| 192 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); | 194 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); |
| 193 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); | 195 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); |
| 194 | 196 |
| 195 notifier()->Reset(); | 197 notifier()->Reset(); |
| 196 observer()->OnCompleted(request, | 198 observer()->OnCompleted( |
| 197 RequestNotifier::SavePageStatus::FOREGROUND_CANCELED); | 199 request, RequestNotifier::BackgroundSavePageResult::FOREGROUND_CANCELED); |
| 198 EXPECT_EQ(LastNotificationType::DOWNLOAD_FAILED, | 200 EXPECT_EQ(LastNotificationType::DOWNLOAD_FAILED, |
| 199 notifier()->last_notification_type()); | 201 notifier()->last_notification_type()); |
| 200 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); | 202 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); |
| 201 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); | 203 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); |
| 202 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); | 204 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); |
| 203 | 205 |
| 204 notifier()->Reset(); | 206 notifier()->Reset(); |
| 205 observer()->OnCompleted(request, | 207 observer()->OnCompleted( |
| 206 RequestNotifier::SavePageStatus::SAVE_FAILED); | 208 request, RequestNotifier::BackgroundSavePageResult::SAVE_FAILED); |
| 207 EXPECT_EQ(LastNotificationType::DOWNLOAD_FAILED, | 209 EXPECT_EQ(LastNotificationType::DOWNLOAD_FAILED, |
| 208 notifier()->last_notification_type()); | 210 notifier()->last_notification_type()); |
| 209 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); | 211 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); |
| 210 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); | 212 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); |
| 211 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); | 213 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); |
| 212 | 214 |
| 213 notifier()->Reset(); | 215 notifier()->Reset(); |
| 214 observer()->OnCompleted(request, RequestNotifier::SavePageStatus::EXPIRED); | 216 observer()->OnCompleted(request, |
| 217 RequestNotifier::BackgroundSavePageResult::EXPIRED); |
| 215 EXPECT_EQ(LastNotificationType::DOWNLOAD_FAILED, | 218 EXPECT_EQ(LastNotificationType::DOWNLOAD_FAILED, |
| 216 notifier()->last_notification_type()); | 219 notifier()->last_notification_type()); |
| 217 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); | 220 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); |
| 218 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); | 221 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); |
| 219 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); | 222 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); |
| 220 | 223 |
| 221 notifier()->Reset(); | 224 notifier()->Reset(); |
| 222 observer()->OnCompleted( | 225 observer()->OnCompleted( |
| 223 request, RequestNotifier::SavePageStatus::RETRY_COUNT_EXCEEDED); | 226 request, RequestNotifier::BackgroundSavePageResult::RETRY_COUNT_EXCEEDED); |
| 224 EXPECT_EQ(LastNotificationType::DOWNLOAD_FAILED, | 227 EXPECT_EQ(LastNotificationType::DOWNLOAD_FAILED, |
| 225 notifier()->last_notification_type()); | 228 notifier()->last_notification_type()); |
| 226 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); | 229 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); |
| 227 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); | 230 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); |
| 228 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); | 231 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); |
| 229 } | 232 } |
| 230 | 233 |
| 231 TEST_F(DownloadNotifyingObserverTest, NamespacesNotVisibleInUI) { | 234 TEST_F(DownloadNotifyingObserverTest, NamespacesNotVisibleInUI) { |
| 232 std::vector<std::string> name_spaces = { | 235 std::vector<std::string> name_spaces = { |
| 233 kBookmarkNamespace, kLastNNamespace, kCCTNamespace, | 236 kBookmarkNamespace, kLastNNamespace, kCCTNamespace, |
| 234 kNTPSuggestionsNamespace, kDefaultNamespace}; | 237 kNTPSuggestionsNamespace, kDefaultNamespace}; |
| 235 | 238 |
| 236 for (auto name_space : name_spaces) { | 239 for (auto name_space : name_spaces) { |
| 237 ClientId invisible_client_id(name_space, kTestGuid); | 240 ClientId invisible_client_id(name_space, kTestGuid); |
| 238 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), invisible_client_id, | 241 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), invisible_client_id, |
| 239 kTestCreationTime, kTestUserRequested); | 242 kTestCreationTime, kTestUserRequested); |
| 240 observer()->OnAdded(request); | 243 observer()->OnAdded(request); |
| 241 EXPECT_EQ(LastNotificationType::NONE, notifier()->last_notification_type()); | 244 EXPECT_EQ(LastNotificationType::NONE, notifier()->last_notification_type()); |
| 242 } | 245 } |
| 243 } | 246 } |
| 244 | 247 |
| 245 } // namespace offline_pages | 248 } // namespace offline_pages |
| OLD | NEW |