Commit 4cdc95ad authored by Sergio Villar Senin's avatar Sergio Villar Senin Committed by Commit Bot

Migrate process_dice_header_delegate_impl_unittest.cc to IdentityTestEnvironment

After successfully migrating the ProcessDiceHeaderDelegateImpl we can
complete the job by also migrating the unit test. Several fake objects
were removed in favour of IdentityTestEnvironment which also provides
an IdentityManager.

Bug: 890791
Change-Id: Ie689268b0b9e2569a4cce5c4abe645d3daa82c7e
Reviewed-on: https://chromium-review.googlesource.com/c/1282743Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Sergio Villar <svillar@igalia.com>
Cr-Commit-Position: refs/heads/master@{#599985}
parent 7a4d9c87
...@@ -12,15 +12,10 @@ ...@@ -12,15 +12,10 @@
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "chrome/common/webui_url_constants.h" #include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/fake_gaia_cookie_manager_service.h"
#include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
#include "components/signin/core/browser/fake_signin_manager.h"
#include "components/signin/core/browser/profile_management_switches.h" #include "components/signin/core/browser/profile_management_switches.h"
#include "components/signin/core/browser/test_signin_client.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "services/identity/public/cpp/identity_manager.h" #include "services/identity/public/cpp/identity_manager.h"
#include "services/identity/public/cpp/identity_test_environment.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace { namespace {
...@@ -37,45 +32,21 @@ class ProcessDiceHeaderDelegateImplTest ...@@ -37,45 +32,21 @@ class ProcessDiceHeaderDelegateImplTest
: public ChromeRenderViewHostTestHarness { : public ChromeRenderViewHostTestHarness {
public: public:
ProcessDiceHeaderDelegateImplTest() ProcessDiceHeaderDelegateImplTest()
: signin_client_(&pref_service_), : enable_sync_called_(false),
token_service_(&pref_service_),
signin_manager_(&signin_client_,
&token_service_,
&account_tracker_service_,
nullptr),
gaia_cookie_manager_service_(&token_service_,
"process_dice_header_delegate",
&signin_client_),
identity_manager_(&signin_manager_,
&token_service_,
&account_tracker_service_,
&gaia_cookie_manager_service_),
enable_sync_called_(false),
show_error_called_(false), show_error_called_(false),
account_id_("12345"), account_id_("12345"),
email_("foo@bar.com"), email_("foo@bar.com"),
auth_error_(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS) { auth_error_(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS) {}
AccountTrackerService::RegisterPrefs(pref_service_.registry());
ProfileOAuth2TokenService::RegisterProfilePrefs(pref_service_.registry());
SigninManager::RegisterProfilePrefs(pref_service_.registry());
account_tracker_service_.Initialize(&pref_service_, base::FilePath());
}
~ProcessDiceHeaderDelegateImplTest() override { ~ProcessDiceHeaderDelegateImplTest() override {}
signin_manager_.Shutdown();
account_tracker_service_.Shutdown();
token_service_.Shutdown();
signin_client_.Shutdown();
gaia_cookie_manager_service_.Shutdown();
}
// Creates a ProcessDiceHeaderDelegateImpl instance. // Creates a ProcessDiceHeaderDelegateImpl instance.
std::unique_ptr<ProcessDiceHeaderDelegateImpl> CreateDelegate( std::unique_ptr<ProcessDiceHeaderDelegateImpl> CreateDelegate(
bool is_sync_signin_tab, bool is_sync_signin_tab,
signin::AccountConsistencyMethod account_consistency) { signin::AccountConsistencyMethod account_consistency) {
return std::make_unique<ProcessDiceHeaderDelegateImpl>( return std::make_unique<ProcessDiceHeaderDelegateImpl>(
web_contents(), account_consistency, &identity_manager_, web_contents(), account_consistency,
is_sync_signin_tab, identity_test_environment_.identity_manager(), is_sync_signin_tab,
base::BindOnce(&ProcessDiceHeaderDelegateImplTest::StartSyncCallback, base::BindOnce(&ProcessDiceHeaderDelegateImplTest::StartSyncCallback,
base::Unretained(this)), base::Unretained(this)),
base::BindOnce( base::BindOnce(
...@@ -101,13 +72,7 @@ class ProcessDiceHeaderDelegateImplTest ...@@ -101,13 +72,7 @@ class ProcessDiceHeaderDelegateImplTest
show_error_called_ = true; show_error_called_ = true;
} }
sync_preferences::TestingPrefServiceSyncable pref_service_; identity::IdentityTestEnvironment identity_test_environment_;
TestSigninClient signin_client_;
FakeProfileOAuth2TokenService token_service_;
AccountTrackerService account_tracker_service_;
FakeSigninManager signin_manager_;
FakeGaiaCookieManagerService gaia_cookie_manager_service_;
identity::IdentityManager identity_manager_;
bool enable_sync_called_; bool enable_sync_called_;
bool show_error_called_; bool show_error_called_;
...@@ -194,7 +159,7 @@ TEST_P(ProcessDiceHeaderDelegateImplTestEnableSync, EnableSync) { ...@@ -194,7 +159,7 @@ TEST_P(ProcessDiceHeaderDelegateImplTestEnableSync, EnableSync) {
NavigateAndCommit(kSigninURL); NavigateAndCommit(kSigninURL);
ASSERT_EQ(kSigninURL, web_contents()->GetVisibleURL()); ASSERT_EQ(kSigninURL, web_contents()->GetVisibleURL());
if (GetParam().signed_in) if (GetParam().signed_in)
signin_manager_.SignIn("gaia_id", "user", "pass"); identity_test_environment_.SetPrimaryAccount(email_);
std::unique_ptr<ProcessDiceHeaderDelegateImpl> delegate = std::unique_ptr<ProcessDiceHeaderDelegateImpl> delegate =
CreateDelegate(GetParam().signin_tab, GetParam().account_consistency); CreateDelegate(GetParam().signin_tab, GetParam().account_consistency);
...@@ -242,7 +207,7 @@ TEST_P(ProcessDiceHeaderDelegateImplTestHandleTokenExchangeFailure, ...@@ -242,7 +207,7 @@ TEST_P(ProcessDiceHeaderDelegateImplTestHandleTokenExchangeFailure,
NavigateAndCommit(kSigninURL); NavigateAndCommit(kSigninURL);
ASSERT_EQ(kSigninURL, web_contents()->GetVisibleURL()); ASSERT_EQ(kSigninURL, web_contents()->GetVisibleURL());
if (GetParam().signed_in) if (GetParam().signed_in)
signin_manager_.SignIn("gaia_id", "user", "pass"); identity_test_environment_.SetPrimaryAccount(email_);
std::unique_ptr<ProcessDiceHeaderDelegateImpl> delegate = std::unique_ptr<ProcessDiceHeaderDelegateImpl> delegate =
CreateDelegate(GetParam().signin_tab, GetParam().account_consistency); CreateDelegate(GetParam().signin_tab, GetParam().account_consistency);
......
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