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_management_notification_factor
y.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_user_manager.h" | 9 #include "chrome/browser/chromeos/login/users/fake_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" |
11 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 11 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 12 #include "chrome/browser/chromeos/policy/consumer_management_notification.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/fake_consumer_management_service.h" | 14 #include "chrome/browser/chromeos/policy/fake_consumer_management_service.h" |
14 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
15 #include "chrome/test/base/testing_profile_manager.h" | 16 #include "chrome/test/base/testing_profile_manager.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 const char* kTestOwner = "test.owner@chromium.org.test"; | 20 const char* kTestOwner = "test.owner@chromium.org.test"; |
20 const char* kTestUser = "test.user@chromium.org.test"; | 21 const char* kTestUser = "test.user@chromium.org.test"; |
21 } | 22 } |
22 | 23 |
23 namespace policy { | 24 namespace policy { |
24 | 25 |
25 class ConsumerEnrollmentHandlerFactoryTest : public testing::Test { | 26 class ConsumerManagementNotificationFactoryTest : public testing::Test { |
26 public: | 27 public: |
27 ConsumerEnrollmentHandlerFactoryTest() | 28 ConsumerManagementNotificationFactoryTest() |
28 : fake_service_(new FakeConsumerManagementService()), | 29 : fake_service_(new FakeConsumerManagementService()), |
29 fake_user_manager_(new chromeos::FakeUserManager()), | 30 fake_user_manager_(new chromeos::FakeUserManager()), |
30 scoped_user_manager_enabler_(fake_user_manager_), | 31 scoped_user_manager_enabler_(fake_user_manager_), |
31 testing_profile_manager_(new TestingProfileManager( | 32 testing_profile_manager_(new TestingProfileManager( |
32 TestingBrowserProcess::GetGlobal())) { | 33 TestingBrowserProcess::GetGlobal())) { |
33 // Set up FakeConsumerManagementService. | 34 // Set up FakeConsumerManagementService. |
34 fake_service_->set_status(ConsumerManagementService::STATUS_ENROLLING); | 35 fake_service_->SetStatusAndEnrollmentStage( |
35 fake_service_->SetEnrollmentStage( | 36 ConsumerManagementService::STATUS_UNENROLLED, |
36 ConsumerManagementService::ENROLLMENT_STAGE_OWNER_STORED); | 37 ConsumerManagementService::ENROLLMENT_STAGE_NONE); |
37 | 38 |
38 // Inject fake objects. | 39 // Inject fake objects. |
39 BrowserPolicyConnectorChromeOS* connector = | 40 BrowserPolicyConnectorChromeOS* connector = |
40 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 41 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
41 connector->SetConsumerManagementServiceForTesting( | 42 connector->SetConsumerManagementServiceForTesting( |
42 make_scoped_ptr(fake_service_)); | 43 make_scoped_ptr(fake_service_)); |
43 | 44 |
44 // Set up FakeUserManager. | 45 // Set up FakeUserManager. |
45 fake_user_manager_->AddUser(kTestOwner); | 46 fake_user_manager_->AddUser(kTestOwner); |
46 fake_user_manager_->AddUser(kTestUser); | 47 fake_user_manager_->AddUser(kTestUser); |
47 fake_user_manager_->set_owner_email(kTestOwner); | 48 fake_user_manager_->set_owner_email(kTestOwner); |
48 } | 49 } |
49 | 50 |
50 virtual void SetUp() override { | 51 virtual void SetUp() override { |
51 ASSERT_TRUE(testing_profile_manager_->SetUp()); | 52 ASSERT_TRUE(testing_profile_manager_->SetUp()); |
52 } | 53 } |
53 | 54 |
54 FakeConsumerManagementService* fake_service_; | 55 FakeConsumerManagementService* fake_service_; |
55 chromeos::FakeUserManager* fake_user_manager_; | 56 chromeos::FakeUserManager* fake_user_manager_; |
56 chromeos::ScopedUserManagerEnabler scoped_user_manager_enabler_; | 57 chromeos::ScopedUserManagerEnabler scoped_user_manager_enabler_; |
57 scoped_ptr<TestingProfileManager> testing_profile_manager_; | 58 scoped_ptr<TestingProfileManager> testing_profile_manager_; |
58 }; | 59 }; |
59 | 60 |
60 TEST_F(ConsumerEnrollmentHandlerFactoryTest, ServiceIsCreated) { | 61 TEST_F(ConsumerManagementNotificationFactoryTest, ServiceIsCreated) { |
61 Profile* profile = testing_profile_manager_->CreateTestingProfile(kTestOwner); | 62 Profile* profile = testing_profile_manager_->CreateTestingProfile(kTestOwner); |
62 EXPECT_TRUE(ConsumerEnrollmentHandlerFactory::GetForBrowserContext(profile)); | 63 EXPECT_TRUE( |
| 64 ConsumerManagementNotificationFactory::GetForBrowserContext(profile)); |
63 } | 65 } |
64 | 66 |
65 TEST_F(ConsumerEnrollmentHandlerFactoryTest, ServiceIsNotCreatedForNonOwner) { | 67 TEST_F(ConsumerManagementNotificationFactoryTest, |
| 68 ServiceIsNotCreatedForNonOwner) { |
66 Profile* profile = testing_profile_manager_->CreateTestingProfile(kTestUser); | 69 Profile* profile = testing_profile_manager_->CreateTestingProfile(kTestUser); |
67 EXPECT_FALSE(ConsumerEnrollmentHandlerFactory::GetForBrowserContext(profile)); | 70 EXPECT_FALSE( |
68 } | 71 ConsumerManagementNotificationFactory::GetForBrowserContext(profile)); |
69 | |
70 TEST_F(ConsumerEnrollmentHandlerFactoryTest, | |
71 ServiceIsNotCreatedIfItHasNothingToDo) { | |
72 fake_service_->set_status(ConsumerManagementService::STATUS_UNENROLLED); | |
73 fake_service_->SetEnrollmentStage( | |
74 ConsumerManagementService::ENROLLMENT_STAGE_NONE); | |
75 | |
76 Profile* profile = testing_profile_manager_->CreateTestingProfile(kTestOwner); | |
77 EXPECT_FALSE(ConsumerEnrollmentHandlerFactory::GetForBrowserContext(profile)); | |
78 } | 72 } |
79 | 73 |
80 } // namespace policy | 74 } // namespace policy |
OLD | NEW |