OLD | NEW |
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" |
11 #include "chrome/browser/chromeos/cros/mock_library_loader.h" | 11 #include "chrome/browser/chromeos/cros/mock_library_loader.h" |
12 #include "chrome/browser/chromeos/login/auth_attempt_state.h" | 12 #include "chrome/browser/chromeos/login/auth_attempt_state.h" |
13 #include "chrome/browser/chromeos/login/mock_auth_attempt_state_resolver.h" | 13 #include "chrome/browser/chromeos/login/mock_auth_attempt_state_resolver.h" |
14 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" | 14 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" |
15 #include "chrome/browser/chromeos/login/online_attempt.h" | 15 #include "chrome/browser/chromeos/login/online_attempt.h" |
16 #include "chrome/browser/chromeos/login/test_attempt_state.h" | 16 #include "chrome/browser/chromeos/login/test_attempt_state.h" |
17 #include "chrome/common/net/gaia/gaia_auth_consumer.h" | 17 #include "chrome/common/net/gaia/gaia_auth_consumer.h" |
18 #include "chrome/common/net/gaia/mock_url_fetcher_factory.h" | 18 #include "chrome/common/net/gaia/mock_url_fetcher_factory.h" |
19 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
20 #include "content/test/test_browser_thread.h" | 20 #include "content/test/test_browser_thread.h" |
21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
| 25 using content::BrowserThread; |
25 using ::testing::AnyNumber; | 26 using ::testing::AnyNumber; |
26 using ::testing::Invoke; | 27 using ::testing::Invoke; |
27 using ::testing::Return; | 28 using ::testing::Return; |
28 using ::testing::_; | 29 using ::testing::_; |
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_(MessageLoop::TYPE_UI), |
37 ui_thread_(BrowserThread::UI, &message_loop_), | 37 ui_thread_(BrowserThread::UI, &message_loop_), |
38 state_("", "", "", "", "", false), | 38 state_("", "", "", "", "", false), |
39 resolver_(new MockAuthAttemptStateResolver) { | 39 resolver_(new MockAuthAttemptStateResolver) { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 241 |
242 TEST_F(OnlineAttemptTest, LoginServiceUnavailable) { | 242 TEST_F(OnlineAttemptTest, LoginServiceUnavailable) { |
243 RunFailureTest( | 243 RunFailureTest( |
244 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE)); | 244 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
245 } | 245 } |
246 | 246 |
247 TEST_F(OnlineAttemptTest, CaptchaErrorOutputted) { | 247 TEST_F(OnlineAttemptTest, CaptchaErrorOutputted) { |
248 GoogleServiceAuthError auth_error = | 248 GoogleServiceAuthError auth_error = |
249 GoogleServiceAuthError::FromClientLoginCaptchaChallenge( | 249 GoogleServiceAuthError::FromClientLoginCaptchaChallenge( |
250 "CCTOKEN", | 250 "CCTOKEN", |
251 GURL("http://accounts.google.com/Captcha?ctoken=CCTOKEN"), | 251 GURL("http://www.google.com/accounts/Captcha?ctoken=CCTOKEN"), |
252 GURL("http://www.google.com/login/captcha")); | 252 GURL("http://www.google.com/login/captcha")); |
253 RunFailureTest(auth_error); | 253 RunFailureTest(auth_error); |
254 } | 254 } |
255 | 255 |
256 TEST_F(OnlineAttemptTest, TwoFactorSuccess) { | 256 TEST_F(OnlineAttemptTest, TwoFactorSuccess) { |
257 EXPECT_CALL(*(resolver_.get()), Resolve()) | 257 EXPECT_CALL(*(resolver_.get()), Resolve()) |
258 .Times(1) | 258 .Times(1) |
259 .RetiresOnSaturation(); | 259 .RetiresOnSaturation(); |
260 GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR); | 260 GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR); |
261 BrowserThread::PostTask( | 261 BrowserThread::PostTask( |
262 BrowserThread::UI, FROM_HERE, | 262 BrowserThread::UI, FROM_HERE, |
263 base::Bind(&OnlineAttempt::OnClientLoginFailure, | 263 base::Bind(&OnlineAttempt::OnClientLoginFailure, |
264 attempt_->weak_factory_.GetWeakPtr(), | 264 attempt_->weak_factory_.GetWeakPtr(), |
265 error)); | 265 error)); |
266 | 266 |
267 // Force UI thread to finish tasks so I can verify |state_|. | 267 // Force UI thread to finish tasks so I can verify |state_|. |
268 message_loop_.RunAllPending(); | 268 message_loop_.RunAllPending(); |
269 EXPECT_TRUE(GoogleServiceAuthError::None() == | 269 EXPECT_TRUE(GoogleServiceAuthError::None() == |
270 state_.online_outcome().error()); | 270 state_.online_outcome().error()); |
271 } | 271 } |
272 | 272 |
273 } // namespace chromeos | 273 } // namespace chromeos |
OLD | NEW |