OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/net/tether_notification_presenter.h" | 5 #include "chrome/browser/chromeos/net/tether_notification_presenter.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace tether { | 21 namespace tether { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 class TestMessageCenter : public message_center::FakeMessageCenter { | 25 class TestMessageCenter : public message_center::FakeMessageCenter { |
26 public: | 26 public: |
27 TestMessageCenter() : message_center::FakeMessageCenter() {} | 27 TestMessageCenter() : message_center::FakeMessageCenter() {} |
28 ~TestMessageCenter() override {} | 28 ~TestMessageCenter() override {} |
29 | 29 |
30 void NotifyNotificationTapped(const std::string& notification_id) { | 30 void NotifyNotificationTapped(const std::string& notification_id) { |
31 // Simulate the notification being removed, since a tap on the notification | |
32 // removes that notification. | |
33 RemoveNotification(notification_id, true /* by_user */); | |
34 | |
35 for (auto& observer : observer_list_) { | 31 for (auto& observer : observer_list_) { |
36 observer.OnNotificationClicked(notification_id); | 32 observer.OnNotificationClicked(notification_id); |
37 } | 33 } |
38 } | 34 } |
39 | 35 |
40 void NotifyNotificationButtonTapped(const std::string& notification_id, | 36 void NotifyNotificationButtonTapped(const std::string& notification_id, |
41 int button_index) { | 37 int button_index) { |
42 // Simulate the notification being removed, since a tap on a notification | |
43 // button removes that notification. | |
44 RemoveNotification(notification_id, true /* by_user */); | |
45 | |
46 for (auto& observer : observer_list_) { | 38 for (auto& observer : observer_list_) { |
47 observer.OnNotificationButtonClicked(notification_id, button_index); | 39 observer.OnNotificationButtonClicked(notification_id, button_index); |
48 } | 40 } |
49 } | 41 } |
50 | 42 |
51 size_t GetNumNotifications() { return notifications_.size(); } | 43 size_t GetNumNotifications() { return notifications_.size(); } |
52 | 44 |
53 // message_center::FakeMessageCenter: | 45 // message_center::FakeMessageCenter: |
54 void AddObserver(message_center::MessageCenterObserver* observer) override { | 46 void AddObserver(message_center::MessageCenterObserver* observer) override { |
55 observer_list_.AddObserver(observer); | 47 observer_list_.AddObserver(observer); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 238 |
247 message_center::Notification* notification = | 239 message_center::Notification* notification = |
248 test_message_center_->FindVisibleNotificationById( | 240 test_message_center_->FindVisibleNotificationById( |
249 GetActiveHostNotificationId()); | 241 GetActiveHostNotificationId()); |
250 EXPECT_TRUE(notification); | 242 EXPECT_TRUE(notification); |
251 EXPECT_EQ(GetActiveHostNotificationId(), notification->id()); | 243 EXPECT_EQ(GetActiveHostNotificationId(), notification->id()); |
252 | 244 |
253 // Tap the notification. | 245 // Tap the notification. |
254 test_message_center_->NotifyNotificationTapped(GetActiveHostNotificationId()); | 246 test_message_center_->NotifyNotificationTapped(GetActiveHostNotificationId()); |
255 VerifySettingsOpened(); | 247 VerifySettingsOpened(); |
| 248 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
| 249 GetActiveHostNotificationId())); |
| 250 EXPECT_EQ(0u, test_message_center_->GetNumNotifications()); |
256 } | 251 } |
257 | 252 |
258 TEST_F(TetherNotificationPresenterTest, TestSetupRequiredNotification) { | 253 TEST_F(TetherNotificationPresenterTest, TestSetupRequiredNotification) { |
259 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 254 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
260 GetSetupRequiredNotificationId())); | 255 GetSetupRequiredNotificationId())); |
261 notification_presenter_->NotifySetupRequired(test_device_.name); | 256 notification_presenter_->NotifySetupRequired(test_device_.name); |
262 | 257 |
263 message_center::Notification* notification = | 258 message_center::Notification* notification = |
264 test_message_center_->FindVisibleNotificationById( | 259 test_message_center_->FindVisibleNotificationById( |
265 GetSetupRequiredNotificationId()); | 260 GetSetupRequiredNotificationId()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 message_center::Notification* notification = | 296 message_center::Notification* notification = |
302 test_message_center_->FindVisibleNotificationById( | 297 test_message_center_->FindVisibleNotificationById( |
303 GetPotentialHotspotNotificationId()); | 298 GetPotentialHotspotNotificationId()); |
304 EXPECT_TRUE(notification); | 299 EXPECT_TRUE(notification); |
305 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); | 300 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); |
306 | 301 |
307 // Tap the notification. | 302 // Tap the notification. |
308 test_message_center_->NotifyNotificationTapped( | 303 test_message_center_->NotifyNotificationTapped( |
309 GetPotentialHotspotNotificationId()); | 304 GetPotentialHotspotNotificationId()); |
310 VerifySettingsOpened(); | 305 VerifySettingsOpened(); |
| 306 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
| 307 GetPotentialHotspotNotificationId())); |
| 308 EXPECT_EQ(0u, test_message_center_->GetNumNotifications()); |
311 } | 309 } |
312 | 310 |
313 TEST_F(TetherNotificationPresenterTest, | 311 TEST_F(TetherNotificationPresenterTest, |
314 TestSinglePotentialHotspotNotification_TapNotificationButton) { | 312 TestSinglePotentialHotspotNotification_TapNotificationButton) { |
315 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 313 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
316 GetPotentialHotspotNotificationId())); | 314 GetPotentialHotspotNotificationId())); |
317 notification_presenter_->NotifyPotentialHotspotNearby(test_device_); | 315 notification_presenter_->NotifyPotentialHotspotNearby(test_device_); |
318 | 316 |
319 message_center::Notification* notification = | 317 message_center::Notification* notification = |
320 test_message_center_->FindVisibleNotificationById( | 318 test_message_center_->FindVisibleNotificationById( |
321 GetPotentialHotspotNotificationId()); | 319 GetPotentialHotspotNotificationId()); |
322 EXPECT_TRUE(notification); | 320 EXPECT_TRUE(notification); |
323 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); | 321 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); |
324 | 322 |
325 // Tap the notification's button. | 323 // Tap the notification's button. |
326 test_message_center_->NotifyNotificationButtonTapped( | 324 test_message_center_->NotifyNotificationButtonTapped( |
327 GetPotentialHotspotNotificationId(), 0 /* button_index */); | 325 GetPotentialHotspotNotificationId(), 0 /* button_index */); |
| 326 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
| 327 GetPotentialHotspotNotificationId())); |
| 328 EXPECT_EQ(0u, test_message_center_->GetNumNotifications()); |
328 | 329 |
329 EXPECT_EQ(test_device_.GetDeviceId(), | 330 EXPECT_EQ(test_device_.GetDeviceId(), |
330 test_network_connect_->network_id_to_connect()); | 331 test_network_connect_->network_id_to_connect()); |
331 } | 332 } |
332 | 333 |
333 TEST_F(TetherNotificationPresenterTest, | 334 TEST_F(TetherNotificationPresenterTest, |
334 TestMultiplePotentialHotspotNotification_RemoveProgrammatically) { | 335 TestMultiplePotentialHotspotNotification_RemoveProgrammatically) { |
335 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 336 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
336 GetPotentialHotspotNotificationId())); | 337 GetPotentialHotspotNotificationId())); |
337 notification_presenter_->NotifyMultiplePotentialHotspotsNearby(); | 338 notification_presenter_->NotifyMultiplePotentialHotspotsNearby(); |
(...skipping 20 matching lines...) Expand all Loading... |
358 message_center::Notification* notification = | 359 message_center::Notification* notification = |
359 test_message_center_->FindVisibleNotificationById( | 360 test_message_center_->FindVisibleNotificationById( |
360 GetPotentialHotspotNotificationId()); | 361 GetPotentialHotspotNotificationId()); |
361 EXPECT_TRUE(notification); | 362 EXPECT_TRUE(notification); |
362 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); | 363 EXPECT_EQ(GetPotentialHotspotNotificationId(), notification->id()); |
363 | 364 |
364 // Tap the notification. | 365 // Tap the notification. |
365 test_message_center_->NotifyNotificationTapped( | 366 test_message_center_->NotifyNotificationTapped( |
366 GetPotentialHotspotNotificationId()); | 367 GetPotentialHotspotNotificationId()); |
367 VerifySettingsOpened(); | 368 VerifySettingsOpened(); |
| 369 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
| 370 GetPotentialHotspotNotificationId())); |
| 371 EXPECT_EQ(0u, test_message_center_->GetNumNotifications()); |
368 } | 372 } |
369 | 373 |
370 TEST_F(TetherNotificationPresenterTest, | 374 TEST_F(TetherNotificationPresenterTest, |
371 TestPotentialHotspotNotifications_UpdatesOneNotification) { | 375 TestPotentialHotspotNotifications_UpdatesOneNotification) { |
372 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 376 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
373 GetPotentialHotspotNotificationId())); | 377 GetPotentialHotspotNotificationId())); |
374 notification_presenter_->NotifyPotentialHotspotNearby(test_device_); | 378 notification_presenter_->NotifyPotentialHotspotNearby(test_device_); |
375 | 379 |
376 message_center::Notification* notification = | 380 message_center::Notification* notification = |
377 test_message_center_->FindVisibleNotificationById( | 381 test_message_center_->FindVisibleNotificationById( |
(...skipping 17 matching lines...) Expand all Loading... |
395 notification_presenter_->RemovePotentialHotspotNotification(); | 399 notification_presenter_->RemovePotentialHotspotNotification(); |
396 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( | 400 EXPECT_FALSE(test_message_center_->FindVisibleNotificationById( |
397 GetPotentialHotspotNotificationId())); | 401 GetPotentialHotspotNotificationId())); |
398 | 402 |
399 VerifySettingsNotOpened(); | 403 VerifySettingsNotOpened(); |
400 } | 404 } |
401 | 405 |
402 } // namespace tether | 406 } // namespace tether |
403 | 407 |
404 } // namespace chromeos | 408 } // namespace chromeos |
OLD | NEW |