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

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: khorimoto@ comments Created 3 years, 7 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 const char kTetherNetworkGuid[] = "tetherNetworkGuid";
42
39 std::string CreateConfigurationJsonString(const std::string& guid) { 43 std::string CreateConfigurationJsonString(const std::string& guid) {
40 std::stringstream ss; 44 std::stringstream ss;
41 ss << "{" 45 ss << "{"
42 << " \"GUID\": \"" << guid << "\"," 46 << " \"GUID\": \"" << guid << "\","
43 << " \"Type\": \"" << shill::kTypeWifi << "\"," 47 << " \"Type\": \"" << shill::kTypeWifi << "\","
44 << " \"State\": \"" << shill::kStateIdle << "\"" 48 << " \"State\": \"" << shill::kStateIdle << "\""
45 << "}"; 49 << "}";
46 return ss.str(); 50 return ss.str();
47 } 51 }
48 52
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 113
110 WifiHotspotConnectorTest() {} 114 WifiHotspotConnectorTest() {}
111 ~WifiHotspotConnectorTest() override {} 115 ~WifiHotspotConnectorTest() override {}
112 116
113 void SetUp() override { 117 void SetUp() override {
114 other_wifi_service_path_.clear(); 118 other_wifi_service_path_.clear();
115 connection_callback_responses_.clear(); 119 connection_callback_responses_.clear();
116 120
117 DBusThreadManager::Initialize(); 121 DBusThreadManager::Initialize();
118 NetworkStateTest::SetUp(); 122 NetworkStateTest::SetUp();
123 network_state_handler()->SetTetherTechnologyState(
124 NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED);
125
119 SetUpShillState(); 126 SetUpShillState();
120 127
121 test_network_connect_ = base::WrapUnique(new TestNetworkConnect(this)); 128 test_network_connect_ = base::WrapUnique(new TestNetworkConnect(this));
129 fake_active_host_ = base::MakeUnique<FakeActiveHost>();
130
131 network_state_handler()->AddTetherNetworkState(
132 kTetherNetworkGuid, "", /* name */
Kyle Horimoto 2017/04/27 01:28:08 Add the comment before the comma: "" /* name */,
lesliewatkins 2017/04/28 21:30:43 Done. I believe 'git cl format' is the culprit fo
133 "", /* carrier */
134 100, /* full battery */
135 100 /* full signal strength */);
136
137 fake_active_host_->SetActiveHostConnecting(kDeviceId, kTetherNetworkGuid);
122 138
123 wifi_hotspot_connector_ = base::WrapUnique(new WifiHotspotConnector( 139 wifi_hotspot_connector_ = base::WrapUnique(new WifiHotspotConnector(
124 network_state_handler(), test_network_connect_.get())); 140 network_state_handler(), test_network_connect_.get(),
141 fake_active_host_.get()));
125 142
126 mock_timer_ = new base::MockTimer(true /* retain_user_task */, 143 mock_timer_ = new base::MockTimer(true /* retain_user_task */,
127 false /* is_repeating */); 144 false /* is_repeating */);
128 wifi_hotspot_connector_->SetTimerForTest(base::WrapUnique(mock_timer_)); 145 wifi_hotspot_connector_->SetTimerForTest(base::WrapUnique(mock_timer_));
129 } 146 }
130 147
131 void SetUpShillState() { 148 void SetUpShillState() {
132 // Add a Wi-Fi service unrelated to the one under test. In some tests, a 149 // Add a Wi-Fi service unrelated to the one under test. In some tests, a
133 // connection from another device is tested. 150 // connection from another device is tested.
134 other_wifi_service_path_ = ConfigureService( 151 other_wifi_service_path_ = ConfigureService(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 last_configuration->GetString(shill::kPassphraseProperty, &password)); 211 last_configuration->GetString(shill::kPassphraseProperty, &password));
195 EXPECT_EQ(expected_password, password); 212 EXPECT_EQ(expected_password, password);
196 } 213 }
197 214
198 std::string wifi_guid; 215 std::string wifi_guid;
199 EXPECT_TRUE( 216 EXPECT_TRUE(
200 last_configuration->GetString(shill::kGuidProperty, &wifi_guid)); 217 last_configuration->GetString(shill::kGuidProperty, &wifi_guid));
201 return wifi_guid; 218 return wifi_guid;
202 } 219 }
203 220
221 void VerifyTetherAndWifiNetworkAssociation(const std::string& wifi_guid) {
222 const NetworkState* wifi_network_state =
223 network_state_handler()->GetNetworkStateFromGuid(wifi_guid);
224 ASSERT_TRUE(wifi_network_state);
225 EXPECT_EQ(fake_active_host_->GetTetherNetworkGuid(),
226 wifi_network_state->tether_guid());
227
228 const NetworkState* tether_network_state =
229 network_state_handler()->GetNetworkStateFromGuid(
230 fake_active_host_->GetTetherNetworkGuid());
Kyle Horimoto 2017/04/27 01:28:08 Note: To get the tether GUID once you change from
lesliewatkins 2017/04/28 21:30:43 I ended up added a second parameter to VerifyTethe
231 ASSERT_TRUE(tether_network_state);
232 EXPECT_EQ(wifi_guid, tether_network_state->tether_guid());
233 }
234
235 void VerifyTetherAndWifiNetworkNotAssociated(const std::string& wifi_guid) {
Kyle Horimoto 2017/04/27 01:28:08 You aren't verifying anything about a tether netwo
lesliewatkins 2017/04/28 21:30:43 Done.
236 const NetworkState* wifi_network_state =
237 network_state_handler()->GetNetworkStateFromGuid(wifi_guid);
238 ASSERT_TRUE(wifi_network_state);
239 EXPECT_TRUE(wifi_network_state->tether_guid().empty());
240 }
241
204 void WifiConnectionCallback(const std::string& wifi_guid) { 242 void WifiConnectionCallback(const std::string& wifi_guid) {
205 connection_callback_responses_.push_back(wifi_guid); 243 connection_callback_responses_.push_back(wifi_guid);
206 } 244 }
207 245
208 base::test::ScopedTaskEnvironment scoped_task_environment_; 246 base::test::ScopedTaskEnvironment scoped_task_environment_;
209 247
210 std::string other_wifi_service_path_; 248 std::string other_wifi_service_path_;
211 std::vector<std::string> connection_callback_responses_; 249 std::vector<std::string> connection_callback_responses_;
212 250
213 base::MockTimer* mock_timer_; 251 base::MockTimer* mock_timer_;
214 std::unique_ptr<TestNetworkConnect> test_network_connect_; 252 std::unique_ptr<TestNetworkConnect> test_network_connect_;
215 253
216 std::unique_ptr<WifiHotspotConnector> wifi_hotspot_connector_; 254 std::unique_ptr<WifiHotspotConnector> wifi_hotspot_connector_;
255 std::unique_ptr<FakeActiveHost> fake_active_host_;
217 256
218 private: 257 private:
219 DISALLOW_COPY_AND_ASSIGN(WifiHotspotConnectorTest); 258 DISALLOW_COPY_AND_ASSIGN(WifiHotspotConnectorTest);
220 }; 259 };
221 260
222 TEST_F(WifiHotspotConnectorTest, TestConnect_NetworkDoesNotBecomeConnectable) { 261 TEST_F(WifiHotspotConnectorTest, TestConnect_NetworkDoesNotBecomeConnectable) {
223 wifi_hotspot_connector_->ConnectToWifiHotspot( 262 wifi_hotspot_connector_->ConnectToWifiHotspot(
224 std::string(kSsid), std::string(kPassword), 263 std::string(kSsid), std::string(kPassword),
225 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, 264 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback,
226 base::Unretained(this))); 265 base::Unretained(this)));
(...skipping 18 matching lines...) Expand all
245 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, 284 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback,
246 base::Unretained(this))); 285 base::Unretained(this)));
247 286
248 std::string wifi_guid = 287 std::string wifi_guid =
249 VerifyLastConfiguration(std::string(kSsid), std::string(kPassword)); 288 VerifyLastConfiguration(std::string(kSsid), std::string(kPassword));
250 EXPECT_FALSE(wifi_guid.empty()); 289 EXPECT_FALSE(wifi_guid.empty());
251 290
252 // Another network becomes connectable. This should not cause the connection 291 // Another network becomes connectable. This should not cause the connection
253 // to start. 292 // to start.
254 NotifyConnectable(other_wifi_service_path_); 293 NotifyConnectable(other_wifi_service_path_);
294 VerifyTetherAndWifiNetworkNotAssociated(wifi_guid);
Kyle Horimoto 2017/04/27 01:28:08 Also verify that the network associated with other
lesliewatkins 2017/04/28 21:30:43 Done.
255 EXPECT_EQ("", test_network_connect_->network_id_to_connect()); 295 EXPECT_EQ("", test_network_connect_->network_id_to_connect());
256 296
257 // Timeout timer fires. 297 // Timeout timer fires.
258 EXPECT_EQ(0u, connection_callback_responses_.size()); 298 EXPECT_EQ(0u, connection_callback_responses_.size());
259 InvokeTimerTask(); 299 InvokeTimerTask();
260 EXPECT_EQ(1u, connection_callback_responses_.size()); 300 EXPECT_EQ(1u, connection_callback_responses_.size());
261 EXPECT_EQ("", connection_callback_responses_[0]); 301 EXPECT_EQ("", connection_callback_responses_[0]);
262 } 302 }
263 303
264 TEST_F(WifiHotspotConnectorTest, TestConnect_CannotConnectToNetwork) { 304 TEST_F(WifiHotspotConnectorTest, TestConnect_CannotConnectToNetwork) {
265 wifi_hotspot_connector_->ConnectToWifiHotspot( 305 wifi_hotspot_connector_->ConnectToWifiHotspot(
266 std::string(kSsid), std::string(kPassword), 306 std::string(kSsid), std::string(kPassword),
267 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, 307 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback,
268 base::Unretained(this))); 308 base::Unretained(this)));
269 309
270 std::string wifi_guid = 310 std::string wifi_guid =
271 VerifyLastConfiguration(std::string(kSsid), std::string(kPassword)); 311 VerifyLastConfiguration(std::string(kSsid), std::string(kPassword));
272 EXPECT_FALSE(wifi_guid.empty()); 312 EXPECT_FALSE(wifi_guid.empty());
273 313
274 // Network becomes connectable. 314 // Network becomes connectable.
275 NotifyConnectable(test_network_connect_->last_service_path_created()); 315 NotifyConnectable(test_network_connect_->last_service_path_created());
316 VerifyTetherAndWifiNetworkAssociation(wifi_guid);
276 EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect()); 317 EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect());
277 318
278 // Network connection does not occur. 319 // Network connection does not occur.
279 EXPECT_EQ(0u, connection_callback_responses_.size()); 320 EXPECT_EQ(0u, connection_callback_responses_.size());
280 321
281 // Timeout timer fires. 322 // Timeout timer fires.
282 InvokeTimerTask(); 323 InvokeTimerTask();
283 EXPECT_EQ(1u, connection_callback_responses_.size()); 324 EXPECT_EQ(1u, connection_callback_responses_.size());
284 EXPECT_EQ("", connection_callback_responses_[0]); 325 EXPECT_EQ("", connection_callback_responses_[0]);
285 } 326 }
286 327
287 TEST_F(WifiHotspotConnectorTest, TestConnect_Success) { 328 TEST_F(WifiHotspotConnectorTest, TestConnect_Success) {
288 wifi_hotspot_connector_->ConnectToWifiHotspot( 329 wifi_hotspot_connector_->ConnectToWifiHotspot(
289 std::string(kSsid), std::string(kPassword), 330 std::string(kSsid), std::string(kPassword),
290 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, 331 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback,
291 base::Unretained(this))); 332 base::Unretained(this)));
292 333
293 std::string wifi_guid = 334 std::string wifi_guid =
294 VerifyLastConfiguration(std::string(kSsid), std::string(kPassword)); 335 VerifyLastConfiguration(std::string(kSsid), std::string(kPassword));
295 EXPECT_FALSE(wifi_guid.empty()); 336 EXPECT_FALSE(wifi_guid.empty());
296 337
297 // Network becomes connectable. 338 // Network becomes connectable.
298 NotifyConnectable(test_network_connect_->last_service_path_created()); 339 NotifyConnectable(test_network_connect_->last_service_path_created());
340 VerifyTetherAndWifiNetworkAssociation(wifi_guid);
299 EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect()); 341 EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect());
300 EXPECT_EQ(0u, connection_callback_responses_.size()); 342 EXPECT_EQ(0u, connection_callback_responses_.size());
301 343
302 // Connection to network successful. 344 // Connection to network successful.
303 NotifyConnected(test_network_connect_->last_service_path_created()); 345 NotifyConnected(test_network_connect_->last_service_path_created());
304 EXPECT_EQ(1u, connection_callback_responses_.size()); 346 EXPECT_EQ(1u, connection_callback_responses_.size());
305 EXPECT_EQ(wifi_guid, connection_callback_responses_[0]); 347 EXPECT_EQ(wifi_guid, connection_callback_responses_[0]);
306 VerifyTimerStopped(); 348 VerifyTimerStopped();
307 } 349 }
308 350
309 TEST_F(WifiHotspotConnectorTest, TestConnect_Success_EmptyPassword) { 351 TEST_F(WifiHotspotConnectorTest, TestConnect_Success_EmptyPassword) {
310 wifi_hotspot_connector_->ConnectToWifiHotspot( 352 wifi_hotspot_connector_->ConnectToWifiHotspot(
311 std::string(kSsid), "", 353 std::string(kSsid), "",
312 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback, 354 base::Bind(&WifiHotspotConnectorTest::WifiConnectionCallback,
313 base::Unretained(this))); 355 base::Unretained(this)));
314 356
315 std::string wifi_guid = VerifyLastConfiguration(std::string(kSsid), ""); 357 std::string wifi_guid = VerifyLastConfiguration(std::string(kSsid), "");
316 EXPECT_FALSE(wifi_guid.empty()); 358 EXPECT_FALSE(wifi_guid.empty());
317 359
318 // Network becomes connectable. 360 // Network becomes connectable.
319 NotifyConnectable(test_network_connect_->last_service_path_created()); 361 NotifyConnectable(test_network_connect_->last_service_path_created());
362 VerifyTetherAndWifiNetworkAssociation(wifi_guid);
320 EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect()); 363 EXPECT_EQ(wifi_guid, test_network_connect_->network_id_to_connect());
321 EXPECT_EQ(0u, connection_callback_responses_.size()); 364 EXPECT_EQ(0u, connection_callback_responses_.size());
322 365
323 // Connection to network successful. 366 // Connection to network successful.
324 NotifyConnected(test_network_connect_->last_service_path_created()); 367 NotifyConnected(test_network_connect_->last_service_path_created());
325 EXPECT_EQ(1u, connection_callback_responses_.size()); 368 EXPECT_EQ(1u, connection_callback_responses_.size());
326 EXPECT_EQ(wifi_guid, connection_callback_responses_[0]); 369 EXPECT_EQ(wifi_guid, connection_callback_responses_[0]);
327 VerifyTimerStopped(); 370 VerifyTimerStopped();
328 } 371 }
329 372
(...skipping 24 matching lines...) Expand all
354 EXPECT_FALSE(service_path2.empty()); 397 EXPECT_FALSE(service_path2.empty());
355 398
356 EXPECT_NE(service_path1, service_path2); 399 EXPECT_NE(service_path1, service_path2);
357 400
358 // The original connection attempt should have gotten a "" response. 401 // The original connection attempt should have gotten a "" response.
359 EXPECT_EQ(1u, connection_callback_responses_.size()); 402 EXPECT_EQ(1u, connection_callback_responses_.size());
360 EXPECT_EQ("", connection_callback_responses_[0]); 403 EXPECT_EQ("", connection_callback_responses_[0]);
361 404
362 // First network becomes connectable. 405 // First network becomes connectable.
363 NotifyConnectable(service_path1); 406 NotifyConnectable(service_path1);
407 VerifyTetherAndWifiNetworkNotAssociated(wifi_guid1);
364 408
365 // A connection should not have started to that GUID. 409 // A connection should not have started to that GUID.
366 EXPECT_EQ("", test_network_connect_->network_id_to_connect()); 410 EXPECT_EQ("", test_network_connect_->network_id_to_connect());
367 EXPECT_EQ(1u, connection_callback_responses_.size()); 411 EXPECT_EQ(1u, connection_callback_responses_.size());
368 412
369 // Second network becomes connectable. 413 // Second network becomes connectable.
370 NotifyConnectable(service_path2); 414 NotifyConnectable(service_path2);
415 VerifyTetherAndWifiNetworkAssociation(wifi_guid2);
371 EXPECT_EQ(wifi_guid2, test_network_connect_->network_id_to_connect()); 416 EXPECT_EQ(wifi_guid2, test_network_connect_->network_id_to_connect());
372 EXPECT_EQ(1u, connection_callback_responses_.size()); 417 EXPECT_EQ(1u, connection_callback_responses_.size());
373 418
374 // Connection to network successful. 419 // Connection to network successful.
375 NotifyConnected(service_path2); 420 NotifyConnected(service_path2);
376 EXPECT_EQ(2u, connection_callback_responses_.size()); 421 EXPECT_EQ(2u, connection_callback_responses_.size());
377 EXPECT_EQ(wifi_guid2, connection_callback_responses_[1]); 422 EXPECT_EQ(wifi_guid2, connection_callback_responses_[1]);
378 VerifyTimerStopped(); 423 VerifyTimerStopped();
379 } 424 }
380 425
Kyle Horimoto 2017/04/27 01:28:08 Please add one additional test which tests this si
lesliewatkins 2017/04/28 21:30:43 Done.
381 } // namespace tether 426 } // namespace tether
382 427
383 } // namespace chromeos 428 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698