Commit 835a4623 authored by anina koehler's avatar anina koehler Committed by Commit Bot

Remove GMOCK warnings in DeviceCloudPolicyManagerChromeOS Tests

When running tests from device_cloud_policy_manager_chromeos_unittest.cc, GMOCK warnings about uninteresting mock function calls are appearing. Similar to ConnectManager(), a helper method ShutdownManager() was created and expect calls for MockCloudExternalDataManagers Connect() and Disconnect() methods were added in the helper methods.

Bug: 1046259
Change-Id: Ibb371bcf8bdaaf04974737f616e4081f8a994b40
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2012281
Commit-Queue: Anina Koehler <aninak@google.com>
Reviewed-by: default avatarAlexander Hendrich <hendrich@chromium.org>
Reviewed-by: default avatarNikita Podguzov <nikitapodguzov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737730}
parent 72f4eb7b
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h" #include "components/prefs/testing_pref_service.h"
#include "components/session_manager/core/session_manager.h" #include "components/session_manager/core/session_manager.h"
#include "content/public/test/test_utils.h"
#include "google_apis/gaia/gaia_oauth_client.h" #include "google_apis/gaia/gaia_oauth_client.h"
#include "google_apis/gaia/gaia_urls.h" #include "google_apis/gaia/gaia_urls.h"
#include "net/url_request/url_request_test_util.h" #include "net/url_request/url_request_test_util.h"
...@@ -165,9 +166,11 @@ class DeviceCloudPolicyManagerChromeOSTest ...@@ -165,9 +166,11 @@ class DeviceCloudPolicyManagerChromeOSTest
store_ = new DeviceCloudPolicyStoreChromeOS( store_ = new DeviceCloudPolicyStoreChromeOS(
device_settings_service_.get(), install_attributes_.get(), device_settings_service_.get(), install_attributes_.get(),
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
auto external_data_manager =
std::make_unique<MockCloudExternalDataManager>();
external_data_manager_ = external_data_manager.get();
manager_ = std::make_unique<TestingDeviceCloudPolicyManagerChromeOS>( manager_ = std::make_unique<TestingDeviceCloudPolicyManagerChromeOS>(
base::WrapUnique(store_), base::WrapUnique(store_), std::move(external_data_manager),
std::make_unique<MockCloudExternalDataManager>(),
base::ThreadTaskRunnerHandle::Get(), &state_keys_broker_); base::ThreadTaskRunnerHandle::Get(), &state_keys_broker_);
RegisterLocalState(local_state_.registry()); RegisterLocalState(local_state_.registry());
...@@ -198,7 +201,7 @@ class DeviceCloudPolicyManagerChromeOSTest ...@@ -198,7 +201,7 @@ class DeviceCloudPolicyManagerChromeOSTest
if (initializer_) if (initializer_)
initializer_->Shutdown(); initializer_->Shutdown();
manager_->Shutdown(); ShutdownManager();
manager_.reset(); manager_.reset();
install_attributes_.reset(); install_attributes_.reset();
...@@ -231,7 +234,10 @@ class DeviceCloudPolicyManagerChromeOSTest ...@@ -231,7 +234,10 @@ class DeviceCloudPolicyManagerChromeOSTest
ASSERT_EQ(chromeos::InstallAttributes::LOCK_SUCCESS, result); ASSERT_EQ(chromeos::InstallAttributes::LOCK_SUCCESS, result);
} }
void ConnectManager() { void ConnectManager(bool expectExternalDataManagerConnectCall = true) {
if (expectExternalDataManagerConnectCall) {
EXPECT_CALL(*external_data_manager_, Connect(_));
}
std::unique_ptr<chromeos::attestation::AttestationFlow> unique_flow( std::unique_ptr<chromeos::attestation::AttestationFlow> unique_flow(
CreateAttestationFlow()); CreateAttestationFlow());
manager_->Initialize(&local_state_); manager_->Initialize(&local_state_);
...@@ -246,6 +252,14 @@ class DeviceCloudPolicyManagerChromeOSTest ...@@ -246,6 +252,14 @@ class DeviceCloudPolicyManagerChromeOSTest
initializer_->SetSystemURLLoaderFactoryForTesting( initializer_->SetSystemURLLoaderFactoryForTesting(
test_url_loader_factory_.GetSafeWeakWrapper()); test_url_loader_factory_.GetSafeWeakWrapper());
initializer_->Init(); initializer_->Init();
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(external_data_manager_);
}
void ShutdownManager() {
EXPECT_CALL(*external_data_manager_, Disconnect());
manager_->Shutdown();
Mock::VerifyAndClearExpectations(external_data_manager_);
} }
void VerifyPolicyPopulated() { void VerifyPolicyPopulated() {
...@@ -295,6 +309,7 @@ class DeviceCloudPolicyManagerChromeOSTest ...@@ -295,6 +309,7 @@ class DeviceCloudPolicyManagerChromeOSTest
DeviceCloudPolicyStoreChromeOS* store_; DeviceCloudPolicyStoreChromeOS* store_;
SchemaRegistry schema_registry_; SchemaRegistry schema_registry_;
MockCloudExternalDataManager* external_data_manager_;
std::unique_ptr<TestingDeviceCloudPolicyManagerChromeOS> manager_; std::unique_ptr<TestingDeviceCloudPolicyManagerChromeOS> manager_;
std::unique_ptr<DeviceCloudPolicyInitializer> initializer_; std::unique_ptr<DeviceCloudPolicyInitializer> initializer_;
network::TestURLLoaderFactory test_url_loader_factory_; network::TestURLLoaderFactory test_url_loader_factory_;
...@@ -334,7 +349,6 @@ TEST_F(DeviceCloudPolicyManagerChromeOSTest, EnrolledDevice) { ...@@ -334,7 +349,6 @@ TEST_F(DeviceCloudPolicyManagerChromeOSTest, EnrolledDevice) {
device_management_service_.StartJobFullControl(&policy_job))); device_management_service_.StartJobFullControl(&policy_job)));
AllowUninterestingRemoteCommandFetches(); AllowUninterestingRemoteCommandFetches();
ConnectManager(); ConnectManager();
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(&device_management_service_); Mock::VerifyAndClearExpectations(&device_management_service_);
ASSERT_TRUE(policy_job); ASSERT_TRUE(policy_job);
ASSERT_EQ(DeviceManagementService::JobConfiguration::TYPE_POLICY_FETCH, ASSERT_EQ(DeviceManagementService::JobConfiguration::TYPE_POLICY_FETCH,
...@@ -343,7 +357,7 @@ TEST_F(DeviceCloudPolicyManagerChromeOSTest, EnrolledDevice) { ...@@ -343,7 +357,7 @@ TEST_F(DeviceCloudPolicyManagerChromeOSTest, EnrolledDevice) {
EXPECT_TRUE(manager_->GetStatusUploader()); EXPECT_TRUE(manager_->GetStatusUploader());
VerifyPolicyPopulated(); VerifyPolicyPopulated();
manager_->Shutdown(); ShutdownManager();
VerifyPolicyPopulated(); VerifyPolicyPopulated();
EXPECT_EQ(store_->policy()->service_account_identity(), EXPECT_EQ(store_->policy()->service_account_identity(),
...@@ -373,7 +387,6 @@ TEST_F(DeviceCloudPolicyManagerChromeOSTest, UnmanagedDevice) { ...@@ -373,7 +387,6 @@ TEST_F(DeviceCloudPolicyManagerChromeOSTest, UnmanagedDevice) {
device_management_service_.StartJobFullControl(&policy_job))); device_management_service_.StartJobFullControl(&policy_job)));
AllowUninterestingRemoteCommandFetches(); AllowUninterestingRemoteCommandFetches();
ConnectManager(); ConnectManager();
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(&device_management_service_); Mock::VerifyAndClearExpectations(&device_management_service_);
ASSERT_TRUE(policy_job); ASSERT_TRUE(policy_job);
ASSERT_EQ(DeviceManagementService::JobConfiguration::TYPE_POLICY_FETCH, ASSERT_EQ(DeviceManagementService::JobConfiguration::TYPE_POLICY_FETCH,
...@@ -408,12 +421,12 @@ TEST_F(DeviceCloudPolicyManagerChromeOSTest, ConsumerDevice) { ...@@ -408,12 +421,12 @@ TEST_F(DeviceCloudPolicyManagerChromeOSTest, ConsumerDevice) {
PolicyBundle bundle; PolicyBundle bundle;
EXPECT_TRUE(manager_->policies().Equals(bundle)); EXPECT_TRUE(manager_->policies().Equals(bundle));
ConnectManager(); ConnectManager(false);
EXPECT_TRUE(manager_->policies().Equals(bundle)); EXPECT_TRUE(manager_->policies().Equals(bundle));
// Should not create a status provider for reporting on consumer devices. // Should not create a status provider for reporting on consumer devices.
EXPECT_FALSE(manager_->GetStatusUploader()); EXPECT_FALSE(manager_->GetStatusUploader());
manager_->Shutdown(); ShutdownManager();
EXPECT_TRUE(manager_->policies().Equals(bundle)); EXPECT_TRUE(manager_->policies().Equals(bundle));
} }
...@@ -450,7 +463,6 @@ TEST_F(DeviceCloudPolicyManagerChromeOSObserverTest, ConnectAndDisconnect) { ...@@ -450,7 +463,6 @@ TEST_F(DeviceCloudPolicyManagerChromeOSObserverTest, ConnectAndDisconnect) {
AllowUninterestingRemoteCommandFetches(); AllowUninterestingRemoteCommandFetches();
EXPECT_CALL(*this, OnDeviceCloudPolicyManagerConnected()); EXPECT_CALL(*this, OnDeviceCloudPolicyManagerConnected());
ConnectManager(); ConnectManager();
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(&device_management_service_); Mock::VerifyAndClearExpectations(&device_management_service_);
Mock::VerifyAndClearExpectations(this); Mock::VerifyAndClearExpectations(this);
EXPECT_TRUE(manager_->core()->service()); // Connected. EXPECT_TRUE(manager_->core()->service()); // Connected.
...@@ -478,6 +490,7 @@ class DeviceCloudPolicyManagerChromeOSEnrollmentTest ...@@ -478,6 +490,7 @@ class DeviceCloudPolicyManagerChromeOSEnrollmentTest
policy_fetch_status_(DM_STATUS_SUCCESS), policy_fetch_status_(DM_STATUS_SUCCESS),
robot_auth_fetch_status_(DM_STATUS_SUCCESS), robot_auth_fetch_status_(DM_STATUS_SUCCESS),
status_(EnrollmentStatus::ForStatus(EnrollmentStatus::SUCCESS)), status_(EnrollmentStatus::ForStatus(EnrollmentStatus::SUCCESS)),
expect_robot_auth_fetch_failure_(false),
done_(false) {} done_(false) {}
void SetUp() override { void SetUp() override {
...@@ -506,7 +519,7 @@ class DeviceCloudPolicyManagerChromeOSEnrollmentTest ...@@ -506,7 +519,7 @@ class DeviceCloudPolicyManagerChromeOSEnrollmentTest
PolicyBundle bundle; PolicyBundle bundle;
EXPECT_TRUE(manager_->policies().Equals(bundle)); EXPECT_TRUE(manager_->policies().Equals(bundle));
ConnectManager(); ConnectManager(false);
} }
void ExpectFailedEnrollment(EnrollmentStatus::Status status) { void ExpectFailedEnrollment(EnrollmentStatus::Status status) {
...@@ -653,11 +666,16 @@ class DeviceCloudPolicyManagerChromeOSEnrollmentTest ...@@ -653,11 +666,16 @@ class DeviceCloudPolicyManagerChromeOSEnrollmentTest
// We return a successful OAuth response via a TestURLLoaderFactory to // We return a successful OAuth response via a TestURLLoaderFactory to
// trigger the happy path for these classes so that enrollment can continue. // trigger the happy path for these classes so that enrollment can continue.
if (robot_auth_fetch_status_ == DM_STATUS_SUCCESS) { if (robot_auth_fetch_status_ == DM_STATUS_SUCCESS) {
if (!expect_robot_auth_fetch_failure_) {
EXPECT_CALL(*external_data_manager_, Connect(_));
}
test_url_loader_factory_.SimulateResponseForPendingRequest( test_url_loader_factory_.SimulateResponseForPendingRequest(
GaiaUrls::GetInstance()->oauth2_token_url(), GaiaUrls::GetInstance()->oauth2_token_url(),
network::URLLoaderCompletionStatus(net::OK), network::URLLoaderCompletionStatus(net::OK),
network::CreateURLResponseHead(url_fetcher_response_code_), network::CreateURLResponseHead(url_fetcher_response_code_),
url_fetcher_response_string_); url_fetcher_response_string_);
content::RunAllTasksUntilIdle();
Mock::VerifyAndClearExpectations(external_data_manager_);
} }
// Process robot refresh token store and policy store. // Process robot refresh token store and policy store.
...@@ -741,6 +759,9 @@ class DeviceCloudPolicyManagerChromeOSEnrollmentTest ...@@ -741,6 +759,9 @@ class DeviceCloudPolicyManagerChromeOSEnrollmentTest
DeviceManagementService::JobConfiguration::ParameterMap query_params_; DeviceManagementService::JobConfiguration::ParameterMap query_params_;
EnrollmentStatus status_; EnrollmentStatus status_;
// Set to true if the robot auth fetch is expected to fail.
bool expect_robot_auth_fetch_failure_;
bool done_; bool done_;
private: private:
...@@ -763,6 +784,7 @@ TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, Reenrollment) { ...@@ -763,6 +784,7 @@ TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, Reenrollment) {
TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, RegistrationFailed) { TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, RegistrationFailed) {
register_status_ = DM_STATUS_REQUEST_FAILED; register_status_ = DM_STATUS_REQUEST_FAILED;
expect_robot_auth_fetch_failure_ = true;
RunTest(); RunTest();
ExpectFailedEnrollment(EnrollmentStatus::REGISTRATION_FAILED); ExpectFailedEnrollment(EnrollmentStatus::REGISTRATION_FAILED);
EXPECT_EQ(DM_STATUS_REQUEST_FAILED, status_.client_status()); EXPECT_EQ(DM_STATUS_REQUEST_FAILED, status_.client_status());
...@@ -778,6 +800,7 @@ TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, ...@@ -778,6 +800,7 @@ TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest,
TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest,
RobotRefreshTokenFetchResponseCodeFailed) { RobotRefreshTokenFetchResponseCodeFailed) {
url_fetcher_response_code_ = net::HTTP_BAD_REQUEST; url_fetcher_response_code_ = net::HTTP_BAD_REQUEST;
expect_robot_auth_fetch_failure_ = true;
RunTest(); RunTest();
ExpectFailedEnrollment(EnrollmentStatus::ROBOT_REFRESH_FETCH_FAILED); ExpectFailedEnrollment(EnrollmentStatus::ROBOT_REFRESH_FETCH_FAILED);
EXPECT_EQ(net::HTTP_BAD_REQUEST, status_.http_status()); EXPECT_EQ(net::HTTP_BAD_REQUEST, status_.http_status());
...@@ -786,6 +809,7 @@ TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, ...@@ -786,6 +809,7 @@ TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest,
TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest,
RobotRefreshTokenFetchResponseStringFailed) { RobotRefreshTokenFetchResponseStringFailed) {
url_fetcher_response_string_ = "invalid response json"; url_fetcher_response_string_ = "invalid response json";
expect_robot_auth_fetch_failure_ = true;
RunTest(); RunTest();
ExpectFailedEnrollment(EnrollmentStatus::ROBOT_REFRESH_FETCH_FAILED); ExpectFailedEnrollment(EnrollmentStatus::ROBOT_REFRESH_FETCH_FAILED);
} }
...@@ -799,6 +823,7 @@ TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, ...@@ -799,6 +823,7 @@ TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest,
"{\"access_token\":\"accessToken4Test\"," "{\"access_token\":\"accessToken4Test\","
"\"expires_in\":1234," "\"expires_in\":1234,"
"\"refresh_token\":\"\"}"; "\"refresh_token\":\"\"}";
expect_robot_auth_fetch_failure_ = true;
RunTest(); RunTest();
ExpectFailedEnrollment(EnrollmentStatus::ROBOT_REFRESH_STORE_FAILED); ExpectFailedEnrollment(EnrollmentStatus::ROBOT_REFRESH_STORE_FAILED);
} }
...@@ -823,6 +848,7 @@ TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, ValidationFailed) { ...@@ -823,6 +848,7 @@ TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, ValidationFailed) {
TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, StoreError) { TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, StoreError) {
session_manager_client_.ForceStorePolicyFailure(true); session_manager_client_.ForceStorePolicyFailure(true);
expect_robot_auth_fetch_failure_ = true;
RunTest(); RunTest();
ExpectFailedEnrollment(EnrollmentStatus::STORE_ERROR); ExpectFailedEnrollment(EnrollmentStatus::STORE_ERROR);
EXPECT_EQ(CloudPolicyStore::STATUS_STORE_ERROR, status_.store_status()); EXPECT_EQ(CloudPolicyStore::STATUS_STORE_ERROR, status_.store_status());
...@@ -830,6 +856,7 @@ TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, StoreError) { ...@@ -830,6 +856,7 @@ TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, StoreError) {
TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) {
session_manager_client_.ForceRetrievePolicyLoadError(true); session_manager_client_.ForceRetrievePolicyLoadError(true);
expect_robot_auth_fetch_failure_ = true;
RunTest(); RunTest();
ExpectFailedEnrollment(EnrollmentStatus::STORE_ERROR); ExpectFailedEnrollment(EnrollmentStatus::STORE_ERROR);
EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, status_.store_status()); EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, status_.store_status());
...@@ -912,6 +939,7 @@ class DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest ...@@ -912,6 +939,7 @@ class DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest
TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, TEST_P(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest,
RobotRefreshSaveFailed) { RobotRefreshSaveFailed) {
// Without the system salt, the robot token can't be stored. // Without the system salt, the robot token can't be stored.
expect_robot_auth_fetch_failure_ = true;
RunTest(); RunTest();
ExpectFailedEnrollment(EnrollmentStatus::ROBOT_REFRESH_STORE_FAILED); ExpectFailedEnrollment(EnrollmentStatus::ROBOT_REFRESH_STORE_FAILED);
} }
......
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