Commit 09c92d7a authored by Sergio Villar Senin's avatar Sergio Villar Senin Committed by Commit Bot

Convert arc_session_manager_browsertest.cc to use IdentityManager

It was using both SigninManager and ProfileOAuth2TokenService fake
objects injected in the profile to signin the user with a refresh
token. The IdentityTestEnvironmentProfileAdaptor could be used to
create the testing profile followed by
IdentityTestEnvironment::MakePrimaryAccountAvailable() to perform the
signin.

Bug: 882864
Change-Id: I6d546a722a0eda4f3d14d6234d819a3964c7d92e
Reviewed-on: https://chromium-review.googlesource.com/c/1338107Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarElijah Taylor <elijahtaylor@chromium.org>
Commit-Queue: Sergio Villar <svillar@igalia.com>
Cr-Commit-Position: refs/heads/master@{#609637}
parent 13921a60
...@@ -26,10 +26,7 @@ ...@@ -26,10 +26,7 @@
#include "chrome/browser/policy/test/local_policy_test_server.h" #include "chrome/browser/policy/test/local_policy_test_server.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" #include "chrome/browser/signin/identity_test_environment_profile_adaptor.h"
#include "chrome/browser/signin/fake_signin_manager_builder.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
...@@ -45,20 +42,18 @@ ...@@ -45,20 +42,18 @@
#include "components/prefs/pref_member.h" #include "components/prefs/pref_member.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager_base.h"
#include "components/user_manager/scoped_user_manager.h" #include "components/user_manager/scoped_user_manager.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "net/base/upload_bytes_element_reader.h" #include "net/base/upload_bytes_element_reader.h"
#include "net/base/upload_data_stream.h" #include "net/base/upload_data_stream.h"
#include "net/url_request/url_request_test_job.h" #include "net/url_request/url_request_test_job.h"
#include "services/identity/public/cpp/identity_test_environment.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace { namespace {
constexpr char kRefreshToken[] = "fake-refresh-token";
// Set managed auth token for Android managed accounts. // Set managed auth token for Android managed accounts.
constexpr char kManagedAuthToken[] = "managed-auth-token"; constexpr char kManagedAuthToken[] = "managed-auth-token";
// Set unmanaged auth token for other Android unmanaged accounts. // Set unmanaged auth token for other Android unmanaged accounts.
...@@ -147,25 +142,14 @@ class ArcSessionManagerTest : public InProcessBrowserTest { ...@@ -147,25 +142,14 @@ class ArcSessionManagerTest : public InProcessBrowserTest {
TestingProfile::Builder profile_builder; TestingProfile::Builder profile_builder;
profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile")); profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile"));
profile_builder.SetProfileName(kFakeUserName); profile_builder.SetProfileName(kFakeUserName);
profile_builder.AddTestingFactory( profile_ = IdentityTestEnvironmentProfileAdaptor::
ProfileOAuth2TokenServiceFactory::GetInstance(), CreateProfileForIdentityTestEnvironment(profile_builder);
base::BindRepeating(&BuildFakeProfileOAuth2TokenService));
profile_builder.AddTestingFactory( identity_test_environment_adaptor_ =
SigninManagerFactory::GetInstance(), std::make_unique<IdentityTestEnvironmentProfileAdaptor>(profile_.get());
base::BindRepeating(&BuildFakeSigninManagerForTesting));
profile_ = profile_builder.Build();
// Seed account info properly. // Seed account info properly.
const std::string account_id_str = identity_test_env()->MakePrimaryAccountAvailable(kFakeUserName);
AccountTrackerServiceFactory::GetForProfile(profile_.get())
->SeedAccountInfo(kFakeGaiaId, kFakeUserName);
token_service_ = static_cast<FakeProfileOAuth2TokenService*>(
ProfileOAuth2TokenServiceFactory::GetForProfile(profile()));
FakeSigninManagerForTesting* fake_signin_manager =
static_cast<FakeSigninManagerForTesting*>(
SigninManagerFactory::GetForProfile(profile()));
fake_signin_manager->SignIn(account_id_str);
token_service_->UpdateCredentials(account_id_str, kRefreshToken);
profile()->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true); profile()->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true);
profile()->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); profile()->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true);
...@@ -195,6 +179,7 @@ class ArcSessionManagerTest : public InProcessBrowserTest { ...@@ -195,6 +179,7 @@ class ArcSessionManagerTest : public InProcessBrowserTest {
// instance in fixture, once), but it should be no op. // instance in fixture, once), but it should be no op.
// TODO(hidehiko): Think about a way to test the code cleanly. // TODO(hidehiko): Think about a way to test the code cleanly.
ArcServiceLauncher::Get()->Shutdown(); ArcServiceLauncher::Get()->Shutdown();
identity_test_environment_adaptor_.reset();
profile_.reset(); profile_.reset();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
user_manager_enabler_.reset(); user_manager_enabler_.reset();
...@@ -219,22 +204,25 @@ class ArcSessionManagerTest : public InProcessBrowserTest { ...@@ -219,22 +204,25 @@ class ArcSessionManagerTest : public InProcessBrowserTest {
Profile* profile() { return profile_.get(); } Profile* profile() { return profile_.get(); }
FakeProfileOAuth2TokenService* token_service() { return token_service_; } identity::IdentityTestEnvironment* identity_test_env() {
return identity_test_environment_adaptor_->identity_test_env();
}
private: private:
std::unique_ptr<policy::LocalPolicyTestServer> test_server_; std::unique_ptr<policy::LocalPolicyTestServer> test_server_;
std::unique_ptr<user_manager::ScopedUserManager> user_manager_enabler_; std::unique_ptr<user_manager::ScopedUserManager> user_manager_enabler_;
std::unique_ptr<IdentityTestEnvironmentProfileAdaptor>
identity_test_environment_adaptor_;
base::ScopedTempDir temp_dir_; base::ScopedTempDir temp_dir_;
std::unique_ptr<TestingProfile> profile_; std::unique_ptr<TestingProfile> profile_;
FakeProfileOAuth2TokenService* token_service_;
DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest);
}; };
IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ConsumerAccount) { IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ConsumerAccount) {
EnableArc(); EnableArc();
token_service()->IssueTokenForAllPendingRequests(kUnmanagedAuthToken, identity_test_env()->WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
base::Time::Max()); kUnmanagedAuthToken, base::Time::Max());
ASSERT_EQ(ArcSessionManager::State::ACTIVE, ASSERT_EQ(ArcSessionManager::State::ACTIVE,
ArcSessionManager::Get()->state()); ArcSessionManager::Get()->state());
} }
...@@ -258,8 +246,8 @@ IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedChromeAccount) { ...@@ -258,8 +246,8 @@ IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedChromeAccount) {
IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedAndroidAccount) { IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedAndroidAccount) {
EnableArc(); EnableArc();
token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, identity_test_env()->WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
base::Time::Max()); kManagedAuthToken, base::Time::Max());
ArcPlayStoreDisabledWaiter().Wait(); ArcPlayStoreDisabledWaiter().Wait();
EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile())); EXPECT_FALSE(IsArcPlayStoreEnabledForProfile(profile()));
} }
......
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