| Index: chrome/browser/policy/user_policy_signin_service_unittest.cc
|
| diff --git a/chrome/browser/policy/user_policy_signin_service_unittest.cc b/chrome/browser/policy/user_policy_signin_service_unittest.cc
|
| index ab7d849269d18494f6128d16a43342fb10633852..f40745273bf71e3efb3c6793456686d86ecc1441 100644
|
| --- a/chrome/browser/policy/user_policy_signin_service_unittest.cc
|
| +++ b/chrome/browser/policy/user_policy_signin_service_unittest.cc
|
| @@ -5,7 +5,7 @@
|
| #include "base/message_loop.h"
|
| #include "base/run_loop.h"
|
| #include "chrome/browser/policy/browser_policy_connector.h"
|
| -#include "chrome/browser/policy/mock_cloud_policy_store.h"
|
| +#include "chrome/browser/policy/mock_user_cloud_policy_store.h"
|
| #include "chrome/browser/policy/user_cloud_policy_manager.h"
|
| #include "chrome/browser/policy/user_policy_signin_service.h"
|
| #include "chrome/browser/policy/user_policy_signin_service_factory.h"
|
| @@ -30,6 +30,9 @@
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| +using testing::AnyNumber;
|
| +using testing::Mock;
|
| +
|
| namespace policy {
|
|
|
| namespace {
|
| @@ -50,22 +53,22 @@ class UserPolicySigninServiceTest : public testing::Test {
|
| static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState(
|
| local_state_.get());
|
|
|
| - // Create a UserCloudPolicyManager with a MockCloudPolicyStore, and build a
|
| - // TestingProfile that uses it.
|
| - mock_store_ = new MockCloudPolicyStore();
|
| - scoped_ptr<UserCloudPolicyManager> manager(new UserCloudPolicyManager(
|
| - scoped_ptr<CloudPolicyStore>(mock_store_), false));
|
| - TestingProfile::Builder builder;
|
| - builder.SetUserCloudPolicyManager(manager.Pass());
|
| - profile_ = builder.Build().Pass();
|
| + // Create a testing profile and bring up a UserCloudPolicyManager with a
|
| + // MockUserCloudPolicyStore.
|
| + profile_.reset(new TestingProfile());
|
| profile_->CreateRequestContext();
|
| profile_->GetPrefs()->SetBoolean(prefs::kLoadCloudPolicyOnSignin, true);
|
| +
|
| + mock_store_ = new MockUserCloudPolicyStore();
|
| + EXPECT_CALL(*mock_store_, Load()).Times(AnyNumber());
|
| + manager_.reset(new UserCloudPolicyManager(
|
| + profile_.get(), scoped_ptr<UserCloudPolicyStore>(mock_store_)));
|
| SigninManagerFactory::GetInstance()->SetTestingFactory(
|
| profile_.get(), FakeSigninManager::Build);
|
|
|
| // Make sure the UserPolicySigninService is created.
|
| UserPolicySigninServiceFactory::GetForProfile(profile_.get());
|
| - testing::Mock::VerifyAndClearExpectations(mock_store_);
|
| + Mock::VerifyAndClearExpectations(mock_store_);
|
| }
|
|
|
| virtual void TearDown() OVERRIDE {
|
| @@ -85,9 +88,10 @@ class UserPolicySigninServiceTest : public testing::Test {
|
| }
|
|
|
| scoped_ptr<TestingProfile> profile_;
|
| - // Weak pointer to a MockCloudPolicyStore - lifetime is managed by the
|
| + // Weak pointer to a MockUserCloudPolicyStore - lifetime is managed by the
|
| // UserCloudPolicyManager.
|
| - MockCloudPolicyStore* mock_store_;
|
| + MockUserCloudPolicyStore* mock_store_;
|
| + scoped_ptr<UserCloudPolicyManager> manager_;
|
|
|
| // BrowserPolicyConnector and UrlFetcherFactory want to initialize and free
|
| // various components asynchronously via tasks, so create fake threads here.
|
| @@ -114,7 +118,7 @@ TEST_F(UserPolicySigninServiceTest, InitWhileSignedOut) {
|
| content::NotificationService::NoDetails());
|
|
|
| // UserCloudPolicyManager should not be initialized.
|
| - ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->cloud_policy_service());
|
| + ASSERT_FALSE(manager_->cloud_policy_service());
|
| }
|
|
|
| TEST_F(UserPolicySigninServiceTest, InitWhileSignedIn) {
|
| @@ -129,7 +133,7 @@ TEST_F(UserPolicySigninServiceTest, InitWhileSignedIn) {
|
| content::NotificationService::NoDetails());
|
|
|
| // UserCloudPolicyManager should be initialized.
|
| - ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->cloud_policy_service());
|
| + ASSERT_TRUE(manager_->cloud_policy_service());
|
|
|
| // Complete initialization of the store.
|
| mock_store_->NotifyStoreLoaded();
|
| @@ -155,7 +159,7 @@ TEST_F(UserPolicySigninServiceTest, SignInAfterInit) {
|
|
|
| // UserCloudPolicyManager should not be initialized since there is no
|
| // signed-in user.
|
| - ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->cloud_policy_service());
|
| + ASSERT_FALSE(manager_->cloud_policy_service());
|
|
|
| // Now sign in the user.
|
| SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername(
|
| @@ -169,7 +173,7 @@ TEST_F(UserPolicySigninServiceTest, SignInAfterInit) {
|
| GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token");
|
|
|
| // UserCloudPolicyManager should be initialized.
|
| - ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->cloud_policy_service());
|
| + ASSERT_TRUE(manager_->cloud_policy_service());
|
|
|
| // Client registration should be in progress since we have an oauth token.
|
| ASSERT_TRUE(IsRequestActive());
|
| @@ -185,7 +189,7 @@ TEST_F(UserPolicySigninServiceTest, UnregisteredClient) {
|
|
|
| // UserCloudPolicyManager should not be initialized since there is no
|
| // signed-in user.
|
| - ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->cloud_policy_service());
|
| + ASSERT_FALSE(manager_->cloud_policy_service());
|
|
|
| // Now sign in the user.
|
| SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername(
|
| @@ -196,7 +200,7 @@ TEST_F(UserPolicySigninServiceTest, UnregisteredClient) {
|
| GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token");
|
|
|
| // UserCloudPolicyManager should be initialized.
|
| - ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->cloud_policy_service());
|
| + ASSERT_TRUE(manager_->cloud_policy_service());
|
|
|
| // Client registration should not be in progress since the store is not
|
| // yet initialized.
|
| @@ -219,7 +223,7 @@ TEST_F(UserPolicySigninServiceTest, RegisteredClient) {
|
|
|
| // UserCloudPolicyManager should not be initialized since there is no
|
| // signed-in user.
|
| - ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->cloud_policy_service());
|
| + ASSERT_FALSE(manager_->cloud_policy_service());
|
|
|
| // Now sign in the user.
|
| SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername(
|
| @@ -230,11 +234,11 @@ TEST_F(UserPolicySigninServiceTest, RegisteredClient) {
|
| GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token");
|
|
|
| // UserCloudPolicyManager should be initialized.
|
| - ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->cloud_policy_service());
|
| + ASSERT_TRUE(manager_->cloud_policy_service());
|
|
|
| // Client registration should not be in progress since the store is not
|
| // yet initialized.
|
| - ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->IsClientRegistered());
|
| + ASSERT_FALSE(manager_->IsClientRegistered());
|
| ASSERT_FALSE(IsRequestActive());
|
|
|
| mock_store_->policy_.reset(new enterprise_management::PolicyData());
|
| @@ -246,7 +250,7 @@ TEST_F(UserPolicySigninServiceTest, RegisteredClient) {
|
|
|
| // Client registration should not be in progress since the client should be
|
| // already registered.
|
| - ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->IsClientRegistered());
|
| + ASSERT_TRUE(manager_->IsClientRegistered());
|
| ASSERT_FALSE(IsRequestActive());
|
| }
|
|
|
| @@ -263,13 +267,13 @@ TEST_F(UserPolicySigninServiceTest, SignOutAfterInit) {
|
| content::NotificationService::NoDetails());
|
|
|
| // UserCloudPolicyManager should be initialized.
|
| - ASSERT_TRUE(profile_->GetUserCloudPolicyManager()->cloud_policy_service());
|
| + ASSERT_TRUE(manager_->cloud_policy_service());
|
|
|
| // Now sign out.
|
| SigninManagerFactory::GetForProfile(profile_.get())->SignOut();
|
|
|
| // UserCloudPolicyManager should be shut down.
|
| - ASSERT_FALSE(profile_->GetUserCloudPolicyManager()->cloud_policy_service());
|
| + ASSERT_FALSE(manager_->cloud_policy_service());
|
| }
|
|
|
| } // namespace
|
|
|