Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/chromeos/hats/hats_notification_controller_unittest.cc

Issue 2794343002: Network traffic annotation added to image_data_fetcher. (Closed)
Patch Set: Annotation updated. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/mock_network_portal_detector.h" 18 #include "chromeos/network/portal_detector/mock_network_portal_detector.h"
19 #include "chromeos/network/portal_detector/network_portal_detector.h" 19 #include "chromeos/network/portal_detector/network_portal_detector.h"
20 #include "components/image_fetcher/core/image_fetcher.h" 20 #include "components/image_fetcher/core/image_fetcher.h"
21 #include "components/image_fetcher/core/image_fetcher_delegate.h" 21 #include "components/image_fetcher/core/image_fetcher_delegate.h"
22 #include "components/image_fetcher/core/request_metadata.h" 22 #include "components/image_fetcher/core/request_metadata.h"
23 #include "components/prefs/pref_service.h" 23 #include "components/prefs/pref_service.h"
24 #include "content/public/test/test_browser_thread_bundle.h" 24 #include "content/public/test/test_browser_thread_bundle.h"
25 #include "content/public/test/test_utils.h" 25 #include "content/public/test/test_utils.h"
26 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
26 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/gfx/image/image_unittest_util.h" 29 #include "ui/gfx/image/image_unittest_util.h"
29 #include "ui/message_center/fake_message_center_tray_delegate.h" 30 #include "ui/message_center/fake_message_center_tray_delegate.h"
30 #include "ui/message_center/message_center.h" 31 #include "ui/message_center/message_center.h"
31 32
32 using testing::_; 33 using testing::_;
33 using testing::AtLeast; 34 using testing::AtLeast;
34 using testing::Invoke; 35 using testing::Invoke;
35 using testing::Return; 36 using testing::Return;
36 using testing::SaveArg; 37 using testing::SaveArg;
37 using testing::StrictMock; 38 using testing::StrictMock;
38 39
39 using image_fetcher::ImageFetcher; 40 using image_fetcher::ImageFetcher;
40 using image_fetcher::ImageFetcherDelegate; 41 using image_fetcher::ImageFetcherDelegate;
41 42
42 namespace chromeos { 43 namespace chromeos {
43 44
44 namespace { 45 namespace {
45 46
46 class MockImageFetcher : public image_fetcher::ImageFetcher { 47 class MockImageFetcher : public image_fetcher::ImageFetcher {
47 public: 48 public:
48 MockImageFetcher() {} 49 MockImageFetcher() {}
49 ~MockImageFetcher() override {} 50 ~MockImageFetcher() override {}
50 51
51 MOCK_METHOD3(StartOrQueueNetworkRequest, 52 MOCK_METHOD4(StartOrQueueNetworkRequest,
52 void(const std::string&, 53 void(const std::string&,
53 const GURL&, 54 const GURL&,
54 const ImageFetcher::ImageFetcherCallback&)); 55 const ImageFetcher::ImageFetcherCallback&,
56 const net::NetworkTrafficAnnotationTag&));
55 MOCK_METHOD1(SetImageFetcherDelegate, void(ImageFetcherDelegate*)); 57 MOCK_METHOD1(SetImageFetcherDelegate, void(ImageFetcherDelegate*));
56 MOCK_METHOD1(SetDataUseServiceName, void(DataUseServiceName)); 58 MOCK_METHOD1(SetDataUseServiceName, void(DataUseServiceName));
57 MOCK_METHOD1(SetImageDownloadLimit, 59 MOCK_METHOD1(SetImageDownloadLimit,
58 void(base::Optional<int64_t> max_download_bytes)); 60 void(base::Optional<int64_t> max_download_bytes));
59 MOCK_METHOD1(SetDesiredImageFrameSize, void(const gfx::Size&)); 61 MOCK_METHOD1(SetDesiredImageFrameSize, void(const gfx::Size&));
60 MOCK_METHOD0(GetImageDecoder, image_fetcher::ImageDecoder*()); 62 MOCK_METHOD0(GetImageDecoder, image_fetcher::ImageDecoder*());
61 63
62 private: 64 private:
63 DISALLOW_COPY_AND_ASSIGN(MockImageFetcher); 65 DISALLOW_COPY_AND_ASSIGN(MockImageFetcher);
64 }; 66 };
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 NetworkState network_state(""); 120 NetworkState network_state("");
119 online_state.status = 121 online_state.status =
120 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; 122 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
121 hats_notification_controller->OnPortalDetectionCompleted( 123 hats_notification_controller->OnPortalDetectionCompleted(
122 &network_state, online_state); 124 &network_state, online_state);
123 })); 125 }));
124 126
125 // Run the image fetcher callback to simulate a successful 1x icon fetch. 127 // Run the image fetcher callback to simulate a successful 1x icon fetch.
126 ON_CALL(*mock_image_fetcher_, 128 ON_CALL(*mock_image_fetcher_,
127 StartOrQueueNetworkRequest( 129 StartOrQueueNetworkRequest(
128 HatsNotificationController::kImageFetcher1xId, _, _)) 130 HatsNotificationController::kImageFetcher1xId, _, _, _))
129 .WillByDefault(Invoke([&hats_notification_controller]( 131 .WillByDefault(Invoke([&hats_notification_controller](
130 const std::string&, const GURL&, 132 const std::string&, const GURL&,
131 const ImageFetcher::ImageFetcherCallback&) { 133 const ImageFetcher::ImageFetcherCallback&,
134 const net::NetworkTrafficAnnotationTag&) {
132 gfx::Image icon_1x(gfx::test::CreateImage()); 135 gfx::Image icon_1x(gfx::test::CreateImage());
133 hats_notification_controller->OnImageFetched( 136 hats_notification_controller->OnImageFetched(
134 HatsNotificationController::kImageFetcher1xId, icon_1x, 137 HatsNotificationController::kImageFetcher1xId, icon_1x,
135 image_fetcher::RequestMetadata()); 138 image_fetcher::RequestMetadata());
136 })); 139 }));
137 140
138 // Run the image fetcher callback to simulate a successful 2x icon fetch. 141 // Run the image fetcher callback to simulate a successful 2x icon fetch.
139 ON_CALL(*mock_image_fetcher_, 142 ON_CALL(*mock_image_fetcher_,
140 StartOrQueueNetworkRequest( 143 StartOrQueueNetworkRequest(
141 HatsNotificationController::kImageFetcher2xId, _, _)) 144 HatsNotificationController::kImageFetcher2xId, _, _, _))
142 .WillByDefault(Invoke([&hats_notification_controller]( 145 .WillByDefault(Invoke([&hats_notification_controller](
143 const std::string&, const GURL&, 146 const std::string&, const GURL&,
144 ImageFetcher::ImageFetcherCallback) { 147 ImageFetcher::ImageFetcherCallback,
148 const net::NetworkTrafficAnnotationTag&) {
145 gfx::Image icon_1x(gfx::test::CreateImage()); 149 gfx::Image icon_1x(gfx::test::CreateImage());
146 hats_notification_controller->OnImageFetched( 150 hats_notification_controller->OnImageFetched(
147 HatsNotificationController::kImageFetcher2xId, icon_1x, 151 HatsNotificationController::kImageFetcher2xId, icon_1x,
148 image_fetcher::RequestMetadata()); 152 image_fetcher::RequestMetadata());
149 })); 153 }));
150 154
151 return hats_notification_controller; 155 return hats_notification_controller;
152 } 156 }
153 157
154 TestingProfile profile_; 158 TestingProfile profile_;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 .Times(1); 203 .Times(1);
200 // Observer is removed if an internet connection is detected. It is called 204 // Observer is removed if an internet connection is detected. It is called
201 // a second time when hats_notification_controller is destroyed. 205 // a second time when hats_notification_controller is destroyed.
202 EXPECT_CALL(mock_network_portal_detector_, 206 EXPECT_CALL(mock_network_portal_detector_,
203 RemoveObserver(hats_notification_controller.get())) 207 RemoveObserver(hats_notification_controller.get()))
204 .Times(2); 208 .Times(2);
205 209
206 EXPECT_CALL(*mock_image_fetcher_, 210 EXPECT_CALL(*mock_image_fetcher_,
207 StartOrQueueNetworkRequest( 211 StartOrQueueNetworkRequest(
208 HatsNotificationController::kImageFetcher1xId, 212 HatsNotificationController::kImageFetcher1xId,
209 GURL(HatsNotificationController::kGoogleIcon1xUrl), _)) 213 GURL(HatsNotificationController::kGoogleIcon1xUrl), _, _))
210 .Times(1); 214 .Times(1);
211 EXPECT_CALL(*mock_image_fetcher_, 215 EXPECT_CALL(*mock_image_fetcher_,
212 StartOrQueueNetworkRequest( 216 StartOrQueueNetworkRequest(
213 HatsNotificationController::kImageFetcher2xId, 217 HatsNotificationController::kImageFetcher2xId,
214 GURL(HatsNotificationController::kGoogleIcon2xUrl), _)) 218 GURL(HatsNotificationController::kGoogleIcon2xUrl), _, _))
215 .Times(1); 219 .Times(1);
216 220
217 hats_notification_controller->Initialize(false); 221 hats_notification_controller->Initialize(false);
218 222
219 // Finally check if notification was launched to confirm initialization. 223 // Finally check if notification was launched to confirm initialization.
220 const Notification* notification = 224 const Notification* notification =
221 g_browser_process->notification_ui_manager()->FindById( 225 g_browser_process->notification_ui_manager()->FindById(
222 HatsNotificationController::kDelegateId, &profile_); 226 HatsNotificationController::kDelegateId, &profile_);
223 EXPECT_TRUE(notification != nullptr); 227 EXPECT_TRUE(notification != nullptr);
224 } 228 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 ASSERT_TRUE(base::Time::FromInternalValue(new_timestamp) > 276 ASSERT_TRUE(base::Time::FromInternalValue(new_timestamp) >
273 base::Time::FromInternalValue(now_timestamp)); 277 base::Time::FromInternalValue(now_timestamp));
274 278
275 // Destructor for HatsController removes self from observer list. 279 // Destructor for HatsController removes self from observer list.
276 EXPECT_CALL(mock_network_portal_detector_, 280 EXPECT_CALL(mock_network_portal_detector_,
277 RemoveObserver(hats_notification_controller.get())) 281 RemoveObserver(hats_notification_controller.get()))
278 .Times(1); 282 .Times(1);
279 } 283 }
280 284
281 } // namespace chromeos 285 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698