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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 164 } |
165 | 165 |
166 void SetTetherTechnologyStateEnabled(bool enabled) { | 166 void SetTetherTechnologyStateEnabled(bool enabled) { |
167 network_state_handler()->SetTetherTechnologyState( | 167 network_state_handler()->SetTetherTechnologyState( |
168 enabled | 168 enabled |
169 ? chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED | 169 ? chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED |
170 : chromeos::NetworkStateHandler::TechnologyState:: | 170 : chromeos::NetworkStateHandler::TechnologyState:: |
171 TECHNOLOGY_AVAILABLE); | 171 TECHNOLOGY_AVAILABLE); |
172 } | 172 } |
173 | 173 |
| 174 void SetCellularTechnologyStateEnabled(bool enabled) { |
| 175 network_state_handler()->SetTechnologyEnabled( |
| 176 chromeos::NetworkTypePattern::Cellular(), enabled, |
| 177 chromeos::network_handler::ErrorCallback()); |
| 178 base::RunLoop().RunUntilIdle(); |
| 179 } |
| 180 |
174 content::TestBrowserThreadBundle thread_bundle_; | 181 content::TestBrowserThreadBundle thread_bundle_; |
175 | 182 |
176 std::unique_ptr<TestingProfile> profile_; | 183 std::unique_ptr<TestingProfile> profile_; |
177 std::unique_ptr<chromeos::FakePowerManagerClient> fake_power_manager_client_; | 184 std::unique_ptr<chromeos::FakePowerManagerClient> fake_power_manager_client_; |
178 std::unique_ptr<ExtendedFakeSessionManagerClient> | 185 std::unique_ptr<ExtendedFakeSessionManagerClient> |
179 fake_session_manager_client_; | 186 fake_session_manager_client_; |
180 std::unique_ptr<TestingPrefServiceSimple> test_pref_service_; | 187 std::unique_ptr<TestingPrefServiceSimple> test_pref_service_; |
181 std::unique_ptr<NiceMock<MockCryptAuthDeviceManager>> | 188 std::unique_ptr<NiceMock<MockCryptAuthDeviceManager>> |
182 mock_cryptauth_device_manager_; | 189 mock_cryptauth_device_manager_; |
183 std::unique_ptr<cryptauth::FakeCryptAuthService> fake_cryptauth_service_; | 190 std::unique_ptr<cryptauth::FakeCryptAuthService> fake_cryptauth_service_; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 ON_CALL(*mock_adapter_, IsPowered()).WillByDefault(Return(false)); | 281 ON_CALL(*mock_adapter_, IsPowered()).WillByDefault(Return(false)); |
275 | 282 |
276 CreateTetherService(); | 283 CreateTetherService(); |
277 | 284 |
278 EXPECT_EQ( | 285 EXPECT_EQ( |
279 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_UNINITIALIZED, | 286 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_UNINITIALIZED, |
280 network_state_handler()->GetTechnologyState( | 287 network_state_handler()->GetTechnologyState( |
281 chromeos::NetworkTypePattern::Tether())); | 288 chromeos::NetworkTypePattern::Tether())); |
282 } | 289 } |
283 | 290 |
| 291 TEST_F(TetherServiceTest, TestCellularIsUnavailable) { |
| 292 test_manager_client()->RemoveTechnology(shill::kTypeCellular); |
| 293 ASSERT_EQ( |
| 294 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_UNAVAILABLE, |
| 295 network_state_handler()->GetTechnologyState( |
| 296 chromeos::NetworkTypePattern::Cellular())); |
| 297 |
| 298 CreateTetherService(); |
| 299 |
| 300 SetTetherTechnologyStateEnabled(false); |
| 301 EXPECT_EQ( |
| 302 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_AVAILABLE, |
| 303 network_state_handler()->GetTechnologyState( |
| 304 chromeos::NetworkTypePattern::Tether())); |
| 305 |
| 306 SetTetherTechnologyStateEnabled(true); |
| 307 EXPECT_EQ(chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED, |
| 308 network_state_handler()->GetTechnologyState( |
| 309 chromeos::NetworkTypePattern::Tether())); |
| 310 } |
| 311 |
| 312 TEST_F(TetherServiceTest, TestCellularIsAvailable) { |
| 313 // TODO (lesliewatkins): Investigate why cellular needs to be removed and |
| 314 // re-added for NetworkStateHandler to return the correct TechnologyState. |
| 315 test_manager_client()->RemoveTechnology(shill::kTypeCellular); |
| 316 test_manager_client()->AddTechnology(shill::kTypeCellular, false); |
| 317 |
| 318 CreateTetherService(); |
| 319 |
| 320 // Cellular disabled |
| 321 SetCellularTechnologyStateEnabled(false); |
| 322 ASSERT_EQ( |
| 323 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_AVAILABLE, |
| 324 network_state_handler()->GetTechnologyState( |
| 325 chromeos::NetworkTypePattern::Cellular())); |
| 326 |
| 327 SetTetherTechnologyStateEnabled(false); |
| 328 EXPECT_EQ( |
| 329 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_UNINITIALIZED, |
| 330 network_state_handler()->GetTechnologyState( |
| 331 chromeos::NetworkTypePattern::Tether())); |
| 332 |
| 333 SetTetherTechnologyStateEnabled(true); |
| 334 EXPECT_EQ( |
| 335 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_UNINITIALIZED, |
| 336 network_state_handler()->GetTechnologyState( |
| 337 chromeos::NetworkTypePattern::Tether())); |
| 338 |
| 339 // Cellular enabled |
| 340 SetCellularTechnologyStateEnabled(true); |
| 341 ASSERT_EQ(chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED, |
| 342 network_state_handler()->GetTechnologyState( |
| 343 chromeos::NetworkTypePattern::Cellular())); |
| 344 |
| 345 SetTetherTechnologyStateEnabled(false); |
| 346 EXPECT_EQ( |
| 347 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_AVAILABLE, |
| 348 network_state_handler()->GetTechnologyState( |
| 349 chromeos::NetworkTypePattern::Tether())); |
| 350 |
| 351 SetTetherTechnologyStateEnabled(true); |
| 352 EXPECT_EQ(chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED, |
| 353 network_state_handler()->GetTechnologyState( |
| 354 chromeos::NetworkTypePattern::Tether())); |
| 355 } |
| 356 |
284 TEST_F(TetherServiceTest, TestEnabled) { | 357 TEST_F(TetherServiceTest, TestEnabled) { |
285 CreateTetherService(); | 358 CreateTetherService(); |
286 | 359 |
287 EXPECT_EQ(chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED, | 360 EXPECT_EQ(chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED, |
288 network_state_handler()->GetTechnologyState( | 361 network_state_handler()->GetTechnologyState( |
289 chromeos::NetworkTypePattern::Tether())); | 362 chromeos::NetworkTypePattern::Tether())); |
290 | 363 |
291 SetTetherTechnologyStateEnabled(false); | 364 SetTetherTechnologyStateEnabled(false); |
292 EXPECT_EQ( | 365 EXPECT_EQ( |
293 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_AVAILABLE, | 366 chromeos::NetworkStateHandler::TechnologyState::TECHNOLOGY_AVAILABLE, |
(...skipping 25 matching lines...) Expand all Loading... |
319 SetTetherTechnologyStateEnabled(false); | 392 SetTetherTechnologyStateEnabled(false); |
320 | 393 |
321 EXPECT_EQ(2, tether_service_->updated_technology_state_count()); | 394 EXPECT_EQ(2, tether_service_->updated_technology_state_count()); |
322 | 395 |
323 SetTetherTechnologyStateEnabled(true); | 396 SetTetherTechnologyStateEnabled(true); |
324 SetTetherTechnologyStateEnabled(true); | 397 SetTetherTechnologyStateEnabled(true); |
325 SetTetherTechnologyStateEnabled(true); | 398 SetTetherTechnologyStateEnabled(true); |
326 | 399 |
327 EXPECT_EQ(3, tether_service_->updated_technology_state_count()); | 400 EXPECT_EQ(3, tether_service_->updated_technology_state_count()); |
328 } | 401 } |
OLD | NEW |