OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/autofill/content/browser/wallet/wallet_signin_helper.h" | 5 #include "components/autofill/content/browser/wallet/wallet_signin_helper.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/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
12 #include "components/autofill/content/browser/wallet/wallet_service_url.h" | 12 #include "components/autofill/content/browser/wallet/wallet_service_url.h" |
13 #include "components/autofill/content/browser/wallet/wallet_signin_helper_delega
te.h" | 13 #include "components/autofill/content/browser/wallet/wallet_signin_helper_delega
te.h" |
14 #include "content/public/browser/storage_partition.h" | |
15 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
16 #include "google_apis/gaia/gaia_constants.h" | 15 #include "google_apis/gaia/gaia_constants.h" |
17 #include "google_apis/gaia/gaia_urls.h" | 16 #include "google_apis/gaia/gaia_urls.h" |
18 #include "google_apis/gaia/google_service_auth_error.h" | 17 #include "google_apis/gaia/google_service_auth_error.h" |
19 #include "net/cookies/canonical_cookie.h" | 18 #include "net/cookies/canonical_cookie.h" |
20 #include "net/cookies/cookie_monster.h" | 19 #include "net/cookies/cookie_monster.h" |
21 #include "net/cookies/cookie_options.h" | 20 #include "net/cookies/cookie_options.h" |
22 #include "net/http/http_status_code.h" | 21 #include "net/http/http_status_code.h" |
23 #include "net/url_request/test_url_fetcher_factory.h" | 22 #include "net/url_request/test_url_fetcher_factory.h" |
24 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 194 } |
196 | 195 |
197 TEST_F(WalletSigninHelperTest, PassiveUserInfoFailedUserInfo) { | 196 TEST_F(WalletSigninHelperTest, PassiveUserInfoFailedUserInfo) { |
198 EXPECT_CALL(mock_delegate_, OnUserNameFetchFailure(_)); | 197 EXPECT_CALL(mock_delegate_, OnUserNameFetchFailure(_)); |
199 signin_helper_->StartUserNameFetch(); | 198 signin_helper_->StartUserNameFetch(); |
200 MockFailedGetAccountInfoResponse404(); | 199 MockFailedGetAccountInfoResponse404(); |
201 } | 200 } |
202 | 201 |
203 TEST_F(WalletSigninHelperTest, GetWalletCookieValueWhenPresent) { | 202 TEST_F(WalletSigninHelperTest, GetWalletCookieValueWhenPresent) { |
204 EXPECT_CALL(mock_delegate_, OnDidFetchWalletCookieValue("gdToken")); | 203 EXPECT_CALL(mock_delegate_, OnDidFetchWalletCookieValue("gdToken")); |
| 204 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL); |
205 net::CookieOptions httponly_options; | 205 net::CookieOptions httponly_options; |
206 httponly_options.set_include_httponly(); | 206 httponly_options.set_include_httponly(); |
207 scoped_ptr<net::CanonicalCookie> cookie( | 207 scoped_ptr<net::CanonicalCookie> cookie( |
208 net::CanonicalCookie::Create(GetPassiveAuthUrl().GetWithEmptyPath(), | 208 net::CanonicalCookie::Create(GetPassiveAuthUrl().GetWithEmptyPath(), |
209 "gdToken=gdToken; HttpOnly", | 209 "gdToken=gdToken; HttpOnly", |
210 base::Time::Now(), | 210 base::Time::Now(), |
211 httponly_options)); | 211 httponly_options)); |
212 | 212 |
213 net::CookieList cookie_list; | 213 net::CookieList cookie_list; |
214 cookie_list.push_back(*cookie); | 214 cookie_list.push_back(*cookie); |
215 | |
216 net::CookieMonster* cookie_monster = | |
217 content::BrowserContext::GetDefaultStoragePartition(&browser_context_)-> | |
218 GetCookieStoreForScheme(GetPassiveAuthUrl().scheme())-> | |
219 GetCookieMonster(); | |
220 cookie_monster->InitializeFrom(cookie_list); | 215 cookie_monster->InitializeFrom(cookie_list); |
| 216 browser_context_.GetRequestContext()->GetURLRequestContext() |
| 217 ->set_cookie_store(cookie_monster); |
221 signin_helper_->StartWalletCookieValueFetch(); | 218 signin_helper_->StartWalletCookieValueFetch(); |
222 base::RunLoop().RunUntilIdle(); | 219 base::RunLoop().RunUntilIdle(); |
223 } | 220 } |
224 | 221 |
225 TEST_F(WalletSigninHelperTest, GetWalletCookieValueWhenMissing) { | 222 TEST_F(WalletSigninHelperTest, GetWalletCookieValueWhenMissing) { |
226 EXPECT_CALL(mock_delegate_, OnDidFetchWalletCookieValue(std::string())); | 223 EXPECT_CALL(mock_delegate_, OnDidFetchWalletCookieValue(std::string())); |
227 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL); | 224 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL); |
228 net::CookieOptions httponly_options; | 225 net::CookieOptions httponly_options; |
229 httponly_options.set_include_httponly(); | 226 httponly_options.set_include_httponly(); |
230 scoped_ptr<net::CanonicalCookie> cookie( | 227 scoped_ptr<net::CanonicalCookie> cookie( |
231 net::CanonicalCookie::Create(GetPassiveAuthUrl().GetWithEmptyPath(), | 228 net::CanonicalCookie::Create(GetPassiveAuthUrl().GetWithEmptyPath(), |
232 "fake_cookie=monkeys; HttpOnly", | 229 "fake_cookie=monkeys; HttpOnly", |
233 base::Time::Now(), | 230 base::Time::Now(), |
234 httponly_options)); | 231 httponly_options)); |
235 | 232 |
236 net::CookieList cookie_list; | 233 net::CookieList cookie_list; |
237 cookie_list.push_back(*cookie); | 234 cookie_list.push_back(*cookie); |
238 cookie_monster->InitializeFrom(cookie_list); | 235 cookie_monster->InitializeFrom(cookie_list); |
239 browser_context_.GetRequestContext()->GetURLRequestContext() | 236 browser_context_.GetRequestContext()->GetURLRequestContext() |
240 ->set_cookie_store(cookie_monster); | 237 ->set_cookie_store(cookie_monster); |
241 signin_helper_->StartWalletCookieValueFetch(); | 238 signin_helper_->StartWalletCookieValueFetch(); |
242 base::RunLoop().RunUntilIdle(); | 239 base::RunLoop().RunUntilIdle(); |
243 } | 240 } |
244 | 241 |
245 // TODO(aruslan): http://crbug.com/188317 Need more tests. | 242 // TODO(aruslan): http://crbug.com/188317 Need more tests. |
246 | 243 |
247 } // namespace wallet | 244 } // namespace wallet |
248 } // namespace autofill | 245 } // namespace autofill |
OLD | NEW |