Commit 944adf7f authored by David Roger's avatar David Roger Committed by Commit Bot

[signin] Remove usage of AuthErrorProvider from tests

Going forward the default API for interacting with authentication error
should be the token service rather than the SigninErrorController.
This CL updates tests to use the token service instead of
AuthErrorProvider to set authentication errors.

TBR=ellyjones

Bug: 836212
Change-Id: I694068a1d037b1f2314d389328b9ccbea5f2bcf3
Reviewed-on: https://chromium-review.googlesource.com/1016642
Commit-Queue: David Roger <droger@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553509}
parent ba44adf8
......@@ -23,7 +23,6 @@
#include "chrome/test/base/testing_profile_manager.h"
#include "components/browser_sync/profile_sync_service.h"
#include "components/browser_sync/profile_sync_service_mock.h"
#include "components/signin/core/browser/fake_auth_status_provider.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/test/test_browser_thread_bundle.h"
......
......@@ -32,8 +32,7 @@ class SigninGlobalError : public GlobalErrorWithStandardBubble,
void AttemptToFixError(Browser* browser);
private:
FRIEND_TEST_ALL_PREFIXES(SigninGlobalErrorTest, NoErrorAuthStatusProviders);
FRIEND_TEST_ALL_PREFIXES(SigninGlobalErrorTest, ErrorAuthStatusProvider);
FRIEND_TEST_ALL_PREFIXES(SigninGlobalErrorTest, Basic);
FRIEND_TEST_ALL_PREFIXES(SigninGlobalErrorTest, AuthStatusEnumerateAllErrors);
// KeyedService:
......
......@@ -16,7 +16,6 @@
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.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_error_controller_factory.h"
......@@ -29,11 +28,12 @@
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/prefs/pref_service.h"
#include "components/signin/core/browser/fake_auth_status_provider.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "google_apis/gaia/oauth2_token_service_delegate.h"
#include "testing/gtest/include/gtest/gtest.h"
static const char kTestAccountId[] = "id-testuser@test.com";
......@@ -50,9 +50,6 @@ class SigninGlobalErrorTest : public testing::Test {
// Create a signed-in profile.
TestingProfile::TestingFactories testing_factories;
testing_factories.push_back(std::make_pair(
ProfileOAuth2TokenServiceFactory::GetInstance(),
BuildFakeProfileOAuth2TokenService));
testing_factories.push_back(std::make_pair(
SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase));
profile_ = profile_manager_.CreateTestingProfile(
......@@ -77,6 +74,16 @@ class SigninGlobalErrorTest : public testing::Test {
SigninGlobalError* global_error() { return global_error_; }
SigninErrorController* error_controller() { return error_controller_; }
void SetAuthError(GoogleServiceAuthError::State state) {
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
token_service->UpdateCredentials(kTestAccountId, "refresh_token");
// TODO(https://crbug.com/836212): Do not use the delegate directly, because
// it is internal API.
token_service->GetDelegate()->UpdateAuthError(
kTestAccountId, GoogleServiceAuthError(state));
}
private:
content::TestBrowserThreadBundle thread_bundle_;
TestingProfileManager profile_manager_;
......@@ -85,40 +92,14 @@ class SigninGlobalErrorTest : public testing::Test {
SigninErrorController* error_controller_;
};
TEST_F(SigninGlobalErrorTest, NoErrorAuthStatusProviders) {
std::unique_ptr<FakeAuthStatusProvider> provider;
ASSERT_FALSE(global_error()->HasMenuItem());
// Add a provider.
provider.reset(new FakeAuthStatusProvider(error_controller()));
ASSERT_FALSE(global_error()->HasMenuItem());
// Remove the provider.
provider.reset();
ASSERT_FALSE(global_error()->HasMenuItem());
}
TEST_F(SigninGlobalErrorTest, ErrorAuthStatusProvider) {
std::unique_ptr<FakeAuthStatusProvider> provider;
std::unique_ptr<FakeAuthStatusProvider> error_provider;
provider.reset(new FakeAuthStatusProvider(error_controller()));
TEST_F(SigninGlobalErrorTest, Basic) {
ASSERT_FALSE(global_error()->HasMenuItem());
error_provider.reset(new FakeAuthStatusProvider(error_controller()));
error_provider->SetAuthError(
kTestAccountId,
GoogleServiceAuthError(
GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
ASSERT_TRUE(global_error()->HasMenuItem());
SetAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
EXPECT_TRUE(global_error()->HasMenuItem());
error_provider.reset();
ASSERT_FALSE(global_error()->HasMenuItem());
provider.reset();
error_provider.reset();
ASSERT_FALSE(global_error()->HasMenuItem());
SetAuthError(GoogleServiceAuthError::NONE);
EXPECT_FALSE(global_error()->HasMenuItem());
}
// Verify that SigninGlobalError ignores certain errors.
......@@ -153,10 +134,10 @@ TEST_F(SigninGlobalErrorTest, AuthStatusEnumerateAllErrors) {
for (size_t i = 0; i < arraysize(table); ++i) {
if (GoogleServiceAuthError::IsDeprecated(table[i].error_state))
continue;
SetAuthError(GoogleServiceAuthError::NONE);
base::HistogramTester histogram_tester;
FakeAuthStatusProvider provider(error_controller());
provider.SetAuthError(kTestAccountId,
GoogleServiceAuthError(table[i].error_state));
SetAuthError(table[i].error_state);
EXPECT_EQ(global_error()->HasMenuItem(), table[i].is_error);
EXPECT_EQ(global_error()->MenuItemLabel().empty(), !table[i].is_error);
......
......@@ -20,7 +20,6 @@
#include "chrome/test/base/testing_profile.h"
#include "components/browser_sync/profile_sync_service_mock.h"
#include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/fake_auth_status_provider.h"
#include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
......
......@@ -13,17 +13,19 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_error_controller_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/profile_sync_test_util.h"
#include "chrome/browser/sync/sync_ui_util.h"
#include "chrome/test/base/testing_profile.h"
#include "components/browser_sync/profile_sync_service_mock.h"
#include "components/signin/core/browser/fake_auth_status_provider.h"
#include "components/signin/core/browser/fake_signin_manager.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "google_apis/gaia/oauth2_token_service_delegate.h"
#include "testing/gmock/include/gmock/gmock-actions.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -100,7 +102,7 @@ class FakeSigninManagerForSyncUIUtilTest : public FakeSigninManagerBase {
// in order to perform tests on the generated messages.
void GetDistinctCase(ProfileSyncServiceMock* service,
FakeSigninManagerForSyncUIUtilTest* signin,
FakeAuthStatusProvider* provider,
ProfileOAuth2TokenService* token_service,
int caseNumber) {
// Auth Error object is returned by reference in mock and needs to stay in
// scope throughout test, so it is owned by calling method. However it is
......@@ -151,8 +153,12 @@ void GetDistinctCase(ProfileSyncServiceMock* service,
syncer::SyncEngine::Status status;
EXPECT_CALL(*service, QueryDetailedSyncStatus(_))
.WillRepeatedly(DoAll(SetArgPointee<0>(status), Return(false)));
provider->SetAuthError(
signin->GetAuthenticatedAccountId(),
std::string account_id = signin->GetAuthenticatedAccountId();
token_service->UpdateCredentials(account_id, "refresh_token");
// TODO(https://crbug.com/836212): Do not use the delegate directly,
// because it is internal API.
token_service->GetDelegate()->UpdateAuthError(
account_id,
GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR));
EXPECT_CALL(*service, HasUnrecoverableError())
.WillRepeatedly(Return(false));
......@@ -275,9 +281,9 @@ TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) {
EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error));
FakeSigninManagerForSyncUIUtilTest signin(profile.get());
signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
std::unique_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider(
SigninErrorControllerFactory::GetForProfile(profile.get())));
GetDistinctCase(&service, &signin, provider.get(), idx);
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile.get());
GetDistinctCase(&service, &signin, token_service, idx);
base::string16 status_label;
base::string16 link_label;
sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION;
......@@ -299,7 +305,6 @@ TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) {
testing::Mock::VerifyAndClearExpectations(&service);
testing::Mock::VerifyAndClearExpectations(&signin);
EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error));
provider.reset();
signin.Shutdown();
}
}
......@@ -316,9 +321,9 @@ TEST_F(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) {
EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error));
FakeSigninManagerForSyncUIUtilTest signin(profile.get());
signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
std::unique_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider(
SigninErrorControllerFactory::GetForProfile(profile.get())));
GetDistinctCase(&service, &signin, provider.get(), idx);
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile.get());
GetDistinctCase(&service, &signin, token_service, idx);
base::string16 status_label;
base::string16 link_label;
sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION;
......@@ -336,7 +341,6 @@ TEST_F(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) {
testing::Mock::VerifyAndClearExpectations(&service);
testing::Mock::VerifyAndClearExpectations(&signin);
EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error));
provider.reset();
signin.Shutdown();
}
}
......
......@@ -11,23 +11,23 @@
#include "base/metrics/field_trial_params.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/signin/signin_error_controller_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/profile_sync_test_util.h"
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "components/browser_sync/profile_sync_service.h"
#include "components/browser_sync/test_profile_sync_service.h"
#include "components/prefs/pref_service.h"
#include "components/signin/core/browser/fake_auth_status_provider.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/sync/driver/fake_sync_service.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/test/test_browser_thread_bundle.h"
typedef GoogleServiceAuthError AuthError;
#include "google_apis/gaia/oauth2_token_service_delegate.h"
namespace {
......@@ -64,13 +64,11 @@ constexpr int kSMSEntrypointBookmarksBubble =
class DesktopIOSPromotionUtilTest : public testing::Test {
public:
DesktopIOSPromotionUtilTest() {}
DesktopIOSPromotionUtilTest()
: local_state_(TestingBrowserProcess::GetGlobal()) {}
~DesktopIOSPromotionUtilTest() override {}
void SetUp() override {
local_state_.reset(new TestingPrefServiceSimple);
TestingBrowserProcess::GetGlobal()->SetLocalState(local_state_.get());
desktop_ios_promotion::RegisterLocalPrefs(local_state_->registry());
auto pref_service =
std::make_unique<sync_preferences::TestingPrefServiceSyncable>();
RegisterUserProfilePrefs(pref_service->registry());
......@@ -87,12 +85,9 @@ class DesktopIOSPromotionUtilTest : public testing::Test {
void TearDown() override {
profile_.reset();
// Ensure that g_accept_requests gets set back to true after test execution.
TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
local_state_.reset();
}
PrefService* local_state() { return local_state_.get(); }
PrefService* local_state() { return local_state_.Get(); }
TestSyncService* sync_service() { return sync_service_; }
......@@ -109,7 +104,7 @@ class DesktopIOSPromotionUtilTest : public testing::Test {
private:
TestSyncService* sync_service_ = nullptr;
content::TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<TestingPrefServiceSimple> local_state_;
ScopedTestingLocalState local_state_;
SigninManagerBase* mock_signin_ = nullptr;
std::unique_ptr<TestingProfile> profile_;
DISALLOW_COPY_AND_ASSIGN(DesktopIOSPromotionUtilTest);
......@@ -178,8 +173,6 @@ TEST_F(DesktopIOSPromotionUtilTest, IsEligibleForIOSPromotionForSavePassword) {
false, true},
};
std::string locale = base::i18n::GetConfiguredLocale();
FakeAuthStatusProvider auth_provider(
SigninErrorControllerFactory::GetForProfile(profile()));
for (const auto& test_case : kTestData) {
SCOPED_TRACE(testing::Message("#test_case = ") << (&test_case - kTestData));
......@@ -189,7 +182,12 @@ TEST_F(DesktopIOSPromotionUtilTest, IsEligibleForIOSPromotionForSavePassword) {
? GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS
: GoogleServiceAuthError::NONE);
auth_provider.SetAuthError("test", error);
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
token_service->UpdateCredentials("test", "refresh_token");
// TODO(https://crbug.com/836212): Do not use the delegate directly, because
// it is internal API.
token_service->GetDelegate()->UpdateAuthError("test", error);
local_state()->SetBoolean(prefs::kSavePasswordsBubbleIOSPromoDismissed,
test_case.is_dismissed);
......
......@@ -21,7 +21,6 @@
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/signin/core/browser/fake_auth_status_provider.h"
#include "components/sync/model/fake_sync_change_processor.h"
#include "components/sync/model/sync_data.h"
#include "components/sync/model/sync_error_factory_mock.h"
......
......@@ -7,6 +7,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.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_error_controller_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/grit/generated_resources.h"
......@@ -14,9 +15,9 @@
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/signin/core/browser/fake_auth_status_provider.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "content/public/test/test_web_ui.h"
#include "google_apis/gaia/oauth2_token_service_delegate.h"
#include "ui/base/l10n/l10n_util.h"
namespace {
......@@ -120,9 +121,12 @@ TEST_F(SigninSupervisedUserImportHandlerTest, AuthError) {
// Set Auth Error.
const GoogleServiceAuthError error(
GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
FakeAuthStatusProvider provider(
SigninErrorControllerFactory::GetForProfile(profile()));
provider.SetAuthError(kTestGaiaId, error);
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
token_service->UpdateCredentials(kTestGaiaId, "refresh_token");
// TODO(https://crbug.com/836212): Do not use the delegate directly, because
// it is internal API.
token_service->GetDelegate()->UpdateAuthError(kTestGaiaId, error);
// Test the JS -> C++ -> JS callback path.
base::ListValue list_args;
......
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