Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <tuple> | 7 #include <tuple> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 28 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 29 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 29 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 30 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 30 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 31 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 31 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 32 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 32 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 33 #include "chrome/browser/policy/profile_policy_connector.h" | 33 #include "chrome/browser/policy/profile_policy_connector.h" |
| 34 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 34 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 35 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 35 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 36 #include "chrome/browser/profiles/profile.h" | 36 #include "chrome/browser/profiles/profile.h" |
| 37 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 37 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 38 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" | |
| 38 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 39 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 39 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
| 40 #include "chrome/test/base/testing_profile.h" | 41 #include "chrome/test/base/testing_profile.h" |
| 41 #include "chromeos/chromeos_switches.h" | 42 #include "chromeos/chromeos_switches.h" |
| 42 #include "chromeos/dbus/dbus_thread_manager.h" | 43 #include "chromeos/dbus/dbus_thread_manager.h" |
| 43 #include "chromeos/dbus/fake_session_manager_client.h" | 44 #include "chromeos/dbus/fake_session_manager_client.h" |
| 44 #include "components/arc/arc_service_manager.h" | 45 #include "components/arc/arc_service_manager.h" |
| 45 #include "components/arc/arc_session_runner.h" | 46 #include "components/arc/arc_session_runner.h" |
| 46 #include "components/arc/arc_util.h" | 47 #include "components/arc/arc_util.h" |
| 47 #include "components/arc/test/fake_arc_session.h" | 48 #include "components/arc/test/fake_arc_session.h" |
| 48 #include "components/prefs/pref_service.h" | 49 #include "components/prefs/pref_service.h" |
| 49 #include "components/prefs/testing_pref_service.h" | 50 #include "components/prefs/testing_pref_service.h" |
| 50 #include "components/signin/core/account_id/account_id.h" | 51 #include "components/signin/core/account_id/account_id.h" |
| 51 #include "components/sync/model/fake_sync_change_processor.h" | 52 #include "components/sync/model/fake_sync_change_processor.h" |
| 52 #include "components/sync/model/sync_error_factory_mock.h" | 53 #include "components/sync/model/sync_error_factory_mock.h" |
| 53 #include "components/sync_preferences/testing_pref_service_syncable.h" | 54 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 54 #include "components/user_manager/user_manager.h" | 55 #include "components/user_manager/user_manager.h" |
| 55 #include "components/user_manager/user_names.h" | 56 #include "components/user_manager/user_names.h" |
| 56 #include "content/public/browser/browser_thread.h" | 57 #include "content/public/browser/browser_thread.h" |
| 57 #include "content/public/test/test_browser_thread_bundle.h" | 58 #include "content/public/test/test_browser_thread_bundle.h" |
| 58 #include "google_apis/gaia/gaia_constants.h" | 59 #include "google_apis/gaia/gaia_constants.h" |
| 59 #include "google_apis/gaia/gaia_urls.h" | 60 #include "google_apis/gaia/gaia_urls.h" |
| 60 #include "net/http/http_status_code.h" | 61 #include "net/http/http_status_code.h" |
| 61 #include "testing/gtest/include/gtest/gtest.h" | 62 #include "testing/gtest/include/gtest/gtest.h" |
| 62 | 63 |
| 63 namespace arc { | 64 namespace arc { |
| 64 | 65 |
| 65 namespace { | 66 namespace { |
| 66 | 67 |
| 68 enum ArcAlwaysStartOption : bool { | |
| 69 ON = true, | |
| 70 OFF = false, | |
| 71 }; | |
| 72 | |
| 67 class FakeLoginDisplayHost : public chromeos::LoginDisplayHost { | 73 class FakeLoginDisplayHost : public chromeos::LoginDisplayHost { |
| 68 public: | 74 public: |
| 69 FakeLoginDisplayHost() { | 75 FakeLoginDisplayHost() { |
| 70 DCHECK(!chromeos::LoginDisplayHost::default_host_); | 76 DCHECK(!chromeos::LoginDisplayHost::default_host_); |
| 71 chromeos::LoginDisplayHost::default_host_ = this; | 77 chromeos::LoginDisplayHost::default_host_ = this; |
| 72 } | 78 } |
| 73 | 79 |
| 74 ~FakeLoginDisplayHost() override { | 80 ~FakeLoginDisplayHost() override { |
| 75 DCHECK_EQ(chromeos::LoginDisplayHost::default_host_, this); | 81 DCHECK_EQ(chromeos::LoginDisplayHost::default_host_, this); |
| 76 chromeos::LoginDisplayHost::default_host_ = nullptr; | 82 chromeos::LoginDisplayHost::default_host_ = nullptr; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 content::TestBrowserThreadBundle thread_bundle_; | 202 content::TestBrowserThreadBundle thread_bundle_; |
| 197 std::unique_ptr<TestingProfile> profile_; | 203 std::unique_ptr<TestingProfile> profile_; |
| 198 std::unique_ptr<ArcServiceManager> arc_service_manager_; | 204 std::unique_ptr<ArcServiceManager> arc_service_manager_; |
| 199 std::unique_ptr<ArcSessionManager> arc_session_manager_; | 205 std::unique_ptr<ArcSessionManager> arc_session_manager_; |
| 200 chromeos::ScopedUserManagerEnabler user_manager_enabler_; | 206 chromeos::ScopedUserManagerEnabler user_manager_enabler_; |
| 201 base::ScopedTempDir temp_dir_; | 207 base::ScopedTempDir temp_dir_; |
| 202 | 208 |
| 203 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTestBase); | 209 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTestBase); |
| 204 }; | 210 }; |
| 205 | 211 |
| 206 class ArcSessionManagerTest : public ArcSessionManagerTestBase { | 212 // Intermediate class so that the children can inject test parameter freely. |
| 213 class AbstractArcSessionManagerTest : public ArcSessionManagerTestBase { | |
| 207 public: | 214 public: |
| 208 ArcSessionManagerTest() = default; | 215 AbstractArcSessionManagerTest() = default; |
| 209 | |
| 210 void SetUp() override { | 216 void SetUp() override { |
| 211 ArcSessionManagerTestBase::SetUp(); | 217 ArcSessionManagerTestBase::SetUp(); |
| 218 if (ShouldArcAlwaysStartInTest() == ArcAlwaysStartOption::ON) | |
| 219 SetArcAlwaysStartForTesting(); | |
| 212 | 220 |
| 213 const AccountId account_id(AccountId::FromUserEmailGaiaId( | 221 const AccountId account_id(AccountId::FromUserEmailGaiaId( |
| 214 profile()->GetProfileUserName(), "1234567890")); | 222 profile()->GetProfileUserName(), "1234567890")); |
| 215 GetFakeUserManager()->AddUser(account_id); | 223 GetFakeUserManager()->AddUser(account_id); |
| 216 GetFakeUserManager()->LoginUser(account_id); | 224 GetFakeUserManager()->LoginUser(account_id); |
| 217 | 225 |
| 218 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, | 226 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| 219 arc_session_manager()->state()); | 227 arc_session_manager()->state()); |
| 220 ASSERT_TRUE(arc_session_manager()->IsSessionStopped()); | 228 ASSERT_TRUE(arc_session_manager()->IsSessionStopped()); |
| 221 } | 229 } |
| 222 | 230 |
| 231 protected: | |
| 232 virtual ArcAlwaysStartOption ShouldArcAlwaysStartInTest() = 0; | |
| 233 | |
| 234 private: | |
| 235 DISALLOW_COPY_AND_ASSIGN(AbstractArcSessionManagerTest); | |
| 236 }; | |
| 237 | |
| 238 class ArcSessionManagerTest | |
| 239 : public AbstractArcSessionManagerTest, | |
| 240 public testing::WithParamInterface<ArcAlwaysStartOption> { | |
| 241 public: | |
| 242 ArcSessionManagerTest() = default; | |
| 243 | |
| 244 protected: | |
| 245 ArcAlwaysStartOption ShouldArcAlwaysStartInTest() override { | |
| 246 return GetParam(); | |
| 247 } | |
| 248 | |
| 223 private: | 249 private: |
| 224 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); | 250 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); |
| 225 }; | 251 }; |
| 226 | 252 |
| 227 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) { | 253 INSTANTIATE_TEST_CASE_P(, |
| 254 ArcSessionManagerTest, | |
| 255 testing::Values(ArcAlwaysStartOption::OFF, | |
| 256 ArcAlwaysStartOption::ON)); | |
| 257 | |
| 258 TEST_P(ArcSessionManagerTest, PrefChangeTriggersService) { | |
| 259 // TODO(victorhsieh): Implement opt-in and opt-out flow. | |
| 260 if (ShouldArcAlwaysStart()) | |
| 261 return; | |
| 262 | |
| 228 ASSERT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); | 263 ASSERT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 229 arc_session_manager()->SetProfile(profile()); | 264 arc_session_manager()->SetProfile(profile()); |
| 230 arc_session_manager()->StartPreferenceHandler(); | 265 arc_session_manager()->StartPreferenceHandler(); |
| 231 | 266 |
| 232 EXPECT_FALSE( | 267 EXPECT_FALSE( |
| 233 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 268 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 234 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 269 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| 235 | 270 |
| 236 SetArcPlayStoreEnabledForProfile(profile(), true); | 271 SetArcPlayStoreEnabledForProfile(profile(), true); |
| 237 base::RunLoop().RunUntilIdle(); | 272 base::RunLoop().RunUntilIdle(); |
| 238 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 273 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 239 arc_session_manager()->state()); | 274 arc_session_manager()->state()); |
| 240 | 275 |
| 241 SetArcPlayStoreEnabledForProfile(profile(), false); | 276 SetArcPlayStoreEnabledForProfile(profile(), false); |
| 242 | 277 |
| 243 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); | 278 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); |
| 244 | 279 |
| 245 // Correctly stop service. | 280 // Correctly stop service. |
| 246 arc_session_manager()->Shutdown(); | 281 arc_session_manager()->Shutdown(); |
| 247 } | 282 } |
| 248 | 283 |
| 249 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService_Restart) { | 284 TEST_P(ArcSessionManagerTest, PrefChangeTriggersService_Restart) { |
| 285 // TODO(victorhsieh): Implement opt-in and opt-out flow. | |
| 286 if (ShouldArcAlwaysStart()) | |
| 287 return; | |
| 288 | |
| 250 // Sets the Google Play Store preference at beginning. | 289 // Sets the Google Play Store preference at beginning. |
| 251 SetArcPlayStoreEnabledForProfile(profile(), true); | 290 SetArcPlayStoreEnabledForProfile(profile(), true); |
| 252 | 291 |
| 253 arc_session_manager()->SetProfile(profile()); | 292 arc_session_manager()->SetProfile(profile()); |
| 254 arc_session_manager()->StartPreferenceHandler(); | 293 arc_session_manager()->StartPreferenceHandler(); |
| 255 | 294 |
| 256 // Setting profile initiates a code fetching process. | 295 // Setting profile initiates a code fetching process. |
| 257 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 296 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 258 arc_session_manager()->state()); | 297 arc_session_manager()->state()); |
| 259 | 298 |
| 260 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 299 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 261 base::RunLoop().RunUntilIdle(); | 300 base::RunLoop().RunUntilIdle(); |
| 262 | 301 |
| 263 // UI is disabled in unit tests and this code is unchanged. | 302 // UI is disabled in unit tests and this code is unchanged. |
| 264 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 303 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 265 arc_session_manager()->state()); | 304 arc_session_manager()->state()); |
| 266 | 305 |
| 267 // Correctly stop service. | 306 // Correctly stop service. |
| 268 arc_session_manager()->Shutdown(); | 307 arc_session_manager()->Shutdown(); |
| 269 } | 308 } |
| 270 | 309 |
| 271 TEST_F(ArcSessionManagerTest, BaseWorkflow) { | 310 TEST_P(ArcSessionManagerTest, BaseWorkflow) { |
| 311 if (ShouldArcAlwaysStart()) | |
| 312 return; | |
| 313 | |
| 272 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); | 314 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); |
| 273 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); | 315 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); |
| 274 | 316 |
| 275 arc_session_manager()->SetProfile(profile()); | 317 arc_session_manager()->SetProfile(profile()); |
| 276 | 318 |
| 277 // By default ARC is not enabled. | 319 // By default ARC is not enabled. |
| 278 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 320 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| 279 | 321 |
| 280 // Enables ARC. First time, ToS negotiation should start. | 322 // Enables ARC. First time, ToS negotiation should start. |
| 281 arc_session_manager()->RequestEnable(); | 323 arc_session_manager()->RequestEnable(); |
| 282 base::RunLoop().RunUntilIdle(); | 324 base::RunLoop().RunUntilIdle(); |
| 283 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 325 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 284 arc_session_manager()->state()); | 326 arc_session_manager()->state()); |
| 285 | 327 |
| 286 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE -> | 328 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE -> |
| 287 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager. | 329 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager. |
| 288 arc_session_manager()->StartArc(); | 330 arc_session_manager()->StartArc(); |
| 289 | 331 |
| 290 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); | 332 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); |
| 291 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null()); | 333 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null()); |
| 292 | 334 |
| 293 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 335 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 294 ASSERT_TRUE(arc_session_manager()->IsSessionRunning()); | 336 ASSERT_TRUE(arc_session_manager()->IsSessionRunning()); |
| 295 | 337 |
| 296 arc_session_manager()->Shutdown(); | 338 arc_session_manager()->Shutdown(); |
| 297 } | 339 } |
| 298 | 340 |
| 299 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) { | 341 TEST_P(ArcSessionManagerTest, CancelFetchingDisablesArc) { |
| 342 // TODO(victorhsieh): Implement opt-in flow on Persistent ARC. | |
| 343 if (ShouldArcAlwaysStart()) | |
| 344 return; | |
| 345 | |
| 300 SetArcPlayStoreEnabledForProfile(profile(), true); | 346 SetArcPlayStoreEnabledForProfile(profile(), true); |
| 301 | 347 |
| 302 // Starts ARC. | 348 // Starts ARC. |
| 303 arc_session_manager()->SetProfile(profile()); | 349 arc_session_manager()->SetProfile(profile()); |
| 304 arc_session_manager()->RequestEnable(); | 350 arc_session_manager()->RequestEnable(); |
| 305 base::RunLoop().RunUntilIdle(); | 351 base::RunLoop().RunUntilIdle(); |
| 306 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 352 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 307 arc_session_manager()->state()); | 353 arc_session_manager()->state()); |
| 308 | 354 |
| 309 // Emulate to cancel the ToS UI (e.g. closing the window). | 355 // Emulate to cancel the ToS UI (e.g. closing the window). |
| 310 arc_session_manager()->CancelAuthCode(); | 356 arc_session_manager()->CancelAuthCode(); |
| 311 | 357 |
| 312 // Google Play Store enabled preference should be set to false, too. | 358 // Google Play Store enabled preference should be set to false, too. |
| 313 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); | 359 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 314 | 360 |
| 315 // Emulate the preference handling. | 361 // Emulate the preference handling. |
| 316 arc_session_manager()->RequestDisable(); | 362 arc_session_manager()->RequestDisable(); |
| 317 | 363 |
| 318 // Wait until data is removed. | 364 // Wait until data is removed. |
| 319 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); | 365 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED)); |
| 320 | 366 |
| 321 // Correctly stop service. | 367 // Correctly stop service. |
| 322 arc_session_manager()->Shutdown(); | 368 arc_session_manager()->Shutdown(); |
| 323 } | 369 } |
| 324 | 370 |
| 325 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) { | 371 TEST_P(ArcSessionManagerTest, CloseUIKeepsArcEnabled) { |
| 372 // TODO(victorhsieh): Implement opt-in flow. | |
| 373 if (ShouldArcAlwaysStart()) | |
| 374 return; | |
| 375 | |
| 326 // Starts ARC. | 376 // Starts ARC. |
| 327 SetArcPlayStoreEnabledForProfile(profile(), true); | 377 SetArcPlayStoreEnabledForProfile(profile(), true); |
| 328 arc_session_manager()->SetProfile(profile()); | 378 arc_session_manager()->SetProfile(profile()); |
| 329 arc_session_manager()->RequestEnable(); | 379 arc_session_manager()->RequestEnable(); |
| 330 base::RunLoop().RunUntilIdle(); | 380 base::RunLoop().RunUntilIdle(); |
| 331 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 381 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 332 arc_session_manager()->state()); | 382 arc_session_manager()->state()); |
| 333 arc_session_manager()->StartArc(); | 383 arc_session_manager()->StartArc(); |
| 334 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 384 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 335 | 385 |
| 336 // When ARC is properly started, closing UI should be no-op. | 386 // When ARC is properly started, closing UI should be no-op. |
| 337 arc_session_manager()->CancelAuthCode(); | 387 arc_session_manager()->CancelAuthCode(); |
| 338 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 388 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 339 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile())); | 389 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile())); |
| 340 | 390 |
| 341 // Correctly stop service. | 391 // Correctly stop service. |
| 342 arc_session_manager()->Shutdown(); | 392 arc_session_manager()->Shutdown(); |
| 343 } | 393 } |
| 344 | 394 |
| 345 TEST_F(ArcSessionManagerTest, Provisioning_Success) { | 395 TEST_P(ArcSessionManagerTest, Provisioning_Success) { |
| 346 PrefService* const prefs = profile()->GetPrefs(); | 396 PrefService* const prefs = profile()->GetPrefs(); |
| 347 | 397 |
| 348 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); | 398 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); |
| 349 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); | 399 EXPECT_TRUE(arc_session_manager()->arc_start_time().is_null()); |
| 350 EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); | 400 EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); |
| 351 | 401 |
| 352 ASSERT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 402 ASSERT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 353 | 403 |
| 354 arc_session_manager()->SetProfile(profile()); | 404 arc_session_manager()->SetProfile(profile()); |
| 355 arc_session_manager()->RequestEnable(); | 405 arc_session_manager()->RequestEnable(); |
| 356 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 406 if (ShouldArcAlwaysStart()) { |
| 357 arc_session_manager()->state()); | 407 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 408 } else { | |
| 409 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | |
| 410 arc_session_manager()->state()); | |
| 411 } | |
| 358 | 412 |
| 359 // Emulate to accept the terms of service. | 413 // Emulate to accept the terms of service. |
| 360 prefs->SetBoolean(prefs::kArcTermsAccepted, true); | 414 prefs->SetBoolean(prefs::kArcTermsAccepted, true); |
| 361 arc_session_manager()->StartArc(); | 415 if (!ShouldArcAlwaysStart()) { |
| 416 arc_session_manager()->StartArc(); | |
| 417 } | |
| 362 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 418 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 363 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); | 419 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); |
| 364 | 420 |
| 365 // Here, provisining is not yet completed, so kArcSignedIn should be false. | 421 // Here, provisining is not yet completed, so kArcSignedIn should be false. |
| 366 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 422 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 367 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null()); | 423 EXPECT_FALSE(arc_session_manager()->arc_start_time().is_null()); |
| 368 EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); | 424 EXPECT_FALSE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); |
| 369 | 425 |
| 370 // Emulate successful provisioning. | 426 // Emulate successful provisioning. |
| 371 arc_session_manager()->OnProvisioningFinished(ProvisioningResult::SUCCESS); | 427 arc_session_manager()->OnProvisioningFinished(ProvisioningResult::SUCCESS); |
| 372 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); | 428 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 373 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 429 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 374 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); | 430 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); |
| 375 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); | 431 EXPECT_TRUE(arc_session_manager()->sign_in_start_time().is_null()); |
| 376 EXPECT_TRUE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); | 432 EXPECT_TRUE(arc_session_manager()->IsPlaystoreLaunchRequestedForTesting()); |
| 377 } | 433 } |
| 378 | 434 |
| 379 TEST_F(ArcSessionManagerTest, Provisioning_Restart) { | 435 TEST_P(ArcSessionManagerTest, Provisioning_Restart) { |
| 380 // Set up the situation that provisioning is successfully done in the | 436 // Set up the situation that provisioning is successfully done in the |
| 381 // previous session. | 437 // previous session. |
| 382 PrefService* const prefs = profile()->GetPrefs(); | 438 PrefService* const prefs = profile()->GetPrefs(); |
| 383 prefs->SetBoolean(prefs::kArcTermsAccepted, true); | 439 prefs->SetBoolean(prefs::kArcTermsAccepted, true); |
| 384 prefs->SetBoolean(prefs::kArcSignedIn, true); | 440 prefs->SetBoolean(prefs::kArcSignedIn, true); |
| 385 | 441 |
| 386 arc_session_manager()->SetProfile(profile()); | 442 arc_session_manager()->SetProfile(profile()); |
| 387 arc_session_manager()->RequestEnable(); | 443 arc_session_manager()->RequestEnable(); |
| 388 | 444 |
| 389 // Second start, no fetching code is expected. | 445 // Second start, no fetching code is expected. |
| 390 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 446 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 391 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); | 447 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); |
| 392 | 448 |
| 393 // Report failure. | 449 // Report failure. |
| 394 arc_session_manager()->OnProvisioningFinished( | 450 arc_session_manager()->OnProvisioningFinished( |
| 395 ProvisioningResult::GMS_NETWORK_ERROR); | 451 ProvisioningResult::GMS_NETWORK_ERROR); |
| 396 // On error, UI to send feedback is showing. In that case, | 452 // On error, UI to send feedback is showing. In that case, |
| 397 // the ARC is still necessary to run on background for gathering the logs. | 453 // the ARC is still necessary to run on background for gathering the logs. |
| 398 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); | 454 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 399 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 455 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 400 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); | 456 EXPECT_TRUE(arc_session_manager()->IsSessionRunning()); |
| 401 | 457 |
| 402 // Correctly stop service. | 458 // Correctly stop service. |
| 403 arc_session_manager()->Shutdown(); | 459 arc_session_manager()->Shutdown(); |
| 404 } | 460 } |
| 405 | 461 |
| 406 TEST_F(ArcSessionManagerTest, RemoveDataDir) { | 462 TEST_P(ArcSessionManagerTest, RemoveDataDir) { |
| 463 // TODO(victorhsieh): Implement data removal on Persistent ARC. | |
| 464 if (ShouldArcAlwaysStart()) | |
| 465 return; | |
| 466 | |
| 407 // Emulate the situation where the initial Google Play Store enabled | 467 // Emulate the situation where the initial Google Play Store enabled |
| 408 // preference is false for managed user, i.e., data dir is being removed at | 468 // preference is false for managed user, i.e., data dir is being removed at |
| 409 // beginning. | 469 // beginning. |
| 410 arc_session_manager()->SetProfile(profile()); | 470 arc_session_manager()->SetProfile(profile()); |
| 411 arc_session_manager()->RemoveArcData(); | 471 arc_session_manager()->RemoveArcData(); |
| 472 | |
| 412 EXPECT_TRUE( | 473 EXPECT_TRUE( |
| 413 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 474 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 414 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, | 475 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, |
| 415 arc_session_manager()->state()); | 476 arc_session_manager()->state()); |
| 416 | 477 |
| 417 // Enable ARC. Data is removed asyncronously. At this moment session manager | 478 // Enable ARC. Data is removed asyncronously. At this moment session manager |
| 418 // should be in REMOVING_DATA_DIR state. | 479 // should be in REMOVING_DATA_DIR state. |
| 419 arc_session_manager()->RequestEnable(); | 480 arc_session_manager()->RequestEnable(); |
| 420 EXPECT_TRUE( | 481 EXPECT_TRUE( |
| 421 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 482 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 435 ASSERT_TRUE( | 496 ASSERT_TRUE( |
| 436 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 497 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 437 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 498 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 438 arc_session_manager()->Shutdown(); | 499 arc_session_manager()->Shutdown(); |
| 439 base::RunLoop().RunUntilIdle(); | 500 base::RunLoop().RunUntilIdle(); |
| 440 // Request should persist. | 501 // Request should persist. |
| 441 ASSERT_TRUE( | 502 ASSERT_TRUE( |
| 442 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 503 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 443 } | 504 } |
| 444 | 505 |
| 445 TEST_F(ArcSessionManagerTest, RemoveDataDir_Restart) { | 506 TEST_P(ArcSessionManagerTest, RemoveDataDir_Restart) { |
| 507 // TODO(victorhsieh): Implement data removal on Persistent ARC. | |
| 508 if (ShouldArcAlwaysStart()) | |
| 509 return; | |
| 510 | |
| 446 // Emulate second sign-in. Data should be removed first and ARC started after. | 511 // Emulate second sign-in. Data should be removed first and ARC started after. |
| 447 PrefService* const prefs = profile()->GetPrefs(); | 512 PrefService* const prefs = profile()->GetPrefs(); |
| 448 prefs->SetBoolean(prefs::kArcDataRemoveRequested, true); | 513 prefs->SetBoolean(prefs::kArcDataRemoveRequested, true); |
| 449 arc_session_manager()->SetProfile(profile()); | 514 arc_session_manager()->SetProfile(profile()); |
| 450 arc_session_manager()->RequestEnable(); | 515 arc_session_manager()->RequestEnable(); |
| 451 EXPECT_TRUE( | 516 EXPECT_TRUE( |
| 452 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 517 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 453 ASSERT_TRUE( | 518 ASSERT_TRUE( |
| 454 WaitForDataRemoved(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE)); | 519 WaitForDataRemoved(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE)); |
| 455 EXPECT_FALSE( | 520 EXPECT_FALSE( |
| 456 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 521 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 457 | 522 |
| 458 arc_session_manager()->Shutdown(); | 523 arc_session_manager()->Shutdown(); |
| 459 } | 524 } |
| 460 | 525 |
| 461 TEST_F(ArcSessionManagerTest, RemoveDataDir_Managed) { | 526 TEST_P(ArcSessionManagerTest, RemoveDataDir_Managed) { |
| 527 // TODO(victorhsieh): Implement data removal on Persistent ARC. | |
| 528 if (ShouldArcAlwaysStart()) | |
| 529 return; | |
| 530 | |
| 462 // Set ARC to be managed and disabled. | 531 // Set ARC to be managed and disabled. |
| 463 profile()->GetTestingPrefService()->SetManagedPref(prefs::kArcEnabled, | 532 profile()->GetTestingPrefService()->SetManagedPref(prefs::kArcEnabled, |
| 464 new base::Value(false)); | 533 new base::Value(false)); |
| 465 | 534 |
| 466 // Starting session manager with prefs::kArcEnabled off in a managed profile | 535 // Starting session manager with prefs::kArcEnabled off in a managed profile |
| 467 // does automatically remove Android's data folder. | 536 // does automatically remove Android's data folder. |
| 468 arc_session_manager()->SetProfile(profile()); | 537 arc_session_manager()->SetProfile(profile()); |
| 469 arc_session_manager()->StartPreferenceHandler(); | 538 arc_session_manager()->StartPreferenceHandler(); |
| 470 EXPECT_TRUE( | 539 EXPECT_TRUE( |
| 471 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 540 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 472 } | 541 } |
| 473 | 542 |
| 474 TEST_F(ArcSessionManagerTest, IgnoreSecondErrorReporting) { | 543 TEST_P(ArcSessionManagerTest, IgnoreSecondErrorReporting) { |
| 475 arc_session_manager()->SetProfile(profile()); | 544 arc_session_manager()->SetProfile(profile()); |
| 476 arc_session_manager()->RequestEnable(); | 545 arc_session_manager()->RequestEnable(); |
| 477 arc_session_manager()->StartArc(); | 546 arc_session_manager()->StartArc(); |
| 478 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 547 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 479 | 548 |
| 480 // Report some failure that does not stop the bridge. | 549 // Report some failure that does not stop the bridge. |
| 481 arc_session_manager()->OnProvisioningFinished( | 550 arc_session_manager()->OnProvisioningFinished( |
| 482 ProvisioningResult::GMS_SIGN_IN_FAILED); | 551 ProvisioningResult::GMS_SIGN_IN_FAILED); |
| 483 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 552 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 484 | 553 |
| 485 // Try to send another error that stops the bridge if sent first. It should | 554 // Try to send another error that stops the bridge if sent first. It should |
| 486 // be ignored. | 555 // be ignored. |
| 487 arc_session_manager()->OnProvisioningFinished( | 556 arc_session_manager()->OnProvisioningFinished( |
| 488 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); | 557 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); |
| 489 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 558 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 490 | 559 |
| 491 arc_session_manager()->Shutdown(); | 560 arc_session_manager()->Shutdown(); |
| 492 } | 561 } |
| 493 | 562 |
| 494 class ArcSessionManagerPolicyTest | 563 class ArcSessionManagerPolicyTest |
| 495 : public ArcSessionManagerTest, | 564 : public AbstractArcSessionManagerTest, |
| 496 public testing::WithParamInterface<std::tuple<base::Value, base::Value>> { | 565 public testing::WithParamInterface< |
| 566 std::tuple<base::Value, base::Value, ArcAlwaysStartOption>> { | |
| 497 public: | 567 public: |
| 498 const base::Value& backup_restore_pref_value() const { | 568 const base::Value& backup_restore_pref_value() const { |
| 499 return std::get<0>(GetParam()); | 569 return std::get<0>(GetParam()); |
| 500 } | 570 } |
| 501 | 571 |
| 502 const base::Value& location_service_pref_value() const { | 572 const base::Value& location_service_pref_value() const { |
| 503 return std::get<1>(GetParam()); | 573 return std::get<1>(GetParam()); |
| 504 } | 574 } |
| 575 | |
| 576 protected: | |
| 577 ArcAlwaysStartOption ShouldArcAlwaysStartInTest() override { | |
| 578 return std::get<2>(GetParam()); | |
| 579 } | |
| 505 }; | 580 }; |
| 506 | 581 |
| 507 TEST_P(ArcSessionManagerPolicyTest, SkippingTerms) { | 582 TEST_P(ArcSessionManagerPolicyTest, SkippingTerms) { |
| 583 // TODO(victorhsieh): Implement opt-in flow. | |
| 584 if (ShouldArcAlwaysStart()) | |
| 585 return; | |
| 586 | |
| 508 sync_preferences::TestingPrefServiceSyncable* const prefs = | 587 sync_preferences::TestingPrefServiceSyncable* const prefs = |
| 509 profile()->GetTestingPrefService(); | 588 profile()->GetTestingPrefService(); |
| 510 | 589 |
| 511 // Backup-restore and location-service prefs are off by default. | 590 // Backup-restore and location-service prefs are off by default. |
| 512 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 591 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
| 513 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcTermsAccepted)); | 592 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcTermsAccepted)); |
| 514 | 593 |
| 515 // Set ARC to be managed. | 594 // Set ARC to be managed. |
| 516 prefs->SetManagedPref(prefs::kArcEnabled, new base::Value(true)); | 595 prefs->SetManagedPref(prefs::kArcEnabled, new base::Value(true)); |
| 517 | 596 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcBackupRestoreEnabled)); | 639 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcBackupRestoreEnabled)); |
| 561 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcLocationServiceEnabled)); | 640 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcLocationServiceEnabled)); |
| 562 | 641 |
| 563 // Stop ARC and shutdown the service. | 642 // Stop ARC and shutdown the service. |
| 564 prefs->RemoveManagedPref(prefs::kArcEnabled); | 643 prefs->RemoveManagedPref(prefs::kArcEnabled); |
| 565 WaitForDataRemoved(ArcSessionManager::State::STOPPED); | 644 WaitForDataRemoved(ArcSessionManager::State::STOPPED); |
| 566 arc_session_manager()->Shutdown(); | 645 arc_session_manager()->Shutdown(); |
| 567 } | 646 } |
| 568 | 647 |
| 569 INSTANTIATE_TEST_CASE_P( | 648 INSTANTIATE_TEST_CASE_P( |
| 570 ArcSessionManagerPolicyTest, | 649 , |
| 571 ArcSessionManagerPolicyTest, | 650 ArcSessionManagerPolicyTest, |
| 572 testing::Combine( | 651 testing::Combine( |
| 573 testing::Values(base::Value(), base::Value(false), base::Value(true)), | 652 testing::Values(base::Value(), base::Value(false), base::Value(true)), |
| 574 testing::Values(base::Value(), base::Value(false), base::Value(true)))); | 653 testing::Values(base::Value(), base::Value(false), base::Value(true)), |
| 654 testing::Values(ArcAlwaysStartOption::OFF, ArcAlwaysStartOption::ON))); | |
| 575 | 655 |
| 576 class ArcSessionManagerKioskTest : public ArcSessionManagerTestBase { | 656 class ArcSessionManagerKioskTest : public ArcSessionManagerTestBase { |
| 577 public: | 657 public: |
| 578 ArcSessionManagerKioskTest() = default; | 658 ArcSessionManagerKioskTest() = default; |
| 579 | 659 |
| 580 void SetUp() override { | 660 void SetUp() override { |
| 581 ArcSessionManagerTestBase::SetUp(); | 661 ArcSessionManagerTestBase::SetUp(); |
| 582 const AccountId account_id( | 662 const AccountId account_id( |
| 583 AccountId::FromUserEmail(profile()->GetProfileUserName())); | 663 AccountId::FromUserEmail(profile()->GetProfileUserName())); |
| 584 GetFakeUserManager()->AddArcKioskAppUser(account_id); | 664 GetFakeUserManager()->AddArcKioskAppUser(account_id); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 600 // and not invoked then, including TearDown(). | 680 // and not invoked then, including TearDown(). |
| 601 bool terminated = false; | 681 bool terminated = false; |
| 602 arc_session_manager()->SetAttemptUserExitCallbackForTesting( | 682 arc_session_manager()->SetAttemptUserExitCallbackForTesting( |
| 603 base::Bind([](bool* terminated) { *terminated = true; }, &terminated)); | 683 base::Bind([](bool* terminated) { *terminated = true; }, &terminated)); |
| 604 | 684 |
| 605 arc_session_manager()->OnProvisioningFinished( | 685 arc_session_manager()->OnProvisioningFinished( |
| 606 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); | 686 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); |
| 607 EXPECT_TRUE(terminated); | 687 EXPECT_TRUE(terminated); |
| 608 } | 688 } |
| 609 | 689 |
| 610 class ArcSessionOobeOptInTest : public ArcSessionManagerTest { | 690 // This class takes two test parameters because both itself and its child need |
| 691 // to be parameterized. Having redundant parameter here avoid the trouble to | |
| 692 // deal with multiple inheritance from WithParamInterface instances. | |
| 693 class ArcSessionOobeOptInTest : public AbstractArcSessionManagerTest, | |
| 694 public testing::WithParamInterface< | |
| 695 std::tuple<ArcAlwaysStartOption, bool>> { | |
|
Luis Héctor Chávez
2017/03/02 21:07:10
Much better :D
| |
| 611 public: | 696 public: |
| 612 ArcSessionOobeOptInTest() = default; | 697 ArcSessionOobeOptInTest() = default; |
| 613 | 698 |
| 614 protected: | 699 protected: |
| 700 ArcAlwaysStartOption ShouldArcAlwaysStartInTest() override { | |
| 701 return std::get<0>(GetParam()); | |
| 702 } | |
| 703 | |
| 615 void CreateLoginDisplayHost() { | 704 void CreateLoginDisplayHost() { |
| 616 fake_login_display_host_ = base::MakeUnique<FakeLoginDisplayHost>(); | 705 fake_login_display_host_ = base::MakeUnique<FakeLoginDisplayHost>(); |
| 617 } | 706 } |
| 618 | 707 |
| 619 void CloseLoginDisplayHost() { fake_login_display_host_.reset(); } | 708 void CloseLoginDisplayHost() { fake_login_display_host_.reset(); } |
| 620 | 709 |
| 621 void AppendEnableArcOOBEOptInSwitch() { | 710 void AppendEnableArcOOBEOptInSwitch() { |
| 622 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 711 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 623 chromeos::switches::kEnableArcOOBEOptIn); | 712 chromeos::switches::kEnableArcOOBEOptIn); |
| 624 } | 713 } |
| 625 | 714 |
| 626 private: | 715 private: |
| 627 std::unique_ptr<FakeLoginDisplayHost> fake_login_display_host_; | 716 std::unique_ptr<FakeLoginDisplayHost> fake_login_display_host_; |
| 628 | 717 |
| 629 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInTest); | 718 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInTest); |
| 630 }; | 719 }; |
| 631 | 720 |
| 632 TEST_F(ArcSessionOobeOptInTest, OobeOptInActive) { | 721 INSTANTIATE_TEST_CASE_P( |
| 722 , | |
| 723 ArcSessionOobeOptInTest, | |
| 724 testing::Combine(testing::Values(ArcAlwaysStartOption::OFF, | |
| 725 ArcAlwaysStartOption::ON), | |
| 726 testing::Values(false) /* dummy */)); | |
| 727 | |
| 728 TEST_P(ArcSessionOobeOptInTest, OobeOptInActive) { | |
| 633 // OOBE OptIn is active in case of OOBE is started for new user and ARC OOBE | 729 // OOBE OptIn is active in case of OOBE is started for new user and ARC OOBE |
| 634 // is enabled by switch. | 730 // is enabled by switch. |
| 635 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); | 731 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); |
| 636 GetFakeUserManager()->set_current_user_new(true); | 732 GetFakeUserManager()->set_current_user_new(true); |
| 637 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); | 733 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); |
| 638 CreateLoginDisplayHost(); | 734 CreateLoginDisplayHost(); |
| 639 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); | 735 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); |
| 640 | 736 |
| 641 AppendEnableArcOOBEOptInSwitch(); | 737 AppendEnableArcOOBEOptInSwitch(); |
| 642 GetFakeUserManager()->set_current_user_new(false); | 738 GetFakeUserManager()->set_current_user_new(false); |
| 643 CloseLoginDisplayHost(); | 739 CloseLoginDisplayHost(); |
| 644 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); | 740 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); |
| 645 GetFakeUserManager()->set_current_user_new(true); | 741 GetFakeUserManager()->set_current_user_new(true); |
| 646 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); | 742 EXPECT_FALSE(ArcSessionManager::IsOobeOptInActive()); |
| 647 CreateLoginDisplayHost(); | 743 CreateLoginDisplayHost(); |
| 648 EXPECT_TRUE(ArcSessionManager::IsOobeOptInActive()); | 744 EXPECT_TRUE(ArcSessionManager::IsOobeOptInActive()); |
| 649 } | 745 } |
| 650 | 746 |
| 651 class ArcSessionOobeOptInNegotiatorTest | 747 class ArcSessionOobeOptInNegotiatorTest |
| 652 : public ArcSessionOobeOptInTest, | 748 : public ArcSessionOobeOptInTest, |
| 653 public chromeos::ArcTermsOfServiceScreenView, | 749 public chromeos::ArcTermsOfServiceScreenView { |
| 654 public testing::WithParamInterface<bool> { | |
| 655 public: | 750 public: |
| 656 ArcSessionOobeOptInNegotiatorTest() = default; | 751 ArcSessionOobeOptInNegotiatorTest() = default; |
| 657 | 752 |
| 658 void SetUp() override { | 753 void SetUp() override { |
| 659 ArcSessionOobeOptInTest::SetUp(); | 754 ArcSessionOobeOptInTest::SetUp(); |
| 660 | 755 |
| 661 AppendEnableArcOOBEOptInSwitch(); | 756 AppendEnableArcOOBEOptInSwitch(); |
| 662 | 757 |
| 663 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenViewForTesting( | 758 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenViewForTesting( |
| 664 this); | 759 this); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 685 // Correctly stop service. | 780 // Correctly stop service. |
| 686 arc_session_manager()->Shutdown(); | 781 arc_session_manager()->Shutdown(); |
| 687 | 782 |
| 688 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenViewForTesting( | 783 ArcTermsOfServiceOobeNegotiator::SetArcTermsOfServiceScreenViewForTesting( |
| 689 nullptr); | 784 nullptr); |
| 690 | 785 |
| 691 ArcSessionOobeOptInTest::TearDown(); | 786 ArcSessionOobeOptInTest::TearDown(); |
| 692 } | 787 } |
| 693 | 788 |
| 694 protected: | 789 protected: |
| 695 bool IsManagedUser() { return GetParam(); } | 790 ArcAlwaysStartOption ShouldArcAlwaysStartInTest() override { |
| 791 return std::get<0>(GetParam()); | |
| 792 } | |
| 793 | |
| 794 bool IsManagedUser() { return std::get<1>(GetParam()); } | |
| 696 | 795 |
| 697 void ReportResult(bool accepted) { | 796 void ReportResult(bool accepted) { |
| 698 for (auto& observer : observer_list_) { | 797 for (auto& observer : observer_list_) { |
| 699 if (accepted) | 798 if (accepted) |
| 700 observer.OnAccept(); | 799 observer.OnAccept(); |
| 701 else | 800 else |
| 702 observer.OnSkip(); | 801 observer.OnSkip(); |
| 703 } | 802 } |
| 704 base::RunLoop().RunUntilIdle(); | 803 base::RunLoop().RunUntilIdle(); |
| 705 } | 804 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 731 } | 830 } |
| 732 | 831 |
| 733 void Hide() override {} | 832 void Hide() override {} |
| 734 | 833 |
| 735 base::ObserverList<chromeos::ArcTermsOfServiceScreenViewObserver> | 834 base::ObserverList<chromeos::ArcTermsOfServiceScreenViewObserver> |
| 736 observer_list_; | 835 observer_list_; |
| 737 | 836 |
| 738 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest); | 837 DISALLOW_COPY_AND_ASSIGN(ArcSessionOobeOptInNegotiatorTest); |
| 739 }; | 838 }; |
| 740 | 839 |
| 741 INSTANTIATE_TEST_CASE_P(ArcSessionOobeOptInNegotiatorTestImpl, | 840 // TODO(victorhsieh): Add test to cover when ARC always start |
| 742 ArcSessionOobeOptInNegotiatorTest, | 841 INSTANTIATE_TEST_CASE_P( |
| 743 ::testing::Values(true, false)); | 842 , |
| 843 ArcSessionOobeOptInNegotiatorTest, | |
| 844 testing::Combine(testing::Values(ArcAlwaysStartOption::OFF), | |
| 845 testing::Bool() /* managed user */)); | |
| 744 | 846 |
| 745 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsAccepted) { | 847 TEST_P(ArcSessionOobeOptInNegotiatorTest, OobeTermsAccepted) { |
| 746 view()->Show(); | 848 view()->Show(); |
| 747 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 849 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 748 arc_session_manager()->state()); | 850 arc_session_manager()->state()); |
| 749 ReportResult(true); | 851 ReportResult(true); |
| 750 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 852 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
| 751 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile())); | 853 EXPECT_TRUE(IsArcPlayStoreEnabledForProfile(profile())); |
| 752 } | 854 } |
| 753 | 855 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 766 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 868 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
| 767 arc_session_manager()->state()); | 869 arc_session_manager()->state()); |
| 768 CloseLoginDisplayHost(); | 870 CloseLoginDisplayHost(); |
| 769 ReportViewDestroyed(); | 871 ReportViewDestroyed(); |
| 770 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 872 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
| 771 if (!IsManagedUser()) | 873 if (!IsManagedUser()) |
| 772 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); | 874 EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); |
| 773 } | 875 } |
| 774 | 876 |
| 775 } // namespace arc | 877 } // namespace arc |
| OLD | NEW |