OLD | NEW |
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 "chrome/browser/chromeos/tether/tether_service.h" | 5 #include "chrome/browser/chromeos/tether/tether_service.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 166 } |
167 | 167 |
168 void SetTetherTechnologyStateEnabled(bool enabled) { | 168 void SetTetherTechnologyStateEnabled(bool enabled) { |
169 network_state_handler()->SetTetherTechnologyState( | 169 network_state_handler()->SetTetherTechnologyState( |
170 enabled | 170 enabled |
171 ? chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED | 171 ? chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED |
172 : chromeos::NetworkStateHandler::TechnologyState:: | 172 : chromeos::NetworkStateHandler::TechnologyState:: |
173 TECHNOLOGY_AVAILABLE); | 173 TECHNOLOGY_AVAILABLE); |
174 } | 174 } |
175 | 175 |
| 176 void SetCellularTechnologyStateEnabled(bool enabled) { |
| 177 network_state_handler()->SetTechnologyEnabled( |
| 178 chromeos::NetworkTypePattern::Cellular(), enabled, |
| 179 chromeos::network_handler::ErrorCallback()); |
| 180 base::RunLoop().RunUntilIdle(); |
| 181 } |
| 182 |
176 content::TestBrowserThreadBundle thread_bundle_; | 183 content::TestBrowserThreadBundle thread_bundle_; |
177 | 184 |
178 std::unique_ptr<TestingProfile> profile_; | 185 std::unique_ptr<TestingProfile> profile_; |
179 std::unique_ptr<chromeos::FakePowerManagerClient> fake_power_manager_client_; | 186 std::unique_ptr<chromeos::FakePowerManagerClient> fake_power_manager_client_; |
180 std::unique_ptr<ExtendedFakeSessionManagerClient> | 187 std::unique_ptr<ExtendedFakeSessionManagerClient> |
181 fake_session_manager_client_; | 188 fake_session_manager_client_; |
182 std::unique_ptr<TestingPrefServiceSimple> test_pref_service_; | 189 std::unique_ptr<TestingPrefServiceSimple> test_pref_service_; |
183 std::unique_ptr<NiceMock<MockCryptAuthDeviceManager>> | 190 std::unique_ptr<NiceMock<MockCryptAuthDeviceManager>> |
184 mock_cryptauth_device_manager_; | 191 mock_cryptauth_device_manager_; |
185 std::unique_ptr<cryptauth::FakeCryptAuthService> fake_cryptauth_service_; | 192 std::unique_ptr<cryptauth::FakeCryptAuthService> fake_cryptauth_service_; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 ON_CALL(*mock_adapter_, IsPowered()).WillByDefault(Return(false)); | 283 ON_CALL(*mock_adapter_, IsPowered()).WillByDefault(Return(false)); |
277 | 284 |
278 CreateTetherService(); | 285 CreateTetherService(); |
279 | 286 |
280 EXPECT_EQ( | 287 EXPECT_EQ( |
281 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_UNINITIALIZED, | 288 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_UNINITIALIZED, |
282 network_state_handler()->GetTechnologyState( | 289 network_state_handler()->GetTechnologyState( |
283 chromeos::NetworkTypePattern::Tether())); | 290 chromeos::NetworkTypePattern::Tether())); |
284 } | 291 } |
285 | 292 |
| 293 TEST_F(TetherServiceTest, TestCellularIsUnavailable) { |
| 294 test_manager_client()->RemoveTechnology(shill::kTypeCellular); |
| 295 ASSERT_EQ( |
| 296 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_UNAVAILABLE, |
| 297 network_state_handler()->GetTechnologyState( |
| 298 chromeos::NetworkTypePattern::Cellular())); |
| 299 |
| 300 CreateTetherService(); |
| 301 |
| 302 SetTetherTechnologyStateEnabled(false); |
| 303 EXPECT_EQ( |
| 304 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_AVAILABLE, |
| 305 network_state_handler()->GetTechnologyState( |
| 306 chromeos::NetworkTypePattern::Tether())); |
| 307 |
| 308 SetTetherTechnologyStateEnabled(true); |
| 309 EXPECT_EQ(chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED, |
| 310 network_state_handler()->GetTechnologyState( |
| 311 chromeos::NetworkTypePattern::Tether())); |
| 312 } |
| 313 |
| 314 TEST_F(TetherServiceTest, TestCellularIsAvailable) { |
| 315 // TODO (lesliewatkins): Investigate why cellular needs to be removed and |
| 316 // re-added for NetworkStateHandler to return the correct TechnologyState. |
| 317 test_manager_client()->RemoveTechnology(shill::kTypeCellular); |
| 318 test_manager_client()->AddTechnology(shill::kTypeCellular, false); |
| 319 |
| 320 CreateTetherService(); |
| 321 |
| 322 // Cellular disabled |
| 323 SetCellularTechnologyStateEnabled(false); |
| 324 ASSERT_EQ( |
| 325 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_AVAILABLE, |
| 326 network_state_handler()->GetTechnologyState( |
| 327 chromeos::NetworkTypePattern::Cellular())); |
| 328 |
| 329 SetTetherTechnologyStateEnabled(false); |
| 330 EXPECT_EQ( |
| 331 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_UNINITIALIZED, |
| 332 network_state_handler()->GetTechnologyState( |
| 333 chromeos::NetworkTypePattern::Tether())); |
| 334 |
| 335 SetTetherTechnologyStateEnabled(true); |
| 336 EXPECT_EQ( |
| 337 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_UNINITIALIZED, |
| 338 network_state_handler()->GetTechnologyState( |
| 339 chromeos::NetworkTypePattern::Tether())); |
| 340 |
| 341 // Cellular enabled |
| 342 SetCellularTechnologyStateEnabled(true); |
| 343 ASSERT_EQ(chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED, |
| 344 network_state_handler()->GetTechnologyState( |
| 345 chromeos::NetworkTypePattern::Cellular())); |
| 346 |
| 347 SetTetherTechnologyStateEnabled(false); |
| 348 EXPECT_EQ( |
| 349 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_AVAILABLE, |
| 350 network_state_handler()->GetTechnologyState( |
| 351 chromeos::NetworkTypePattern::Tether())); |
| 352 |
| 353 SetTetherTechnologyStateEnabled(true); |
| 354 EXPECT_EQ(chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED, |
| 355 network_state_handler()->GetTechnologyState( |
| 356 chromeos::NetworkTypePattern::Tether())); |
| 357 } |
| 358 |
286 TEST_F(TetherServiceTest, TestEnabled) { | 359 TEST_F(TetherServiceTest, TestEnabled) { |
287 CreateTetherService(); | 360 CreateTetherService(); |
288 | 361 |
289 EXPECT_EQ(chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED, | 362 EXPECT_EQ(chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED, |
290 network_state_handler()->GetTechnologyState( | 363 network_state_handler()->GetTechnologyState( |
291 chromeos::NetworkTypePattern::Tether())); | 364 chromeos::NetworkTypePattern::Tether())); |
292 | 365 |
293 SetTetherTechnologyStateEnabled(false); | 366 SetTetherTechnologyStateEnabled(false); |
294 EXPECT_EQ( | 367 EXPECT_EQ( |
295 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_AVAILABLE, | 368 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_AVAILABLE, |
296 network_state_handler()->GetTechnologyState( | 369 network_state_handler()->GetTechnologyState( |
297 chromeos::NetworkTypePattern::Tether())); | 370 chromeos::NetworkTypePattern::Tether())); |
298 EXPECT_FALSE( | 371 EXPECT_FALSE( |
299 profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringEnabled)); | 372 profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringEnabled)); |
300 | 373 |
301 SetTetherTechnologyStateEnabled(true); | 374 SetTetherTechnologyStateEnabled(true); |
302 EXPECT_EQ(chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED, | 375 EXPECT_EQ(chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED, |
303 network_state_handler()->GetTechnologyState( | 376 network_state_handler()->GetTechnologyState( |
304 chromeos::NetworkTypePattern::Tether())); | 377 chromeos::NetworkTypePattern::Tether())); |
305 EXPECT_TRUE( | 378 EXPECT_TRUE( |
306 profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringEnabled)); | 379 profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringEnabled)); |
307 } | 380 } |
308 | 381 |
309 // Test against a past defect that made TetherService and NetworkStateHandler | 382 // Test against a past defect that made TetherService and NetworkStateHandler |
310 // repeatly update technology state after the other did so. TetherService should | 383 // repeatly update technology state after the other did so. TetherService should |
311 // only update technology state if NetworkStateHandler has provided a different | 384 // only update technology state if NetworkStateHandler has provided a different |
312 // state than the user preference. | 385 // state than the user preference. |
313 TEST_F(TetherServiceTest, TestEnabledMultipleChanges) { | 386 TEST_F(TetherServiceTest, TestEnabledMultipleChanges) { |
314 CreateTetherService(); | 387 CreateTetherService(); |
315 // CreateTetherService calls RunUntilIdle() so OnBluetoothAdapterFetched() | 388 // CreateTetherService calls RunUntilIdle() so UpdateTetherTechnologyState() |
316 // will have been called which calls UpdateTetherTechnologyState(). | 389 // may be called multiple times in the initialization process. |
317 EXPECT_EQ(1, tether_service_->updated_technology_state_count()); | 390 int updated_technology_state_count = |
| 391 tether_service_->updated_technology_state_count(); |
318 | 392 |
319 SetTetherTechnologyStateEnabled(false); | 393 SetTetherTechnologyStateEnabled(false); |
320 SetTetherTechnologyStateEnabled(false); | 394 SetTetherTechnologyStateEnabled(false); |
321 SetTetherTechnologyStateEnabled(false); | 395 SetTetherTechnologyStateEnabled(false); |
322 | 396 |
323 EXPECT_EQ(2, tether_service_->updated_technology_state_count()); | 397 updated_technology_state_count++; |
| 398 EXPECT_EQ(updated_technology_state_count, |
| 399 tether_service_->updated_technology_state_count()); |
324 | 400 |
325 SetTetherTechnologyStateEnabled(true); | 401 SetTetherTechnologyStateEnabled(true); |
326 SetTetherTechnologyStateEnabled(true); | 402 SetTetherTechnologyStateEnabled(true); |
327 SetTetherTechnologyStateEnabled(true); | 403 SetTetherTechnologyStateEnabled(true); |
328 | 404 |
329 EXPECT_EQ(3, tether_service_->updated_technology_state_count()); | 405 updated_technology_state_count++; |
| 406 EXPECT_EQ(updated_technology_state_count, |
| 407 tether_service_->updated_technology_state_count()); |
330 } | 408 } |
OLD | NEW |