Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: chrome/browser/chromeos/net/network_portal_notification_controller_unittest.cc

Issue 2698473007: Convert path usage in NetworkListViewBase subclasses to use guids. (Closed)
Patch Set: Tweak NetworkPortalNotificationControllerTest to create GUIDs for new NetworkStates. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/macros.h" 6 #include "base/macros.h"
7 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" 7 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
8 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 8 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
9 #include "chrome/browser/chromeos/net/network_portal_notification_controller.h" 9 #include "chrome/browser/chromeos/net/network_portal_notification_controller.h"
10 #include "chromeos/chromeos_switches.h" 10 #include "chromeos/chromeos_switches.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 private: 93 private:
94 ScopedUserManagerEnabler user_manager_enabler_; 94 ScopedUserManagerEnabler user_manager_enabler_;
95 NetworkPortalNotificationController controller_; 95 NetworkPortalNotificationController controller_;
96 NotificationObserver observer_; 96 NotificationObserver observer_;
97 97
98 DISALLOW_COPY_AND_ASSIGN(NetworkPortalNotificationControllerTest); 98 DISALLOW_COPY_AND_ASSIGN(NetworkPortalNotificationControllerTest);
99 }; 99 };
100 100
101 TEST_F(NetworkPortalNotificationControllerTest, NetworkStateChanged) { 101 TEST_F(NetworkPortalNotificationControllerTest, NetworkStateChanged) {
102 NetworkState wifi("wifi"); 102 NetworkState wifi("wifi");
103 wifi.SetGuid("wifi");
103 NetworkPortalDetector::CaptivePortalState wifi_state; 104 NetworkPortalDetector::CaptivePortalState wifi_state;
104 105
105 // Notification is not displayed for online state. 106 // Notification is not displayed for online state.
106 wifi_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; 107 wifi_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
107 wifi_state.response_code = 204; 108 wifi_state.response_code = 204;
108 OnPortalDetectionCompleted(&wifi, wifi_state); 109 OnPortalDetectionCompleted(&wifi, wifi_state);
109 ASSERT_FALSE(HasNotification()); 110 ASSERT_FALSE(HasNotification());
110 111
111 // Notification is displayed for portal state 112 // Notification is displayed for portal state
112 wifi_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; 113 wifi_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL;
113 wifi_state.response_code = 200; 114 wifi_state.response_code = 200;
114 OnPortalDetectionCompleted(&wifi, wifi_state); 115 OnPortalDetectionCompleted(&wifi, wifi_state);
115 ASSERT_TRUE(HasNotification()); 116 ASSERT_TRUE(HasNotification());
116 117
117 // Notification is closed for online state. 118 // Notification is closed for online state.
118 wifi_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; 119 wifi_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
119 wifi_state.response_code = 204; 120 wifi_state.response_code = 204;
120 OnPortalDetectionCompleted(&wifi, wifi_state); 121 OnPortalDetectionCompleted(&wifi, wifi_state);
121 ASSERT_FALSE(HasNotification()); 122 ASSERT_FALSE(HasNotification());
122 } 123 }
123 124
124 TEST_F(NetworkPortalNotificationControllerTest, NetworkChanged) { 125 TEST_F(NetworkPortalNotificationControllerTest, NetworkChanged) {
125 NetworkState wifi1("wifi1"); 126 NetworkState wifi1("wifi1");
127 wifi1.SetGuid("wifi1");
126 NetworkPortalDetector::CaptivePortalState wifi1_state; 128 NetworkPortalDetector::CaptivePortalState wifi1_state;
127 wifi1_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; 129 wifi1_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL;
128 wifi1_state.response_code = 200; 130 wifi1_state.response_code = 200;
129 OnPortalDetectionCompleted(&wifi1, wifi1_state); 131 OnPortalDetectionCompleted(&wifi1, wifi1_state);
130 ASSERT_TRUE(HasNotification()); 132 ASSERT_TRUE(HasNotification());
131 133
132 MessageCenter::Get()->RemoveNotification(kNotificationId, true /* by_user */); 134 MessageCenter::Get()->RemoveNotification(kNotificationId, true /* by_user */);
133 ASSERT_FALSE(HasNotification()); 135 ASSERT_FALSE(HasNotification());
134 136
135 // User already closed notification about portal state for this network, 137 // User already closed notification about portal state for this network,
136 // so notification shouldn't be displayed second time. 138 // so notification shouldn't be displayed second time.
137 OnPortalDetectionCompleted(&wifi1, wifi1_state); 139 OnPortalDetectionCompleted(&wifi1, wifi1_state);
138 ASSERT_FALSE(HasNotification()); 140 ASSERT_FALSE(HasNotification());
139 141
140 NetworkState wifi2("wifi2"); 142 NetworkState wifi2("wifi2");
143 wifi2.SetGuid("wifi2");
141 NetworkPortalDetector::CaptivePortalState wifi2_state; 144 NetworkPortalDetector::CaptivePortalState wifi2_state;
142 wifi2_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; 145 wifi2_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
143 wifi2_state.response_code = 204; 146 wifi2_state.response_code = 204;
144 147
145 // Second network is in online state, so there shouldn't be any 148 // Second network is in online state, so there shouldn't be any
146 // notifications. 149 // notifications.
147 OnPortalDetectionCompleted(&wifi2, wifi2_state); 150 OnPortalDetectionCompleted(&wifi2, wifi2_state);
148 ASSERT_FALSE(HasNotification()); 151 ASSERT_FALSE(HasNotification());
149 152
150 // User switches back to the first network, so notification should 153 // User switches back to the first network, so notification should
151 // be displayed. 154 // be displayed.
152 OnPortalDetectionCompleted(&wifi1, wifi1_state); 155 OnPortalDetectionCompleted(&wifi1, wifi1_state);
153 ASSERT_TRUE(HasNotification()); 156 ASSERT_TRUE(HasNotification());
154 } 157 }
155 158
156 TEST_F(NetworkPortalNotificationControllerTest, NotificationUpdated) { 159 TEST_F(NetworkPortalNotificationControllerTest, NotificationUpdated) {
157 NetworkPortalDetector::CaptivePortalState portal_state; 160 NetworkPortalDetector::CaptivePortalState portal_state;
158 portal_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; 161 portal_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL;
159 portal_state.response_code = 200; 162 portal_state.response_code = 200;
160 163
161 // First network is behind a captive portal, so notification should 164 // First network is behind a captive portal, so notification should
162 // be displayed. 165 // be displayed.
163 NetworkState wifi1("wifi1"); 166 NetworkState wifi1("wifi1");
167 wifi1.SetGuid("wifi1");
164 OnPortalDetectionCompleted(&wifi1, portal_state); 168 OnPortalDetectionCompleted(&wifi1, portal_state);
165 ASSERT_TRUE(HasNotification()); 169 ASSERT_TRUE(HasNotification());
166 EXPECT_EQ(1u, observer().add_count()); 170 EXPECT_EQ(1u, observer().add_count());
167 EXPECT_EQ(0u, observer().remove_count()); 171 EXPECT_EQ(0u, observer().remove_count());
168 EXPECT_EQ(0u, observer().update_count()); 172 EXPECT_EQ(0u, observer().update_count());
169 173
170 // Second network is also behind a captive portal, so notification 174 // Second network is also behind a captive portal, so notification
171 // should be updated. 175 // should be updated.
172 NetworkState wifi2("wifi2"); 176 NetworkState wifi2("wifi2");
177 wifi2.SetGuid("wifi2");
173 OnPortalDetectionCompleted(&wifi2, portal_state); 178 OnPortalDetectionCompleted(&wifi2, portal_state);
174 ASSERT_TRUE(HasNotification()); 179 ASSERT_TRUE(HasNotification());
175 EXPECT_EQ(1u, observer().add_count()); 180 EXPECT_EQ(1u, observer().add_count());
176 EXPECT_EQ(0u, observer().remove_count()); 181 EXPECT_EQ(0u, observer().remove_count());
177 EXPECT_EQ(1u, observer().update_count()); 182 EXPECT_EQ(1u, observer().update_count());
178 183
179 // User closes the notification. 184 // User closes the notification.
180 MessageCenter::Get()->RemoveNotification(kNotificationId, true /* by_user */); 185 MessageCenter::Get()->RemoveNotification(kNotificationId, true /* by_user */);
181 ASSERT_FALSE(HasNotification()); 186 ASSERT_FALSE(HasNotification());
182 EXPECT_EQ(1u, observer().add_count()); 187 EXPECT_EQ(1u, observer().add_count());
(...skipping 12 matching lines...) Expand all
195 // Network was switched (by shill or by user) to wifi1. Notification 200 // Network was switched (by shill or by user) to wifi1. Notification
196 // should be displayed. 201 // should be displayed.
197 OnPortalDetectionCompleted(&wifi1, portal_state); 202 OnPortalDetectionCompleted(&wifi1, portal_state);
198 ASSERT_TRUE(HasNotification()); 203 ASSERT_TRUE(HasNotification());
199 EXPECT_EQ(2u, observer().add_count()); 204 EXPECT_EQ(2u, observer().add_count());
200 EXPECT_EQ(1u, observer().remove_count()); 205 EXPECT_EQ(1u, observer().remove_count());
201 EXPECT_EQ(1u, observer().update_count()); 206 EXPECT_EQ(1u, observer().update_count());
202 } 207 }
203 208
204 } // namespace chromeos 209 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698