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_factory.h" | 5 #include "chrome/browser/chromeos/policy/consumer_enrollment_handler_factory.h" |
6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
7 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/browser_process_platform_part.h" | 9 #include "chrome/browser/browser_process_platform_part.h" |
9 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 10 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
10 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 11 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
11 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 12 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
12 #include "chrome/browser/chromeos/policy/consumer_management_service.h" | 13 #include "chrome/browser/chromeos/policy/consumer_management_service.h" |
13 #include "chrome/browser/chromeos/policy/consumer_management_stage.h" | 14 #include "chrome/browser/chromeos/policy/consumer_management_stage.h" |
14 #include "chrome/browser/chromeos/policy/fake_consumer_management_service.h" | 15 #include "chrome/browser/chromeos/policy/fake_consumer_management_service.h" |
15 #include "chrome/test/base/testing_browser_process.h" | 16 #include "chrome/test/base/testing_browser_process.h" |
16 #include "chrome/test/base/testing_profile_manager.h" | 17 #include "chrome/test/base/testing_profile_manager.h" |
(...skipping 17 matching lines...) Expand all Loading... |
34 new TestingProfileManager(TestingBrowserProcess::GetGlobal())) { | 35 new TestingProfileManager(TestingBrowserProcess::GetGlobal())) { |
35 // Set up FakeConsumerManagementService. | 36 // Set up FakeConsumerManagementService. |
36 fake_service_->SetStatusAndStage( | 37 fake_service_->SetStatusAndStage( |
37 ConsumerManagementService::STATUS_ENROLLING, | 38 ConsumerManagementService::STATUS_ENROLLING, |
38 ConsumerManagementStage::EnrollmentOwnerStored()); | 39 ConsumerManagementStage::EnrollmentOwnerStored()); |
39 | 40 |
40 // Inject fake objects. | 41 // Inject fake objects. |
41 BrowserPolicyConnectorChromeOS* connector = | 42 BrowserPolicyConnectorChromeOS* connector = |
42 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 43 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
43 connector->SetConsumerManagementServiceForTesting( | 44 connector->SetConsumerManagementServiceForTesting( |
44 make_scoped_ptr(fake_service_)); | 45 base::WrapUnique(fake_service_)); |
45 | 46 |
46 // Set up FakeChromeUserManager. | 47 // Set up FakeChromeUserManager. |
47 fake_user_manager_->AddUser(owner_account_id); | 48 fake_user_manager_->AddUser(owner_account_id); |
48 fake_user_manager_->AddUser(test_account_id); | 49 fake_user_manager_->AddUser(test_account_id); |
49 fake_user_manager_->set_owner_id(owner_account_id); | 50 fake_user_manager_->set_owner_id(owner_account_id); |
50 } | 51 } |
51 | 52 |
52 void SetUp() override { | 53 void SetUp() override { |
53 testing::Test::SetUp(); | 54 testing::Test::SetUp(); |
54 | 55 |
55 ASSERT_TRUE(testing_profile_manager_->SetUp()); | 56 ASSERT_TRUE(testing_profile_manager_->SetUp()); |
56 } | 57 } |
57 | 58 |
58 const AccountId owner_account_id = AccountId::FromUserEmail(kTestOwner); | 59 const AccountId owner_account_id = AccountId::FromUserEmail(kTestOwner); |
59 const AccountId test_account_id = AccountId::FromUserEmail(kTestUser); | 60 const AccountId test_account_id = AccountId::FromUserEmail(kTestUser); |
60 | 61 |
61 content::TestBrowserThreadBundle thread_bundle_; | 62 content::TestBrowserThreadBundle thread_bundle_; |
62 FakeConsumerManagementService* fake_service_; | 63 FakeConsumerManagementService* fake_service_; |
63 chromeos::FakeChromeUserManager* fake_user_manager_; | 64 chromeos::FakeChromeUserManager* fake_user_manager_; |
64 chromeos::ScopedUserManagerEnabler scoped_user_manager_enabler_; | 65 chromeos::ScopedUserManagerEnabler scoped_user_manager_enabler_; |
65 scoped_ptr<TestingProfileManager> testing_profile_manager_; | 66 std::unique_ptr<TestingProfileManager> testing_profile_manager_; |
66 }; | 67 }; |
67 | 68 |
68 TEST_F(ConsumerEnrollmentHandlerFactoryTest, ServiceIsCreated) { | 69 TEST_F(ConsumerEnrollmentHandlerFactoryTest, ServiceIsCreated) { |
69 Profile* profile = testing_profile_manager_->CreateTestingProfile( | 70 Profile* profile = testing_profile_manager_->CreateTestingProfile( |
70 owner_account_id.GetUserEmail()); | 71 owner_account_id.GetUserEmail()); |
71 EXPECT_TRUE(ConsumerEnrollmentHandlerFactory::GetForBrowserContext(profile)); | 72 EXPECT_TRUE(ConsumerEnrollmentHandlerFactory::GetForBrowserContext(profile)); |
72 } | 73 } |
73 | 74 |
74 TEST_F(ConsumerEnrollmentHandlerFactoryTest, ServiceIsNotCreatedForNonOwner) { | 75 TEST_F(ConsumerEnrollmentHandlerFactoryTest, ServiceIsNotCreatedForNonOwner) { |
75 Profile* profile = testing_profile_manager_->CreateTestingProfile(kTestUser); | 76 Profile* profile = testing_profile_manager_->CreateTestingProfile(kTestUser); |
76 EXPECT_FALSE(ConsumerEnrollmentHandlerFactory::GetForBrowserContext(profile)); | 77 EXPECT_FALSE(ConsumerEnrollmentHandlerFactory::GetForBrowserContext(profile)); |
77 } | 78 } |
78 | 79 |
79 TEST_F(ConsumerEnrollmentHandlerFactoryTest, | 80 TEST_F(ConsumerEnrollmentHandlerFactoryTest, |
80 ServiceIsNotCreatedIfItHasNothingToDo) { | 81 ServiceIsNotCreatedIfItHasNothingToDo) { |
81 fake_service_->SetStatusAndStage( | 82 fake_service_->SetStatusAndStage( |
82 ConsumerManagementService::STATUS_UNENROLLED, | 83 ConsumerManagementService::STATUS_UNENROLLED, |
83 ConsumerManagementStage::None()); | 84 ConsumerManagementStage::None()); |
84 | 85 |
85 Profile* profile = testing_profile_manager_->CreateTestingProfile(kTestOwner); | 86 Profile* profile = testing_profile_manager_->CreateTestingProfile(kTestOwner); |
86 EXPECT_FALSE(ConsumerEnrollmentHandlerFactory::GetForBrowserContext(profile)); | 87 EXPECT_FALSE(ConsumerEnrollmentHandlerFactory::GetForBrowserContext(profile)); |
87 } | 88 } |
88 | 89 |
89 } // namespace policy | 90 } // namespace policy |
OLD | NEW |