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

Side by Side Diff: chrome/browser/chromeos/login/online_attempt_unittest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "chrome/browser/chromeos/cros/cros_library.h" 10 #include "chrome/browser/chromeos/cros/cros_library.h"
(...skipping 15 matching lines...) Expand all
26 using ::testing::Invoke; 26 using ::testing::Invoke;
27 using ::testing::Return; 27 using ::testing::Return;
28 using ::testing::_; 28 using ::testing::_;
29 using content::BrowserThread; 29 using content::BrowserThread;
30 30
31 namespace chromeos { 31 namespace chromeos {
32 32
33 class OnlineAttemptTest : public testing::Test { 33 class OnlineAttemptTest : public testing::Test {
34 public: 34 public:
35 OnlineAttemptTest() 35 OnlineAttemptTest()
36 : message_loop_(MessageLoop::TYPE_UI), 36 : message_loop_(base::MessageLoop::TYPE_UI),
37 ui_thread_(BrowserThread::UI, &message_loop_), 37 ui_thread_(BrowserThread::UI, &message_loop_),
38 state_(UserContext(), "", "", "", User::USER_TYPE_REGULAR, false), 38 state_(UserContext(), "", "", "", User::USER_TYPE_REGULAR, false),
39 resolver_(new MockAuthAttemptStateResolver) { 39 resolver_(new MockAuthAttemptStateResolver) {
40 } 40 }
41 41
42 virtual ~OnlineAttemptTest() {} 42 virtual ~OnlineAttemptTest() {}
43 43
44 virtual void SetUp() { 44 virtual void SetUp() {
45 attempt_.reset(new OnlineAttempt(&state_, resolver_.get())); 45 attempt_.reset(new OnlineAttempt(&state_, resolver_.get()));
46 } 46 }
(...skipping 18 matching lines...) Expand all
65 65
66 void CancelLogin(OnlineAttempt* auth) { 66 void CancelLogin(OnlineAttempt* auth) {
67 BrowserThread::PostTask( 67 BrowserThread::PostTask(
68 BrowserThread::UI, FROM_HERE, 68 BrowserThread::UI, FROM_HERE,
69 base::Bind(&OnlineAttempt::CancelClientLogin, 69 base::Bind(&OnlineAttempt::CancelClientLogin,
70 auth->weak_factory_.GetWeakPtr())); 70 auth->weak_factory_.GetWeakPtr()));
71 } 71 }
72 72
73 static void Quit() { 73 static void Quit() {
74 BrowserThread::PostTask( 74 BrowserThread::PostTask(
75 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure()); 75 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure());
76 } 76 }
77 77
78 static void RunThreadTest() { 78 static void RunThreadTest() {
79 MessageLoop::current()->RunUntilIdle(); 79 base::MessageLoop::current()->RunUntilIdle();
80 } 80 }
81 81
82 MessageLoop message_loop_; 82 base::MessageLoop message_loop_;
83 content::TestBrowserThread ui_thread_; 83 content::TestBrowserThread ui_thread_;
84 TestAttemptState state_; 84 TestAttemptState state_;
85 scoped_ptr<MockAuthAttemptStateResolver> resolver_; 85 scoped_ptr<MockAuthAttemptStateResolver> resolver_;
86 scoped_ptr<OnlineAttempt> attempt_; 86 scoped_ptr<OnlineAttempt> attempt_;
87 87
88 // Initializes / shuts down a stub CrosLibrary. 88 // Initializes / shuts down a stub CrosLibrary.
89 chromeos::ScopedStubCrosEnabler stub_cros_enabler_; 89 chromeos::ScopedStubCrosEnabler stub_cros_enabler_;
90 }; 90 };
91 91
92 TEST_F(OnlineAttemptTest, LoginSuccess) { 92 TEST_F(OnlineAttemptTest, LoginSuccess) {
(...skipping 21 matching lines...) Expand all
114 // This is how we inject fake URLFetcher objects, with a factory. 114 // This is how we inject fake URLFetcher objects, with a factory.
115 // This factory creates fake URLFetchers that Start() a fake fetch attempt 115 // This factory creates fake URLFetchers that Start() a fake fetch attempt
116 // and then come back on the UI thread saying they've been canceled. 116 // and then come back on the UI thread saying they've been canceled.
117 MockURLFetcherFactory<GotCanceledFetcher> factory; 117 MockURLFetcherFactory<GotCanceledFetcher> factory;
118 118
119 attempt_->Initiate(&profile); 119 attempt_->Initiate(&profile);
120 BrowserThread::PostTask( 120 BrowserThread::PostTask(
121 BrowserThread::UI, FROM_HERE, 121 BrowserThread::UI, FROM_HERE,
122 base::Bind(&OnlineAttemptTest::RunThreadTest)); 122 base::Bind(&OnlineAttemptTest::RunThreadTest));
123 123
124 MessageLoop::current()->Run(); 124 base::MessageLoop::current()->Run();
125 125
126 EXPECT_TRUE(error == state_.online_outcome().error()); 126 EXPECT_TRUE(error == state_.online_outcome().error());
127 EXPECT_EQ(LoginFailure::NETWORK_AUTH_FAILED, 127 EXPECT_EQ(LoginFailure::NETWORK_AUTH_FAILED,
128 state_.online_outcome().reason()); 128 state_.online_outcome().reason());
129 } 129 }
130 130
131 TEST_F(OnlineAttemptTest, LoginTimeout) { 131 TEST_F(OnlineAttemptTest, LoginTimeout) {
132 LoginFailure error(LoginFailure::LOGIN_TIMED_OUT); 132 LoginFailure error(LoginFailure::LOGIN_TIMED_OUT);
133 TestingProfile profile; 133 TestingProfile profile;
134 134
135 EXPECT_CALL(*(resolver_.get()), Resolve()) 135 EXPECT_CALL(*(resolver_.get()), Resolve())
136 .WillOnce(Invoke(OnlineAttemptTest::Quit)) 136 .WillOnce(Invoke(OnlineAttemptTest::Quit))
137 .RetiresOnSaturation(); 137 .RetiresOnSaturation();
138 138
139 // This is how we inject fake URLFetcher objects, with a factory. 139 // This is how we inject fake URLFetcher objects, with a factory.
140 // This factory creates fake URLFetchers that Start() a fake fetch attempt 140 // This factory creates fake URLFetchers that Start() a fake fetch attempt
141 // and then come back on the UI thread saying they've been canceled. 141 // and then come back on the UI thread saying they've been canceled.
142 MockURLFetcherFactory<ExpectCanceledFetcher> factory; 142 MockURLFetcherFactory<ExpectCanceledFetcher> factory;
143 143
144 attempt_->Initiate(&profile); 144 attempt_->Initiate(&profile);
145 BrowserThread::PostTask( 145 BrowserThread::PostTask(
146 BrowserThread::UI, FROM_HERE, 146 BrowserThread::UI, FROM_HERE,
147 base::Bind(&OnlineAttemptTest::RunThreadTest)); 147 base::Bind(&OnlineAttemptTest::RunThreadTest));
148 148
149 // Post a task to cancel the login attempt. 149 // Post a task to cancel the login attempt.
150 CancelLogin(attempt_.get()); 150 CancelLogin(attempt_.get());
151 151
152 MessageLoop::current()->Run(); 152 base::MessageLoop::current()->Run();
153 153
154 EXPECT_EQ(LoginFailure::LOGIN_TIMED_OUT, state_.online_outcome().reason()); 154 EXPECT_EQ(LoginFailure::LOGIN_TIMED_OUT, state_.online_outcome().reason());
155 } 155 }
156 156
157 TEST_F(OnlineAttemptTest, HostedLoginRejected) { 157 TEST_F(OnlineAttemptTest, HostedLoginRejected) {
158 LoginFailure error( 158 LoginFailure error(
159 LoginFailure::FromNetworkAuthFailure( 159 LoginFailure::FromNetworkAuthFailure(
160 GoogleServiceAuthError( 160 GoogleServiceAuthError(
161 GoogleServiceAuthError::HOSTED_NOT_ALLOWED))); 161 GoogleServiceAuthError::HOSTED_NOT_ALLOWED)));
162 TestingProfile profile; 162 TestingProfile profile;
163 163
164 EXPECT_CALL(*(resolver_.get()), Resolve()) 164 EXPECT_CALL(*(resolver_.get()), Resolve())
165 .WillOnce(Invoke(OnlineAttemptTest::Quit)) 165 .WillOnce(Invoke(OnlineAttemptTest::Quit))
166 .RetiresOnSaturation(); 166 .RetiresOnSaturation();
167 167
168 // This is how we inject fake URLFetcher objects, with a factory. 168 // This is how we inject fake URLFetcher objects, with a factory.
169 MockURLFetcherFactory<HostedFetcher> factory; 169 MockURLFetcherFactory<HostedFetcher> factory;
170 170
171 TestAttemptState local_state(UserContext(), "", "", "", 171 TestAttemptState local_state(UserContext(), "", "", "",
172 User::USER_TYPE_REGULAR, true); 172 User::USER_TYPE_REGULAR, true);
173 attempt_.reset(new OnlineAttempt(&local_state, resolver_.get())); 173 attempt_.reset(new OnlineAttempt(&local_state, resolver_.get()));
174 attempt_->Initiate(&profile); 174 attempt_->Initiate(&profile);
175 BrowserThread::PostTask( 175 BrowserThread::PostTask(
176 BrowserThread::UI, FROM_HERE, 176 BrowserThread::UI, FROM_HERE,
177 base::Bind(&OnlineAttemptTest::RunThreadTest)); 177 base::Bind(&OnlineAttemptTest::RunThreadTest));
178 178
179 MessageLoop::current()->Run(); 179 base::MessageLoop::current()->Run();
180 180
181 EXPECT_EQ(error, local_state.online_outcome()); 181 EXPECT_EQ(error, local_state.online_outcome());
182 EXPECT_EQ(LoginFailure::NETWORK_AUTH_FAILED, 182 EXPECT_EQ(LoginFailure::NETWORK_AUTH_FAILED,
183 local_state.online_outcome().reason()); 183 local_state.online_outcome().reason());
184 } 184 }
185 185
186 TEST_F(OnlineAttemptTest, FullLogin) { 186 TEST_F(OnlineAttemptTest, FullLogin) {
187 TestingProfile profile; 187 TestingProfile profile;
188 188
189 EXPECT_CALL(*(resolver_.get()), Resolve()) 189 EXPECT_CALL(*(resolver_.get()), Resolve())
190 .WillOnce(Invoke(OnlineAttemptTest::Quit)) 190 .WillOnce(Invoke(OnlineAttemptTest::Quit))
191 .RetiresOnSaturation(); 191 .RetiresOnSaturation();
192 192
193 // This is how we inject fake URLFetcher objects, with a factory. 193 // This is how we inject fake URLFetcher objects, with a factory.
194 MockURLFetcherFactory<SuccessFetcher> factory; 194 MockURLFetcherFactory<SuccessFetcher> factory;
195 195
196 TestAttemptState local_state(UserContext(), "", "", "", 196 TestAttemptState local_state(UserContext(), "", "", "",
197 User::USER_TYPE_REGULAR, true); 197 User::USER_TYPE_REGULAR, true);
198 attempt_.reset(new OnlineAttempt(&local_state, resolver_.get())); 198 attempt_.reset(new OnlineAttempt(&local_state, resolver_.get()));
199 attempt_->Initiate(&profile); 199 attempt_->Initiate(&profile);
200 BrowserThread::PostTask( 200 BrowserThread::PostTask(
201 BrowserThread::UI, FROM_HERE, 201 BrowserThread::UI, FROM_HERE,
202 base::Bind(&OnlineAttemptTest::RunThreadTest)); 202 base::Bind(&OnlineAttemptTest::RunThreadTest));
203 203
204 MessageLoop::current()->Run(); 204 base::MessageLoop::current()->Run();
205 205
206 EXPECT_EQ(LoginFailure::LoginFailureNone(), local_state.online_outcome()); 206 EXPECT_EQ(LoginFailure::LoginFailureNone(), local_state.online_outcome());
207 } 207 }
208 208
209 TEST_F(OnlineAttemptTest, LoginNetFailure) { 209 TEST_F(OnlineAttemptTest, LoginNetFailure) {
210 RunFailureTest( 210 RunFailureTest(
211 GoogleServiceAuthError::FromConnectionError(net::ERR_CONNECTION_RESET)); 211 GoogleServiceAuthError::FromConnectionError(net::ERR_CONNECTION_RESET));
212 } 212 }
213 213
214 TEST_F(OnlineAttemptTest, LoginDenied) { 214 TEST_F(OnlineAttemptTest, LoginDenied) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 attempt_->weak_factory_.GetWeakPtr(), 251 attempt_->weak_factory_.GetWeakPtr(),
252 error)); 252 error));
253 253
254 // Force UI thread to finish tasks so I can verify |state_|. 254 // Force UI thread to finish tasks so I can verify |state_|.
255 message_loop_.RunUntilIdle(); 255 message_loop_.RunUntilIdle();
256 EXPECT_TRUE(GoogleServiceAuthError::AuthErrorNone() == 256 EXPECT_TRUE(GoogleServiceAuthError::AuthErrorNone() ==
257 state_.online_outcome().error()); 257 state_.online_outcome().error());
258 } 258 }
259 259
260 } // namespace chromeos 260 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/mock_url_fetchers.cc ('k') | chrome/browser/chromeos/login/parallel_authenticator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698