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

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

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

Powered by Google App Engine
This is Rietveld 408576698