| 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" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 g_browser_process->notification_ui_manager()->StartShutdown(); | 116 g_browser_process->notification_ui_manager()->StartShutdown(); |
| 117 // The notifications may be deleted async. | 117 // The notifications may be deleted async. |
| 118 base::RunLoop loop; | 118 base::RunLoop loop; |
| 119 loop.RunUntilIdle(); | 119 loop.RunUntilIdle(); |
| 120 profile_manager_.reset(); | 120 profile_manager_.reset(); |
| 121 network_portal_detector::InitializeForTesting(nullptr); | 121 network_portal_detector::InitializeForTesting(nullptr); |
| 122 BrowserWithTestWindowTest::TearDown(); | 122 BrowserWithTestWindowTest::TearDown(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 scoped_refptr<HatsNotificationController> InstantiateHatsController() { | 125 scoped_refptr<HatsNotificationController> InstantiateHatsController() { |
| 126 MockImageFetcher* mock_image_fetcher_ = new MockImageFetcher; | 126 mock_image_fetcher_ = new MockImageFetcher; |
| 127 // The initialization will fail since the function IsNewDevice() will return | 127 // The initialization will fail since the function IsNewDevice() will return |
| 128 // true. | 128 // true. |
| 129 scoped_refptr<HatsNotificationController> hats_notification_controller = | 129 scoped_refptr<HatsNotificationController> hats_notification_controller = |
| 130 new HatsNotificationController(&profile_, mock_image_fetcher_); | 130 new HatsNotificationController(&profile_, mock_image_fetcher_); |
| 131 | 131 |
| 132 // HatsController::IsNewDevice() is run on a blocking thread. | 132 // HatsController::IsNewDevice() is run on a blocking thread. |
| 133 content::RunAllBlockingPoolTasksUntilIdle(); | 133 content::RunAllBlockingPoolTasksUntilIdle(); |
| 134 | 134 |
| 135 // Send a callback to the observer to simulate internet connectivity is | 135 // Send a callback to the observer to simulate internet connectivity is |
| 136 // present on device. | 136 // present on device. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 hats_notification_controller->OnImageFetched( | 170 hats_notification_controller->OnImageFetched( |
| 171 HatsNotificationController::kImageFetcher2xId, icon_1x, | 171 HatsNotificationController::kImageFetcher2xId, icon_1x, |
| 172 image_fetcher::RequestMetadata()); | 172 image_fetcher::RequestMetadata()); |
| 173 })); | 173 })); |
| 174 | 174 |
| 175 return hats_notification_controller; | 175 return hats_notification_controller; |
| 176 } | 176 } |
| 177 | 177 |
| 178 TestingProfile profile_; | 178 TestingProfile profile_; |
| 179 StrictMock<MockNetworkPortalDetector> mock_network_portal_detector_; | 179 StrictMock<MockNetworkPortalDetector> mock_network_portal_detector_; |
| 180 MockImageFetcher* mock_image_fetcher_; |
| 180 | 181 |
| 181 private: | 182 private: |
| 182 std::unique_ptr<TestingProfileManager> profile_manager_; | 183 std::unique_ptr<TestingProfileManager> profile_manager_; |
| 183 | 184 |
| 184 DISALLOW_COPY_AND_ASSIGN(HatsNotificationControllerTest); | 185 DISALLOW_COPY_AND_ASSIGN(HatsNotificationControllerTest); |
| 185 }; | 186 }; |
| 186 | 187 |
| 187 TEST_F(HatsNotificationControllerTest, NewDevice_ShouldNotShowNotification) { | 188 TEST_F(HatsNotificationControllerTest, NewDevice_ShouldNotShowNotification) { |
| 188 int64_t initial_timestamp = base::Time::Now().ToInternalValue(); | 189 int64_t initial_timestamp = base::Time::Now().ToInternalValue(); |
| 189 PrefService* pref_service = profile_.GetPrefs(); | 190 PrefService* pref_service = profile_.GetPrefs(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 219 // NetworkPortalDetector to detect internet connectivity. | 220 // NetworkPortalDetector to detect internet connectivity. |
| 220 EXPECT_CALL(mock_network_portal_detector_, | 221 EXPECT_CALL(mock_network_portal_detector_, |
| 221 AddAndFireObserver(hats_notification_controller.get())) | 222 AddAndFireObserver(hats_notification_controller.get())) |
| 222 .Times(1); | 223 .Times(1); |
| 223 // Observer is removed if an internet connection is detected. It is called | 224 // Observer is removed if an internet connection is detected. It is called |
| 224 // a second time when hats_notification_controller is destroyed. | 225 // a second time when hats_notification_controller is destroyed. |
| 225 EXPECT_CALL(mock_network_portal_detector_, | 226 EXPECT_CALL(mock_network_portal_detector_, |
| 226 RemoveObserver(hats_notification_controller.get())) | 227 RemoveObserver(hats_notification_controller.get())) |
| 227 .Times(2); | 228 .Times(2); |
| 228 | 229 |
| 230 EXPECT_CALL(*mock_image_fetcher_, |
| 231 StartOrQueueNetworkRequest( |
| 232 HatsNotificationController::kImageFetcher1xId, |
| 233 GURL(HatsNotificationController::kGoogleIcon1xUrl), _)) |
| 234 .Times(1); |
| 235 EXPECT_CALL(*mock_image_fetcher_, |
| 236 StartOrQueueNetworkRequest( |
| 237 HatsNotificationController::kImageFetcher2xId, |
| 238 GURL(HatsNotificationController::kGoogleIcon2xUrl), _)) |
| 239 .Times(1); |
| 240 |
| 229 hats_notification_controller->Initialize(false); | 241 hats_notification_controller->Initialize(false); |
| 230 | 242 |
| 231 // Finally check if notification was launched to confirm initialization. | 243 // Finally check if notification was launched to confirm initialization. |
| 232 const Notification* notification = | 244 const Notification* notification = |
| 233 g_browser_process->notification_ui_manager()->FindById( | 245 g_browser_process->notification_ui_manager()->FindById( |
| 234 HatsNotificationController::kDelegateId, &profile_); | 246 HatsNotificationController::kDelegateId, &profile_); |
| 235 EXPECT_TRUE(notification != nullptr); | 247 EXPECT_TRUE(notification != nullptr); |
| 236 } | 248 } |
| 237 | 249 |
| 238 TEST_F(HatsNotificationControllerTest, NoInternet_DoNotShowNotification) { | 250 TEST_F(HatsNotificationControllerTest, NoInternet_DoNotShowNotification) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 ASSERT_TRUE(base::Time::FromInternalValue(new_timestamp) > | 296 ASSERT_TRUE(base::Time::FromInternalValue(new_timestamp) > |
| 285 base::Time::FromInternalValue(now_timestamp)); | 297 base::Time::FromInternalValue(now_timestamp)); |
| 286 | 298 |
| 287 // Destructor for HatsController removes self from observer list. | 299 // Destructor for HatsController removes self from observer list. |
| 288 EXPECT_CALL(mock_network_portal_detector_, | 300 EXPECT_CALL(mock_network_portal_detector_, |
| 289 RemoveObserver(hats_notification_controller.get())) | 301 RemoveObserver(hats_notification_controller.get())) |
| 290 .Times(1); | 302 .Times(1); |
| 291 } | 303 } |
| 292 | 304 |
| 293 } // namespace chromeos | 305 } // namespace chromeos |
| OLD | NEW |