Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / signin / fake_gaia_cookie_manager_service.cc
blob304e40fca14bf66682a2f5a4d9b9210684f7fdbe
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),
32 "",
33 net::HTTP_NOT_FOUND,
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",
43 net::HTTP_OK,
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),
52 "[\"f\", []]",
53 net::HTTP_OK,
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),
63 base::StringPrintf(
64 "[\"f\", [[\"b\", 0, \"n\", \"%s\", \"p\", 0, 0, 0, 0, 1, \"%s\"]]]",
65 email, gaia_id),
66 net::HTTP_OK,
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),
76 base::StringPrintf(
77 "[\"f\", [[\"b\", 0, \"n\", \"%s\", \"p\", 0, 0, 0, 0, %d, \"%s\"]]]",
78 email, expired ? 0 : 1, gaia_id),
79 net::HTTP_OK,
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),
90 base::StringPrintf(
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),
94 net::HTTP_OK,
95 net::URLRequestStatus::SUCCESS);
98 void FakeGaiaCookieManagerService::SetListAccountsResponseTwoAccountsWithExpiry(
99 const char* email1,
100 const char* gaia_id1,
101 bool account1_expired,
102 const char* email2,
103 const char* gaia_id2,
104 bool account2_expired) {
105 DCHECK(url_fetcher_factory_);
106 url_fetcher_factory_->SetFakeResponse(
107 GaiaUrls::GetInstance()->ListAccountsURLWithSource(
108 GaiaConstants::kChromeSource),
109 base::StringPrintf(
110 "[\"f\", [[\"b\", 0, \"n\", \"%s\", \"p\", 0, 0, 0, 0, %d, \"%s\"], "
111 "[\"b\", 0, \"n\", \"%s\", \"p\", 0, 0, 0, 0, %d, \"%s\"]]]",
112 email1, account1_expired ? 0 : 1, gaia_id1, email2,
113 account2_expired ? 0 : 1, gaia_id2),
114 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
117 // static
118 scoped_ptr<KeyedService> FakeGaiaCookieManagerService::Build(
119 content::BrowserContext* context) {
120 Profile* profile = Profile::FromBrowserContext(context);
121 return make_scoped_ptr(new FakeGaiaCookieManagerService(
122 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
123 GaiaConstants::kChromeSource,
124 ChromeSigninClientFactory::GetForProfile(profile)));