Chromium Code Reviews| Index: chrome/browser/policy/cloud_policy_controller_unittest.cc |
| diff --git a/chrome/browser/policy/cloud_policy_controller_unittest.cc b/chrome/browser/policy/cloud_policy_controller_unittest.cc |
| index 7e828db82927fb0d69d55e05478aa91ffa1e355e..3daf1d85b0bea63449d2fd0f615a9dc763353943 100644 |
| --- a/chrome/browser/policy/cloud_policy_controller_unittest.cc |
| +++ b/chrome/browser/policy/cloud_policy_controller_unittest.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/message_loop.h" |
| #include "base/scoped_temp_dir.h" |
| +#include "chrome/browser/policy/cloud_policy_data.h" |
|
pastarmovj
2011/07/06 12:11:57
I thought you had this already included in the hea
gfeher
2011/07/06 15:14:20
This unittest doesn't have a header!
|
| #include "chrome/browser/policy/device_management_service.h" |
|
Joao da Silva
2011/07/06 16:45:14
Nit: device_management_service.h not used
gfeher
2011/07/07 13:51:00
Done.
|
| #include "chrome/browser/policy/device_token_fetcher.h" |
| #include "chrome/browser/policy/logging_work_scheduler.h" |
| @@ -32,42 +33,13 @@ using ::testing::InSequence; |
| using ::testing::Mock; |
| using ::testing::Return; |
| -class MockCloudPolicyIdentityStrategy : public CloudPolicyIdentityStrategy { |
| - public: |
| - MockCloudPolicyIdentityStrategy() {} |
| - virtual ~MockCloudPolicyIdentityStrategy() {} |
| - |
| - MOCK_METHOD0(GetDeviceToken, std::string()); |
| - MOCK_METHOD0(GetDeviceID, std::string()); |
| - MOCK_METHOD0(GetMachineID, std::string()); |
| - MOCK_METHOD0(GetMachineModel, std::string()); |
| - MOCK_METHOD0(GetPolicyType, std::string()); |
| - MOCK_METHOD0(GetPolicyRegisterType, em::DeviceRegisterRequest_Type()); |
| - |
| - MOCK_METHOD2(GetCredentials, bool(std::string*, std::string*)); |
| - virtual void OnDeviceTokenAvailable(const std::string&) {} |
| - |
| - private: |
| - DISALLOW_COPY_AND_ASSIGN(MockCloudPolicyIdentityStrategy); |
| -}; |
| - |
| -ACTION_P2(MockCloudPolicyIdentityStrategyGetCredentials, username, auth_token) { |
| - *arg0 = username; |
| - *arg1 = auth_token; |
| - return true; |
| -} |
| - |
| class MockDeviceTokenFetcher : public DeviceTokenFetcher { |
| public: |
| explicit MockDeviceTokenFetcher(CloudPolicyCacheBase* cache) |
| - : DeviceTokenFetcher(NULL, cache, NULL) {} |
| + : DeviceTokenFetcher(NULL, cache, NULL, NULL) {} |
| virtual ~MockDeviceTokenFetcher() {} |
| - MOCK_METHOD0(GetDeviceToken, const std::string&()); |
| - MOCK_METHOD5(FetchToken, |
| - void(const std::string&, const std::string&, |
| - em::DeviceRegisterRequest_Type, |
| - const std::string&, const std::string&)); |
| + MOCK_METHOD0(FetchToken, void()); |
| MOCK_METHOD0(SetUnmanagedState, void()); |
| private: |
| @@ -88,15 +60,17 @@ class CloudPolicyControllerTest : public testing::Test { |
| temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"))); |
| token_fetcher_.reset(new MockDeviceTokenFetcher(cache_.get())); |
| service_.set_backend(&backend_); |
| + policy_data_.reset(CloudPolicyData::CreateForUserPolicies()); |
| } |
| virtual void TearDown() { |
| controller_.reset(); // Unregisters observers. |
| + policy_data_.reset(); |
| } |
| void CreateNewController() { |
| controller_.reset(new CloudPolicyController( |
| - &service_, cache_.get(), token_fetcher_.get(), &identity_strategy_, |
| + &service_, cache_.get(), token_fetcher_.get(), policy_data_.get(), |
| ¬ifier_, new DummyWorkScheduler)); |
| } |
| @@ -107,33 +81,6 @@ class CloudPolicyControllerTest : public testing::Test { |
| ASSERT_TRUE(Value::Equals(&expected, policy_map->Get(kPolicyDisableSpdy))); |
| } |
| - void SetupIdentityStrategy( |
| - const std::string& device_token, |
| - const std::string& device_id, |
| - const std::string& machine_id, |
| - const std::string& machine_model, |
| - const std::string& policy_type, |
| - const em::DeviceRegisterRequest_Type& policy_register_type, |
| - const std::string& user_name, |
| - const std::string& auth_token) { |
| - EXPECT_CALL(identity_strategy_, GetDeviceToken()).WillRepeatedly( |
| - Return(device_token)); |
| - EXPECT_CALL(identity_strategy_, GetDeviceID()).WillRepeatedly( |
| - Return(device_id)); |
| - EXPECT_CALL(identity_strategy_, GetMachineID()).WillRepeatedly( |
| - Return(machine_id)); |
| - EXPECT_CALL(identity_strategy_, GetMachineModel()).WillRepeatedly( |
| - Return(machine_model)); |
| - EXPECT_CALL(identity_strategy_, GetPolicyType()).WillRepeatedly( |
| - Return(policy_type)); |
| - EXPECT_CALL(identity_strategy_, GetPolicyRegisterType()).WillRepeatedly( |
| - Return(policy_register_type)); |
| - if (!user_name.empty()) { |
| - EXPECT_CALL(identity_strategy_, GetCredentials(_, _)).WillRepeatedly( |
| - MockCloudPolicyIdentityStrategyGetCredentials(user_name, auth_token)); |
| - } |
| - } |
| - |
| void StopMessageLoop() { |
| loop_.QuitNow(); |
| } |
| @@ -142,7 +89,7 @@ class CloudPolicyControllerTest : public testing::Test { |
| scoped_ptr<CloudPolicyCacheBase> cache_; |
| scoped_ptr<CloudPolicyController> controller_; |
| scoped_ptr<MockDeviceTokenFetcher> token_fetcher_; |
| - MockCloudPolicyIdentityStrategy identity_strategy_; |
| + scoped_ptr<CloudPolicyData> policy_data_; |
| MockDeviceManagementBackend backend_; |
| MockDeviceManagementService service_; |
| PolicyNotifier notifier_; |
| @@ -159,9 +106,8 @@ class CloudPolicyControllerTest : public testing::Test { |
| // If a device token is present when the controller starts up, it should |
| // fetch and apply policy. |
| TEST_F(CloudPolicyControllerTest, StartupWithDeviceToken) { |
| - SetupIdentityStrategy("fake_device_token", "device_id", "machine_id", |
| - "machine_model", "google/chromeos/user", |
| - em::DeviceRegisterRequest::USER, "", ""); |
| + policy_data_->SetupForTesting("fake_device_token", "device_id", "", "", |
| + true); |
| EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(DoAll( |
| InvokeWithoutArgs(this, &CloudPolicyControllerTest::StopMessageLoop), |
| MockDeviceManagementBackendSucceedSpdyCloudPolicy())); |
| @@ -173,10 +119,9 @@ TEST_F(CloudPolicyControllerTest, StartupWithDeviceToken) { |
| // If no device token is present when the controller starts up, it should |
| // instruct the token_fetcher_ to fetch one. |
| TEST_F(CloudPolicyControllerTest, StartupWithoutDeviceToken) { |
| - SetupIdentityStrategy("", "device_id", "machine_id", "machine_model", |
| - "google/chromeos/user", em::DeviceRegisterRequest::USER, |
| - "a@b.com", "auth_token"); |
| - EXPECT_CALL(*token_fetcher_.get(), FetchToken(_, _, _, _, _)).Times(1); |
| + policy_data_->SetupForTesting("", "device_id", "a@b.com", "auth_token", |
| + true); |
| + EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); |
| CreateNewController(); |
| loop_.RunAllPending(); |
| } |
| @@ -184,10 +129,9 @@ TEST_F(CloudPolicyControllerTest, StartupWithoutDeviceToken) { |
| // If the current user belongs to a known non-managed domain, no token fetch |
| // should be initiated. |
| TEST_F(CloudPolicyControllerTest, StartupUnmanagedUser) { |
| - SetupIdentityStrategy("", "device_id", "machine_id", "machine_mode", |
| - "google/chromeos/user", em::DeviceRegisterRequest::USER, |
| - "DannoHelper@gmail.com", "auth_token"); |
| - EXPECT_CALL(*token_fetcher_.get(), FetchToken(_, _, _, _, _)).Times(0); |
| + policy_data_->SetupForTesting("", "device_id", "DannoHelper@gmail.com", |
| + "auth_token", true); |
| + EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(0); |
| CreateNewController(); |
| loop_.RunAllPending(); |
| } |
| @@ -195,10 +139,9 @@ TEST_F(CloudPolicyControllerTest, StartupUnmanagedUser) { |
| // After policy has been fetched successfully, a new fetch should be triggered |
| // after the refresh interval has timed out. |
| TEST_F(CloudPolicyControllerTest, RefreshAfterSuccessfulPolicy) { |
| - SetupIdentityStrategy("device_token", "device_id", "machine_id", |
| - "machine_model", "google/chromeos/user", |
| - em::DeviceRegisterRequest::USER, |
| - "DannoHelperDelegate@b.com", "auth_token"); |
| + policy_data_->SetupForTesting("device_token", "device_id", |
| + "DannoHelperDelegate@b.com", |
| + "auth_token", true); |
| { |
| InSequence s; |
| EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| @@ -215,10 +158,9 @@ TEST_F(CloudPolicyControllerTest, RefreshAfterSuccessfulPolicy) { |
| // If policy fetching failed, it should be retried. |
| TEST_F(CloudPolicyControllerTest, RefreshAfterError) { |
| - SetupIdentityStrategy("device_token", "device_id", "machine_id", |
| - "machine_model", "google/chromeos/user", |
| - em::DeviceRegisterRequest::USER, |
| - "DannoHelperDelegateImpl@b.com", "auth_token"); |
| + policy_data_->SetupForTesting("device_token", "device_id", |
| + "DannoHelperDelegateImpl@b.com", |
| + "auth_token", true); |
| { |
| InSequence s; |
| EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| @@ -237,14 +179,12 @@ TEST_F(CloudPolicyControllerTest, RefreshAfterError) { |
| // If the backend reports that the device token was invalid, the controller |
| // should instruct the token fetcher to fetch a new token. |
| TEST_F(CloudPolicyControllerTest, InvalidToken) { |
| - SetupIdentityStrategy("device_token", "device_id", "machine_id", |
| - "machine_model", "google/chromeos/user", |
| - em::DeviceRegisterRequest::USER, |
| - "standup@ten.am", "auth"); |
| + policy_data_->SetupForTesting("device_token", "device_id", |
| + "standup@ten.am", "auth", true); |
| EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| MockDeviceManagementBackendFailPolicy( |
| DeviceManagementBackend::kErrorServiceManagementTokenInvalid)); |
| - EXPECT_CALL(*token_fetcher_.get(), FetchToken(_, _, _, _, _)).Times(1); |
| + EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); |
| CreateNewController(); |
| loop_.RunAllPending(); |
| } |
| @@ -252,14 +192,12 @@ TEST_F(CloudPolicyControllerTest, InvalidToken) { |
| // If the backend reports that the device is unknown to the server, the |
| // controller should instruct the token fetcher to fetch a new token. |
| TEST_F(CloudPolicyControllerTest, DeviceNotFound) { |
| - SetupIdentityStrategy("device_token", "device_id", "machine_id", |
| - "machine_model", "google/chromeos/user", |
| - em::DeviceRegisterRequest::USER, |
| - "me@you.com", "auth"); |
| + policy_data_->SetupForTesting("device_token", "device_id", |
| + "me@you.com", "auth", true); |
| EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| MockDeviceManagementBackendFailPolicy( |
| DeviceManagementBackend::kErrorServiceDeviceNotFound)); |
| - EXPECT_CALL(*token_fetcher_.get(), FetchToken(_, _, _, _, _)).Times(1); |
| + EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1); |
| CreateNewController(); |
| loop_.RunAllPending(); |
| } |
| @@ -268,10 +206,8 @@ TEST_F(CloudPolicyControllerTest, DeviceNotFound) { |
| // should instruct the token fetcher to fetch a new token (which will in turn |
| // set and persist the correct 'unmanaged' state). |
| TEST_F(CloudPolicyControllerTest, NoLongerManaged) { |
| - SetupIdentityStrategy("device_token", "device_id", "machine_id", |
| - "machine_model", "google/chromeos/user", |
| - em::DeviceRegisterRequest::USER, |
| - "who@what.com", "auth"); |
| + policy_data_->SetupForTesting("device_token", "device_id", |
| + "who@what.com", "auth", true); |
| EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( |
| MockDeviceManagementBackendFailPolicy( |
| DeviceManagementBackend::kErrorServiceManagementNotSupported)); |