| 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" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" |
| 12 #include "base/test/scoped_task_environment.h" | 13 #include "base/test/scoped_task_environment.h" |
| 13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
| 15 #include "chromeos/chromeos_switches.h" | 16 #include "chromeos/chromeos_switches.h" |
| 16 #include "chromeos/dbus/dbus_thread_manager.h" | 17 #include "chromeos/dbus/dbus_thread_manager.h" |
| 17 #include "chromeos/dbus/fake_power_manager_client.h" | 18 #include "chromeos/dbus/fake_power_manager_client.h" |
| 18 #include "chromeos/dbus/fake_session_manager_client.h" | 19 #include "chromeos/dbus/fake_session_manager_client.h" |
| 19 #include "chromeos/dbus/power_manager_client.h" | 20 #include "chromeos/dbus/power_manager_client.h" |
| 20 #include "chromeos/dbus/session_manager_client.h" | 21 #include "chromeos/dbus/session_manager_client.h" |
| 21 #include "chromeos/network/network_connect.h" | 22 #include "chromeos/network/network_connect.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 ShutdownNetworkState(); | 140 ShutdownNetworkState(); |
| 140 chromeos::NetworkStateTest::TearDown(); | 141 chromeos::NetworkStateTest::TearDown(); |
| 141 chromeos::DBusThreadManager::Shutdown(); | 142 chromeos::DBusThreadManager::Shutdown(); |
| 142 } | 143 } |
| 143 | 144 |
| 144 void CreateTetherService() { | 145 void CreateTetherService() { |
| 145 tether_service_ = base::WrapUnique(new TestTetherService( | 146 tether_service_ = base::WrapUnique(new TestTetherService( |
| 146 profile_.get(), fake_power_manager_client_.get(), | 147 profile_.get(), fake_power_manager_client_.get(), |
| 147 fake_session_manager_client_.get(), fake_cryptauth_service_.get(), | 148 fake_session_manager_client_.get(), fake_cryptauth_service_.get(), |
| 148 network_state_handler())); | 149 network_state_handler())); |
| 150 base::RunLoop().RunUntilIdle(); |
| 149 } | 151 } |
| 150 | 152 |
| 151 void ShutdownTetherService() { | 153 void ShutdownTetherService() { |
| 152 if (tether_service_) | 154 if (tether_service_) |
| 153 tether_service_->Shutdown(); | 155 tether_service_->Shutdown(); |
| 154 } | 156 } |
| 155 | 157 |
| 156 void SetIsScreenLocked(bool is_screen_locked) { | 158 void SetIsScreenLocked(bool is_screen_locked) { |
| 157 fake_session_manager_client_->set_is_screen_locked(is_screen_locked); | 159 fake_session_manager_client_->set_is_screen_locked(is_screen_locked); |
| 158 if (is_screen_locked) | 160 if (is_screen_locked) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 | 235 |
| 234 TEST_F(TetherServiceTest, TestFeatureFlagDisabled) { | 236 TEST_F(TetherServiceTest, TestFeatureFlagDisabled) { |
| 235 EXPECT_FALSE(TetherService::Get(profile_.get())); | 237 EXPECT_FALSE(TetherService::Get(profile_.get())); |
| 236 } | 238 } |
| 237 | 239 |
| 238 TEST_F(TetherServiceTest, TestFeatureFlagEnabled) { | 240 TEST_F(TetherServiceTest, TestFeatureFlagEnabled) { |
| 239 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 241 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 240 chromeos::switches::kEnableTether); | 242 chromeos::switches::kEnableTether); |
| 241 | 243 |
| 242 TetherService* tether_service = TetherService::Get(profile_.get()); | 244 TetherService* tether_service = TetherService::Get(profile_.get()); |
| 243 EXPECT_TRUE(tether_service); | 245 ASSERT_TRUE(tether_service); |
| 246 base::RunLoop().RunUntilIdle(); |
| 244 tether_service->Shutdown(); | 247 tether_service->Shutdown(); |
| 245 } | 248 } |
| 246 | 249 |
| 247 TEST_F(TetherServiceTest, TestNoTetherHosts) { | 250 TEST_F(TetherServiceTest, TestNoTetherHosts) { |
| 248 ON_CALL(*mock_cryptauth_device_manager_, GetTetherHosts()) | 251 ON_CALL(*mock_cryptauth_device_manager_, GetTetherHosts()) |
| 249 .WillByDefault(Return(std::vector<cryptauth::ExternalDeviceInfo>())); | 252 .WillByDefault(Return(std::vector<cryptauth::ExternalDeviceInfo>())); |
| 250 | 253 |
| 251 CreateTetherService(); | 254 CreateTetherService(); |
| 252 | 255 |
| 253 EXPECT_EQ( | 256 EXPECT_EQ( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 EXPECT_TRUE( | 303 EXPECT_TRUE( |
| 301 profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringEnabled)); | 304 profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringEnabled)); |
| 302 } | 305 } |
| 303 | 306 |
| 304 // Test against a past defect that made TetherService and NetworkStateHandler | 307 // Test against a past defect that made TetherService and NetworkStateHandler |
| 305 // repeatly update technology state after the other did so. TetherService should | 308 // repeatly update technology state after the other did so. TetherService should |
| 306 // only update technology state if NetworkStateHandler has provided a different | 309 // only update technology state if NetworkStateHandler has provided a different |
| 307 // state than the user preference. | 310 // state than the user preference. |
| 308 TEST_F(TetherServiceTest, TestEnabledMultipleChanges) { | 311 TEST_F(TetherServiceTest, TestEnabledMultipleChanges) { |
| 309 CreateTetherService(); | 312 CreateTetherService(); |
| 310 | 313 // CreateTetherService calls RunUntilIdle() so OnBluetoothAdapterFetched() |
| 311 EXPECT_EQ(0, tether_service_->updated_technology_state_count()); | 314 // will have been called which calls UpdateTetherTechnologyState(). |
| 315 EXPECT_EQ(1, tether_service_->updated_technology_state_count()); |
| 312 | 316 |
| 313 SetTetherTechnologyStateEnabled(false); | 317 SetTetherTechnologyStateEnabled(false); |
| 314 SetTetherTechnologyStateEnabled(false); | 318 SetTetherTechnologyStateEnabled(false); |
| 315 SetTetherTechnologyStateEnabled(false); | 319 SetTetherTechnologyStateEnabled(false); |
| 316 | 320 |
| 317 EXPECT_EQ(1, tether_service_->updated_technology_state_count()); | 321 EXPECT_EQ(2, tether_service_->updated_technology_state_count()); |
| 318 | 322 |
| 319 SetTetherTechnologyStateEnabled(true); | 323 SetTetherTechnologyStateEnabled(true); |
| 320 SetTetherTechnologyStateEnabled(true); | 324 SetTetherTechnologyStateEnabled(true); |
| 321 SetTetherTechnologyStateEnabled(true); | 325 SetTetherTechnologyStateEnabled(true); |
| 322 | 326 |
| 323 EXPECT_EQ(2, tether_service_->updated_technology_state_count()); | 327 EXPECT_EQ(3, tether_service_->updated_technology_state_count()); |
| 324 } | 328 } |
| OLD | NEW |