Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: chrome/browser/chromeos/policy/consumer_management_service_unittest.cc

Issue 493613002: Add an enrolling state for consumer management section in settings page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dn
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_management_service.h" 5 #include "chrome/browser/chromeos/policy/consumer_management_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/prefs/pref_registry_simple.h" 10 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/testing_pref_service.h" 11 #include "base/prefs/testing_pref_service.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/browser_process_platform_part.h" 14 #include "chrome/browser/browser_process_platform_part.h"
15 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" 16 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
19 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" 19 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h"
20 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" 20 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h"
21 #include "chrome/browser/chromeos/policy/fake_device_cloud_policy_initializer.h" 21 #include "chrome/browser/chromeos/policy/fake_device_cloud_policy_initializer.h"
22 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
22 #include "chrome/browser/notifications/notification_ui_manager.h" 23 #include "chrome/browser/notifications/notification_ui_manager.h"
23 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 25 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
25 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" 26 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
26 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 27 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
27 #include "chrome/browser/signin/signin_manager_factory.h" 28 #include "chrome/browser/signin/signin_manager_factory.h"
28 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
29 #include "chrome/test/base/browser_with_test_window_test.h" 30 #include "chrome/test/base/browser_with_test_window_test.h"
30 #include "chrome/test/base/testing_browser_process.h" 31 #include "chrome/test/base/testing_browser_process.h"
31 #include "chrome/test/base/testing_profile.h" 32 #include "chrome/test/base/testing_profile.h"
32 #include "chrome/test/base/testing_profile_manager.h" 33 #include "chrome/test/base/testing_profile_manager.h"
33 #include "chromeos/dbus/cryptohome/rpc.pb.h" 34 #include "chromeos/dbus/cryptohome/rpc.pb.h"
34 #include "chromeos/dbus/cryptohome_client.h" 35 #include "chromeos/dbus/cryptohome_client.h"
35 #include "chromeos/dbus/mock_cryptohome_client.h" 36 #include "chromeos/dbus/mock_cryptohome_client.h"
36 #include "components/policy/core/common/cloud/device_management_service.h" 37 #include "components/policy/core/common/cloud/device_management_service.h"
37 #include "components/signin/core/browser/profile_oauth2_token_service.h" 38 #include "components/signin/core/browser/profile_oauth2_token_service.h"
38 #include "components/signin/core/browser/signin_manager_base.h" 39 #include "components/signin/core/browser/signin_manager_base.h"
39 #include "content/public/browser/notification_details.h" 40 #include "content/public/browser/notification_details.h"
40 #include "content/public/browser/notification_source.h" 41 #include "content/public/browser/notification_source.h"
41 #include "google_apis/gaia/google_service_auth_error.h" 42 #include "google_apis/gaia/google_service_auth_error.h"
42 #include "policy/proto/device_management_backend.pb.h" 43 #include "policy/proto/device_management_backend.pb.h"
43 #include "testing/gmock/include/gmock/gmock.h" 44 #include "testing/gmock/include/gmock/gmock.h"
44 #include "testing/gtest/include/gtest/gtest.h" 45 #include "testing/gtest/include/gtest/gtest.h"
45 46
46 using testing::Invoke; 47 using testing::Invoke;
47 using testing::NiceMock; 48 using testing::NiceMock;
48 using testing::Return; 49 using testing::Return;
49 using testing::_; 50 using testing::_;
50 51
52 namespace em = enterprise_management;
53
51 namespace { 54 namespace {
52 const char* kAttributeOwnerId = "consumer_management.owner_id"; 55 const char* kAttributeOwnerId = "consumer_management.owner_id";
53 const char* kTestOwner = "test@chromium.org.test"; 56 const char* kTestOwner = "test@chromium.org.test";
54 } 57 }
55 58
56 namespace policy { 59 namespace policy {
57 60
58 class ConsumerManagementServiceTest : public BrowserWithTestWindowTest { 61 class ConsumerManagementServiceTest : public BrowserWithTestWindowTest {
59 public: 62 public:
60 ConsumerManagementServiceTest() 63 ConsumerManagementServiceTest()
61 : service_(new ConsumerManagementService(&mock_cryptohome_client_)), 64 : service_(new ConsumerManagementService(&mock_cryptohome_client_, NULL)),
62 cryptohome_result_(false), 65 cryptohome_result_(false),
63 set_owner_status_(false) { 66 set_owner_status_(false) {
64 ON_CALL(mock_cryptohome_client_, GetBootAttribute(_, _)) 67 ON_CALL(mock_cryptohome_client_, GetBootAttribute(_, _))
65 .WillByDefault( 68 .WillByDefault(
66 Invoke(this, &ConsumerManagementServiceTest::MockGetBootAttribute)); 69 Invoke(this, &ConsumerManagementServiceTest::MockGetBootAttribute));
67 ON_CALL(mock_cryptohome_client_, SetBootAttribute(_, _)) 70 ON_CALL(mock_cryptohome_client_, SetBootAttribute(_, _))
68 .WillByDefault( 71 .WillByDefault(
69 Invoke(this, &ConsumerManagementServiceTest::MockSetBootAttribute)); 72 Invoke(this, &ConsumerManagementServiceTest::MockSetBootAttribute));
70 ON_CALL(mock_cryptohome_client_, FlushAndSignBootAttributes(_, _)) 73 ON_CALL(mock_cryptohome_client_, FlushAndSignBootAttributes(_, _))
71 .WillByDefault( 74 .WillByDefault(
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 124 }
122 125
123 void OnGetOwnerDone(const std::string& owner) { 126 void OnGetOwnerDone(const std::string& owner) {
124 owner_ = owner; 127 owner_ = owner;
125 } 128 }
126 129
127 void OnSetOwnerDone(bool status) { 130 void OnSetOwnerDone(bool status) {
128 set_owner_status_ = status; 131 set_owner_status_ = status;
129 } 132 }
130 133
134 // Variables for building the service.
131 NiceMock<chromeos::MockCryptohomeClient> mock_cryptohome_client_; 135 NiceMock<chromeos::MockCryptohomeClient> mock_cryptohome_client_;
132 scoped_ptr<ConsumerManagementService> service_; 136 scoped_ptr<ConsumerManagementService> service_;
133 137
134 scoped_ptr<TestingProfileManager> testing_profile_manager_; 138 scoped_ptr<TestingProfileManager> testing_profile_manager_;
139
140 // Variables for setting the return value or catching the arguments of mock
141 // functions.
135 chromeos::DBusMethodCallStatus cryptohome_status_; 142 chromeos::DBusMethodCallStatus cryptohome_status_;
136 bool cryptohome_result_; 143 bool cryptohome_result_;
137 cryptohome::BaseReply cryptohome_reply_; 144 cryptohome::BaseReply cryptohome_reply_;
138 cryptohome::GetBootAttributeRequest get_boot_attribute_request_; 145 cryptohome::GetBootAttributeRequest get_boot_attribute_request_;
139 cryptohome::SetBootAttributeRequest set_boot_attribute_request_; 146 cryptohome::SetBootAttributeRequest set_boot_attribute_request_;
140
141 std::string owner_; 147 std::string owner_;
142 bool set_owner_status_; 148 bool set_owner_status_;
143 }; 149 };
144 150
145 TEST_F(ConsumerManagementServiceTest, CanGetEnrollmentState) { 151 TEST_F(ConsumerManagementServiceTest, CanGetEnrollmentState) {
146 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_NONE, 152 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_NONE,
147 service_->GetEnrollmentState()); 153 service_->GetEnrollmentState());
148 154
149 SetEnrollmentState(ConsumerManagementService::ENROLLMENT_REQUESTED); 155 SetEnrollmentState(ConsumerManagementService::ENROLLMENT_REQUESTED);
150 156
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 cryptohome_status_ = chromeos::DBUS_METHOD_CALL_FAILURE; 209 cryptohome_status_ = chromeos::DBUS_METHOD_CALL_FAILURE;
204 cryptohome_result_ = false; 210 cryptohome_result_ = false;
205 211
206 service_->SetOwner(kTestOwner, 212 service_->SetOwner(kTestOwner,
207 base::Bind(&ConsumerManagementServiceTest::OnSetOwnerDone, 213 base::Bind(&ConsumerManagementServiceTest::OnSetOwnerDone,
208 base::Unretained(this))); 214 base::Unretained(this)));
209 215
210 EXPECT_FALSE(set_owner_status_); 216 EXPECT_FALSE(set_owner_status_);
211 } 217 }
212 218
219 TEST_F(ConsumerManagementServiceTest, IsEnrollingWorks) {
220 SetEnrollmentState(ConsumerManagementService::ENROLLMENT_NONE);
221 EXPECT_FALSE(service_->IsEnrolling());
222
223 SetEnrollmentState(ConsumerManagementService::ENROLLMENT_REQUESTED);
224 EXPECT_TRUE(service_->IsEnrolling());
225
226 SetEnrollmentState(ConsumerManagementService::ENROLLMENT_OWNER_STORED);
227 EXPECT_TRUE(service_->IsEnrolling());
228
229 SetEnrollmentState(ConsumerManagementService::ENROLLMENT_SUCCESS);
230 EXPECT_FALSE(service_->IsEnrolling());
231
232 SetEnrollmentState(ConsumerManagementService::ENROLLMENT_CANCELED);
233 EXPECT_FALSE(service_->IsEnrolling());
234 }
235
236 class ConsumerManagementServiceSettingsTest
237 : public chromeos::DeviceSettingsTestBase {
238 public:
239 ConsumerManagementServiceSettingsTest()
240 : service_(new ConsumerManagementService(
241 NULL, &device_settings_service_)) {
242 }
243
244 void SetManagementMode(em::PolicyData::ManagementMode mode) {
245 device_policy_.policy_data().set_management_mode(mode);
bartfab (slow) 2014/08/20 14:40:02 Nit: #include "chrome/browser/chromeos/policy/devi
davidyu 2014/08/21 09:40:29 Done.
246 device_policy_.Build();
247 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
248 ReloadDeviceSettings();
249 }
250
251 NiceMock<chromeos::MockCryptohomeClient> mock_cryptohome_client_;
252 scoped_ptr<ConsumerManagementService> service_;
bartfab (slow) 2014/08/20 14:40:02 Nit: #include "base/memory/scoped_ptr.h"
davidyu 2014/08/21 09:40:29 Done.
253 };
254
255 TEST_F(ConsumerManagementServiceSettingsTest, IsEnrolledWorks) {
256 SetManagementMode(em::PolicyData::NOT_MANAGED);
257 EXPECT_FALSE(service_->IsEnrolled());
258
259 SetManagementMode(em::PolicyData::ENTERPRISE_MANAGED);
260 EXPECT_FALSE(service_->IsEnrolled());
261
262 SetManagementMode(em::PolicyData::CONSUMER_MANAGED);
263 EXPECT_TRUE(service_->IsEnrolled());
264 }
265
213 class ConsumerManagementServiceEnrollmentTest 266 class ConsumerManagementServiceEnrollmentTest
214 : public ConsumerManagementServiceTest { 267 : public ConsumerManagementServiceTest {
215 public: 268 public:
216 ConsumerManagementServiceEnrollmentTest() 269 ConsumerManagementServiceEnrollmentTest()
217 : mock_user_manager_(new NiceMock<chromeos::MockUserManager>()), 270 : mock_user_manager_(new NiceMock<chromeos::MockUserManager>()),
218 scoped_user_manager_enabler_(mock_user_manager_), 271 scoped_user_manager_enabler_(mock_user_manager_),
219 fake_initializer_(new FakeDeviceCloudPolicyInitializer()), 272 fake_initializer_(new FakeDeviceCloudPolicyInitializer()),
220 enrollment_status_(EnrollmentStatus::ForStatus( 273 enrollment_status_(EnrollmentStatus::ForStatus(
221 EnrollmentStatus::STATUS_SUCCESS)) { 274 EnrollmentStatus::STATUS_SUCCESS)) {
222 // Set up MockUserManager. The first user will be the owner. 275 // Set up MockUserManager. The first user will be the owner.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 EXPECT_FALSE(HasEnrollmentNotification()); 407 EXPECT_FALSE(HasEnrollmentNotification());
355 408
356 RunEnrollmentTest(); 409 RunEnrollmentTest();
357 410
358 EXPECT_FALSE(fake_initializer_->is_start_enrollment_called()); 411 EXPECT_FALSE(fake_initializer_->is_start_enrollment_called());
359 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_NONE, GetEnrollmentState()); 412 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_NONE, GetEnrollmentState());
360 EXPECT_TRUE(HasEnrollmentNotification()); 413 EXPECT_TRUE(HasEnrollmentNotification());
361 } 414 }
362 415
363 } // namespace policy 416 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698