| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/login/login_utils.h" | 5 #include "chrome/browser/chromeos/login/login_utils.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 387 |
| 388 DISALLOW_COPY_AND_ASSIGN(LoginUtilsTest); | 388 DISALLOW_COPY_AND_ASSIGN(LoginUtilsTest); |
| 389 }; | 389 }; |
| 390 | 390 |
| 391 class LoginUtilsBlockingLoginTest | 391 class LoginUtilsBlockingLoginTest |
| 392 : public LoginUtilsTest, | 392 : public LoginUtilsTest, |
| 393 public testing::WithParamInterface<int> {}; | 393 public testing::WithParamInterface<int> {}; |
| 394 | 394 |
| 395 TEST_F(LoginUtilsTest, NormalLoginDoesntBlock) { | 395 TEST_F(LoginUtilsTest, NormalLoginDoesntBlock) { |
| 396 UserManager* user_manager = UserManager::Get(); | 396 UserManager* user_manager = UserManager::Get(); |
| 397 ASSERT_TRUE(!user_manager->IsUserLoggedIn() || | 397 ASSERT_TRUE(!user_manager->IsUserLoggedIn()); |
| 398 user_manager->IsLoggedInAsStub()); | |
| 399 EXPECT_FALSE(connector_->IsEnterpriseManaged()); | 398 EXPECT_FALSE(connector_->IsEnterpriseManaged()); |
| 400 EXPECT_FALSE(prepared_profile_); | 399 EXPECT_FALSE(prepared_profile_); |
| 401 | 400 |
| 402 // The profile will be created without waiting for a policy response. | 401 // The profile will be created without waiting for a policy response. |
| 403 PrepareProfile(kUsername); | 402 PrepareProfile(kUsername); |
| 404 | 403 |
| 405 EXPECT_TRUE(prepared_profile_); | 404 EXPECT_TRUE(prepared_profile_); |
| 406 ASSERT_TRUE(user_manager->IsUserLoggedIn() && | 405 ASSERT_TRUE(user_manager->IsUserLoggedIn()); |
| 407 !user_manager->IsLoggedInAsStub()); | |
| 408 EXPECT_EQ(kUsername, user_manager->GetLoggedInUser().email()); | 406 EXPECT_EQ(kUsername, user_manager->GetLoggedInUser().email()); |
| 409 } | 407 } |
| 410 | 408 |
| 411 TEST_F(LoginUtilsTest, EnterpriseLoginDoesntBlockForNormalUser) { | 409 TEST_F(LoginUtilsTest, EnterpriseLoginDoesntBlockForNormalUser) { |
| 412 UserManager* user_manager = UserManager::Get(); | 410 UserManager* user_manager = UserManager::Get(); |
| 413 ASSERT_TRUE(!user_manager->IsUserLoggedIn() || | 411 ASSERT_TRUE(!user_manager->IsUserLoggedIn()); |
| 414 user_manager->IsLoggedInAsStub()); | |
| 415 EXPECT_FALSE(connector_->IsEnterpriseManaged()); | 412 EXPECT_FALSE(connector_->IsEnterpriseManaged()); |
| 416 EXPECT_FALSE(prepared_profile_); | 413 EXPECT_FALSE(prepared_profile_); |
| 417 | 414 |
| 418 // Enroll the device. | 415 // Enroll the device. |
| 419 LockDevice(kUsername); | 416 LockDevice(kUsername); |
| 420 | 417 |
| 421 ASSERT_TRUE(!user_manager->IsUserLoggedIn() || | 418 ASSERT_TRUE(!user_manager->IsUserLoggedIn()); |
| 422 user_manager->IsLoggedInAsStub()); | |
| 423 EXPECT_TRUE(connector_->IsEnterpriseManaged()); | 419 EXPECT_TRUE(connector_->IsEnterpriseManaged()); |
| 424 EXPECT_EQ(kDomain, connector_->GetEnterpriseDomain()); | 420 EXPECT_EQ(kDomain, connector_->GetEnterpriseDomain()); |
| 425 EXPECT_FALSE(prepared_profile_); | 421 EXPECT_FALSE(prepared_profile_); |
| 426 | 422 |
| 427 // Login with a non-enterprise user shouldn't block. | 423 // Login with a non-enterprise user shouldn't block. |
| 428 PrepareProfile(kUsernameOtherDomain); | 424 PrepareProfile(kUsernameOtherDomain); |
| 429 | 425 |
| 430 EXPECT_TRUE(prepared_profile_); | 426 EXPECT_TRUE(prepared_profile_); |
| 431 ASSERT_TRUE(user_manager->IsUserLoggedIn() && | 427 ASSERT_TRUE(user_manager->IsUserLoggedIn()); |
| 432 !user_manager->IsLoggedInAsStub()); | |
| 433 EXPECT_EQ(kUsernameOtherDomain, user_manager->GetLoggedInUser().email()); | 428 EXPECT_EQ(kUsernameOtherDomain, user_manager->GetLoggedInUser().email()); |
| 434 } | 429 } |
| 435 | 430 |
| 436 TEST_P(LoginUtilsBlockingLoginTest, EnterpriseLoginBlocksForEnterpriseUser) { | 431 TEST_P(LoginUtilsBlockingLoginTest, EnterpriseLoginBlocksForEnterpriseUser) { |
| 437 UserManager* user_manager = UserManager::Get(); | 432 UserManager* user_manager = UserManager::Get(); |
| 438 ASSERT_TRUE(!user_manager->IsUserLoggedIn() || | 433 ASSERT_TRUE(!user_manager->IsUserLoggedIn()); |
| 439 user_manager->IsLoggedInAsStub()); | |
| 440 EXPECT_FALSE(connector_->IsEnterpriseManaged()); | 434 EXPECT_FALSE(connector_->IsEnterpriseManaged()); |
| 441 EXPECT_FALSE(prepared_profile_); | 435 EXPECT_FALSE(prepared_profile_); |
| 442 | 436 |
| 443 // Enroll the device. | 437 // Enroll the device. |
| 444 LockDevice(kUsername); | 438 LockDevice(kUsername); |
| 445 | 439 |
| 446 ASSERT_TRUE(!user_manager->IsUserLoggedIn() || | 440 ASSERT_TRUE(!user_manager->IsUserLoggedIn()); |
| 447 user_manager->IsLoggedInAsStub()); | |
| 448 EXPECT_TRUE(connector_->IsEnterpriseManaged()); | 441 EXPECT_TRUE(connector_->IsEnterpriseManaged()); |
| 449 EXPECT_EQ(kDomain, connector_->GetEnterpriseDomain()); | 442 EXPECT_EQ(kDomain, connector_->GetEnterpriseDomain()); |
| 450 EXPECT_FALSE(prepared_profile_); | 443 EXPECT_FALSE(prepared_profile_); |
| 451 | 444 |
| 452 // Login with a user of the enterprise domain waits for policy. | 445 // Login with a user of the enterprise domain waits for policy. |
| 453 PrepareProfile(kUsername); | 446 PrepareProfile(kUsername); |
| 454 | 447 |
| 455 EXPECT_FALSE(prepared_profile_); | 448 EXPECT_FALSE(prepared_profile_); |
| 456 ASSERT_TRUE(user_manager->IsUserLoggedIn() && | 449 ASSERT_TRUE(user_manager->IsUserLoggedIn()); |
| 457 !user_manager->IsLoggedInAsStub()); | |
| 458 | 450 |
| 459 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); | 451 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); |
| 460 net::TestURLFetcher* fetcher; | 452 net::TestURLFetcher* fetcher; |
| 461 | 453 |
| 462 // |steps| is the test parameter, and is the number of successful fetches. | 454 // |steps| is the test parameter, and is the number of successful fetches. |
| 463 // The first incomplete fetch will fail. In any case, the profile creation | 455 // The first incomplete fetch will fail. In any case, the profile creation |
| 464 // should resume. | 456 // should resume. |
| 465 int steps = GetParam(); | 457 int steps = GetParam(); |
| 466 | 458 |
| 467 do { | 459 do { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 } | 514 } |
| 523 | 515 |
| 524 INSTANTIATE_TEST_CASE_P( | 516 INSTANTIATE_TEST_CASE_P( |
| 525 LoginUtilsBlockingLoginTestInstance, | 517 LoginUtilsBlockingLoginTestInstance, |
| 526 LoginUtilsBlockingLoginTest, | 518 LoginUtilsBlockingLoginTest, |
| 527 testing::Values(0, 1, 2, 3, 4, 5)); | 519 testing::Values(0, 1, 2, 3, 4, 5)); |
| 528 | 520 |
| 529 } // namespace | 521 } // namespace |
| 530 | 522 |
| 531 } | 523 } |
| OLD | NEW |