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

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

Issue 751703003: Implemented consumer management unenrollment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dcpm
Patch Set: Created 5 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/device_cloud_policy_manager_chromeos.h" 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 21 matching lines...) Expand all
32 #include "chrome/test/base/testing_profile.h" 32 #include "chrome/test/base/testing_profile.h"
33 #include "chromeos/cryptohome/system_salt_getter.h" 33 #include "chromeos/cryptohome/system_salt_getter.h"
34 #include "chromeos/dbus/dbus_client_implementation_type.h" 34 #include "chromeos/dbus/dbus_client_implementation_type.h"
35 #include "chromeos/dbus/dbus_thread_manager.h" 35 #include "chromeos/dbus/dbus_thread_manager.h"
36 #include "chromeos/dbus/fake_cryptohome_client.h" 36 #include "chromeos/dbus/fake_cryptohome_client.h"
37 #include "chromeos/dbus/fake_session_manager_client.h" 37 #include "chromeos/dbus/fake_session_manager_client.h"
38 #include "chromeos/system/fake_statistics_provider.h" 38 #include "chromeos/system/fake_statistics_provider.h"
39 #include "chromeos/system/statistics_provider.h" 39 #include "chromeos/system/statistics_provider.h"
40 #include "components/policy/core/common/cloud/cloud_policy_client.h" 40 #include "components/policy/core/common/cloud/cloud_policy_client.h"
41 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 41 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
42 #include "components/policy/core/common/cloud/cloud_policy_core.h"
42 #include "components/policy/core/common/cloud/mock_device_management_service.h" 43 #include "components/policy/core/common/cloud/mock_device_management_service.h"
43 #include "components/policy/core/common/external_data_fetcher.h" 44 #include "components/policy/core/common/external_data_fetcher.h"
44 #include "components/policy/core/common/schema_registry.h" 45 #include "components/policy/core/common/schema_registry.h"
45 #include "google_apis/gaia/gaia_oauth_client.h" 46 #include "google_apis/gaia/gaia_oauth_client.h"
46 #include "net/url_request/test_url_fetcher_factory.h" 47 #include "net/url_request/test_url_fetcher_factory.h"
47 #include "net/url_request/url_request_test_util.h" 48 #include "net/url_request/url_request_test_util.h"
48 #include "policy/policy_constants.h" 49 #include "policy/policy_constants.h"
49 #include "policy/proto/device_management_backend.pb.h" 50 #include "policy/proto/device_management_backend.pb.h"
50 #include "testing/gmock/include/gmock/gmock.h" 51 #include "testing/gmock/include/gmock/gmock.h"
51 #include "testing/gtest/include/gtest/gtest.h" 52 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 191 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
191 .Set(key::kDeviceMetricsReportingEnabled, 192 .Set(key::kDeviceMetricsReportingEnabled,
192 POLICY_LEVEL_MANDATORY, 193 POLICY_LEVEL_MANDATORY,
193 POLICY_SCOPE_MACHINE, 194 POLICY_SCOPE_MACHINE,
194 new base::FundamentalValue(false), 195 new base::FundamentalValue(false),
195 NULL); 196 NULL);
196 EXPECT_TRUE(manager_->policies().Equals(bundle)); 197 EXPECT_TRUE(manager_->policies().Equals(bundle));
197 } 198 }
198 199
199 MOCK_METHOD0(OnDeviceCloudPolicyManagerConnected, void()); 200 MOCK_METHOD0(OnDeviceCloudPolicyManagerConnected, void());
201 MOCK_METHOD0(OnDeviceCloudPolicyManagerDisconnected, void());
200 202
201 scoped_ptr<EnterpriseInstallAttributes> install_attributes_; 203 scoped_ptr<EnterpriseInstallAttributes> install_attributes_;
202 204
203 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 205 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
204 net::TestURLFetcherFactory url_fetcher_factory_; 206 net::TestURLFetcherFactory url_fetcher_factory_;
205 int url_fetcher_response_code_; 207 int url_fetcher_response_code_;
206 std::string url_fetcher_response_string_; 208 std::string url_fetcher_response_string_;
207 TestingPrefServiceSimple local_state_; 209 TestingPrefServiceSimple local_state_;
208 MockDeviceManagementService device_management_service_; 210 MockDeviceManagementService device_management_service_;
209 MockDeviceManagementService consumer_device_management_service_; 211 MockDeviceManagementService consumer_device_management_service_;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 321
320 ConnectManager(); 322 ConnectManager();
321 EXPECT_TRUE(manager_->policies().Equals(bundle)); 323 EXPECT_TRUE(manager_->policies().Equals(bundle));
322 // Should not create a status provider for reporting on consumer devices. 324 // Should not create a status provider for reporting on consumer devices.
323 EXPECT_FALSE(manager_->HasStatusProvider()); 325 EXPECT_FALSE(manager_->HasStatusProvider());
324 326
325 manager_->Shutdown(); 327 manager_->Shutdown();
326 EXPECT_TRUE(manager_->policies().Equals(bundle)); 328 EXPECT_TRUE(manager_->policies().Equals(bundle));
327 } 329 }
328 330
329 TEST_F(DeviceCloudPolicyManagerChromeOSTest, ObserverIsNotifiedOnConnected) { 331 TEST_F(DeviceCloudPolicyManagerChromeOSTest, ConnectAndDisconnect) {
330 LockDevice(); 332 LockDevice();
331 FlushDeviceSettings(); 333 FlushDeviceSettings();
334 EXPECT_FALSE(manager_->core()->service()); // Not connected.
332 335
336 // Connect the manager.
333 MockDeviceManagementJob* policy_fetch_job = nullptr; 337 MockDeviceManagementJob* policy_fetch_job = nullptr;
334 EXPECT_CALL(device_management_service_, 338 EXPECT_CALL(device_management_service_,
335 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH, _)) 339 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH, _))
336 .WillOnce(device_management_service_.CreateAsyncJob(&policy_fetch_job)); 340 .WillOnce(device_management_service_.CreateAsyncJob(&policy_fetch_job));
337 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _)); 341 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _));
338 EXPECT_CALL(*this, OnDeviceCloudPolicyManagerConnected()); 342 EXPECT_CALL(*this, OnDeviceCloudPolicyManagerConnected());
339
340 ConnectManager(); 343 ConnectManager();
341 base::RunLoop().RunUntilIdle(); 344 base::RunLoop().RunUntilIdle();
345 Mock::VerifyAndClearExpectations(&device_management_service_);
346 Mock::VerifyAndClearExpectations(this);
347 EXPECT_TRUE(manager_->core()->service()); // Connected.
348
349 // Disconnect the manager.
350 EXPECT_CALL(*this, OnDeviceCloudPolicyManagerDisconnected());
351 manager_->Disconnect();
352 EXPECT_FALSE(manager_->core()->service()); // Not connnected.
342 } 353 }
343 354
344 class DeviceCloudPolicyManagerChromeOSEnrollmentTest 355 class DeviceCloudPolicyManagerChromeOSEnrollmentTest
345 : public DeviceCloudPolicyManagerChromeOSTest { 356 : public DeviceCloudPolicyManagerChromeOSTest {
346 public: 357 public:
347 void Done(EnrollmentStatus status) { 358 void Done(EnrollmentStatus status) {
348 status_ = status; 359 status_ = status;
349 done_ = true; 360 done_ = true;
350 } 361 }
351 362
363 MOCK_METHOD1(OnUnregistered, void(bool));
364
352 protected: 365 protected:
353 DeviceCloudPolicyManagerChromeOSEnrollmentTest() 366 DeviceCloudPolicyManagerChromeOSEnrollmentTest()
354 : management_mode_(MANAGEMENT_MODE_ENTERPRISE_MANAGED), 367 : management_mode_(MANAGEMENT_MODE_ENTERPRISE_MANAGED),
355 register_status_(DM_STATUS_SUCCESS), 368 register_status_(DM_STATUS_SUCCESS),
356 policy_fetch_status_(DM_STATUS_SUCCESS), 369 policy_fetch_status_(DM_STATUS_SUCCESS),
357 robot_auth_fetch_status_(DM_STATUS_SUCCESS), 370 robot_auth_fetch_status_(DM_STATUS_SUCCESS),
358 store_result_(true), 371 store_result_(true),
359 status_(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS)), 372 status_(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS)),
360 done_(false) {} 373 done_(false) {}
361 374
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 666
654 device_policy_.policy_data().set_management_mode(em::PolicyData::LOCAL_OWNER); 667 device_policy_.policy_data().set_management_mode(em::PolicyData::LOCAL_OWNER);
655 device_policy_.Build(); 668 device_policy_.Build();
656 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); 669 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
657 ReloadDeviceSettings(); 670 ReloadDeviceSettings();
658 671
659 RunTest(); 672 RunTest();
660 ExpectSuccessfulEnrollment(); 673 ExpectSuccessfulEnrollment();
661 } 674 }
662 675
676 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, UnregisterSucceeds) {
677 // Enroll first.
678 RunTest();
679 ExpectSuccessfulEnrollment();
680
681 // Set up mock objects for the upcoming unregistration job.
682 em::DeviceManagementResponse response;
683 response.mutable_unregister_response();
684 EXPECT_CALL(device_management_service_,
685 CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, _))
686 .WillOnce(device_management_service_.SucceedJob(response));
687 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _));
688 EXPECT_CALL(*this, OnUnregistered(true));
689
690 // Start unregistering.
691 manager_->Unregister(base::Bind(
692 &DeviceCloudPolicyManagerChromeOSEnrollmentTest::OnUnregistered,
693 base::Unretained(this)));
694 }
695
696 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, UnregisterFails) {
697 // Enroll first.
698 RunTest();
699 ExpectSuccessfulEnrollment();
700
701 // Set up mock objects for the upcoming unregistration job.
702 EXPECT_CALL(device_management_service_,
703 CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, _))
704 .WillOnce(device_management_service_.FailJob(DM_STATUS_REQUEST_FAILED));
705 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _));
706 EXPECT_CALL(*this, OnUnregistered(false));
707
708 // Start unregistering.
709 manager_->Unregister(base::Bind(
710 &DeviceCloudPolicyManagerChromeOSEnrollmentTest::OnUnregistered,
711 base::Unretained(this)));
712 }
713
663 // A subclass that runs with a blank system salt. 714 // A subclass that runs with a blank system salt.
664 class DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest 715 class DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest
665 : public DeviceCloudPolicyManagerChromeOSEnrollmentTest { 716 : public DeviceCloudPolicyManagerChromeOSEnrollmentTest {
666 protected: 717 protected:
667 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest() { 718 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest() {
668 // Set up a FakeCryptohomeClient with a blank system salt. 719 // Set up a FakeCryptohomeClient with a blank system salt.
669 fake_cryptohome_client_->set_system_salt(std::vector<uint8>()); 720 fake_cryptohome_client_->set_system_salt(std::vector<uint8>());
670 } 721 }
671 }; 722 };
672 723
673 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, 724 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest,
674 RobotRefreshSaveFailed) { 725 RobotRefreshSaveFailed) {
675 // Without the system salt, the robot token can't be stored. 726 // Without the system salt, the robot token can't be stored.
676 RunTest(); 727 RunTest();
677 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); 728 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED);
678 } 729 }
679 730
680 } // namespace 731 } // namespace
681 } // namespace policy 732 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698