Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: chrome/browser/chromeos/login/mock_url_fetchers.cc

Issue 286933002: [cros login] Split login related classes into subfolders. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix includes in new tests Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/chromeos/login/mock_url_fetchers.h"
6
7 #include <errno.h>
8
9 #include "base/bind.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/strings/stringprintf.h"
12 #include "net/http/http_status_code.h"
13 #include "net/url_request/url_fetcher.h"
14 #include "net/url_request/url_fetcher_delegate.h"
15 #include "net/url_request/url_request_status.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "url/gurl.h"
18
19 namespace chromeos {
20
21 ExpectCanceledFetcher::ExpectCanceledFetcher(
22 bool success,
23 const GURL& url,
24 const std::string& results,
25 net::URLFetcher::RequestType request_type,
26 net::URLFetcherDelegate* d)
27 : net::TestURLFetcher(0, url, d),
28 weak_factory_(this) {
29 }
30
31 ExpectCanceledFetcher::~ExpectCanceledFetcher() {
32 }
33
34 void ExpectCanceledFetcher::Start() {
35 base::MessageLoop::current()->PostDelayedTask(
36 FROM_HERE,
37 base::Bind(&ExpectCanceledFetcher::CompleteFetch,
38 weak_factory_.GetWeakPtr()),
39 base::TimeDelta::FromMilliseconds(100));
40 }
41
42 void ExpectCanceledFetcher::CompleteFetch() {
43 ADD_FAILURE() << "Fetch completed in ExpectCanceledFetcher!";
44 base::MessageLoop::current()->Quit(); // Allow exiting even if we mess up.
45 }
46
47 GotCanceledFetcher::GotCanceledFetcher(
48 bool success,
49 const GURL& url,
50 const std::string& results,
51 net::URLFetcher::RequestType request_type,
52 net::URLFetcherDelegate* d)
53 : net::TestURLFetcher(0, url, d) {
54 set_url(url);
55 set_status(net::URLRequestStatus(net::URLRequestStatus::CANCELED, 0));
56 set_response_code(net::HTTP_FORBIDDEN);
57 }
58
59 GotCanceledFetcher::~GotCanceledFetcher() {}
60
61 void GotCanceledFetcher::Start() {
62 delegate()->OnURLFetchComplete(this);
63 }
64
65 SuccessFetcher::SuccessFetcher(bool success,
66 const GURL& url,
67 const std::string& results,
68 net::URLFetcher::RequestType request_type,
69 net::URLFetcherDelegate* d)
70 : net::TestURLFetcher(0, url, d) {
71 set_url(url);
72 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0));
73 set_response_code(net::HTTP_OK);
74 }
75
76 SuccessFetcher::~SuccessFetcher() {}
77
78 void SuccessFetcher::Start() {
79 delegate()->OnURLFetchComplete(this);
80 }
81
82 FailFetcher::FailFetcher(bool success,
83 const GURL& url,
84 const std::string& results,
85 net::URLFetcher::RequestType request_type,
86 net::URLFetcherDelegate* d)
87 : net::TestURLFetcher(0, url, d) {
88 set_url(url);
89 set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED, ECONNRESET));
90 set_response_code(net::HTTP_OK);
91 }
92
93 FailFetcher::~FailFetcher() {}
94
95 void FailFetcher::Start() {
96 delegate()->OnURLFetchComplete(this);
97 }
98
99 // static
100 const char CaptchaFetcher::kCaptchaToken[] = "token";
101 // static
102 const char CaptchaFetcher::kCaptchaUrlBase[] = "http://accounts.google.com/";
103 // static
104 const char CaptchaFetcher::kCaptchaUrlFragment[] = "fragment";
105 // static
106 const char CaptchaFetcher::kUnlockUrl[] = "http://what.ever";
107
108
109 CaptchaFetcher::CaptchaFetcher(bool success,
110 const GURL& url,
111 const std::string& results,
112 net::URLFetcher::RequestType request_type,
113 net::URLFetcherDelegate* d)
114 : net::TestURLFetcher(0, url, d) {
115 set_url(url);
116 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0));
117 set_response_code(net::HTTP_FORBIDDEN);
118 SetResponseString(base::StringPrintf("Error=%s\n"
119 "Url=%s\n"
120 "CaptchaUrl=%s\n"
121 "CaptchaToken=%s\n",
122 "CaptchaRequired",
123 kUnlockUrl,
124 kCaptchaUrlFragment,
125 kCaptchaToken));
126 }
127
128 CaptchaFetcher::~CaptchaFetcher() {}
129
130 // static
131 std::string CaptchaFetcher::GetCaptchaToken() {
132 return kCaptchaToken;
133 }
134
135 // static
136 std::string CaptchaFetcher::GetCaptchaUrl() {
137 return std::string(kCaptchaUrlBase).append(kCaptchaUrlFragment);
138 }
139
140 // static
141 std::string CaptchaFetcher::GetUnlockUrl() {
142 return kUnlockUrl;
143 }
144
145 void CaptchaFetcher::Start() {
146 delegate()->OnURLFetchComplete(this);
147 }
148
149 HostedFetcher::HostedFetcher(bool success,
150 const GURL& url,
151 const std::string& results,
152 net::URLFetcher::RequestType request_type,
153 net::URLFetcherDelegate* d)
154 : net::TestURLFetcher(0, url, d) {
155 set_url(url);
156 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0));
157 set_response_code(net::HTTP_OK);
158 }
159
160 HostedFetcher::~HostedFetcher() {}
161
162 void HostedFetcher::Start() {
163 VLOG(1) << upload_data();
164 if (upload_data().find("HOSTED") == std::string::npos) {
165 VLOG(1) << "HostedFetcher failing request";
166 set_response_code(net::HTTP_FORBIDDEN);
167 SetResponseString("Error=BadAuthentication");
168 }
169 delegate()->OnURLFetchComplete(this);
170 }
171
172 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/mock_url_fetchers.h ('k') | chrome/browser/chromeos/login/mock_user_image_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698