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 "base/strings/string_split.h" | 5 #include "base/strings/string_split.h" |
6 #include "chrome/browser/chromeos/hats/hats_notification_controller.h" | 6 #include "chrome/browser/chromeos/hats/hats_notification_controller.h" |
7 #include "chrome/browser/notifications/message_center_notification_manager.h" | 7 #include "chrome/browser/notifications/message_center_notification_manager.h" |
8 #include "chrome/browser/notifications/notification.h" | 8 #include "chrome/browser/notifications/notification.h" |
9 #include "chrome/browser/notifications/notification_ui_manager.h" | 9 #include "chrome/browser/notifications/notification_ui_manager.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
11 #include "chrome/test/base/browser_with_test_window_test.h" | 11 #include "chrome/test/base/browser_with_test_window_test.h" |
12 #include "chrome/test/base/testing_browser_process.h" | 12 #include "chrome/test/base/testing_browser_process.h" |
13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
14 #include "chrome/test/base/testing_profile_manager.h" | 14 #include "chrome/test/base/testing_profile_manager.h" |
15 #include "chromeos/network/network_state.h" | 15 #include "chromeos/network/network_state.h" |
16 #include "chromeos/network/portal_detector/network_portal_detector.h" | 16 #include "chromeos/network/portal_detector/network_portal_detector.h" |
17 #include "components/image_fetcher/image_fetcher.h" | 17 #include "components/image_fetcher/image_fetcher.h" |
18 #include "components/image_fetcher/image_fetcher_delegate.h" | 18 #include "components/image_fetcher/image_fetcher_delegate.h" |
| 19 #include "components/image_fetcher/request_metadata.h" |
19 #include "components/prefs/pref_service.h" | 20 #include "components/prefs/pref_service.h" |
20 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
21 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "ui/gfx/image/image_unittest_util.h" | 25 #include "ui/gfx/image/image_unittest_util.h" |
25 #include "ui/message_center/fake_message_center_tray_delegate.h" | 26 #include "ui/message_center/fake_message_center_tray_delegate.h" |
26 #include "ui/message_center/message_center.h" | 27 #include "ui/message_center/message_center.h" |
27 | 28 |
28 using testing::_; | 29 using testing::_; |
29 using testing::AtLeast; | 30 using testing::AtLeast; |
30 using testing::Invoke; | 31 using testing::Invoke; |
31 using testing::Return; | 32 using testing::Return; |
32 using testing::SaveArg; | 33 using testing::SaveArg; |
33 using testing::StrictMock; | 34 using testing::StrictMock; |
34 | 35 |
| 36 using image_fetcher::ImageFetcher; |
35 using image_fetcher::ImageFetcherDelegate; | 37 using image_fetcher::ImageFetcherDelegate; |
36 | 38 |
37 namespace chromeos { | 39 namespace chromeos { |
38 | 40 |
39 namespace { | 41 namespace { |
40 | 42 |
41 class MockNetworkPortalDetector : public NetworkPortalDetector { | 43 class MockNetworkPortalDetector : public NetworkPortalDetector { |
42 public: | 44 public: |
43 MockNetworkPortalDetector() {} | 45 MockNetworkPortalDetector() {} |
44 ~MockNetworkPortalDetector() override {} | 46 ~MockNetworkPortalDetector() override {} |
(...skipping 16 matching lines...) Expand all Loading... |
61 | 63 |
62 private: | 64 private: |
63 DISALLOW_COPY_AND_ASSIGN(MockNetworkPortalDetector); | 65 DISALLOW_COPY_AND_ASSIGN(MockNetworkPortalDetector); |
64 }; | 66 }; |
65 | 67 |
66 class MockImageFetcher : public image_fetcher::ImageFetcher { | 68 class MockImageFetcher : public image_fetcher::ImageFetcher { |
67 public: | 69 public: |
68 MockImageFetcher() {} | 70 MockImageFetcher() {} |
69 ~MockImageFetcher() override {} | 71 ~MockImageFetcher() override {} |
70 | 72 |
71 MOCK_METHOD3( | 73 MOCK_METHOD3(StartOrQueueNetworkRequest, |
72 StartOrQueueNetworkRequest, | 74 void(const std::string&, |
73 void(const std::string&, | 75 const GURL&, |
74 const GURL&, | 76 const ImageFetcher::ImageFetcherCallback&)); |
75 base::Callback<void(const std::string&, const gfx::Image&)>)); | |
76 MOCK_METHOD1(SetImageFetcherDelegate, void(ImageFetcherDelegate*)); | 77 MOCK_METHOD1(SetImageFetcherDelegate, void(ImageFetcherDelegate*)); |
77 MOCK_METHOD1(SetDataUseServiceName, void(DataUseServiceName)); | 78 MOCK_METHOD1(SetDataUseServiceName, void(DataUseServiceName)); |
78 MOCK_METHOD1(SetDesiredImageFrameSize, void(const gfx::Size&)); | 79 MOCK_METHOD1(SetDesiredImageFrameSize, void(const gfx::Size&)); |
79 MOCK_METHOD0(GetImageDecoder, image_fetcher::ImageDecoder*()); | 80 MOCK_METHOD0(GetImageDecoder, image_fetcher::ImageDecoder*()); |
80 | 81 |
81 private: | 82 private: |
82 DISALLOW_COPY_AND_ASSIGN(MockImageFetcher); | 83 DISALLOW_COPY_AND_ASSIGN(MockImageFetcher); |
83 }; | 84 }; |
84 | 85 |
85 } // namespace | 86 } // namespace |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; | 137 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; |
137 hats_notification_controller->OnPortalDetectionCompleted( | 138 hats_notification_controller->OnPortalDetectionCompleted( |
138 &network_state, online_state); | 139 &network_state, online_state); |
139 })); | 140 })); |
140 | 141 |
141 // Run the image fetcher callback to simulate a successful 1x icon fetch. | 142 // Run the image fetcher callback to simulate a successful 1x icon fetch. |
142 ON_CALL(*mock_image_fetcher_, | 143 ON_CALL(*mock_image_fetcher_, |
143 StartOrQueueNetworkRequest( | 144 StartOrQueueNetworkRequest( |
144 HatsNotificationController::kImageFetcher1xId, _, _)) | 145 HatsNotificationController::kImageFetcher1xId, _, _)) |
145 .WillByDefault(Invoke([&hats_notification_controller]( | 146 .WillByDefault(Invoke([&hats_notification_controller]( |
146 const std::string&, const GURL&, | 147 const std::string&, const GURL&, |
147 base::Callback<void(const std::string&, const gfx::Image&)>) { | 148 const ImageFetcher::ImageFetcherCallback&) { |
148 gfx::Image icon_1x(gfx::test::CreateImage()); | 149 gfx::Image icon_1x(gfx::test::CreateImage()); |
149 hats_notification_controller->OnImageFetched( | 150 hats_notification_controller->OnImageFetched( |
150 HatsNotificationController::kImageFetcher1xId, icon_1x); | 151 HatsNotificationController::kImageFetcher1xId, icon_1x, |
| 152 image_fetcher::RequestMetadata()); |
151 })); | 153 })); |
152 | 154 |
153 // Run the image fetcher callback to simulate a successful 2x icon fetch. | 155 // Run the image fetcher callback to simulate a successful 2x icon fetch. |
154 ON_CALL(*mock_image_fetcher_, | 156 ON_CALL(*mock_image_fetcher_, |
155 StartOrQueueNetworkRequest( | 157 StartOrQueueNetworkRequest( |
156 HatsNotificationController::kImageFetcher2xId, _, _)) | 158 HatsNotificationController::kImageFetcher2xId, _, _)) |
157 .WillByDefault(Invoke([&hats_notification_controller]( | 159 .WillByDefault(Invoke([&hats_notification_controller]( |
158 const std::string&, const GURL&, | 160 const std::string&, const GURL&, |
159 base::Callback<void(const std::string&, const gfx::Image&)>) { | 161 ImageFetcher::ImageFetcherCallback) { |
160 gfx::Image icon_1x(gfx::test::CreateImage()); | 162 gfx::Image icon_1x(gfx::test::CreateImage()); |
161 hats_notification_controller->OnImageFetched( | 163 hats_notification_controller->OnImageFetched( |
162 HatsNotificationController::kImageFetcher2xId, icon_1x); | 164 HatsNotificationController::kImageFetcher2xId, icon_1x, |
| 165 image_fetcher::RequestMetadata()); |
163 })); | 166 })); |
164 | 167 |
165 return hats_notification_controller; | 168 return hats_notification_controller; |
166 } | 169 } |
167 | 170 |
168 TestingProfile profile_; | 171 TestingProfile profile_; |
169 StrictMock<MockNetworkPortalDetector> mock_network_portal_detector_; | 172 StrictMock<MockNetworkPortalDetector> mock_network_portal_detector_; |
170 | 173 |
171 private: | 174 private: |
172 std::unique_ptr<TestingProfileManager> profile_manager_; | 175 std::unique_ptr<TestingProfileManager> profile_manager_; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 ASSERT_TRUE(base::Time::FromInternalValue(new_timestamp) > | 277 ASSERT_TRUE(base::Time::FromInternalValue(new_timestamp) > |
275 base::Time::FromInternalValue(now_timestamp)); | 278 base::Time::FromInternalValue(now_timestamp)); |
276 | 279 |
277 // Destructor for HatsController removes self from observer list. | 280 // Destructor for HatsController removes self from observer list. |
278 EXPECT_CALL(mock_network_portal_detector_, | 281 EXPECT_CALL(mock_network_portal_detector_, |
279 RemoveObserver(hats_notification_controller.get())) | 282 RemoveObserver(hats_notification_controller.get())) |
280 .Times(1); | 283 .Times(1); |
281 } | 284 } |
282 | 285 |
283 } // namespace chromeos | 286 } // namespace chromeos |
OLD | NEW |