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

Side by Side Diff: chromeos/components/tether/wifi_hotspot_connector_unittest.cc

Issue 2819303002: Changed wifi arcs to mobile bars for Tether network. (Closed)
Patch Set: Created 3 years, 8 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 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 "chromeos/components/tether/wifi_hotspot_connector.h" 5 #include "chromeos/components/tether/wifi_hotspot_connector.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <sstream> 8 #include <sstream>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/test/scoped_task_environment.h" 13 #include "base/test/scoped_task_environment.h"
14 #include "base/timer/mock_timer.h" 14 #include "base/timer/mock_timer.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chromeos/components/tether/fake_active_host.h"
16 #include "chromeos/dbus/dbus_thread_manager.h" 17 #include "chromeos/dbus/dbus_thread_manager.h"
17 #include "chromeos/dbus/shill_device_client.h" 18 #include "chromeos/dbus/shill_device_client.h"
18 #include "chromeos/dbus/shill_service_client.h" 19 #include "chromeos/dbus/shill_service_client.h"
19 #include "chromeos/network/network_connect.h" 20 #include "chromeos/network/network_connect.h"
20 #include "chromeos/network/network_state.h" 21 #include "chromeos/network/network_state.h"
21 #include "chromeos/network/network_state_handler.h" 22 #include "chromeos/network/network_state_handler.h"
22 #include "chromeos/network/network_state_test.h" 23 #include "chromeos/network/network_state_test.h"
23 #include "chromeos/network/shill_property_util.h" 24 #include "chromeos/network/shill_property_util.h"
24 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" 27 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h"
27 28
28 namespace chromeos { 29 namespace chromeos {
29 30
30 namespace tether { 31 namespace tether {
31 32
32 namespace { 33 namespace {
33 34
34 const char kSsid[] = "ssid"; 35 const char kSsid[] = "ssid";
35 const char kPassword[] = "password"; 36 const char kPassword[] = "password";
36 37
37 const char kOtherWifiServiceGuid[] = "otherWifiServiceGuid"; 38 const char kOtherWifiServiceGuid[] = "otherWifiServiceGuid";
38 39
40 const char kDeviceId[] = "deviceId";
41
39 std::string CreateConfigurationJsonString(const std::string& guid) { 42 std::string CreateConfigurationJsonString(const std::string& guid) {
40 std::stringstream ss; 43 std::stringstream ss;
41 ss << "{" 44 ss << "{"
42 << " \"GUID\": \"" << guid << "\"," 45 << " \"GUID\": \"" << guid << "\","
43 << " \"Type\": \"" << shill::kTypeWifi << "\"," 46 << " \"Type\": \"" << shill::kTypeWifi << "\","
44 << " \"State\": \"" << shill::kStateIdle << "\"" 47 << " \"State\": \"" << shill::kStateIdle << "\""
45 << "}"; 48 << "}";
46 return ss.str(); 49 return ss.str();
47 } 50 }
48 51
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 116
114 void SetUp() override { 117 void SetUp() override {
115 other_wifi_service_path_.clear(); 118 other_wifi_service_path_.clear();
116 connection_callback_responses_.clear(); 119 connection_callback_responses_.clear();
117 120
118 DBusThreadManager::Initialize(); 121 DBusThreadManager::Initialize();
119 NetworkStateTest::SetUp(); 122 NetworkStateTest::SetUp();
120 SetUpShillState(); 123 SetUpShillState();
121 124
122 test_network_connect_ = base::WrapUnique(new TestNetworkConnect(this)); 125 test_network_connect_ = base::WrapUnique(new TestNetworkConnect(this));
126 fake_active_host_ = base::WrapUnique(new FakeActiveHost());
Kyle Horimoto 2017/04/17 19:50:04 nit: Use base::MakeUnique<FakeActiveHost>().
lesliewatkins 2017/04/27 00:33:53 Done.
127
128 network_state_handler()->AddTetherNetworkState(kDeviceId, "");
Kyle Horimoto 2017/04/17 19:50:04 You should be passing a tether network GUID, not a
lesliewatkins 2017/04/27 00:33:54 Done.
129
130 fake_active_host_->SetActiveHostConnecting(kDeviceId, kDeviceId);
Kyle Horimoto 2017/04/17 19:50:04 Also pass the GUID here as well. Don't use the sam
lesliewatkins 2017/04/27 00:33:54 Done.
123 131
124 wifi_hotspot_connector_ = base::WrapUnique(new WifiHotspotConnector( 132 wifi_hotspot_connector_ = base::WrapUnique(new WifiHotspotConnector(
125 network_state_handler(), test_network_connect_.get())); 133 network_state_handler(), test_network_connect_.get(),
134 fake_active_host_.get()));
126 135
127 mock_timer_ = new base::MockTimer(true /* retain_user_task */, 136 mock_timer_ = new base::MockTimer(true /* retain_user_task */,
128 false /* is_repeating */); 137 false /* is_repeating */);
129 wifi_hotspot_connector_->SetTimerForTest(base::WrapUnique(mock_timer_)); 138 wifi_hotspot_connector_->SetTimerForTest(base::WrapUnique(mock_timer_));
130 } 139 }
131 140
132 void SetUpShillState() { 141 void SetUpShillState() {
133 // Add a Wi-Fi service unrelated to the one under test. In some tests, a 142 // Add a Wi-Fi service unrelated to the one under test. In some tests, a
134 // connection from another device is tested. 143 // connection from another device is tested.
135 other_wifi_service_path_ = ConfigureService( 144 other_wifi_service_path_ = ConfigureService(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 last_configuration->GetString(shill::kPassphraseProperty, &password)); 204 last_configuration->GetString(shill::kPassphraseProperty, &password));
196 EXPECT_EQ(expected_password, password); 205 EXPECT_EQ(expected_password, password);
197 } 206 }
198 207
199 std::string wifi_guid; 208 std::string wifi_guid;
200 EXPECT_TRUE( 209 EXPECT_TRUE(
201 last_configuration->GetString(shill::kGuidProperty, &wifi_guid)); 210 last_configuration->GetString(shill::kGuidProperty, &wifi_guid));
202 return wifi_guid; 211 return wifi_guid;
203 } 212 }
204 213
214 void VerifyTetherAndWifiNetworkAssociation(const std::string& wifi_guid) {
215 const NetworkState* wifi_network_state =
216 network_state_handler()->GetNetworkStateFromGuid(wifi_guid);
217 EXPECT_TRUE(wifi_network_state);
218 EXPECT_EQ(fake_active_host_->GetTetherNetworkGuid(),
219 wifi_network_state->tether_guid());
220
221 const NetworkState* tether_network_state =
222 network_state_handler()->GetNetworkStateFromGuid(
223 fake_active_host_->GetTetherNetworkGuid());
224 EXPECT_TRUE(tether_network_state);
225 EXPECT_EQ(wifi_guid, tether_network_state->tether_guid());
226 }
227
228 void VerifyTetherAndWifiNetworkDisassociation(const std::string& wifi_guid) {
Kyle Horimoto 2017/04/17 19:50:04 nit: Rename this to VerifyTetherAndWifiNetworkNotA
lesliewatkins 2017/04/27 00:33:53 Done.
229 const NetworkState* wifi_network_state =
230 network_state_handler()->GetNetworkStateFromGuid(wifi_guid);
231 EXPECT_TRUE(wifi_network_state);
232 EXPECT_NE(fake_active_host_->GetTetherNetworkGuid(),
Kyle Horimoto 2017/04/17 19:50:04 Here, the tether GUID should be "". Assert that th
lesliewatkins 2017/04/27 00:33:53 Done.
lesliewatkins 2017/04/27 00:33:53 Done.
233 wifi_network_state->tether_guid());
234
235 const NetworkState* tether_network_state =
236 network_state_handler()->GetNetworkStateFromGuid(
237 fake_active_host_->GetTetherNetworkGuid());
238 EXPECT_TRUE(tether_network_state);
239 EXPECT_NE(wifi_guid, tether_network_state->tether_guid());
240 }
241
205 void WifiConnectionCallback(const std::string& wifi_guid) { 242 void WifiConnectionCallback(const std::string& wifi_guid) {
206 connection_callback_responses_.push_back(wifi_guid); 243 connection_callback_responses_.push_back(wifi_guid);
207 } 244 }
208 245
209 base::test::ScopedTaskEnvironment scoped_task_environment_; 246 base::test::ScopedTaskEnvironment scoped_task_environment_;
210 247
211 std::string other_wifi_service_path_; 248 std::string other_wifi_service_path_;
212 std::vector<std::string> connection_callback_responses_; 249 std::vector<std::string> connection_callback_responses_;
213 250
214 base::MockTimer* mock_timer_; 251 base::MockTimer* mock_timer_;
215 std::unique_ptr<TestNetworkConnect> test_network_connect_; 252 std::unique_ptr<TestNetworkConnect> test_network_connect_;
216 253
217 std::unique_ptr<WifiHotspotConnector> wifi_hotspot_connector_; 254 std::unique_ptr<WifiHotspotConnector> wifi_hotspot_connector_;
218 255
219 private: 256 private:
257 std::unique_ptr<FakeActiveHost> fake_active_host_;
Kyle Horimoto 2017/04/17 19:50:04 Move this up to the protected section underneath t
lesliewatkins 2017/04/27 00:33:53 Done.
258
220 DISALLOW_COPY_AND_ASSIGN(WifiHotspotConnectorTest); 259 DISALLOW_COPY_AND_ASSIGN(WifiHotspotConnectorTest);
221 }; 260 };
222 261
223 TEST_F(WifiHotspotConnectorTest, TestConnect_NetworkDoesNotBecomeConnectable) { 262 TEST_F(WifiHotspotConnectorTest, TestConnect_NetworkDoesNotBecomeConnectable) {
224 wifi_hotspot_connector_->ConnectToWifiHotspot( 263 wifi_hotspot_connector_->ConnectToWifiHotspot(
225 std::string(kSsid), std::string(kPassword), 264 std::string(kSsid), std::string(kPassword),
226 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, 265 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback,
227 base::Unretained(this))); 266 base::Unretained(this)));
228 267
229 std::string wifi_guid = 268 std::string wifi_guid =
(...skipping 16 matching lines...) Expand all
246 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, 285 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback,
247 base::Unretained(this))); 286 base::Unretained(this)));
248 287
249 std::string wifi_guid = 288 std::string wifi_guid =
250 VerifyLastConfiguration(std::string(kSsid), std::string(kPassword)); 289 VerifyLastConfiguration(std::string(kSsid), std::string(kPassword));
251 EXPECT_FALSE(wifi_guid.empty()); 290 EXPECT_FALSE(wifi_guid.empty());
252 291
253 // Another network becomes connectable. This should not cause the connection 292 // Another network becomes connectable. This should not cause the connection
254 // to start. 293 // to start.
255 NotifyConnectable(other_wifi_service_path_); 294 NotifyConnectable(other_wifi_service_path_);
295 VerifyTetherAndWifiNetworkDisassociation(wifi_guid);
256 EXPECT_EQ("", test_network_connect_->network_id_to_connect()); 296 EXPECT_EQ("", test_network_connect_->network_id_to_connect());
257 297
258 // Timeout timer fires. 298 // Timeout timer fires.
259 EXPECT_EQ(0u, connection_callback_responses_.size()); 299 EXPECT_EQ(0u, connection_callback_responses_.size());
260 InvokeTimerTask(); 300 InvokeTimerTask();
261 EXPECT_EQ(1u, connection_callback_responses_.size()); 301 EXPECT_EQ(1u, connection_callback_responses_.size());
262 EXPECT_EQ("", connection_callback_responses_[0]); 302 EXPECT_EQ("", connection_callback_responses_[0]);
263 } 303 }
264 304
265 TEST_F(WifiHotspotConnectorTest, TestConnect_CannotConnectToNetwork) { 305 TEST_F(WifiHotspotConnectorTest, TestConnect_CannotConnectToNetwork) {
266 wifi_hotspot_connector_->ConnectToWifiHotspot( 306 wifi_hotspot_connector_->ConnectToWifiHotspot(
267 std::string(kSsid), std::string(kPassword), 307 std::string(kSsid), std::string(kPassword),
268 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, 308 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback,
269 base::Unretained(this))); 309 base::Unretained(this)));
270 310
271 std::string wifi_guid = 311 std::string wifi_guid =
272 VerifyLastConfiguration(std::string(kSsid), std::string(kPassword)); 312 VerifyLastConfiguration(std::string(kSsid), std::string(kPassword));
273 EXPECT_FALSE(wifi_guid.empty()); 313 EXPECT_FALSE(wifi_guid.empty());
274 314
275 // Network becomes connectable. 315 // Network becomes connectable.
276 NotifyConnectable(test_network_connect_->last_service_path_created()); 316 NotifyConnectable(test_network_connect_->last_service_path_created());
317 VerifyTetherAndWifiNetworkAssociation(wifi_guid);
277 EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect()); 318 EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect());
278 319
279 // Network connection does not occur. 320 // Network connection does not occur.
280 EXPECT_EQ(0u, connection_callback_responses_.size()); 321 EXPECT_EQ(0u, connection_callback_responses_.size());
281 322
282 // Timeout timer fires. 323 // Timeout timer fires.
283 InvokeTimerTask(); 324 InvokeTimerTask();
284 EXPECT_EQ(1u, connection_callback_responses_.size()); 325 EXPECT_EQ(1u, connection_callback_responses_.size());
285 EXPECT_EQ("", connection_callback_responses_[0]); 326 EXPECT_EQ("", connection_callback_responses_[0]);
286 } 327 }
287 328
288 TEST_F(WifiHotspotConnectorTest, TestConnect_Success) { 329 TEST_F(WifiHotspotConnectorTest, TestConnect_Success) {
289 wifi_hotspot_connector_->ConnectToWifiHotspot( 330 wifi_hotspot_connector_->ConnectToWifiHotspot(
290 std::string(kSsid), std::string(kPassword), 331 std::string(kSsid), std::string(kPassword),
291 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, 332 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback,
292 base::Unretained(this))); 333 base::Unretained(this)));
293 334
294 std::string wifi_guid = 335 std::string wifi_guid =
295 VerifyLastConfiguration(std::string(kSsid), std::string(kPassword)); 336 VerifyLastConfiguration(std::string(kSsid), std::string(kPassword));
296 EXPECT_FALSE(wifi_guid.empty()); 337 EXPECT_FALSE(wifi_guid.empty());
297 338
298 // Network becomes connectable. 339 // Network becomes connectable.
299 NotifyConnectable(test_network_connect_->last_service_path_created()); 340 NotifyConnectable(test_network_connect_->last_service_path_created());
341 VerifyTetherAndWifiNetworkAssociation(wifi_guid);
300 EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect()); 342 EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect());
301 EXPECT_EQ(0u, connection_callback_responses_.size()); 343 EXPECT_EQ(0u, connection_callback_responses_.size());
302 344
303 // Connection to network successful. 345 // Connection to network successful.
304 NotifyConnected(test_network_connect_->last_service_path_created()); 346 NotifyConnected(test_network_connect_->last_service_path_created());
305 EXPECT_EQ(1u, connection_callback_responses_.size()); 347 EXPECT_EQ(1u, connection_callback_responses_.size());
306 EXPECT_EQ(wifi_guid, connection_callback_responses_[0]); 348 EXPECT_EQ(wifi_guid, connection_callback_responses_[0]);
307 VerifyTimerStopped(); 349 VerifyTimerStopped();
308 } 350 }
309 351
310 TEST_F(WifiHotspotConnectorTest, TestConnect_Success_EmptyPassword) { 352 TEST_F(WifiHotspotConnectorTest, TestConnect_Success_EmptyPassword) {
311 wifi_hotspot_connector_->ConnectToWifiHotspot( 353 wifi_hotspot_connector_->ConnectToWifiHotspot(
312 std::string(kSsid), "", 354 std::string(kSsid), "",
313 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, 355 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback,
314 base::Unretained(this))); 356 base::Unretained(this)));
315 357
316 std::string wifi_guid = VerifyLastConfiguration(std::string(kSsid), ""); 358 std::string wifi_guid = VerifyLastConfiguration(std::string(kSsid), "");
317 EXPECT_FALSE(wifi_guid.empty()); 359 EXPECT_FALSE(wifi_guid.empty());
318 360
319 // Network becomes connectable. 361 // Network becomes connectable.
320 NotifyConnectable(test_network_connect_->last_service_path_created()); 362 NotifyConnectable(test_network_connect_->last_service_path_created());
363 VerifyTetherAndWifiNetworkAssociation(wifi_guid);
321 EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect()); 364 EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect());
322 EXPECT_EQ(0u, connection_callback_responses_.size()); 365 EXPECT_EQ(0u, connection_callback_responses_.size());
323 366
324 // Connection to network successful. 367 // Connection to network successful.
325 NotifyConnected(test_network_connect_->last_service_path_created()); 368 NotifyConnected(test_network_connect_->last_service_path_created());
326 EXPECT_EQ(1u, connection_callback_responses_.size()); 369 EXPECT_EQ(1u, connection_callback_responses_.size());
327 EXPECT_EQ(wifi_guid, connection_callback_responses_[0]); 370 EXPECT_EQ(wifi_guid, connection_callback_responses_[0]);
328 VerifyTimerStopped(); 371 VerifyTimerStopped();
329 } 372 }
330 373
(...skipping 24 matching lines...) Expand all
355 EXPECT_FALSE(service_path2.empty()); 398 EXPECT_FALSE(service_path2.empty());
356 399
357 EXPECT_NE(service_path1, service_path2); 400 EXPECT_NE(service_path1, service_path2);
358 401
359 // The original connection attempt should have gotten a "" response. 402 // The original connection attempt should have gotten a "" response.
360 EXPECT_EQ(1u, connection_callback_responses_.size()); 403 EXPECT_EQ(1u, connection_callback_responses_.size());
361 EXPECT_EQ("", connection_callback_responses_[0]); 404 EXPECT_EQ("", connection_callback_responses_[0]);
362 405
363 // First network becomes connectable. 406 // First network becomes connectable.
364 NotifyConnectable(service_path1); 407 NotifyConnectable(service_path1);
408 VerifyTetherAndWifiNetworkDisassociation(wifi_guid1);
365 409
366 // A connection should not have started to that GUID. 410 // A connection should not have started to that GUID.
367 EXPECT_EQ("", test_network_connect_->network_id_to_connect()); 411 EXPECT_EQ("", test_network_connect_->network_id_to_connect());
368 EXPECT_EQ(1u, connection_callback_responses_.size()); 412 EXPECT_EQ(1u, connection_callback_responses_.size());
369 413
370 // Second network becomes connectable. 414 // Second network becomes connectable.
371 NotifyConnectable(service_path2); 415 NotifyConnectable(service_path2);
416 VerifyTetherAndWifiNetworkAssociation(wifi_guid2);
372 EXPECT_EQ(wifi_guid2, test_network_connect_->network_id_to_connect()); 417 EXPECT_EQ(wifi_guid2, test_network_connect_->network_id_to_connect());
373 EXPECT_EQ(1u, connection_callback_responses_.size()); 418 EXPECT_EQ(1u, connection_callback_responses_.size());
374 419
375 // Connection to network successful. 420 // Connection to network successful.
376 NotifyConnected(service_path2); 421 NotifyConnected(service_path2);
377 EXPECT_EQ(2u, connection_callback_responses_.size()); 422 EXPECT_EQ(2u, connection_callback_responses_.size());
378 EXPECT_EQ(wifi_guid2, connection_callback_responses_[1]); 423 EXPECT_EQ(wifi_guid2, connection_callback_responses_[1]);
379 VerifyTimerStopped(); 424 VerifyTimerStopped();
380 } 425 }
381 426
382 } // namespace tether 427 } // namespace tether
383 428
384 } // namespace cryptauth 429 } // namespace cryptauth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698