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

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: Rebase. 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 22 matching lines...) Expand all
33 #include "chrome/test/base/testing_profile.h" 33 #include "chrome/test/base/testing_profile.h"
34 #include "chromeos/cryptohome/system_salt_getter.h" 34 #include "chromeos/cryptohome/system_salt_getter.h"
35 #include "chromeos/dbus/dbus_client_implementation_type.h" 35 #include "chromeos/dbus/dbus_client_implementation_type.h"
36 #include "chromeos/dbus/dbus_thread_manager.h" 36 #include "chromeos/dbus/dbus_thread_manager.h"
37 #include "chromeos/dbus/fake_cryptohome_client.h" 37 #include "chromeos/dbus/fake_cryptohome_client.h"
38 #include "chromeos/dbus/fake_session_manager_client.h" 38 #include "chromeos/dbus/fake_session_manager_client.h"
39 #include "chromeos/system/fake_statistics_provider.h" 39 #include "chromeos/system/fake_statistics_provider.h"
40 #include "chromeos/system/statistics_provider.h" 40 #include "chromeos/system/statistics_provider.h"
41 #include "components/policy/core/common/cloud/cloud_policy_client.h" 41 #include "components/policy/core/common/cloud/cloud_policy_client.h"
42 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 42 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
43 #include "components/policy/core/common/cloud/cloud_policy_core.h"
43 #include "components/policy/core/common/cloud/mock_device_management_service.h" 44 #include "components/policy/core/common/cloud/mock_device_management_service.h"
44 #include "components/policy/core/common/external_data_fetcher.h" 45 #include "components/policy/core/common/external_data_fetcher.h"
45 #include "components/policy/core/common/schema_registry.h" 46 #include "components/policy/core/common/schema_registry.h"
46 #include "google_apis/gaia/gaia_oauth_client.h" 47 #include "google_apis/gaia/gaia_oauth_client.h"
47 #include "net/url_request/test_url_fetcher_factory.h" 48 #include "net/url_request/test_url_fetcher_factory.h"
48 #include "net/url_request/url_request_test_util.h" 49 #include "net/url_request/url_request_test_util.h"
49 #include "policy/policy_constants.h" 50 #include "policy/policy_constants.h"
50 #include "policy/proto/device_management_backend.pb.h" 51 #include "policy/proto/device_management_backend.pb.h"
51 #include "testing/gmock/include/gmock/gmock.h" 52 #include "testing/gmock/include/gmock/gmock.h"
52 #include "testing/gtest/include/gtest/gtest.h" 53 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 137 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 668
656 device_policy_.policy_data().set_management_mode(em::PolicyData::LOCAL_OWNER); 669 device_policy_.policy_data().set_management_mode(em::PolicyData::LOCAL_OWNER);
657 device_policy_.Build(); 670 device_policy_.Build();
658 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); 671 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
659 ReloadDeviceSettings(); 672 ReloadDeviceSettings();
660 673
661 RunTest(); 674 RunTest();
662 ExpectSuccessfulEnrollment(); 675 ExpectSuccessfulEnrollment();
663 } 676 }
664 677
678 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, UnregisterSucceeds) {
679 // Enroll first.
680 RunTest();
681 ExpectSuccessfulEnrollment();
682
683 // Set up mock objects for the upcoming unregistration job.
684 em::DeviceManagementResponse response;
685 response.mutable_unregister_response();
686 EXPECT_CALL(device_management_service_,
687 CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, _))
688 .WillOnce(device_management_service_.SucceedJob(response));
689 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _));
690 EXPECT_CALL(*this, OnUnregistered(true));
691
692 // Start unregistering.
693 manager_->Unregister(base::Bind(
694 &DeviceCloudPolicyManagerChromeOSEnrollmentTest::OnUnregistered,
695 base::Unretained(this)));
696 }
697
698 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, UnregisterFails) {
699 // Enroll first.
700 RunTest();
701 ExpectSuccessfulEnrollment();
702
703 // Set up mock objects for the upcoming unregistration job.
704 EXPECT_CALL(device_management_service_,
705 CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, _))
706 .WillOnce(device_management_service_.FailJob(DM_STATUS_REQUEST_FAILED));
707 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _));
708 EXPECT_CALL(*this, OnUnregistered(false));
709
710 // Start unregistering.
711 manager_->Unregister(base::Bind(
712 &DeviceCloudPolicyManagerChromeOSEnrollmentTest::OnUnregistered,
713 base::Unretained(this)));
714 }
715
665 // A subclass that runs with a blank system salt. 716 // A subclass that runs with a blank system salt.
666 class DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest 717 class DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest
667 : public DeviceCloudPolicyManagerChromeOSEnrollmentTest { 718 : public DeviceCloudPolicyManagerChromeOSEnrollmentTest {
668 protected: 719 protected:
669 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest() { 720 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest() {
670 // Set up a FakeCryptohomeClient with a blank system salt. 721 // Set up a FakeCryptohomeClient with a blank system salt.
671 fake_cryptohome_client_->set_system_salt(std::vector<uint8>()); 722 fake_cryptohome_client_->set_system_salt(std::vector<uint8>());
672 } 723 }
673 }; 724 };
674 725
675 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, 726 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest,
676 RobotRefreshSaveFailed) { 727 RobotRefreshSaveFailed) {
677 // Without the system salt, the robot token can't be stored. 728 // Without the system salt, the robot token can't be stored.
678 RunTest(); 729 RunTest();
679 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); 730 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED);
680 } 731 }
681 732
682 } // namespace 733 } // namespace
683 } // namespace policy 734 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698