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

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: Created 6 years, 1 month 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 ec6144ffb67606b9097741b2ecc7ace60575f7ec..b9b71f89fdd002f24aaec443e47b0da65dd064b1 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
@@ -18,6 +18,7 @@
#include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h"
#include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
#include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
+#include "chrome/browser/chromeos/policy/fake_consumer_management_service.h"
#include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
@@ -159,7 +160,8 @@ class DeviceCloudPolicyManagerChromeOSTest
&state_keys_broker_,
store_,
manager_.get(),
- &device_settings_service_));
+ &device_settings_service_,
+ &consumer_management_service_));
initializer_->Init();
}
@@ -175,6 +177,7 @@ class DeviceCloudPolicyManagerChromeOSTest
}
MOCK_METHOD0(OnDeviceCloudPolicyManagerConnected, void());
+ MOCK_METHOD0(OnDeviceCloudPolicyManagerDisconnected, void());
scoped_ptr<EnterpriseInstallAttributes> install_attributes_;
@@ -195,6 +198,7 @@ class DeviceCloudPolicyManagerChromeOSTest
DeviceCloudPolicyStoreChromeOS* store_;
SchemaRegistry schema_registry_;
scoped_ptr<DeviceCloudPolicyManagerChromeOS> manager_;
+ FakeConsumerManagementService consumer_management_service_;
scoped_ptr<DeviceCloudPolicyInitializer> initializer_;
private:
@@ -272,21 +276,31 @@ TEST_F(DeviceCloudPolicyManagerChromeOSTest, UnmanagedDevice) {
}
TEST_F(DeviceCloudPolicyManagerChromeOSTest, ConsumerDevice) {
+ consumer_management_service_.SetStatusAndStage(
+ ConsumerManagementService::STATUS_ENROLLED,
bartfab (slow) 2014/11/28 13:25:18 Nit: #include "chrome/browser/chromeos/policy/cons
davidyu 2014/12/01 17:05:22 Done.
+ ConsumerManagementStage(ConsumerManagementStage::NONE));
bartfab (slow) 2014/11/28 13:25:18 Nit: #include "chrome/browser/chromeos/policy/cons
davidyu 2014/12/01 17:05:22 Done.
FlushDeviceSettings();
EXPECT_EQ(CloudPolicyStore::STATUS_BAD_STATE, store_->status());
EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
PolicyBundle bundle;
EXPECT_TRUE(manager_->policies().Equals(bundle));
+ EXPECT_FALSE(manager_->core()->service()); // Not connected.
bartfab (slow) 2014/11/28 13:25:18 Nit: #include "components/policy/core/common/cloud
davidyu 2014/12/01 17:05:22 Done.
ConnectManager();
+ base::RunLoop().RunUntilIdle();
EXPECT_TRUE(manager_->policies().Equals(bundle));
+ EXPECT_TRUE(manager_->core()->service()); // Connected.
+
+ manager_->Disconnect();
+ EXPECT_FALSE(manager_->core()->service()); // Not connected.
manager_->Shutdown();
EXPECT_TRUE(manager_->policies().Equals(bundle));
}
-TEST_F(DeviceCloudPolicyManagerChromeOSTest, ObserverIsNotifiedWhenConnected) {
+TEST_F(DeviceCloudPolicyManagerChromeOSTest,
+ ObserverIsNotifiedWhenConnectedAndDisconnected) {
LockDevice();
FlushDeviceSettings();
@@ -299,6 +313,11 @@ TEST_F(DeviceCloudPolicyManagerChromeOSTest, ObserverIsNotifiedWhenConnected) {
ConnectManager();
base::RunLoop().RunUntilIdle();
+ Mock::VerifyAndClearExpectations(&device_management_service_);
+ Mock::VerifyAndClearExpectations(this);
+
+ EXPECT_CALL(*this, OnDeviceCloudPolicyManagerDisconnected());
+ manager_->Disconnect();
}
class DeviceCloudPolicyManagerChromeOSEnrollmentTest
@@ -309,6 +328,8 @@ class DeviceCloudPolicyManagerChromeOSEnrollmentTest
done_ = true;
}
+ MOCK_METHOD1(OnUnregistered, void(bool));
+
protected:
DeviceCloudPolicyManagerChromeOSEnrollmentTest()
: is_auto_enrollment_(false),
@@ -619,6 +640,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