Commit c70ac47a authored by Swapnil's avatar Swapnil Committed by Commit Bot

Add unit tests for CloudPolicyClient

UploadExtensionInstallReport and CancelExtensionInstallReport methods
are used in event based reporting for policy based extensions in
CloudPolicyClient. This CL adds unit tests for these methods.

Bug: 1101714
Change-Id: Id0322508fc1e67456658a982172e4171d45c2fb4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2279210Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Commit-Queue: Swapnil Gupta <swapnilgupta@google.com>
Cr-Commit-Position: refs/heads/master@{#785313}
parent 7a024e00
...@@ -1626,7 +1626,7 @@ TEST_F(CloudPolicyClientTest, CancelUploadAppInstallReport) { ...@@ -1626,7 +1626,7 @@ TEST_F(CloudPolicyClientTest, CancelUploadAppInstallReport) {
std::move(callback)); std::move(callback));
EXPECT_EQ(1, client_->GetActiveRequestCountForTest()); EXPECT_EQ(1, client_->GetActiveRequestCountForTest());
// The job expected by the call to ExpectUploadAppInstallReport() completes // The job expected by the call to ExpectRealTimeReport() completes
// when base::RunLoop().RunUntilIdle() is called. To simulate a cancel // when base::RunLoop().RunUntilIdle() is called. To simulate a cancel
// before the response for the request is processed, make sure to cancel it // before the response for the request is processed, make sure to cancel it
// before running a loop. // before running a loop.
...@@ -1672,6 +1672,85 @@ TEST_F(CloudPolicyClientTest, UploadAppInstallReportSupersedesPending) { ...@@ -1672,6 +1672,85 @@ TEST_F(CloudPolicyClientTest, UploadAppInstallReportSupersedesPending) {
EXPECT_EQ(0, client_->GetActiveRequestCountForTest()); EXPECT_EQ(0, client_->GetActiveRequestCountForTest());
} }
TEST_F(CloudPolicyClientTest, UploadExtensionInstallReport) {
RegisterClient();
ExpectRealtimeReport();
EXPECT_CALL(callback_observer_, OnCallbackComplete(true)).Times(1);
CloudPolicyClient::StatusCallback callback =
base::BindOnce(&MockStatusCallbackObserver::OnCallbackComplete,
base::Unretained(&callback_observer_));
client_->UploadExtensionInstallReport(MakeDefaultRealtimeReport(),
std::move(callback));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(
DeviceManagementService::JobConfiguration::TYPE_UPLOAD_REAL_TIME_REPORT,
job_type_);
EXPECT_EQ(DM_STATUS_SUCCESS, client_->status());
}
TEST_F(CloudPolicyClientTest, CancelUploadExtensionInstallReport) {
RegisterClient();
ExpectRealtimeReport();
EXPECT_CALL(callback_observer_, OnCallbackComplete(true)).Times(0);
CloudPolicyClient::StatusCallback callback =
base::BindOnce(&MockStatusCallbackObserver::OnCallbackComplete,
base::Unretained(&callback_observer_));
em::ExtensionInstallReportRequest app_install_report;
client_->UploadExtensionInstallReport(MakeDefaultRealtimeReport(),
std::move(callback));
EXPECT_EQ(1, client_->GetActiveRequestCountForTest());
// The job expected by the call to ExpectRealTimeReport() completes
// when base::RunLoop().RunUntilIdle() is called. To simulate a cancel
// before the response for the request is processed, make sure to cancel it
// before running a loop.
client_->CancelExtensionInstallReportUpload();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, client_->GetActiveRequestCountForTest());
EXPECT_EQ(
DeviceManagementService::JobConfiguration::TYPE_UPLOAD_REAL_TIME_REPORT,
job_type_);
}
TEST_F(CloudPolicyClientTest, UploadExtensionInstallReportSupersedesPending) {
RegisterClient();
ExpectRealtimeReport();
EXPECT_CALL(callback_observer_, OnCallbackComplete(true)).Times(0);
CloudPolicyClient::StatusCallback callback =
base::BindOnce(&MockStatusCallbackObserver::OnCallbackComplete,
base::Unretained(&callback_observer_));
client_->UploadExtensionInstallReport(MakeDefaultRealtimeReport(),
std::move(callback));
EXPECT_EQ(1, client_->GetActiveRequestCountForTest());
Mock::VerifyAndClearExpectations(&service_);
Mock::VerifyAndClearExpectations(&callback_observer_);
// Starting another extension install report upload should cancel the pending
// one.
ExpectRealtimeReport();
EXPECT_CALL(callback_observer_, OnCallbackComplete(true)).Times(1);
callback = base::BindOnce(&MockStatusCallbackObserver::OnCallbackComplete,
base::Unretained(&callback_observer_));
client_->UploadExtensionInstallReport(MakeDefaultRealtimeReport(),
std::move(callback));
EXPECT_EQ(1, client_->GetActiveRequestCountForTest());
base::RunLoop().RunUntilIdle();
EXPECT_EQ(
DeviceManagementService::JobConfiguration::TYPE_UPLOAD_REAL_TIME_REPORT,
job_type_);
EXPECT_EQ(DM_STATUS_SUCCESS, client_->status());
EXPECT_EQ(0, client_->GetActiveRequestCountForTest());
}
#endif #endif
TEST_F(CloudPolicyClientTest, MultipleActiveRequests) { TEST_F(CloudPolicyClientTest, MultipleActiveRequests) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment