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.
5 #include "chrome/browser/signin/fake_gaia_cookie_manager_service.h"
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"
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
) {}
22 void FakeGaiaCookieManagerService::Init(
23 net::FakeURLFetcherFactory
* url_fetcher_factory
) {
24 url_fetcher_factory_
= url_fetcher_factory
;
27 void FakeGaiaCookieManagerService::SetListAccountsResponseHttpNotFound() {
28 DCHECK(url_fetcher_factory_
);
29 url_fetcher_factory_
->SetFakeResponse(
30 GaiaUrls::GetInstance()->ListAccountsURLWithSource(
31 GaiaConstants::kChromeSource
),
34 net::URLRequestStatus::SUCCESS
);
37 void FakeGaiaCookieManagerService::SetListAccountsResponseWebLoginRequired() {
38 DCHECK(url_fetcher_factory_
);
39 url_fetcher_factory_
->SetFakeResponse(
40 GaiaUrls::GetInstance()->ListAccountsURLWithSource(
41 GaiaConstants::kChromeSource
),
42 "Info=WebLoginRequired",
44 net::URLRequestStatus::SUCCESS
);
47 void FakeGaiaCookieManagerService::SetListAccountsResponseNoAccounts() {
48 DCHECK(url_fetcher_factory_
);
49 url_fetcher_factory_
->SetFakeResponse(
50 GaiaUrls::GetInstance()->ListAccountsURLWithSource(
51 GaiaConstants::kChromeSource
),
54 net::URLRequestStatus::SUCCESS
);
57 void FakeGaiaCookieManagerService::SetListAccountsResponseOneAccount(
58 const char* email
, const char* gaia_id
) {
59 DCHECK(url_fetcher_factory_
);
60 url_fetcher_factory_
->SetFakeResponse(
61 GaiaUrls::GetInstance()->ListAccountsURLWithSource(
62 GaiaConstants::kChromeSource
),
64 "[\"f\", [[\"b\", 0, \"n\", \"%s\", \"p\", 0, 0, 0, 0, 1, \"%s\"]]]",
67 net::URLRequestStatus::SUCCESS
);
70 void FakeGaiaCookieManagerService::SetListAccountsResponseOneAccountWithExpiry(
71 const char* email
, const char* gaia_id
, bool expired
) {
72 DCHECK(url_fetcher_factory_
);
73 url_fetcher_factory_
->SetFakeResponse(
74 GaiaUrls::GetInstance()->ListAccountsURLWithSource(
75 GaiaConstants::kChromeSource
),
77 "[\"f\", [[\"b\", 0, \"n\", \"%s\", \"p\", 0, 0, 0, 0, %d, \"%s\"]]]",
78 email
, expired
? 0 : 1, gaia_id
),
80 net::URLRequestStatus::SUCCESS
);
83 void FakeGaiaCookieManagerService::SetListAccountsResponseTwoAccounts(
84 const char* email1
, const char* gaia_id1
,
85 const char* email2
, const char* gaia_id2
) {
86 DCHECK(url_fetcher_factory_
);
87 url_fetcher_factory_
->SetFakeResponse(
88 GaiaUrls::GetInstance()->ListAccountsURLWithSource(
89 GaiaConstants::kChromeSource
),
91 "[\"f\", [[\"b\", 0, \"n\", \"%s\", \"p\", 0, 0, 0, 0, 1, \"%s\"], "
92 "[\"b\", 0, \"n\", \"%s\", \"p\", 0, 0, 0, 0, 1, \"%s\"]]]",
93 email1
, gaia_id1
, email2
, gaia_id2
),
95 net::URLRequestStatus::SUCCESS
);
98 void FakeGaiaCookieManagerService::SetListAccountsResponseTwoAccountsWithExpiry(
99 const char* account1
, bool account1_expired
,
100 const char* account2
, bool account2_expired
) {
101 DCHECK(url_fetcher_factory_
);
102 url_fetcher_factory_
->SetFakeResponse(
103 GaiaUrls::GetInstance()->ListAccountsURLWithSource(
104 GaiaConstants::kChromeSource
),
106 "[\"f\", [[\"b\", 0, \"n\", \"%s\", \"p\", 0, 0, 0, 0, %d, \"28\"], "
107 "[\"b\", 0, \"n\", \"%s\", \"p\", 0, 0, 0, 0, %d, \"29\"]]]",
108 account1
, account1_expired
? 0 : 1,
109 account2
, account2_expired
? 0 : 1),
111 net::URLRequestStatus::SUCCESS
);
115 scoped_ptr
<KeyedService
> FakeGaiaCookieManagerService::Build(
116 content::BrowserContext
* context
) {
117 Profile
* profile
= Profile::FromBrowserContext(context
);
118 return make_scoped_ptr(new FakeGaiaCookieManagerService(
119 ProfileOAuth2TokenServiceFactory::GetForProfile(profile
),
120 GaiaConstants::kChromeSource
,
121 ChromeSigninClientFactory::GetForProfile(profile
)));