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 "chrome/browser/signin/signin_manager.h" | 5 #include "chrome/browser/signin/signin_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/password_manager/encryptor.h" | 12 #include "chrome/browser/password_manager/encryptor.h" |
13 #include "chrome/browser/prefs/browser_prefs.h" | 13 #include "chrome/browser/prefs/browser_prefs.h" |
14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
15 #include "chrome/browser/signin/token_service.h" | 15 #include "chrome/browser/signin/token_service.h" |
16 #include "chrome/browser/signin/token_service_unittest.h" | 16 #include "chrome/browser/signin/token_service_unittest.h" |
17 #include "chrome/browser/webdata/web_data_service.h" | 17 #include "chrome/browser/webdata/web_data_service.h" |
18 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
19 #include "chrome/common/net/gaia/gaia_constants.h" | 19 #include "chrome/common/net/gaia/gaia_constants.h" |
20 #include "chrome/common/net/gaia/gaia_urls.h" | 20 #include "chrome/common/net/gaia/gaia_urls.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "chrome/test/base/testing_browser_process.h" | 22 #include "chrome/test/base/testing_browser_process.h" |
23 #include "chrome/test/base/testing_pref_service.h" | 23 #include "chrome/test/base/testing_pref_service.h" |
24 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
25 #include "content/public/test/test_url_fetcher_factory.h" | 25 #include "net/url_request/test_url_fetcher_factory.h" |
26 #include "net/url_request/url_request.h" | 26 #include "net/url_request/url_request.h" |
27 #include "net/url_request/url_request_status.h" | 27 #include "net/url_request/url_request_status.h" |
28 | 28 |
29 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 const char kGetTokenPairValidResponse[] = | 34 const char kGetTokenPairValidResponse[] = |
35 "{" | 35 "{" |
(...skipping 28 matching lines...) Expand all Loading... |
64 manager_.reset(NULL); | 64 manager_.reset(NULL); |
65 static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState(NULL); | 65 static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState(NULL); |
66 prefs_.reset(NULL); | 66 prefs_.reset(NULL); |
67 TokenServiceTestHarness::TearDown(); | 67 TokenServiceTestHarness::TearDown(); |
68 } | 68 } |
69 | 69 |
70 void SetupFetcherAndComplete(const std::string& url, | 70 void SetupFetcherAndComplete(const std::string& url, |
71 int response_code, | 71 int response_code, |
72 const net::ResponseCookies& cookies, | 72 const net::ResponseCookies& cookies, |
73 const std::string& response_string) { | 73 const std::string& response_string) { |
74 TestURLFetcher* fetcher = factory_.GetFetcherByID(0); | 74 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); |
75 DCHECK(fetcher); | 75 DCHECK(fetcher); |
76 DCHECK(fetcher->delegate()); | 76 DCHECK(fetcher->delegate()); |
77 | 77 |
78 fetcher->set_url(GURL(url)); | 78 fetcher->set_url(GURL(url)); |
79 fetcher->set_status(net::URLRequestStatus()); | 79 fetcher->set_status(net::URLRequestStatus()); |
80 fetcher->set_response_code(response_code); | 80 fetcher->set_response_code(response_code); |
81 fetcher->SetResponseString(response_string); | 81 fetcher->SetResponseString(response_string); |
82 fetcher->set_cookies(cookies); | 82 fetcher->set_cookies(cookies); |
83 fetcher->delegate()->OnURLFetchComplete(fetcher); | 83 fetcher->delegate()->OnURLFetchComplete(fetcher); |
84 } | 84 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 174 |
175 void SimulateValidResponseGetClientInfo(bool isGPlusUser) { | 175 void SimulateValidResponseGetClientInfo(bool isGPlusUser) { |
176 // Simulate the correct ClientLogin response. | 176 // Simulate the correct ClientLogin response. |
177 std::string response_string = isGPlusUser ? | 177 std::string response_string = isGPlusUser ? |
178 "email=user@gmail.com\nallServices=googleme" : | 178 "email=user@gmail.com\nallServices=googleme" : |
179 "email=user@gmail.com\nallServices="; | 179 "email=user@gmail.com\nallServices="; |
180 SetupFetcherAndComplete(GaiaUrls::GetInstance()->get_user_info_url(), 200, | 180 SetupFetcherAndComplete(GaiaUrls::GetInstance()->get_user_info_url(), 200, |
181 net::ResponseCookies(), response_string); | 181 net::ResponseCookies(), response_string); |
182 } | 182 } |
183 | 183 |
184 TestURLFetcherFactory factory_; | 184 net::TestURLFetcherFactory factory_; |
185 scoped_ptr<SigninManager> manager_; | 185 scoped_ptr<SigninManager> manager_; |
186 content::TestNotificationTracker google_login_success_; | 186 content::TestNotificationTracker google_login_success_; |
187 content::TestNotificationTracker google_login_failure_; | 187 content::TestNotificationTracker google_login_failure_; |
188 scoped_ptr<TestingPrefService> prefs_; | 188 scoped_ptr<TestingPrefService> prefs_; |
189 }; | 189 }; |
190 | 190 |
191 // NOTE: ClientLogin's "StartSignin" is called after collecting credentials | 191 // NOTE: ClientLogin's "StartSignin" is called after collecting credentials |
192 // from the user. | 192 // from the user. |
193 TEST_F(SigninManagerTest, SignInClientLogin) { | 193 TEST_F(SigninManagerTest, SignInClientLogin) { |
194 manager_->Initialize(profile_.get()); | 194 manager_->Initialize(profile_.get()); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 | 457 |
458 manager_->ProvideOAuthChallengeResponse( | 458 manager_->ProvideOAuthChallengeResponse( |
459 GoogleServiceAuthError::CAPTCHA_REQUIRED, "token", "solution"); | 459 GoogleServiceAuthError::CAPTCHA_REQUIRED, "token", "solution"); |
460 | 460 |
461 SimulateProvideOAuthChallengeResponseValid(); | 461 SimulateProvideOAuthChallengeResponseValid(); |
462 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); | 462 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); |
463 | 463 |
464 EXPECT_EQ(1U, google_login_success_.size()); | 464 EXPECT_EQ(1U, google_login_success_.size()); |
465 EXPECT_EQ(1U, google_login_failure_.size()); | 465 EXPECT_EQ(1U, google_login_failure_.size()); |
466 } | 466 } |
OLD | NEW |