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 "chrome/browser/chromeos/hats/hats_notification_controller.h" | 5 #include "chrome/browser/chromeos/hats/hats_notification_controller.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
9 #include "chrome/browser/notifications/message_center_notification_manager.h" | 9 #include "chrome/browser/notifications/message_center_notification_manager.h" |
10 #include "chrome/browser/notifications/notification.h" | 10 #include "chrome/browser/notifications/notification.h" |
11 #include "chrome/browser/notifications/notification_ui_manager.h" | 11 #include "chrome/browser/notifications/notification_ui_manager.h" |
12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
13 #include "chrome/test/base/browser_with_test_window_test.h" | 13 #include "chrome/test/base/browser_with_test_window_test.h" |
14 #include "chrome/test/base/testing_browser_process.h" | 14 #include "chrome/test/base/testing_browser_process.h" |
15 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
16 #include "chrome/test/base/testing_profile_manager.h" | 16 #include "chrome/test/base/testing_profile_manager.h" |
17 #include "chromeos/network/network_state.h" | 17 #include "chromeos/network/network_state.h" |
18 #include "chromeos/network/portal_detector/network_portal_detector.h" | 18 #include "chromeos/network/portal_detector/network_portal_detector.h" |
19 #include "components/image_fetcher/core/image_fetcher.h" | 19 #include "components/image_fetcher/core/image_fetcher.h" |
20 #include "components/image_fetcher/core/image_fetcher_delegate.h" | 20 #include "components/image_fetcher/core/image_fetcher_delegate.h" |
21 #include "components/image_fetcher/core/request_metadata.h" | 21 #include "components/image_fetcher/core/request_metadata.h" |
22 #include "components/prefs/pref_service.h" | 22 #include "components/prefs/pref_service.h" |
23 #include "content/public/test/test_browser_thread_bundle.h" | 23 #include "content/public/test/test_browser_thread_bundle.h" |
24 #include "content/public/test/test_utils.h" | 24 #include "content/public/test/test_utils.h" |
| 25 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "ui/gfx/image/image_unittest_util.h" | 28 #include "ui/gfx/image/image_unittest_util.h" |
28 #include "ui/message_center/fake_message_center_tray_delegate.h" | 29 #include "ui/message_center/fake_message_center_tray_delegate.h" |
29 #include "ui/message_center/message_center.h" | 30 #include "ui/message_center/message_center.h" |
30 | 31 |
31 using testing::_; | 32 using testing::_; |
32 using testing::AtLeast; | 33 using testing::AtLeast; |
33 using testing::Invoke; | 34 using testing::Invoke; |
34 using testing::Return; | 35 using testing::Return; |
(...skipping 30 matching lines...) Expand all Loading... |
65 | 66 |
66 private: | 67 private: |
67 DISALLOW_COPY_AND_ASSIGN(MockNetworkPortalDetector); | 68 DISALLOW_COPY_AND_ASSIGN(MockNetworkPortalDetector); |
68 }; | 69 }; |
69 | 70 |
70 class MockImageFetcher : public image_fetcher::ImageFetcher { | 71 class MockImageFetcher : public image_fetcher::ImageFetcher { |
71 public: | 72 public: |
72 MockImageFetcher() {} | 73 MockImageFetcher() {} |
73 ~MockImageFetcher() override {} | 74 ~MockImageFetcher() override {} |
74 | 75 |
75 MOCK_METHOD3(StartOrQueueNetworkRequest, | 76 MOCK_METHOD4(StartOrQueueNetworkRequest, |
76 void(const std::string&, | 77 void(const std::string&, |
77 const GURL&, | 78 const GURL&, |
78 const ImageFetcher::ImageFetcherCallback&)); | 79 const ImageFetcher::ImageFetcherCallback&, |
| 80 const net::NetworkTrafficAnnotationTag&)); |
79 MOCK_METHOD1(SetImageFetcherDelegate, void(ImageFetcherDelegate*)); | 81 MOCK_METHOD1(SetImageFetcherDelegate, void(ImageFetcherDelegate*)); |
80 MOCK_METHOD1(SetDataUseServiceName, void(DataUseServiceName)); | 82 MOCK_METHOD1(SetDataUseServiceName, void(DataUseServiceName)); |
81 MOCK_METHOD1(SetImageDownloadLimit, | 83 MOCK_METHOD1(SetImageDownloadLimit, |
82 void(base::Optional<int64_t> max_download_bytes)); | 84 void(base::Optional<int64_t> max_download_bytes)); |
83 MOCK_METHOD1(SetDesiredImageFrameSize, void(const gfx::Size&)); | 85 MOCK_METHOD1(SetDesiredImageFrameSize, void(const gfx::Size&)); |
84 MOCK_METHOD0(GetImageDecoder, image_fetcher::ImageDecoder*()); | 86 MOCK_METHOD0(GetImageDecoder, image_fetcher::ImageDecoder*()); |
85 | 87 |
86 private: | 88 private: |
87 DISALLOW_COPY_AND_ASSIGN(MockImageFetcher); | 89 DISALLOW_COPY_AND_ASSIGN(MockImageFetcher); |
88 }; | 90 }; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 NetworkState network_state(""); | 144 NetworkState network_state(""); |
143 online_state.status = | 145 online_state.status = |
144 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; | 146 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; |
145 hats_notification_controller->OnPortalDetectionCompleted( | 147 hats_notification_controller->OnPortalDetectionCompleted( |
146 &network_state, online_state); | 148 &network_state, online_state); |
147 })); | 149 })); |
148 | 150 |
149 // Run the image fetcher callback to simulate a successful 1x icon fetch. | 151 // Run the image fetcher callback to simulate a successful 1x icon fetch. |
150 ON_CALL(*mock_image_fetcher_, | 152 ON_CALL(*mock_image_fetcher_, |
151 StartOrQueueNetworkRequest( | 153 StartOrQueueNetworkRequest( |
152 HatsNotificationController::kImageFetcher1xId, _, _)) | 154 HatsNotificationController::kImageFetcher1xId, _, _, _)) |
153 .WillByDefault(Invoke([&hats_notification_controller]( | 155 .WillByDefault(Invoke([&hats_notification_controller]( |
154 const std::string&, const GURL&, | 156 const std::string&, const GURL&, |
155 const ImageFetcher::ImageFetcherCallback&) { | 157 const ImageFetcher::ImageFetcherCallback&, |
| 158 const net::NetworkTrafficAnnotationTag&) { |
156 gfx::Image icon_1x(gfx::test::CreateImage()); | 159 gfx::Image icon_1x(gfx::test::CreateImage()); |
157 hats_notification_controller->OnImageFetched( | 160 hats_notification_controller->OnImageFetched( |
158 HatsNotificationController::kImageFetcher1xId, icon_1x, | 161 HatsNotificationController::kImageFetcher1xId, icon_1x, |
159 image_fetcher::RequestMetadata()); | 162 image_fetcher::RequestMetadata()); |
160 })); | 163 })); |
161 | 164 |
162 // Run the image fetcher callback to simulate a successful 2x icon fetch. | 165 // Run the image fetcher callback to simulate a successful 2x icon fetch. |
163 ON_CALL(*mock_image_fetcher_, | 166 ON_CALL(*mock_image_fetcher_, |
164 StartOrQueueNetworkRequest( | 167 StartOrQueueNetworkRequest( |
165 HatsNotificationController::kImageFetcher2xId, _, _)) | 168 HatsNotificationController::kImageFetcher2xId, _, _, _)) |
166 .WillByDefault(Invoke([&hats_notification_controller]( | 169 .WillByDefault(Invoke([&hats_notification_controller]( |
167 const std::string&, const GURL&, | 170 const std::string&, const GURL&, |
168 ImageFetcher::ImageFetcherCallback) { | 171 ImageFetcher::ImageFetcherCallback, |
| 172 const net::NetworkTrafficAnnotationTag&) { |
169 gfx::Image icon_1x(gfx::test::CreateImage()); | 173 gfx::Image icon_1x(gfx::test::CreateImage()); |
170 hats_notification_controller->OnImageFetched( | 174 hats_notification_controller->OnImageFetched( |
171 HatsNotificationController::kImageFetcher2xId, icon_1x, | 175 HatsNotificationController::kImageFetcher2xId, icon_1x, |
172 image_fetcher::RequestMetadata()); | 176 image_fetcher::RequestMetadata()); |
173 })); | 177 })); |
174 | 178 |
175 return hats_notification_controller; | 179 return hats_notification_controller; |
176 } | 180 } |
177 | 181 |
178 TestingProfile profile_; | 182 TestingProfile profile_; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 .Times(1); | 227 .Times(1); |
224 // Observer is removed if an internet connection is detected. It is called | 228 // Observer is removed if an internet connection is detected. It is called |
225 // a second time when hats_notification_controller is destroyed. | 229 // a second time when hats_notification_controller is destroyed. |
226 EXPECT_CALL(mock_network_portal_detector_, | 230 EXPECT_CALL(mock_network_portal_detector_, |
227 RemoveObserver(hats_notification_controller.get())) | 231 RemoveObserver(hats_notification_controller.get())) |
228 .Times(2); | 232 .Times(2); |
229 | 233 |
230 EXPECT_CALL(*mock_image_fetcher_, | 234 EXPECT_CALL(*mock_image_fetcher_, |
231 StartOrQueueNetworkRequest( | 235 StartOrQueueNetworkRequest( |
232 HatsNotificationController::kImageFetcher1xId, | 236 HatsNotificationController::kImageFetcher1xId, |
233 GURL(HatsNotificationController::kGoogleIcon1xUrl), _)) | 237 GURL(HatsNotificationController::kGoogleIcon1xUrl), _, _)) |
234 .Times(1); | 238 .Times(1); |
235 EXPECT_CALL(*mock_image_fetcher_, | 239 EXPECT_CALL(*mock_image_fetcher_, |
236 StartOrQueueNetworkRequest( | 240 StartOrQueueNetworkRequest( |
237 HatsNotificationController::kImageFetcher2xId, | 241 HatsNotificationController::kImageFetcher2xId, |
238 GURL(HatsNotificationController::kGoogleIcon2xUrl), _)) | 242 GURL(HatsNotificationController::kGoogleIcon2xUrl), _, _)) |
239 .Times(1); | 243 .Times(1); |
240 | 244 |
241 hats_notification_controller->Initialize(false); | 245 hats_notification_controller->Initialize(false); |
242 | 246 |
243 // Finally check if notification was launched to confirm initialization. | 247 // Finally check if notification was launched to confirm initialization. |
244 const Notification* notification = | 248 const Notification* notification = |
245 g_browser_process->notification_ui_manager()->FindById( | 249 g_browser_process->notification_ui_manager()->FindById( |
246 HatsNotificationController::kDelegateId, &profile_); | 250 HatsNotificationController::kDelegateId, &profile_); |
247 EXPECT_TRUE(notification != nullptr); | 251 EXPECT_TRUE(notification != nullptr); |
248 } | 252 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 ASSERT_TRUE(base::Time::FromInternalValue(new_timestamp) > | 300 ASSERT_TRUE(base::Time::FromInternalValue(new_timestamp) > |
297 base::Time::FromInternalValue(now_timestamp)); | 301 base::Time::FromInternalValue(now_timestamp)); |
298 | 302 |
299 // Destructor for HatsController removes self from observer list. | 303 // Destructor for HatsController removes self from observer list. |
300 EXPECT_CALL(mock_network_portal_detector_, | 304 EXPECT_CALL(mock_network_portal_detector_, |
301 RemoveObserver(hats_notification_controller.get())) | 305 RemoveObserver(hats_notification_controller.get())) |
302 .Times(1); | 306 .Times(1); |
303 } | 307 } |
304 | 308 |
305 } // namespace chromeos | 309 } // namespace chromeos |
OLD | NEW |