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