| 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/downloads/offline_page_download_notifier.h" | 11 #include "components/offline_pages/downloads/offline_page_download_notifier.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 namespace offline_pages { | 14 namespace offline_pages { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 static const int64_t kTestOfflineId = 42L; | 17 static const int64_t kTestOfflineId = 42L; |
| 17 static const char kTestUrl[] = "http://foo.com/bar"; | 18 static const char kTestUrl[] = "http://foo.com/bar"; |
| 18 static const char kTestGuid[] = "cccccccc-cccc-4ccc-0ccc-ccccccccccc1"; | 19 static const char kTestGuid[] = "cccccccc-cccc-4ccc-0ccc-ccccccccccc1"; |
| 19 static const ClientId kTestClientId(kDownloadNamespace, kTestGuid); | 20 static const ClientId kTestClientId(kDownloadNamespace, kTestGuid); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 std::unique_ptr<DownloadNotifyingObserver> observer_; | 115 std::unique_ptr<DownloadNotifyingObserver> observer_; |
| 115 }; | 116 }; |
| 116 | 117 |
| 117 DownloadNotifyingObserverTest::DownloadNotifyingObserverTest() {} | 118 DownloadNotifyingObserverTest::DownloadNotifyingObserverTest() {} |
| 118 | 119 |
| 119 DownloadNotifyingObserverTest::~DownloadNotifyingObserverTest() {} | 120 DownloadNotifyingObserverTest::~DownloadNotifyingObserverTest() {} |
| 120 | 121 |
| 121 void DownloadNotifyingObserverTest::SetUp() { | 122 void DownloadNotifyingObserverTest::SetUp() { |
| 122 std::unique_ptr<TestNotifier> notifier(new TestNotifier); | 123 std::unique_ptr<TestNotifier> notifier(new TestNotifier); |
| 123 notifier_ = notifier.get(); | 124 notifier_ = notifier.get(); |
| 124 observer_.reset(new DownloadNotifyingObserver(std::move(notifier))); | 125 observer_.reset(new DownloadNotifyingObserver(std::move(notifier), |
| 126 new ClientPolicyController())); |
| 125 } | 127 } |
| 126 | 128 |
| 127 TEST_F(DownloadNotifyingObserverTest, OnAdded) { | 129 TEST_F(DownloadNotifyingObserverTest, OnAdded) { |
| 128 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, | 130 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, |
| 129 kTestCreationTime, kTestUserRequested); | 131 kTestCreationTime, kTestUserRequested); |
| 130 observer()->OnAdded(request); | 132 observer()->OnAdded(request); |
| 131 EXPECT_EQ(LastNotificationType::DOWNLOAD_PROGRESS, | 133 EXPECT_EQ(LastNotificationType::DOWNLOAD_PROGRESS, |
| 132 notifier()->last_notification_type()); | 134 notifier()->last_notification_type()); |
| 133 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); | 135 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); |
| 134 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); | 136 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 for (auto name_space : name_spaces) { | 241 for (auto name_space : name_spaces) { |
| 240 ClientId invisible_client_id(name_space, kTestGuid); | 242 ClientId invisible_client_id(name_space, kTestGuid); |
| 241 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), invisible_client_id, | 243 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), invisible_client_id, |
| 242 kTestCreationTime, kTestUserRequested); | 244 kTestCreationTime, kTestUserRequested); |
| 243 observer()->OnAdded(request); | 245 observer()->OnAdded(request); |
| 244 EXPECT_EQ(LastNotificationType::NONE, notifier()->last_notification_type()); | 246 EXPECT_EQ(LastNotificationType::NONE, notifier()->last_notification_type()); |
| 245 } | 247 } |
| 246 } | 248 } |
| 247 | 249 |
| 248 } // namespace offline_pages | 250 } // namespace offline_pages |
| OLD | NEW |