Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: chrome/browser/signin/signin_global_error_unittest.cc

Issue 1299543002: Delete dead signin code (SigninGlobalError) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix mac? Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/signin/signin_global_error.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/test/histogram_tester.h"
11 #include "chrome/browser/prefs/pref_service_syncable.h"
12 #include "chrome/browser/profiles/profile_info_cache.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/profiles/profile_metrics.h"
15 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
16 #include "chrome/browser/signin/fake_signin_manager_builder.h"
17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
18 #include "chrome/browser/signin/signin_error_controller_factory.h"
19 #include "chrome/browser/signin/signin_global_error_factory.h"
20 #include "chrome/browser/signin/signin_manager_factory.h"
21 #include "chrome/browser/ui/global_error/global_error_service.h"
22 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
23 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/testing_browser_process.h"
25 #include "chrome/test/base/testing_profile.h"
26 #include "chrome/test/base/testing_profile_manager.h"
27 #include "components/signin/core/browser/fake_auth_status_provider.h"
28 #include "components/signin/core/browser/signin_error_controller.h"
29 #include "components/signin/core/browser/signin_manager.h"
30 #include "content/public/test/test_browser_thread_bundle.h"
31 #include "testing/gtest/include/gtest/gtest.h"
32
33 static const char kTestAccountId[] = "id-testuser@test.com";
34 static const char kTestGaiaId[] = "gaiaid-testuser@test.com";
35 static const char kTestUsername[] = "testuser@test.com";
36
37 class SigninGlobalErrorTest : public testing::Test {
38 public:
39 SigninGlobalErrorTest() :
40 profile_manager_(TestingBrowserProcess::GetGlobal()) {}
41
42 void SetUp() override {
43 ASSERT_TRUE(profile_manager_.SetUp());
44
45 // Create a signed-in profile.
46 TestingProfile::TestingFactories testing_factories;
47 testing_factories.push_back(std::make_pair(
48 ProfileOAuth2TokenServiceFactory::GetInstance(),
49 BuildFakeProfileOAuth2TokenService));
50 testing_factories.push_back(std::make_pair(
51 SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase));
52 profile_ = profile_manager_.CreateTestingProfile(
53 "Person 1", scoped_ptr<PrefServiceSyncable>(),
54 base::UTF8ToUTF16("Person 1"), 0, std::string(), testing_factories);
55
56 SigninManagerFactory::GetForProfile(profile())
57 ->SetAuthenticatedAccountInfo(kTestAccountId, kTestUsername);
58 ProfileInfoCache& cache =
59 profile_manager_.profile_manager()->GetProfileInfoCache();
60 cache.SetAuthInfoOfProfileAtIndex(
61 cache.GetIndexOfProfileWithPath(profile()->GetPath()),
62 kTestGaiaId, base::UTF8ToUTF16(kTestUsername));
63
64 global_error_ = SigninGlobalErrorFactory::GetForProfile(profile());
65 error_controller_ = SigninErrorControllerFactory::GetForProfile(profile());
66 }
67
68 TestingProfile* profile() { return profile_; }
69 TestingProfileManager* testing_profile_manager() {
70 return &profile_manager_;
71 }
72 SigninGlobalError* global_error() { return global_error_; }
73 SigninErrorController* error_controller() { return error_controller_; }
74
75 private:
76 content::TestBrowserThreadBundle thread_bundle_;
77 TestingProfileManager profile_manager_;
78 TestingProfile* profile_;
79 SigninGlobalError* global_error_;
80 SigninErrorController* error_controller_;
81 };
82
83 TEST_F(SigninGlobalErrorTest, NoErrorAuthStatusProviders) {
84 scoped_ptr<FakeAuthStatusProvider> provider;
85
86 ASSERT_FALSE(global_error()->HasMenuItem());
87
88 // Add a provider.
89 provider.reset(new FakeAuthStatusProvider(error_controller()));
90 ASSERT_FALSE(global_error()->HasMenuItem());
91
92 // Remove the provider.
93 provider.reset();
94 ASSERT_FALSE(global_error()->HasMenuItem());
95 }
96
97 TEST_F(SigninGlobalErrorTest, ErrorAuthStatusProvider) {
98 scoped_ptr<FakeAuthStatusProvider> provider;
99 scoped_ptr<FakeAuthStatusProvider> error_provider;
100
101 provider.reset(new FakeAuthStatusProvider(error_controller()));
102 ASSERT_FALSE(global_error()->HasMenuItem());
103
104 error_provider.reset(new FakeAuthStatusProvider(error_controller()));
105 error_provider->SetAuthError(
106 kTestAccountId,
107 GoogleServiceAuthError(
108 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
109 ASSERT_TRUE(global_error()->HasMenuItem());
110
111 error_provider.reset();
112 ASSERT_FALSE(global_error()->HasMenuItem());
113
114 provider.reset();
115 error_provider.reset();
116 ASSERT_FALSE(global_error()->HasMenuItem());
117 }
118
119 // Verify that SigninGlobalError ignores certain errors.
120 TEST_F(SigninGlobalErrorTest, AuthStatusEnumerateAllErrors) {
121 typedef struct {
122 GoogleServiceAuthError::State error_state;
123 bool is_error;
124 } ErrorTableEntry;
125
126 ErrorTableEntry table[] = {
127 { GoogleServiceAuthError::NONE, false },
128 { GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, true },
129 { GoogleServiceAuthError::USER_NOT_SIGNED_UP, true },
130 { GoogleServiceAuthError::CONNECTION_FAILED, false },
131 { GoogleServiceAuthError::CAPTCHA_REQUIRED, true },
132 { GoogleServiceAuthError::ACCOUNT_DELETED, true },
133 { GoogleServiceAuthError::ACCOUNT_DISABLED, true },
134 { GoogleServiceAuthError::SERVICE_UNAVAILABLE, true },
135 { GoogleServiceAuthError::TWO_FACTOR, true },
136 { GoogleServiceAuthError::REQUEST_CANCELED, true },
137 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true },
138 { GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE, true },
139 { GoogleServiceAuthError::SERVICE_ERROR, true },
140 { GoogleServiceAuthError::WEB_LOGIN_REQUIRED, true },
141 };
142 static_assert(arraysize(table) == GoogleServiceAuthError::NUM_STATES,
143 "table size should match number of auth error types");
144
145 // Mark the profile with an active timestamp so profile_metrics logs it.
146 testing_profile_manager()->UpdateLastUser(profile());
147
148 for (size_t i = 0; i < arraysize(table); ++i) {
149 base::HistogramTester histogram_tester;
150 FakeAuthStatusProvider provider(error_controller());
151 provider.SetAuthError(kTestAccountId,
152 GoogleServiceAuthError(table[i].error_state));
153
154 EXPECT_EQ(global_error()->HasMenuItem(), table[i].is_error);
155 EXPECT_EQ(global_error()->MenuItemLabel().empty(), !table[i].is_error);
156 EXPECT_EQ(global_error()->GetBubbleViewMessages().empty(),
157 !table[i].is_error);
158 EXPECT_FALSE(global_error()->GetBubbleViewTitle().empty());
159 EXPECT_FALSE(global_error()->GetBubbleViewAcceptButtonLabel().empty());
160 EXPECT_TRUE(global_error()->GetBubbleViewCancelButtonLabel().empty());
161
162 ProfileMetrics::LogNumberOfProfiles(
163 testing_profile_manager()->profile_manager());
164
165 if (table[i].is_error)
166 histogram_tester.ExpectBucketCount("Signin.AuthError", i, 1);
167 histogram_tester.ExpectBucketCount(
168 "Profile.NumberOfProfilesWithAuthErrors", table[i].is_error, 1);
169 }
170 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/signin_global_error_factory.cc ('k') | chrome/browser/signin/signin_ui_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698