Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / consumer_enrollment_handler_factory_unittest.cc
blobb1c209d798332437f69d598d32c98c54afb79cf6
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.
5 #include "chrome/browser/chromeos/policy/consumer_enrollment_handler_factory.h"
7 #include "chrome/browser/browser_process.h"
8 #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/scoped_user_manager_enabler.h"
11 #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_stage.h"
14 #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_profile_manager.h"
17 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "testing/gtest/include/gtest/gtest.h"
20 namespace {
21 const char* kTestOwner = "test.owner@chromium.org.test";
22 const char* kTestUser = "test.user@chromium.org.test";
25 namespace policy {
27 class ConsumerEnrollmentHandlerFactoryTest : public testing::Test {
28 public:
29 ConsumerEnrollmentHandlerFactoryTest()
30 : fake_service_(new FakeConsumerManagementService()),
31 fake_user_manager_(new chromeos::FakeChromeUserManager()),
32 scoped_user_manager_enabler_(fake_user_manager_),
33 testing_profile_manager_(
34 new TestingProfileManager(TestingBrowserProcess::GetGlobal())) {
35 // Set up FakeConsumerManagementService.
36 fake_service_->SetStatusAndStage(
37 ConsumerManagementService::STATUS_ENROLLING,
38 ConsumerManagementStage::EnrollmentOwnerStored());
40 // Inject fake objects.
41 BrowserPolicyConnectorChromeOS* connector =
42 g_browser_process->platform_part()->browser_policy_connector_chromeos();
43 connector->SetConsumerManagementServiceForTesting(
44 make_scoped_ptr(fake_service_));
46 // Set up FakeChromeUserManager.
47 fake_user_manager_->AddUser(kTestOwner);
48 fake_user_manager_->AddUser(kTestUser);
49 fake_user_manager_->set_owner_email(kTestOwner);
52 void SetUp() override {
53 ASSERT_TRUE(testing_profile_manager_->SetUp());
56 content::TestBrowserThreadBundle thread_bundle_;
57 FakeConsumerManagementService* fake_service_;
58 chromeos::FakeChromeUserManager* fake_user_manager_;
59 chromeos::ScopedUserManagerEnabler scoped_user_manager_enabler_;
60 scoped_ptr<TestingProfileManager> testing_profile_manager_;
63 TEST_F(ConsumerEnrollmentHandlerFactoryTest, ServiceIsCreated) {
64 Profile* profile = testing_profile_manager_->CreateTestingProfile(kTestOwner);
65 EXPECT_TRUE(ConsumerEnrollmentHandlerFactory::GetForBrowserContext(profile));
68 TEST_F(ConsumerEnrollmentHandlerFactoryTest, ServiceIsNotCreatedForNonOwner) {
69 Profile* profile = testing_profile_manager_->CreateTestingProfile(kTestUser);
70 EXPECT_FALSE(ConsumerEnrollmentHandlerFactory::GetForBrowserContext(profile));
73 TEST_F(ConsumerEnrollmentHandlerFactoryTest,
74 ServiceIsNotCreatedIfItHasNothingToDo) {
75 fake_service_->SetStatusAndStage(
76 ConsumerManagementService::STATUS_UNENROLLED,
77 ConsumerManagementStage::None());
79 Profile* profile = testing_profile_manager_->CreateTestingProfile(kTestOwner);
80 EXPECT_FALSE(ConsumerEnrollmentHandlerFactory::GetForBrowserContext(profile));
83 } // namespace policy