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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc
diff --git a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc
index 5b46bb0f6a4ae7cdd7970341b559f8d3ccb36d5a..64d0183970bc0643dcca664d690ada68e5b26755 100644
--- a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc
+++ b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc
@@ -40,6 +40,7 @@
#include "chromeos/system/statistics_provider.h"
#include "components/policy/core/common/cloud/cloud_policy_client.h"
#include "components/policy/core/common/cloud/cloud_policy_constants.h"
+#include "components/policy/core/common/cloud/cloud_policy_core.h"
#include "components/policy/core/common/cloud/mock_device_management_service.h"
#include "components/policy/core/common/external_data_fetcher.h"
#include "components/policy/core/common/schema_registry.h"
@@ -197,6 +198,7 @@ class DeviceCloudPolicyManagerChromeOSTest
}
MOCK_METHOD0(OnDeviceCloudPolicyManagerConnected, void());
+ MOCK_METHOD0(OnDeviceCloudPolicyManagerDisconnected, void());
scoped_ptr<EnterpriseInstallAttributes> install_attributes_;
@@ -326,19 +328,28 @@ TEST_F(DeviceCloudPolicyManagerChromeOSTest, ConsumerDevice) {
EXPECT_TRUE(manager_->policies().Equals(bundle));
}
-TEST_F(DeviceCloudPolicyManagerChromeOSTest, ObserverIsNotifiedOnConnected) {
+TEST_F(DeviceCloudPolicyManagerChromeOSTest, ConnectAndDisconnect) {
LockDevice();
FlushDeviceSettings();
+ EXPECT_FALSE(manager_->core()->service()); // Not connected.
+ // Connect the manager.
MockDeviceManagementJob* policy_fetch_job = nullptr;
EXPECT_CALL(device_management_service_,
CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH, _))
.WillOnce(device_management_service_.CreateAsyncJob(&policy_fetch_job));
EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _));
EXPECT_CALL(*this, OnDeviceCloudPolicyManagerConnected());
-
ConnectManager();
base::RunLoop().RunUntilIdle();
+ Mock::VerifyAndClearExpectations(&device_management_service_);
+ Mock::VerifyAndClearExpectations(this);
+ EXPECT_TRUE(manager_->core()->service()); // Connected.
+
+ // Disconnect the manager.
+ EXPECT_CALL(*this, OnDeviceCloudPolicyManagerDisconnected());
+ manager_->Disconnect();
+ EXPECT_FALSE(manager_->core()->service()); // Not connnected.
}
class DeviceCloudPolicyManagerChromeOSEnrollmentTest
@@ -349,6 +360,8 @@ class DeviceCloudPolicyManagerChromeOSEnrollmentTest
done_ = true;
}
+ MOCK_METHOD1(OnUnregistered, void(bool));
+
protected:
DeviceCloudPolicyManagerChromeOSEnrollmentTest()
: management_mode_(MANAGEMENT_MODE_ENTERPRISE_MANAGED),
@@ -662,6 +675,44 @@ TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest,
ExpectSuccessfulEnrollment();
}
+TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, UnregisterSucceeds) {
+ // Enroll first.
+ RunTest();
+ ExpectSuccessfulEnrollment();
+
+ // Set up mock objects for the upcoming unregistration job.
+ em::DeviceManagementResponse response;
+ response.mutable_unregister_response();
+ EXPECT_CALL(device_management_service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, _))
+ .WillOnce(device_management_service_.SucceedJob(response));
+ EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _));
+ EXPECT_CALL(*this, OnUnregistered(true));
+
+ // Start unregistering.
+ manager_->Unregister(base::Bind(
+ &DeviceCloudPolicyManagerChromeOSEnrollmentTest::OnUnregistered,
+ base::Unretained(this)));
+}
+
+TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, UnregisterFails) {
+ // Enroll first.
+ RunTest();
+ ExpectSuccessfulEnrollment();
+
+ // Set up mock objects for the upcoming unregistration job.
+ EXPECT_CALL(device_management_service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, _))
+ .WillOnce(device_management_service_.FailJob(DM_STATUS_REQUEST_FAILED));
+ EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _));
+ EXPECT_CALL(*this, OnUnregistered(false));
+
+ // Start unregistering.
+ manager_->Unregister(base::Bind(
+ &DeviceCloudPolicyManagerChromeOSEnrollmentTest::OnUnregistered,
+ base::Unretained(this)));
+}
+
// A subclass that runs with a blank system salt.
class DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest
: public DeviceCloudPolicyManagerChromeOSEnrollmentTest {

Powered by Google App Engine
This is Rietveld 408576698