OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/signin/fake_gaia_cookie_manager_service.h" |
| 6 |
| 7 #include "base/strings/stringprintf.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
| 10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 11 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 12 #include "google_apis/gaia/gaia_constants.h" |
| 13 #include "google_apis/gaia/gaia_urls.h" |
| 14 |
| 15 FakeGaiaCookieManagerService::FakeGaiaCookieManagerService( |
| 16 OAuth2TokenService* token_service, |
| 17 const std::string& source, |
| 18 SigninClient* client) : |
| 19 GaiaCookieManagerService(token_service, source, client), |
| 20 url_fetcher_factory_(NULL) {} |
| 21 |
| 22 void FakeGaiaCookieManagerService::Init( |
| 23 net::FakeURLFetcherFactory* url_fetcher_factory) { |
| 24 url_fetcher_factory_ = url_fetcher_factory; |
| 25 } |
| 26 |
| 27 void FakeGaiaCookieManagerService::SetListAccountsResponseHttpNotFound() { |
| 28 DCHECK(url_fetcher_factory_); |
| 29 url_fetcher_factory_->SetFakeResponse( |
| 30 GaiaUrls::GetInstance()->ListAccountsURLWithSource( |
| 31 GaiaConstants::kChromeSource), |
| 32 "", |
| 33 net::HTTP_NOT_FOUND, |
| 34 net::URLRequestStatus::SUCCESS); |
| 35 } |
| 36 |
| 37 void FakeGaiaCookieManagerService::SetListAccountsResponseNoAccounts() { |
| 38 DCHECK(url_fetcher_factory_); |
| 39 url_fetcher_factory_->SetFakeResponse( |
| 40 GaiaUrls::GetInstance()->ListAccountsURLWithSource( |
| 41 GaiaConstants::kChromeSource), |
| 42 "[\"f\", []]", |
| 43 net::HTTP_OK, |
| 44 net::URLRequestStatus::SUCCESS); |
| 45 } |
| 46 |
| 47 void FakeGaiaCookieManagerService::SetListAccountsResponseOneAccount( |
| 48 const char* account) { |
| 49 DCHECK(url_fetcher_factory_); |
| 50 url_fetcher_factory_->SetFakeResponse( |
| 51 GaiaUrls::GetInstance()->ListAccountsURLWithSource( |
| 52 GaiaConstants::kChromeSource), |
| 53 base::StringPrintf( |
| 54 "[\"f\", [[\"b\", 0, \"n\", \"%s\", \"p\", 0, 0, 0, 0, 1]]]", |
| 55 account), |
| 56 net::HTTP_OK, |
| 57 net::URLRequestStatus::SUCCESS); |
| 58 } |
| 59 |
| 60 void FakeGaiaCookieManagerService::SetListAccountsResponseOneAccountWithExpiry( |
| 61 const char* account, bool expired) { |
| 62 DCHECK(url_fetcher_factory_); |
| 63 url_fetcher_factory_->SetFakeResponse( |
| 64 GaiaUrls::GetInstance()->ListAccountsURLWithSource( |
| 65 GaiaConstants::kChromeSource), |
| 66 base::StringPrintf( |
| 67 "[\"f\", [[\"b\", 0, \"n\", \"%s\", \"p\", 0, 0, 0, 0, %d]]]", |
| 68 account, expired ? 0 : 1), |
| 69 net::HTTP_OK, |
| 70 net::URLRequestStatus::SUCCESS); |
| 71 } |
| 72 |
| 73 void FakeGaiaCookieManagerService::SetListAccountsResponseTwoAccounts( |
| 74 const char* account1, const char* account2) { |
| 75 DCHECK(url_fetcher_factory_); |
| 76 url_fetcher_factory_->SetFakeResponse( |
| 77 GaiaUrls::GetInstance()->ListAccountsURLWithSource( |
| 78 GaiaConstants::kChromeSource), |
| 79 base::StringPrintf( |
| 80 "[\"f\", [[\"b\", 0, \"n\", \"%s\", \"p\", 0, 0, 0, 0, 1], " |
| 81 "[\"b\", 0, \"n\", \"%s\", \"p\", 0, 0, 0, 0, 1]]]", |
| 82 account1, account2), |
| 83 net::HTTP_OK, |
| 84 net::URLRequestStatus::SUCCESS); |
| 85 } |
| 86 |
| 87 void FakeGaiaCookieManagerService::SetListAccountsResponseTwoAccountsWithExpiry( |
| 88 const char* account1, bool account1_expired, |
| 89 const char* account2, bool account2_expired) { |
| 90 DCHECK(url_fetcher_factory_); |
| 91 url_fetcher_factory_->SetFakeResponse( |
| 92 GaiaUrls::GetInstance()->ListAccountsURLWithSource( |
| 93 GaiaConstants::kChromeSource), |
| 94 base::StringPrintf( |
| 95 "[\"f\", [[\"b\", 0, \"n\", \"%s\", \"p\", 0, 0, 0, 0, %d], " |
| 96 "[\"b\", 0, \"n\", \"%s\", \"p\", 0, 0, 0, 0, %d]]]", |
| 97 account1, account1_expired ? 0 : 1, |
| 98 account2, account2_expired ? 0 : 1), |
| 99 net::HTTP_OK, |
| 100 net::URLRequestStatus::SUCCESS); |
| 101 } |
| 102 |
| 103 // static |
| 104 KeyedService* FakeGaiaCookieManagerService::Build( |
| 105 content::BrowserContext* context) { |
| 106 Profile* profile = Profile::FromBrowserContext(context); |
| 107 FakeGaiaCookieManagerService* service = new FakeGaiaCookieManagerService( |
| 108 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
| 109 GaiaConstants::kChromeSource, |
| 110 ChromeSigninClientFactory::GetForProfile(profile)); |
| 111 return service; |
| 112 } |
OLD | NEW |