| 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..b358a1ff1166ef7166d186461412490d650bf84f 100644
|
| --- a/chrome/browser/policy/cloud_policy_controller_unittest.cc
|
| +++ b/chrome/browser/policy/cloud_policy_controller_unittest.cc
|
| @@ -6,68 +6,33 @@
|
|
|
| #include "base/message_loop.h"
|
| #include "base/scoped_temp_dir.h"
|
| -#include "chrome/browser/policy/device_management_service.h"
|
| +#include "chrome/browser/policy/cloud_policy_data_store.h"
|
| #include "chrome/browser/policy/device_token_fetcher.h"
|
| #include "chrome/browser/policy/logging_work_scheduler.h"
|
| -#include "chrome/browser/policy/mock_configuration_policy_store.h"
|
| #include "chrome/browser/policy/mock_device_management_backend.h"
|
| #include "chrome/browser/policy/mock_device_management_service.h"
|
| #include "chrome/browser/policy/policy_notifier.h"
|
| -#include "chrome/browser/policy/proto/device_management_backend.pb.h"
|
| #include "chrome/browser/policy/user_policy_cache.h"
|
| #include "content/browser/browser_thread.h"
|
| #include "policy/policy_constants.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| -const char kTestToken[] = "cloud_policy_controller_test_auth_token";
|
| -
|
| namespace policy {
|
|
|
| -namespace em = enterprise_management;
|
| -
|
| using ::testing::_;
|
| using ::testing::AtLeast;
|
| 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 +53,17 @@ class CloudPolicyControllerTest : public testing::Test {
|
| temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest")));
|
| token_fetcher_.reset(new MockDeviceTokenFetcher(cache_.get()));
|
| service_.set_backend(&backend_);
|
| + data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies());
|
| }
|
|
|
| virtual void TearDown() {
|
| controller_.reset(); // Unregisters observers.
|
| + data_store_.reset();
|
| }
|
|
|
| void CreateNewController() {
|
| controller_.reset(new CloudPolicyController(
|
| - &service_, cache_.get(), token_fetcher_.get(), &identity_strategy_,
|
| + &service_, cache_.get(), token_fetcher_.get(), data_store_.get(),
|
| ¬ifier_, new DummyWorkScheduler));
|
| }
|
|
|
| @@ -107,33 +74,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 +82,7 @@ class CloudPolicyControllerTest : public testing::Test {
|
| scoped_ptr<CloudPolicyCacheBase> cache_;
|
| scoped_ptr<CloudPolicyController> controller_;
|
| scoped_ptr<MockDeviceTokenFetcher> token_fetcher_;
|
| - MockCloudPolicyIdentityStrategy identity_strategy_;
|
| + scoped_ptr<CloudPolicyDataStore> data_store_;
|
| MockDeviceManagementBackend backend_;
|
| MockDeviceManagementService service_;
|
| PolicyNotifier notifier_;
|
| @@ -159,9 +99,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, "", "");
|
| + data_store_->SetupForTesting("fake_device_token", "device_id", "", "",
|
| + true);
|
| EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(DoAll(
|
| InvokeWithoutArgs(this, &CloudPolicyControllerTest::StopMessageLoop),
|
| MockDeviceManagementBackendSucceedSpdyCloudPolicy()));
|
| @@ -173,10 +112,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);
|
| + data_store_->SetupForTesting("", "device_id", "a@b.com", "auth_token",
|
| + true);
|
| + EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1);
|
| CreateNewController();
|
| loop_.RunAllPending();
|
| }
|
| @@ -184,10 +122,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);
|
| + data_store_->SetupForTesting("", "device_id", "DannoHelper@gmail.com",
|
| + "auth_token", true);
|
| + EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(0);
|
| CreateNewController();
|
| loop_.RunAllPending();
|
| }
|
| @@ -195,10 +132,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");
|
| + data_store_->SetupForTesting("device_token", "device_id",
|
| + "DannoHelperDelegate@b.com",
|
| + "auth_token", true);
|
| {
|
| InSequence s;
|
| EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
|
| @@ -215,10 +151,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");
|
| + data_store_->SetupForTesting("device_token", "device_id",
|
| + "DannoHelperDelegateImpl@b.com",
|
| + "auth_token", true);
|
| {
|
| InSequence s;
|
| EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
|
| @@ -237,14 +172,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");
|
| + data_store_->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 +185,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");
|
| + data_store_->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 +199,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");
|
| + data_store_->SetupForTesting("device_token", "device_id",
|
| + "who@what.com", "auth", true);
|
| EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
|
| MockDeviceManagementBackendFailPolicy(
|
| DeviceManagementBackend::kErrorServiceManagementNotSupported));
|
|
|