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

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

Issue 7524033: Add a scoper object for URLFetcher::Factory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "chrome/browser/chromeos/cros/cros_library.h" 9 #include "chrome/browser/chromeos/cros/cros_library.h"
10 #include "chrome/browser/chromeos/cros/mock_library_loader.h" 10 #include "chrome/browser/chromeos/cros/mock_library_loader.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 TestingProfile profile; 125 TestingProfile profile;
126 126
127 EXPECT_CALL(*(resolver_.get()), Resolve()) 127 EXPECT_CALL(*(resolver_.get()), Resolve())
128 .WillOnce(Invoke(OnlineAttemptTest::Quit)) 128 .WillOnce(Invoke(OnlineAttemptTest::Quit))
129 .RetiresOnSaturation(); 129 .RetiresOnSaturation();
130 130
131 // This is how we inject fake URLFetcher objects, with a factory. 131 // This is how we inject fake URLFetcher objects, with a factory.
132 // This factory creates fake URLFetchers that Start() a fake fetch attempt 132 // This factory creates fake URLFetchers that Start() a fake fetch attempt
133 // and then come back on the IO thread saying they've been canceled. 133 // and then come back on the IO thread saying they've been canceled.
134 MockFactory<GotCanceledFetcher> factory; 134 MockFactory<GotCanceledFetcher> factory;
135 URLFetcher::set_factory(&factory);
136 135
137 attempt_->Initiate(&profile); 136 attempt_->Initiate(&profile);
138 BrowserThread::PostTask( 137 BrowserThread::PostTask(
139 BrowserThread::IO, FROM_HERE, 138 BrowserThread::IO, FROM_HERE,
140 NewRunnableFunction(&OnlineAttemptTest::RunThreadTest)); 139 NewRunnableFunction(&OnlineAttemptTest::RunThreadTest));
141 140
142 MessageLoop::current()->Run(); 141 MessageLoop::current()->Run();
143 142
144 EXPECT_TRUE(error == state_.online_outcome().error()); 143 EXPECT_TRUE(error == state_.online_outcome().error());
145 EXPECT_EQ(LoginFailure::NETWORK_AUTH_FAILED, 144 EXPECT_EQ(LoginFailure::NETWORK_AUTH_FAILED,
146 state_.online_outcome().reason()); 145 state_.online_outcome().reason());
147 URLFetcher::set_factory(NULL);
148 } 146 }
149 147
150 TEST_F(OnlineAttemptTest, LoginTimeout) { 148 TEST_F(OnlineAttemptTest, LoginTimeout) {
151 LoginFailure error(LoginFailure::LOGIN_TIMED_OUT); 149 LoginFailure error(LoginFailure::LOGIN_TIMED_OUT);
152 TestingProfile profile; 150 TestingProfile profile;
153 151
154 EXPECT_CALL(*(resolver_.get()), Resolve()) 152 EXPECT_CALL(*(resolver_.get()), Resolve())
155 .WillOnce(Invoke(OnlineAttemptTest::Quit)) 153 .WillOnce(Invoke(OnlineAttemptTest::Quit))
156 .RetiresOnSaturation(); 154 .RetiresOnSaturation();
157 155
158 // This is how we inject fake URLFetcher objects, with a factory. 156 // This is how we inject fake URLFetcher objects, with a factory.
159 // This factory creates fake URLFetchers that Start() a fake fetch attempt 157 // This factory creates fake URLFetchers that Start() a fake fetch attempt
160 // and then come back on the IO thread saying they've been canceled. 158 // and then come back on the IO thread saying they've been canceled.
161 MockFactory<ExpectCanceledFetcher> factory; 159 MockFactory<ExpectCanceledFetcher> factory;
162 URLFetcher::set_factory(&factory);
163 160
164 attempt_->Initiate(&profile); 161 attempt_->Initiate(&profile);
165 BrowserThread::PostTask( 162 BrowserThread::PostTask(
166 BrowserThread::IO, FROM_HERE, 163 BrowserThread::IO, FROM_HERE,
167 NewRunnableFunction(&OnlineAttemptTest::RunThreadTest)); 164 NewRunnableFunction(&OnlineAttemptTest::RunThreadTest));
168 165
169 // Post a task to cancel the login attempt. 166 // Post a task to cancel the login attempt.
170 CancelLogin(attempt_.get()); 167 CancelLogin(attempt_.get());
171 168
172 MessageLoop::current()->Run(); 169 MessageLoop::current()->Run();
173 170
174 EXPECT_EQ(LoginFailure::LOGIN_TIMED_OUT, state_.online_outcome().reason()); 171 EXPECT_EQ(LoginFailure::LOGIN_TIMED_OUT, state_.online_outcome().reason());
175 URLFetcher::set_factory(NULL);
176 } 172 }
177 173
178 TEST_F(OnlineAttemptTest, HostedLoginRejected) { 174 TEST_F(OnlineAttemptTest, HostedLoginRejected) {
179 LoginFailure error( 175 LoginFailure error(
180 LoginFailure::FromNetworkAuthFailure( 176 LoginFailure::FromNetworkAuthFailure(
181 GoogleServiceAuthError( 177 GoogleServiceAuthError(
182 GoogleServiceAuthError::HOSTED_NOT_ALLOWED))); 178 GoogleServiceAuthError::HOSTED_NOT_ALLOWED)));
183 TestingProfile profile; 179 TestingProfile profile;
184 180
185 EXPECT_CALL(*(resolver_.get()), Resolve()) 181 EXPECT_CALL(*(resolver_.get()), Resolve())
186 .WillOnce(Invoke(OnlineAttemptTest::Quit)) 182 .WillOnce(Invoke(OnlineAttemptTest::Quit))
187 .RetiresOnSaturation(); 183 .RetiresOnSaturation();
188 184
189 // This is how we inject fake URLFetcher objects, with a factory. 185 // This is how we inject fake URLFetcher objects, with a factory.
190 MockFactory<HostedFetcher> factory; 186 MockFactory<HostedFetcher> factory;
191 URLFetcher::set_factory(&factory);
192 187
193 TestAttemptState local_state("", "", "", "", "", true); 188 TestAttemptState local_state("", "", "", "", "", true);
194 attempt_ = new OnlineAttempt(&local_state, resolver_.get()); 189 attempt_ = new OnlineAttempt(&local_state, resolver_.get());
195 attempt_->Initiate(&profile); 190 attempt_->Initiate(&profile);
196 BrowserThread::PostTask( 191 BrowserThread::PostTask(
197 BrowserThread::IO, FROM_HERE, 192 BrowserThread::IO, FROM_HERE,
198 NewRunnableFunction(&OnlineAttemptTest::RunThreadTest)); 193 NewRunnableFunction(&OnlineAttemptTest::RunThreadTest));
199 194
200 MessageLoop::current()->Run(); 195 MessageLoop::current()->Run();
201 196
202 EXPECT_EQ(error, local_state.online_outcome()); 197 EXPECT_EQ(error, local_state.online_outcome());
203 EXPECT_EQ(LoginFailure::NETWORK_AUTH_FAILED, 198 EXPECT_EQ(LoginFailure::NETWORK_AUTH_FAILED,
204 local_state.online_outcome().reason()); 199 local_state.online_outcome().reason());
205 URLFetcher::set_factory(NULL);
206 } 200 }
207 201
208 TEST_F(OnlineAttemptTest, FullLogin) { 202 TEST_F(OnlineAttemptTest, FullLogin) {
209 TestingProfile profile; 203 TestingProfile profile;
210 204
211 EXPECT_CALL(*(resolver_.get()), Resolve()) 205 EXPECT_CALL(*(resolver_.get()), Resolve())
212 .WillOnce(Invoke(OnlineAttemptTest::Quit)) 206 .WillOnce(Invoke(OnlineAttemptTest::Quit))
213 .RetiresOnSaturation(); 207 .RetiresOnSaturation();
214 208
215 // This is how we inject fake URLFetcher objects, with a factory. 209 // This is how we inject fake URLFetcher objects, with a factory.
216 MockFactory<SuccessFetcher> factory; 210 MockFactory<SuccessFetcher> factory;
217 URLFetcher::set_factory(&factory);
218 211
219 TestAttemptState local_state("", "", "", "", "", true); 212 TestAttemptState local_state("", "", "", "", "", true);
220 attempt_ = new OnlineAttempt(&local_state, resolver_.get()); 213 attempt_ = new OnlineAttempt(&local_state, resolver_.get());
221 attempt_->Initiate(&profile); 214 attempt_->Initiate(&profile);
222 BrowserThread::PostTask( 215 BrowserThread::PostTask(
223 BrowserThread::IO, FROM_HERE, 216 BrowserThread::IO, FROM_HERE,
224 NewRunnableFunction(&OnlineAttemptTest::RunThreadTest)); 217 NewRunnableFunction(&OnlineAttemptTest::RunThreadTest));
225 218
226 MessageLoop::current()->Run(); 219 MessageLoop::current()->Run();
227 220
228 EXPECT_EQ(LoginFailure::None(), local_state.online_outcome()); 221 EXPECT_EQ(LoginFailure::None(), local_state.online_outcome());
229 URLFetcher::set_factory(NULL);
230 } 222 }
231 223
232 TEST_F(OnlineAttemptTest, LoginNetFailure) { 224 TEST_F(OnlineAttemptTest, LoginNetFailure) {
233 RunFailureTest( 225 RunFailureTest(
234 GoogleServiceAuthError::FromConnectionError(net::ERR_CONNECTION_RESET)); 226 GoogleServiceAuthError::FromConnectionError(net::ERR_CONNECTION_RESET));
235 } 227 }
236 228
237 TEST_F(OnlineAttemptTest, LoginDenied) { 229 TEST_F(OnlineAttemptTest, LoginDenied) {
238 RunFailureTest( 230 RunFailureTest(
239 GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); 231 GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 error)); 267 error));
276 268
277 // Force IO thread to finish tasks so I can verify |state_|. 269 // Force IO thread to finish tasks so I can verify |state_|.
278 io_thread_.Stop(); 270 io_thread_.Stop();
279 EXPECT_TRUE(GoogleServiceAuthError::None() == 271 EXPECT_TRUE(GoogleServiceAuthError::None() ==
280 state_.online_outcome().error()); 272 state_.online_outcome().error());
281 EXPECT_TRUE(GaiaAuthConsumer::ClientLoginResult() == state_.credentials()); 273 EXPECT_TRUE(GaiaAuthConsumer::ClientLoginResult() == state_.credentials());
282 } 274 }
283 275
284 } // namespace chromeos 276 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698