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