Commit b3321402 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

[s13n] Convert profile_downloader_unittest.cc away from using ProfileOAuth2TokenService

BUG=904407

Change-Id: Ibfc219bb273a7ff8ee1d8693ca2f25994a038f5b
Reviewed-on: https://chromium-review.googlesource.com/c/1335907Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#607981}
parent f2099695
...@@ -11,16 +11,15 @@ ...@@ -11,16 +11,15 @@
#include "chrome/browser/signin/account_fetcher_service_factory.h" #include "chrome/browser/signin/account_fetcher_service_factory.h"
#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/fake_account_fetcher_service_builder.h" #include "chrome/browser/signin/fake_account_fetcher_service_builder.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/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/test_signin_client_builder.h" #include "chrome/browser/signin/test_signin_client_builder.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.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_account_fetcher_service.h" #include "components/signin/core/browser/fake_account_fetcher_service.h"
#include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
#include "components/signin/core/browser/test_signin_client.h" #include "components/signin/core/browser/test_signin_client.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "net/url_request/test_url_fetcher_factory.h" #include "net/url_request/test_url_fetcher_factory.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace { namespace {
...@@ -36,9 +35,10 @@ const std::string kTestInvalidPictureURL = "invalid_picture_url"; ...@@ -36,9 +35,10 @@ const std::string kTestInvalidPictureURL = "invalid_picture_url";
} // namespace } // namespace
class ProfileDownloaderTest : public testing::Test, class ProfileDownloaderTest
public ProfileDownloaderDelegate, : public testing::Test,
public OAuth2TokenService::DiagnosticsObserver { public ProfileDownloaderDelegate,
public identity::IdentityManager::DiagnosticsObserver {
protected: protected:
ProfileDownloaderTest() ProfileDownloaderTest()
: thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {}
...@@ -46,25 +46,31 @@ class ProfileDownloaderTest : public testing::Test, ...@@ -46,25 +46,31 @@ class ProfileDownloaderTest : public testing::Test,
void SetUp() override { void SetUp() override {
TestingProfile::Builder builder; TestingProfile::Builder builder;
builder.AddTestingFactory(
ProfileOAuth2TokenServiceFactory::GetInstance(),
base::BindRepeating(&BuildFakeProfileOAuth2TokenService));
builder.AddTestingFactory( builder.AddTestingFactory(
AccountFetcherServiceFactory::GetInstance(), AccountFetcherServiceFactory::GetInstance(),
base::BindRepeating(&FakeAccountFetcherServiceBuilder::BuildForTests)); base::BindRepeating(&FakeAccountFetcherServiceBuilder::BuildForTests));
profile_ = builder.Build();
profile_ = IdentityTestEnvironmentProfileAdaptor::
CreateProfileForIdentityTestEnvironment(builder);
account_tracker_service_ = account_tracker_service_ =
AccountTrackerServiceFactory::GetForProfile(profile_.get()); AccountTrackerServiceFactory::GetForProfile(profile_.get());
account_fetcher_service_ = static_cast<FakeAccountFetcherService*>( account_fetcher_service_ = static_cast<FakeAccountFetcherService*>(
AccountFetcherServiceFactory::GetForProfile(profile_.get())); AccountFetcherServiceFactory::GetForProfile(profile_.get()));
token_service_ = static_cast<FakeProfileOAuth2TokenService*>(
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()));
profile_downloader_.reset(new ProfileDownloader(this)); profile_downloader_.reset(new ProfileDownloader(this));
token_service_->AddDiagnosticsObserver(this); identity_test_env_profile_adaptor_ =
std::make_unique<IdentityTestEnvironmentProfileAdaptor>(profile_.get());
identity_test_env_ =
identity_test_env_profile_adaptor_->identity_test_env();
DCHECK(identity_test_env_);
identity_test_env_->identity_manager()->AddDiagnosticsObserver(this);
} }
void TearDown() override { token_service_->RemoveDiagnosticsObserver(this); } void TearDown() override {
identity_test_env_->identity_manager()->RemoveDiagnosticsObserver(this);
}
bool NeedsProfilePicture() const override { return true; }; bool NeedsProfilePicture() const override { return true; };
int GetDesiredImageSideLength() const override { return 128; }; int GetDesiredImageSideLength() const override { return 128; };
...@@ -86,11 +92,10 @@ class ProfileDownloaderTest : public testing::Test, ...@@ -86,11 +92,10 @@ class ProfileDownloaderTest : public testing::Test,
kTestLocale, picture_url); kTestLocale, picture_url);
} }
// OAuth2TokenService::DiagnosticsObserver: // IdentityManager::DiagnosticsObserver:
void OnAccessTokenRequested( void OnAccessTokenRequested(const std::string& account_id,
const std::string& account_id, const std::string& consumer_id,
const std::string& consumer_id, const identity::ScopeSet& scopes) override {
const OAuth2TokenService::ScopeSet& scopes) override {
// This flow should be invoked only when a test has explicitly set up // This flow should be invoked only when a test has explicitly set up
// preconditions so that ProfileDownloader will request access tokens. // preconditions so that ProfileDownloader will request access tokens.
DCHECK(!on_access_token_request_callback_.is_null()); DCHECK(!on_access_token_request_callback_.is_null());
...@@ -106,9 +111,11 @@ class ProfileDownloaderTest : public testing::Test, ...@@ -106,9 +111,11 @@ class ProfileDownloaderTest : public testing::Test,
AccountTrackerService* account_tracker_service_; AccountTrackerService* account_tracker_service_;
FakeAccountFetcherService* account_fetcher_service_; FakeAccountFetcherService* account_fetcher_service_;
FakeProfileOAuth2TokenService* token_service_;
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<Profile> profile_; std::unique_ptr<Profile> profile_;
std::unique_ptr<IdentityTestEnvironmentProfileAdaptor>
identity_test_env_profile_adaptor_;
identity::IdentityTestEnvironment* identity_test_env_;
base::OnceClosure on_access_token_request_callback_; base::OnceClosure on_access_token_request_callback_;
std::string account_id_for_access_token_request_; std::string account_id_for_access_token_request_;
std::unique_ptr<ProfileDownloader> profile_downloader_; std::unique_ptr<ProfileDownloader> profile_downloader_;
...@@ -117,7 +124,7 @@ class ProfileDownloaderTest : public testing::Test, ...@@ -117,7 +124,7 @@ class ProfileDownloaderTest : public testing::Test,
TEST_F(ProfileDownloaderTest, FetchAccessToken) { TEST_F(ProfileDownloaderTest, FetchAccessToken) {
std::string account_id = std::string account_id =
account_tracker_service_->SeedAccountInfo(kTestGaia, kTestEmail); account_tracker_service_->SeedAccountInfo(kTestGaia, kTestEmail);
token_service_->UpdateCredentials(account_id, "refresh_token"); identity_test_env_->SetRefreshTokenForAccount(account_id);
base::RunLoop run_loop; base::RunLoop run_loop;
set_on_access_token_requested_callback(run_loop.QuitClosure()); set_on_access_token_requested_callback(run_loop.QuitClosure());
......
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