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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 NotificationObserver observer_; | 91 NotificationObserver observer_; |
92 | 92 |
93 DISALLOW_COPY_AND_ASSIGN(NetworkPortalNotificationControllerTest); | 93 DISALLOW_COPY_AND_ASSIGN(NetworkPortalNotificationControllerTest); |
94 }; | 94 }; |
95 | 95 |
96 TEST_F(NetworkPortalNotificationControllerTest, NetworkStateChanged) { | 96 TEST_F(NetworkPortalNotificationControllerTest, NetworkStateChanged) { |
97 NetworkState wifi("wifi"); | 97 NetworkState wifi("wifi"); |
98 NetworkPortalDetector::CaptivePortalState wifi_state; | 98 NetworkPortalDetector::CaptivePortalState wifi_state; |
99 | 99 |
100 // Notification is not displayed for online state. | 100 // Notification is not displayed for online state. |
101 wifi_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; | 101 wifi_state.status = captive_portal::CAPTIVE_PORTAL_STATUS_ONLINE; |
102 wifi_state.response_code = 204; | 102 wifi_state.response_code = 204; |
103 OnPortalDetectionCompleted(&wifi, wifi_state); | 103 OnPortalDetectionCompleted(&wifi, wifi_state); |
104 ASSERT_FALSE(HasNotification()); | 104 ASSERT_FALSE(HasNotification()); |
105 | 105 |
106 // Notification is displayed for portal state | 106 // Notification is displayed for portal state |
107 wifi_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; | 107 wifi_state.status = captive_portal::CAPTIVE_PORTAL_STATUS_PORTAL; |
108 wifi_state.response_code = 200; | 108 wifi_state.response_code = 200; |
109 OnPortalDetectionCompleted(&wifi, wifi_state); | 109 OnPortalDetectionCompleted(&wifi, wifi_state); |
110 ASSERT_TRUE(HasNotification()); | 110 ASSERT_TRUE(HasNotification()); |
111 | 111 |
112 // Notification is closed for online state. | 112 // Notification is closed for online state. |
113 wifi_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; | 113 wifi_state.status = captive_portal::CAPTIVE_PORTAL_STATUS_ONLINE; |
114 wifi_state.response_code = 204; | 114 wifi_state.response_code = 204; |
115 OnPortalDetectionCompleted(&wifi, wifi_state); | 115 OnPortalDetectionCompleted(&wifi, wifi_state); |
116 ASSERT_FALSE(HasNotification()); | 116 ASSERT_FALSE(HasNotification()); |
117 } | 117 } |
118 | 118 |
119 TEST_F(NetworkPortalNotificationControllerTest, NetworkChanged) { | 119 TEST_F(NetworkPortalNotificationControllerTest, NetworkChanged) { |
120 NetworkState wifi1("wifi1"); | 120 NetworkState wifi1("wifi1"); |
121 NetworkPortalDetector::CaptivePortalState wifi1_state; | 121 NetworkPortalDetector::CaptivePortalState wifi1_state; |
122 wifi1_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; | 122 wifi1_state.status = captive_portal::CAPTIVE_PORTAL_STATUS_PORTAL; |
123 wifi1_state.response_code = 200; | 123 wifi1_state.response_code = 200; |
124 OnPortalDetectionCompleted(&wifi1, wifi1_state); | 124 OnPortalDetectionCompleted(&wifi1, wifi1_state); |
125 ASSERT_TRUE(HasNotification()); | 125 ASSERT_TRUE(HasNotification()); |
126 | 126 |
127 MessageCenter::Get()->RemoveNotification(kNotificationId, true /* by_user */); | 127 MessageCenter::Get()->RemoveNotification(kNotificationId, true /* by_user */); |
128 ASSERT_FALSE(HasNotification()); | 128 ASSERT_FALSE(HasNotification()); |
129 | 129 |
130 // User already closed notification about portal state for this network, | 130 // User already closed notification about portal state for this network, |
131 // so notification shouldn't be displayed second time. | 131 // so notification shouldn't be displayed second time. |
132 OnPortalDetectionCompleted(&wifi1, wifi1_state); | 132 OnPortalDetectionCompleted(&wifi1, wifi1_state); |
133 ASSERT_FALSE(HasNotification()); | 133 ASSERT_FALSE(HasNotification()); |
134 | 134 |
135 NetworkState wifi2("wifi2"); | 135 NetworkState wifi2("wifi2"); |
136 NetworkPortalDetector::CaptivePortalState wifi2_state; | 136 NetworkPortalDetector::CaptivePortalState wifi2_state; |
137 wifi2_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; | 137 wifi2_state.status = captive_portal::CAPTIVE_PORTAL_STATUS_ONLINE; |
138 wifi2_state.response_code = 204; | 138 wifi2_state.response_code = 204; |
139 | 139 |
140 // Second network is in online state, so there shouldn't be any | 140 // Second network is in online state, so there shouldn't be any |
141 // notifications. | 141 // notifications. |
142 OnPortalDetectionCompleted(&wifi2, wifi2_state); | 142 OnPortalDetectionCompleted(&wifi2, wifi2_state); |
143 ASSERT_FALSE(HasNotification()); | 143 ASSERT_FALSE(HasNotification()); |
144 | 144 |
145 // User switches back to the first network, so notification should | 145 // User switches back to the first network, so notification should |
146 // be displayed. | 146 // be displayed. |
147 OnPortalDetectionCompleted(&wifi1, wifi1_state); | 147 OnPortalDetectionCompleted(&wifi1, wifi1_state); |
148 ASSERT_TRUE(HasNotification()); | 148 ASSERT_TRUE(HasNotification()); |
149 } | 149 } |
150 | 150 |
151 TEST_F(NetworkPortalNotificationControllerTest, NotificationUpdated) { | 151 TEST_F(NetworkPortalNotificationControllerTest, NotificationUpdated) { |
152 NetworkPortalDetector::CaptivePortalState portal_state; | 152 NetworkPortalDetector::CaptivePortalState portal_state; |
153 portal_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; | 153 portal_state.status = captive_portal::CAPTIVE_PORTAL_STATUS_PORTAL; |
154 portal_state.response_code = 200; | 154 portal_state.response_code = 200; |
155 | 155 |
156 // First network is behind a captive portal, so notification should | 156 // First network is behind a captive portal, so notification should |
157 // be displayed. | 157 // be displayed. |
158 NetworkState wifi1("wifi1"); | 158 NetworkState wifi1("wifi1"); |
159 OnPortalDetectionCompleted(&wifi1, portal_state); | 159 OnPortalDetectionCompleted(&wifi1, portal_state); |
160 ASSERT_TRUE(HasNotification()); | 160 ASSERT_TRUE(HasNotification()); |
161 EXPECT_EQ(1u, observer().add_count()); | 161 EXPECT_EQ(1u, observer().add_count()); |
162 EXPECT_EQ(0u, observer().remove_count()); | 162 EXPECT_EQ(0u, observer().remove_count()); |
163 EXPECT_EQ(0u, observer().update_count()); | 163 EXPECT_EQ(0u, observer().update_count()); |
(...skipping 26 matching lines...) Expand all Loading... |
190 // Network was switched (by shill or by user) to wifi1. Notification | 190 // Network was switched (by shill or by user) to wifi1. Notification |
191 // should be displayed. | 191 // should be displayed. |
192 OnPortalDetectionCompleted(&wifi1, portal_state); | 192 OnPortalDetectionCompleted(&wifi1, portal_state); |
193 ASSERT_TRUE(HasNotification()); | 193 ASSERT_TRUE(HasNotification()); |
194 EXPECT_EQ(2u, observer().add_count()); | 194 EXPECT_EQ(2u, observer().add_count()); |
195 EXPECT_EQ(1u, observer().remove_count()); | 195 EXPECT_EQ(1u, observer().remove_count()); |
196 EXPECT_EQ(1u, observer().update_count()); | 196 EXPECT_EQ(1u, observer().update_count()); |
197 } | 197 } |
198 | 198 |
199 } // namespace chromeos | 199 } // namespace chromeos |
OLD | NEW |