| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 106 |
| 106 // testing::Test implementation: | 107 // testing::Test implementation: |
| 107 void SetUp() override; | 108 void SetUp() override; |
| 108 | 109 |
| 109 TestNotifier* notifier() const { return notifier_; } | 110 TestNotifier* notifier() const { return notifier_; } |
| 110 DownloadNotifyingObserver* observer() { return observer_.get(); } | 111 DownloadNotifyingObserver* observer() { return observer_.get(); } |
| 111 | 112 |
| 112 private: | 113 private: |
| 113 TestNotifier* notifier_; | 114 TestNotifier* notifier_; |
| 114 std::unique_ptr<DownloadNotifyingObserver> observer_; | 115 std::unique_ptr<DownloadNotifyingObserver> observer_; |
| 116 std::unique_ptr<ClientPolicyController> policy_controller_; |
| 115 }; | 117 }; |
| 116 | 118 |
| 117 DownloadNotifyingObserverTest::DownloadNotifyingObserverTest() {} | 119 DownloadNotifyingObserverTest::DownloadNotifyingObserverTest() {} |
| 118 | 120 |
| 119 DownloadNotifyingObserverTest::~DownloadNotifyingObserverTest() {} | 121 DownloadNotifyingObserverTest::~DownloadNotifyingObserverTest() {} |
| 120 | 122 |
| 121 void DownloadNotifyingObserverTest::SetUp() { | 123 void DownloadNotifyingObserverTest::SetUp() { |
| 122 std::unique_ptr<TestNotifier> notifier(new TestNotifier); | 124 std::unique_ptr<TestNotifier> notifier(new TestNotifier); |
| 125 policy_controller_.reset(new ClientPolicyController()); |
| 123 notifier_ = notifier.get(); | 126 notifier_ = notifier.get(); |
| 124 observer_.reset(new DownloadNotifyingObserver(std::move(notifier))); | 127 observer_.reset(new DownloadNotifyingObserver(std::move(notifier), |
| 128 policy_controller_.get())); |
| 125 } | 129 } |
| 126 | 130 |
| 127 TEST_F(DownloadNotifyingObserverTest, OnAdded) { | 131 TEST_F(DownloadNotifyingObserverTest, OnAdded) { |
| 128 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, | 132 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, |
| 129 kTestCreationTime, kTestUserRequested); | 133 kTestCreationTime, kTestUserRequested); |
| 130 observer()->OnAdded(request); | 134 observer()->OnAdded(request); |
| 131 EXPECT_EQ(LastNotificationType::DOWNLOAD_PROGRESS, | 135 EXPECT_EQ(LastNotificationType::DOWNLOAD_PROGRESS, |
| 132 notifier()->last_notification_type()); | 136 notifier()->last_notification_type()); |
| 133 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); | 137 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); |
| 134 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); | 138 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) { | 243 for (auto name_space : name_spaces) { |
| 240 ClientId invisible_client_id(name_space, kTestGuid); | 244 ClientId invisible_client_id(name_space, kTestGuid); |
| 241 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), invisible_client_id, | 245 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), invisible_client_id, |
| 242 kTestCreationTime, kTestUserRequested); | 246 kTestCreationTime, kTestUserRequested); |
| 243 observer()->OnAdded(request); | 247 observer()->OnAdded(request); |
| 244 EXPECT_EQ(LastNotificationType::NONE, notifier()->last_notification_type()); | 248 EXPECT_EQ(LastNotificationType::NONE, notifier()->last_notification_type()); |
| 245 } | 249 } |
| 246 } | 250 } |
| 247 | 251 |
| 248 } // namespace offline_pages | 252 } // namespace offline_pages |
| OLD | NEW |