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