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 12 matching lines...) Expand all Loading... |
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 virtual void OnNotificationAdded( |
33 const std::string& notification_id) OVERRIDE { | 33 const std::string& notification_id) override { |
34 if (notification_id == kNotificationId) | 34 if (notification_id == kNotificationId) |
35 ++add_count_; | 35 ++add_count_; |
36 } | 36 } |
37 | 37 |
38 virtual void OnNotificationRemoved(const std::string& notification_id, | 38 virtual void OnNotificationRemoved(const std::string& notification_id, |
39 bool /* by_user */) OVERRIDE { | 39 bool /* by_user */) override { |
40 if (notification_id == kNotificationId) | 40 if (notification_id == kNotificationId) |
41 ++remove_count_; | 41 ++remove_count_; |
42 } | 42 } |
43 | 43 |
44 virtual void OnNotificationUpdated( | 44 virtual void OnNotificationUpdated( |
45 const std::string& notification_id) OVERRIDE { | 45 const std::string& notification_id) override { |
46 if (notification_id == kNotificationId) | 46 if (notification_id == kNotificationId) |
47 ++update_count_; | 47 ++update_count_; |
48 } | 48 } |
49 | 49 |
50 unsigned add_count() const { return add_count_; } | 50 unsigned add_count() const { return add_count_; } |
51 unsigned remove_count() const { return remove_count_; } | 51 unsigned remove_count() const { return remove_count_; } |
52 unsigned update_count() const { return update_count_; } | 52 unsigned update_count() const { return update_count_; } |
53 | 53 |
54 private: | 54 private: |
55 unsigned add_count_; | 55 unsigned add_count_; |
56 unsigned remove_count_; | 56 unsigned remove_count_; |
57 unsigned update_count_; | 57 unsigned update_count_; |
58 | 58 |
59 DISALLOW_COPY_AND_ASSIGN(NotificationObserver); | 59 DISALLOW_COPY_AND_ASSIGN(NotificationObserver); |
60 }; | 60 }; |
61 | 61 |
62 } // namespace | 62 } // namespace |
63 | 63 |
64 class NetworkPortalNotificationControllerTest : public testing::Test { | 64 class NetworkPortalNotificationControllerTest : public testing::Test { |
65 public: | 65 public: |
66 NetworkPortalNotificationControllerTest() {} | 66 NetworkPortalNotificationControllerTest() {} |
67 virtual ~NetworkPortalNotificationControllerTest() {} | 67 virtual ~NetworkPortalNotificationControllerTest() {} |
68 | 68 |
69 virtual void SetUp() OVERRIDE { | 69 virtual void SetUp() override { |
70 CommandLine* cl = CommandLine::ForCurrentProcess(); | 70 CommandLine* cl = CommandLine::ForCurrentProcess(); |
71 cl->AppendSwitch(switches::kEnableNetworkPortalNotification); | 71 cl->AppendSwitch(switches::kEnableNetworkPortalNotification); |
72 MessageCenter::Initialize(); | 72 MessageCenter::Initialize(); |
73 MessageCenter::Get()->AddObserver(&observer_); | 73 MessageCenter::Get()->AddObserver(&observer_); |
74 } | 74 } |
75 | 75 |
76 virtual void TearDown() OVERRIDE { | 76 virtual void TearDown() override { |
77 MessageCenter::Get()->RemoveObserver(&observer_); | 77 MessageCenter::Get()->RemoveObserver(&observer_); |
78 MessageCenter::Shutdown(); | 78 MessageCenter::Shutdown(); |
79 } | 79 } |
80 | 80 |
81 protected: | 81 protected: |
82 void OnPortalDetectionCompleted( | 82 void OnPortalDetectionCompleted( |
83 const NetworkState* network, | 83 const NetworkState* network, |
84 const NetworkPortalDetector::CaptivePortalState& state) { | 84 const NetworkPortalDetector::CaptivePortalState& state) { |
85 controller_.OnPortalDetectionCompleted(network, state); | 85 controller_.OnPortalDetectionCompleted(network, state); |
86 } | 86 } |
(...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 | 191 // Network was switched (by shill or by user) to wifi1. Notification |
192 // should be displayed. | 192 // should be displayed. |
193 OnPortalDetectionCompleted(&wifi1, portal_state); | 193 OnPortalDetectionCompleted(&wifi1, portal_state); |
194 ASSERT_TRUE(HasNotification()); | 194 ASSERT_TRUE(HasNotification()); |
195 EXPECT_EQ(2u, observer().add_count()); | 195 EXPECT_EQ(2u, observer().add_count()); |
196 EXPECT_EQ(1u, observer().remove_count()); | 196 EXPECT_EQ(1u, observer().remove_count()); |
197 EXPECT_EQ(1u, observer().update_count()); | 197 EXPECT_EQ(1u, observer().update_count()); |
198 } | 198 } |
199 | 199 |
200 } // namespace chromeos | 200 } // namespace chromeos |
OLD | NEW |