| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "chrome/browser/chromeos/net/network_portal_notification_controller.h" | 6 #include "chrome/browser/chromeos/net/network_portal_notification_controller.h" |
| 7 #include "chromeos/chromeos_switches.h" | 7 #include "chromeos/chromeos_switches.h" |
| 8 #include "chromeos/network/network_state.h" | 8 #include "chromeos/network/network_state.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/message_center/message_center.h" | 10 #include "ui/message_center/message_center.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 bool HasNotification() { | 22 bool HasNotification() { |
| 23 MessageCenter* message_center = MessageCenter::Get(); | 23 MessageCenter* message_center = MessageCenter::Get(); |
| 24 return message_center->FindVisibleNotificationById(kNotificationId); | 24 return message_center->FindVisibleNotificationById(kNotificationId); |
| 25 } | 25 } |
| 26 | 26 |
| 27 class NotificationObserver : public message_center::MessageCenterObserver { | 27 class NotificationObserver : public message_center::MessageCenterObserver { |
| 28 public: | 28 public: |
| 29 NotificationObserver() : add_count_(0), remove_count_(0), update_count_(0) {} | 29 NotificationObserver() : add_count_(0), remove_count_(0), update_count_(0) {} |
| 30 | 30 |
| 31 // Overridden from message_center::MessageCenterObserver: | 31 // Overridden from message_center::MessageCenterObserver: |
| 32 virtual void OnNotificationAdded( | 32 void OnNotificationAdded(const std::string& notification_id) override { |
| 33 const std::string& notification_id) override { | |
| 34 if (notification_id == kNotificationId) | 33 if (notification_id == kNotificationId) |
| 35 ++add_count_; | 34 ++add_count_; |
| 36 } | 35 } |
| 37 | 36 |
| 38 virtual void OnNotificationRemoved(const std::string& notification_id, | 37 void OnNotificationRemoved(const std::string& notification_id, |
| 39 bool /* by_user */) override { | 38 bool /* by_user */) override { |
| 40 if (notification_id == kNotificationId) | 39 if (notification_id == kNotificationId) |
| 41 ++remove_count_; | 40 ++remove_count_; |
| 42 } | 41 } |
| 43 | 42 |
| 44 virtual void OnNotificationUpdated( | 43 void OnNotificationUpdated(const std::string& notification_id) override { |
| 45 const std::string& notification_id) override { | |
| 46 if (notification_id == kNotificationId) | 44 if (notification_id == kNotificationId) |
| 47 ++update_count_; | 45 ++update_count_; |
| 48 } | 46 } |
| 49 | 47 |
| 50 unsigned add_count() const { return add_count_; } | 48 unsigned add_count() const { return add_count_; } |
| 51 unsigned remove_count() const { return remove_count_; } | 49 unsigned remove_count() const { return remove_count_; } |
| 52 unsigned update_count() const { return update_count_; } | 50 unsigned update_count() const { return update_count_; } |
| 53 | 51 |
| 54 private: | 52 private: |
| 55 unsigned add_count_; | 53 unsigned add_count_; |
| 56 unsigned remove_count_; | 54 unsigned remove_count_; |
| 57 unsigned update_count_; | 55 unsigned update_count_; |
| 58 | 56 |
| 59 DISALLOW_COPY_AND_ASSIGN(NotificationObserver); | 57 DISALLOW_COPY_AND_ASSIGN(NotificationObserver); |
| 60 }; | 58 }; |
| 61 | 59 |
| 62 } // namespace | 60 } // namespace |
| 63 | 61 |
| 64 class NetworkPortalNotificationControllerTest : public testing::Test { | 62 class NetworkPortalNotificationControllerTest : public testing::Test { |
| 65 public: | 63 public: |
| 66 NetworkPortalNotificationControllerTest() {} | 64 NetworkPortalNotificationControllerTest() {} |
| 67 virtual ~NetworkPortalNotificationControllerTest() {} | 65 ~NetworkPortalNotificationControllerTest() override {} |
| 68 | 66 |
| 69 virtual void SetUp() override { | 67 void SetUp() override { |
| 70 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); | 68 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
| 71 cl->AppendSwitch(switches::kEnableNetworkPortalNotification); | 69 cl->AppendSwitch(switches::kEnableNetworkPortalNotification); |
| 72 MessageCenter::Initialize(); | 70 MessageCenter::Initialize(); |
| 73 MessageCenter::Get()->AddObserver(&observer_); | 71 MessageCenter::Get()->AddObserver(&observer_); |
| 74 } | 72 } |
| 75 | 73 |
| 76 virtual void TearDown() override { | 74 void TearDown() override { |
| 77 MessageCenter::Get()->RemoveObserver(&observer_); | 75 MessageCenter::Get()->RemoveObserver(&observer_); |
| 78 MessageCenter::Shutdown(); | 76 MessageCenter::Shutdown(); |
| 79 } | 77 } |
| 80 | 78 |
| 81 protected: | 79 protected: |
| 82 void OnPortalDetectionCompleted( | 80 void OnPortalDetectionCompleted( |
| 83 const NetworkState* network, | 81 const NetworkState* network, |
| 84 const NetworkPortalDetector::CaptivePortalState& state) { | 82 const NetworkPortalDetector::CaptivePortalState& state) { |
| 85 controller_.OnPortalDetectionCompleted(network, state); | 83 controller_.OnPortalDetectionCompleted(network, state); |
| 86 } | 84 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // Network was switched (by shill or by user) to wifi1. Notification | 189 // Network was switched (by shill or by user) to wifi1. Notification |
| 192 // should be displayed. | 190 // should be displayed. |
| 193 OnPortalDetectionCompleted(&wifi1, portal_state); | 191 OnPortalDetectionCompleted(&wifi1, portal_state); |
| 194 ASSERT_TRUE(HasNotification()); | 192 ASSERT_TRUE(HasNotification()); |
| 195 EXPECT_EQ(2u, observer().add_count()); | 193 EXPECT_EQ(2u, observer().add_count()); |
| 196 EXPECT_EQ(1u, observer().remove_count()); | 194 EXPECT_EQ(1u, observer().remove_count()); |
| 197 EXPECT_EQ(1u, observer().update_count()); | 195 EXPECT_EQ(1u, observer().update_count()); |
| 198 } | 196 } |
| 199 | 197 |
| 200 } // namespace chromeos | 198 } // namespace chromeos |
| OLD | NEW |