| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/policy/consumer_enrollment_handler.h" | 5 #include "chrome/browser/chromeos/policy/consumer_enrollment_handler.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/browser_process_platform_part.h" | 13 #include "chrome/browser/browser_process_platform_part.h" |
| 11 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 14 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 12 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 15 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 13 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 16 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 14 #include "chrome/browser/chromeos/policy/consumer_management_service.h" | 17 #include "chrome/browser/chromeos/policy/consumer_management_service.h" |
| 15 #include "chrome/browser/chromeos/policy/consumer_management_stage.h" | 18 #include "chrome/browser/chromeos/policy/consumer_management_stage.h" |
| 16 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" | 19 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" |
| 17 #include "chrome/browser/chromeos/policy/fake_consumer_management_service.h" | 20 #include "chrome/browser/chromeos/policy/fake_consumer_management_service.h" |
| 18 #include "chrome/browser/chromeos/policy/fake_device_cloud_policy_initializer.h" | 21 #include "chrome/browser/chromeos/policy/fake_device_cloud_policy_initializer.h" |
| 22 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 19 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 23 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
| 20 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 24 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| 21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 22 #include "chrome/browser/signin/signin_manager_factory.h" | 26 #include "chrome/browser/signin/signin_manager_factory.h" |
| 23 #include "chrome/test/base/testing_browser_process.h" | 27 #include "chrome/test/base/testing_browser_process.h" |
| 24 #include "chrome/test/base/testing_profile_manager.h" | 28 #include "chrome/test/base/testing_profile_manager.h" |
| 25 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 29 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 26 #include "components/signin/core/browser/signin_manager_base.h" | 30 #include "components/signin/core/browser/signin_manager_base.h" |
| 27 #include "content/public/test/test_browser_thread_bundle.h" | 31 #include "content/public/test/test_browser_thread_bundle.h" |
| 28 #include "google_apis/gaia/google_service_auth_error.h" | 32 #include "google_apis/gaia/google_service_auth_error.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 58 make_scoped_ptr(fake_initializer_)); | 62 make_scoped_ptr(fake_initializer_)); |
| 59 | 63 |
| 60 // Set up FakeChromeUserManager. | 64 // Set up FakeChromeUserManager. |
| 61 fake_user_manager_->AddUser(kTestOwner); | 65 fake_user_manager_->AddUser(kTestOwner); |
| 62 fake_user_manager_->AddUser(kTestUser); | 66 fake_user_manager_->AddUser(kTestUser); |
| 63 fake_user_manager_->set_owner_email(kTestOwner); | 67 fake_user_manager_->set_owner_email(kTestOwner); |
| 64 } | 68 } |
| 65 | 69 |
| 66 void SetUp() override { | 70 void SetUp() override { |
| 67 ASSERT_TRUE(testing_profile_manager_->SetUp()); | 71 ASSERT_TRUE(testing_profile_manager_->SetUp()); |
| 68 profile_ = testing_profile_manager_->CreateTestingProfile(kTestUser); | 72 TestingProfile::TestingFactories factories; |
| 69 | 73 factories.push_back( |
| 70 // Set up FakeProfileOAuth2TokenService and issue a fake refresh token. | 74 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), |
| 71 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory( | 75 BuildAutoIssuingFakeProfileOAuth2TokenService)); |
| 72 profile_, &BuildAutoIssuingFakeProfileOAuth2TokenService); | 76 profile_ = testing_profile_manager_->CreateTestingProfile( |
| 73 GetFakeProfileOAuth2TokenService()-> | 77 kTestUser, scoped_ptr<PrefServiceSyncable>(), |
| 74 IssueRefreshTokenForUser(kTestOwner, "fake_token"); | 78 base::UTF8ToUTF16(kTestUser), 0, std::string(), factories); |
| 75 | 79 |
| 76 // Set up the authenticated user name and ID. | 80 // Set up the authenticated user name and ID. |
| 77 SigninManagerFactory::GetForProfile(profile_)-> | 81 SigninManagerFactory::GetForProfile(profile_) |
| 78 SetAuthenticatedUsername(kTestOwner); | 82 ->SetAuthenticatedAccountInfo(kTestOwner, kTestOwner); |
| 83 |
| 84 // Issue a fake refresh token. |
| 85 GetFakeProfileOAuth2TokenService()->IssueRefreshTokenForUser(kTestOwner, |
| 86 "fake_token"); |
| 79 } | 87 } |
| 80 | 88 |
| 81 FakeProfileOAuth2TokenService* GetFakeProfileOAuth2TokenService() { | 89 FakeProfileOAuth2TokenService* GetFakeProfileOAuth2TokenService() { |
| 82 return static_cast<FakeProfileOAuth2TokenService*>( | 90 return static_cast<FakeProfileOAuth2TokenService*>( |
| 83 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)); | 91 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)); |
| 84 } | 92 } |
| 85 | 93 |
| 86 void RunEnrollmentTest() { | 94 void RunEnrollmentTest() { |
| 87 handler_.reset( | 95 handler_.reset( |
| 88 new ConsumerEnrollmentHandler(profile_, fake_service_, NULL)); | 96 new ConsumerEnrollmentHandler(profile_, fake_service_, NULL)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 EnrollmentStatus::STATUS_REGISTRATION_FAILED)); | 147 EnrollmentStatus::STATUS_REGISTRATION_FAILED)); |
| 140 | 148 |
| 141 RunEnrollmentTest(); | 149 RunEnrollmentTest(); |
| 142 | 150 |
| 143 EXPECT_TRUE(fake_initializer_->was_start_enrollment_called()); | 151 EXPECT_TRUE(fake_initializer_->was_start_enrollment_called()); |
| 144 EXPECT_EQ(ConsumerManagementStage::EnrollmentDMServerFailed(), | 152 EXPECT_EQ(ConsumerManagementStage::EnrollmentDMServerFailed(), |
| 145 fake_service_->GetStage()); | 153 fake_service_->GetStage()); |
| 146 } | 154 } |
| 147 | 155 |
| 148 } // namespace policy | 156 } // namespace policy |
| OLD | NEW |