Chromium Code Reviews| 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_unenrollment_handler.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/message_loop/message_loop_proxy.h" | |
| 11 #include "chrome/browser/chromeos/policy/consumer_management_service.h" | |
| 12 #include "chrome/browser/chromeos/policy/consumer_management_stage.h" | |
| 13 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" | |
| 14 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | |
| 15 #include "chrome/browser/chromeos/policy/fake_consumer_management_service.h" | |
| 16 #include "chrome/browser/chromeos/policy/fake_device_cloud_policy_manager.h" | |
| 17 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | |
| 18 #include "chromeos/dbus/fake_cryptohome_client.h" | |
| 19 #include "components/ownership/mock_owner_key_util.h" | |
| 20 #include "policy/proto/device_management_backend.pb.h" | |
| 21 #include "testing/gtest/include/gtest/gtest.h" | |
| 22 | |
| 23 namespace policy { | |
| 24 | |
| 25 class ConsumerUnenrollmentHandlerTest | |
| 26 : public chromeos::DeviceSettingsTestBase { | |
| 27 public: | |
| 28 ConsumerUnenrollmentHandlerTest() | |
| 29 : fake_service_(new FakeConsumerManagementService()), | |
| 30 fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()), | |
| 31 install_attributes_( | |
| 32 new EnterpriseInstallAttributes(fake_cryptohome_client_)) { | |
| 33 // Set up FakeConsumerManagementService. | |
| 34 fake_service_->SetStatusAndStage( | |
| 35 ConsumerManagementService::STATUS_ENROLLED, | |
| 36 ConsumerManagementStage(ConsumerManagementStage::NONE)); | |
| 37 | |
| 38 } | |
| 39 | |
| 40 void SetUp() override { | |
| 41 DeviceSettingsTestBase::SetUp(); | |
| 42 | |
| 43 // Set up the ownership, so that we can modify device settings. | |
| 44 owner_key_util_->SetPrivateKey(device_policy_.GetSigningKey()); | |
| 45 InitOwner(device_policy_.policy_data().username(), true); | |
| 46 FlushDeviceSettings(); | |
| 47 | |
| 48 // Set up DeviceSettingsService. | |
| 49 device_settings_service_.SetManagementSettings( | |
| 50 enterprise_management::PolicyData::CONSUMER_MANAGED, | |
| 51 "fake_request_token", | |
| 52 "fake_device_id", | |
| 53 base::Bind(&ConsumerUnenrollmentHandlerTest::OnManagementSettingsSet, | |
| 54 base::Unretained(this))); | |
| 55 FlushDeviceSettings(); | |
| 56 | |
| 57 // Set up FakeDeviceCloudPolicyManager. | |
| 58 scoped_ptr<DeviceCloudPolicyStoreChromeOS> store_( | |
| 59 new DeviceCloudPolicyStoreChromeOS( | |
| 60 &device_settings_service_, | |
| 61 install_attributes_.get(), | |
| 62 base::MessageLoopProxy::current())); | |
|
bartfab (slow)
2014/11/28 13:25:18
Nit: Here and below: MessageLoopProxy is deprecate
davidyu
2014/12/01 17:05:22
Done.
| |
| 63 fake_manager_.reset(new FakeDeviceCloudPolicyManager( | |
| 64 store_.Pass(), | |
| 65 base::MessageLoopProxy::current())); | |
| 66 } | |
| 67 | |
| 68 void OnManagementSettingsSet() { | |
| 69 EXPECT_EQ(chromeos::DeviceSettingsService::STORE_SUCCESS, | |
|
bartfab (slow)
2014/11/28 13:25:18
Nit: #include "chrome/browser/chromeos/settings/de
davidyu
2014/12/01 17:05:22
Done.
| |
| 70 device_settings_service_.status()); | |
| 71 } | |
| 72 | |
| 73 void RunUnenrollment() { | |
| 74 handler_.reset(new ConsumerUnenrollmentHandler( | |
| 75 &device_settings_service_, | |
| 76 fake_service_.get(), | |
| 77 fake_manager_.get())); | |
| 78 handler_->Start(); | |
| 79 FlushDeviceSettings(); | |
| 80 } | |
| 81 | |
| 82 scoped_ptr<FakeConsumerManagementService> fake_service_; | |
| 83 chromeos::FakeCryptohomeClient* fake_cryptohome_client_; | |
| 84 scoped_ptr<EnterpriseInstallAttributes> install_attributes_; | |
| 85 scoped_ptr<FakeDeviceCloudPolicyManager> fake_manager_; | |
| 86 | |
| 87 scoped_ptr<ConsumerUnenrollmentHandler> handler_; | |
| 88 }; | |
| 89 | |
| 90 TEST_F(ConsumerUnenrollmentHandlerTest, UnenrollmentSucceeds) { | |
| 91 EXPECT_EQ(ConsumerManagementStage::NONE, fake_service_->GetStage().value()); | |
| 92 | |
| 93 RunUnenrollment(); | |
| 94 | |
| 95 EXPECT_EQ(ConsumerManagementStage::UNENROLLMENT_SUCCESS, | |
| 96 fake_service_->GetStage().value()); | |
| 97 EXPECT_EQ(enterprise_management::PolicyData::LOCAL_OWNER, | |
| 98 device_settings_service_.policy_data()->management_mode()); | |
| 99 EXPECT_FALSE(device_settings_service_.policy_data()->has_request_token()); | |
| 100 EXPECT_FALSE(device_settings_service_.policy_data()->has_device_id()); | |
| 101 } | |
| 102 | |
| 103 TEST_F(ConsumerUnenrollmentHandlerTest, | |
| 104 UnenrollmentFailsOnServerError) { | |
| 105 EXPECT_EQ(ConsumerManagementStage::NONE, fake_service_->GetStage().value()); | |
| 106 fake_manager_->set_unregister_result(false); | |
| 107 | |
| 108 RunUnenrollment(); | |
| 109 | |
| 110 EXPECT_EQ(ConsumerManagementStage::UNENROLLMENT_DM_SERVER_FAILED, | |
| 111 fake_service_->GetStage().value()); | |
| 112 EXPECT_EQ(enterprise_management::PolicyData::CONSUMER_MANAGED, | |
| 113 device_settings_service_.policy_data()->management_mode()); | |
| 114 EXPECT_EQ("fake_request_token", | |
| 115 device_settings_service_.policy_data()->request_token()); | |
| 116 EXPECT_EQ("fake_device_id", | |
| 117 device_settings_service_.policy_data()->device_id()); | |
| 118 } | |
| 119 | |
| 120 } // namespace policy | |
| OLD | NEW |