Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / consumer_enrollment_handler_factory_unittest.cc
blob8e56c1973d8057b117b6fd8b9002ec3e20b50583
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 "testing/gtest/include/gtest/gtest.h"
19 namespace {
20 const char* kTestOwner = "test.owner@chromium.org.test";
21 const char* kTestUser = "test.user@chromium.org.test";
24 namespace policy {
26 class ConsumerEnrollmentHandlerFactoryTest : public testing::Test {
27 public:
28 ConsumerEnrollmentHandlerFactoryTest()
29 : fake_service_(new FakeConsumerManagementService()),
30 fake_user_manager_(new chromeos::FakeChromeUserManager()),
31 scoped_user_manager_enabler_(fake_user_manager_),
32 testing_profile_manager_(
33 new TestingProfileManager(TestingBrowserProcess::GetGlobal())) {
34 // Set up FakeConsumerManagementService.
35 fake_service_->SetStatusAndStage(
36 ConsumerManagementService::STATUS_ENROLLING,
37 ConsumerManagementStage::EnrollmentOwnerStored());
39 // Inject fake objects.
40 BrowserPolicyConnectorChromeOS* connector =
41 g_browser_process->platform_part()->browser_policy_connector_chromeos();
42 connector->SetConsumerManagementServiceForTesting(
43 make_scoped_ptr(fake_service_));
45 // Set up FakeChromeUserManager.
46 fake_user_manager_->AddUser(kTestOwner);
47 fake_user_manager_->AddUser(kTestUser);
48 fake_user_manager_->set_owner_email(kTestOwner);
51 void SetUp() override {
52 ASSERT_TRUE(testing_profile_manager_->SetUp());
55 FakeConsumerManagementService* fake_service_;
56 chromeos::FakeChromeUserManager* fake_user_manager_;
57 chromeos::ScopedUserManagerEnabler scoped_user_manager_enabler_;
58 scoped_ptr<TestingProfileManager> testing_profile_manager_;
61 TEST_F(ConsumerEnrollmentHandlerFactoryTest, ServiceIsCreated) {
62 Profile* profile = testing_profile_manager_->CreateTestingProfile(kTestOwner);
63 EXPECT_TRUE(ConsumerEnrollmentHandlerFactory::GetForBrowserContext(profile));
66 TEST_F(ConsumerEnrollmentHandlerFactoryTest, ServiceIsNotCreatedForNonOwner) {
67 Profile* profile = testing_profile_manager_->CreateTestingProfile(kTestUser);
68 EXPECT_FALSE(ConsumerEnrollmentHandlerFactory::GetForBrowserContext(profile));
71 TEST_F(ConsumerEnrollmentHandlerFactoryTest,
72 ServiceIsNotCreatedIfItHasNothingToDo) {
73 fake_service_->SetStatusAndStage(
74 ConsumerManagementService::STATUS_UNENROLLED,
75 ConsumerManagementStage::None());
77 Profile* profile = testing_profile_manager_->CreateTestingProfile(kTestOwner);
78 EXPECT_FALSE(ConsumerEnrollmentHandlerFactory::GetForBrowserContext(profile));
81 } // namespace policy