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

Side by Side Diff: chromeos/login/auth/mock_url_fetchers.cc

Issue 402403004: Refactoring : Move OnlineAttempt to chromeos/login (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Yet another merge with ToT Created 6 years, 4 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
« no previous file with comments | « chromeos/login/auth/mock_url_fetchers.h ('k') | chromeos/login/auth/online_attempt.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/chromeos/login/auth/mock_url_fetchers.h" 5 #include "chromeos/login/auth/mock_url_fetchers.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "net/http/http_status_code.h" 12 #include "net/http/http_status_code.h"
13 #include "net/url_request/url_fetcher.h" 13 #include "net/url_request/url_fetcher.h"
14 #include "net/url_request/url_fetcher_delegate.h" 14 #include "net/url_request/url_fetcher_delegate.h"
15 #include "net/url_request/url_request_status.h" 15 #include "net/url_request/url_request_status.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "url/gurl.h" 17 #include "url/gurl.h"
18 18
19 namespace chromeos { 19 namespace chromeos {
20 20
21 ExpectCanceledFetcher::ExpectCanceledFetcher( 21 ExpectCanceledFetcher::ExpectCanceledFetcher(
22 bool success, 22 bool success,
23 const GURL& url, 23 const GURL& url,
24 const std::string& results, 24 const std::string& results,
25 net::URLFetcher::RequestType request_type, 25 net::URLFetcher::RequestType request_type,
26 net::URLFetcherDelegate* d) 26 net::URLFetcherDelegate* d)
27 : net::TestURLFetcher(0, url, d), 27 : net::TestURLFetcher(0, url, d), weak_factory_(this) {
28 weak_factory_(this) {
29 } 28 }
30 29
31 ExpectCanceledFetcher::~ExpectCanceledFetcher() { 30 ExpectCanceledFetcher::~ExpectCanceledFetcher() {
32 } 31 }
33 32
34 void ExpectCanceledFetcher::Start() { 33 void ExpectCanceledFetcher::Start() {
35 base::MessageLoop::current()->PostDelayedTask( 34 base::MessageLoop::current()->PostDelayedTask(
36 FROM_HERE, 35 FROM_HERE,
37 base::Bind(&ExpectCanceledFetcher::CompleteFetch, 36 base::Bind(&ExpectCanceledFetcher::CompleteFetch,
38 weak_factory_.GetWeakPtr()), 37 weak_factory_.GetWeakPtr()),
(...skipping 10 matching lines...) Expand all
49 const GURL& url, 48 const GURL& url,
50 const std::string& results, 49 const std::string& results,
51 net::URLFetcher::RequestType request_type, 50 net::URLFetcher::RequestType request_type,
52 net::URLFetcherDelegate* d) 51 net::URLFetcherDelegate* d)
53 : net::TestURLFetcher(0, url, d) { 52 : net::TestURLFetcher(0, url, d) {
54 set_url(url); 53 set_url(url);
55 set_status(net::URLRequestStatus(net::URLRequestStatus::CANCELED, 0)); 54 set_status(net::URLRequestStatus(net::URLRequestStatus::CANCELED, 0));
56 set_response_code(net::HTTP_FORBIDDEN); 55 set_response_code(net::HTTP_FORBIDDEN);
57 } 56 }
58 57
59 GotCanceledFetcher::~GotCanceledFetcher() {} 58 GotCanceledFetcher::~GotCanceledFetcher() {
59 }
60 60
61 void GotCanceledFetcher::Start() { 61 void GotCanceledFetcher::Start() {
62 delegate()->OnURLFetchComplete(this); 62 delegate()->OnURLFetchComplete(this);
63 } 63 }
64 64
65 SuccessFetcher::SuccessFetcher(bool success, 65 SuccessFetcher::SuccessFetcher(bool success,
66 const GURL& url, 66 const GURL& url,
67 const std::string& results, 67 const std::string& results,
68 net::URLFetcher::RequestType request_type, 68 net::URLFetcher::RequestType request_type,
69 net::URLFetcherDelegate* d) 69 net::URLFetcherDelegate* d)
70 : net::TestURLFetcher(0, url, d) { 70 : net::TestURLFetcher(0, url, d) {
71 set_url(url); 71 set_url(url);
72 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); 72 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0));
73 set_response_code(net::HTTP_OK); 73 set_response_code(net::HTTP_OK);
74 } 74 }
75 75
76 SuccessFetcher::~SuccessFetcher() {} 76 SuccessFetcher::~SuccessFetcher() {
77 }
77 78
78 void SuccessFetcher::Start() { 79 void SuccessFetcher::Start() {
79 delegate()->OnURLFetchComplete(this); 80 delegate()->OnURLFetchComplete(this);
80 } 81 }
81 82
82 FailFetcher::FailFetcher(bool success, 83 FailFetcher::FailFetcher(bool success,
83 const GURL& url, 84 const GURL& url,
84 const std::string& results, 85 const std::string& results,
85 net::URLFetcher::RequestType request_type, 86 net::URLFetcher::RequestType request_type,
86 net::URLFetcherDelegate* d) 87 net::URLFetcherDelegate* d)
87 : net::TestURLFetcher(0, url, d) { 88 : net::TestURLFetcher(0, url, d) {
88 set_url(url); 89 set_url(url);
89 set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED, ECONNRESET)); 90 set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED, ECONNRESET));
90 set_response_code(net::HTTP_OK); 91 set_response_code(net::HTTP_OK);
91 } 92 }
92 93
93 FailFetcher::~FailFetcher() {} 94 FailFetcher::~FailFetcher() {
95 }
94 96
95 void FailFetcher::Start() { 97 void FailFetcher::Start() {
96 delegate()->OnURLFetchComplete(this); 98 delegate()->OnURLFetchComplete(this);
97 } 99 }
98 100
99 // static 101 // static
100 const char CaptchaFetcher::kCaptchaToken[] = "token"; 102 const char CaptchaFetcher::kCaptchaToken[] = "token";
101 // static 103 // static
102 const char CaptchaFetcher::kCaptchaUrlBase[] = "http://accounts.google.com/"; 104 const char CaptchaFetcher::kCaptchaUrlBase[] = "http://accounts.google.com/";
103 // static 105 // static
104 const char CaptchaFetcher::kCaptchaUrlFragment[] = "fragment"; 106 const char CaptchaFetcher::kCaptchaUrlFragment[] = "fragment";
105 // static 107 // static
106 const char CaptchaFetcher::kUnlockUrl[] = "http://what.ever"; 108 const char CaptchaFetcher::kUnlockUrl[] = "http://what.ever";
107 109
108
109 CaptchaFetcher::CaptchaFetcher(bool success, 110 CaptchaFetcher::CaptchaFetcher(bool success,
110 const GURL& url, 111 const GURL& url,
111 const std::string& results, 112 const std::string& results,
112 net::URLFetcher::RequestType request_type, 113 net::URLFetcher::RequestType request_type,
113 net::URLFetcherDelegate* d) 114 net::URLFetcherDelegate* d)
114 : net::TestURLFetcher(0, url, d) { 115 : net::TestURLFetcher(0, url, d) {
115 set_url(url); 116 set_url(url);
116 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); 117 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0));
117 set_response_code(net::HTTP_FORBIDDEN); 118 set_response_code(net::HTTP_FORBIDDEN);
118 SetResponseString(base::StringPrintf("Error=%s\n" 119 SetResponseString(base::StringPrintf(
119 "Url=%s\n" 120 "Error=%s\n"
120 "CaptchaUrl=%s\n" 121 "Url=%s\n"
121 "CaptchaToken=%s\n", 122 "CaptchaUrl=%s\n"
122 "CaptchaRequired", 123 "CaptchaToken=%s\n",
123 kUnlockUrl, 124 "CaptchaRequired",
124 kCaptchaUrlFragment, 125 kUnlockUrl,
125 kCaptchaToken)); 126 kCaptchaUrlFragment,
127 kCaptchaToken));
126 } 128 }
127 129
128 CaptchaFetcher::~CaptchaFetcher() {} 130 CaptchaFetcher::~CaptchaFetcher() {
131 }
129 132
130 // static 133 // static
131 std::string CaptchaFetcher::GetCaptchaToken() { 134 std::string CaptchaFetcher::GetCaptchaToken() {
132 return kCaptchaToken; 135 return kCaptchaToken;
133 } 136 }
134 137
135 // static 138 // static
136 std::string CaptchaFetcher::GetCaptchaUrl() { 139 std::string CaptchaFetcher::GetCaptchaUrl() {
137 return std::string(kCaptchaUrlBase).append(kCaptchaUrlFragment); 140 return std::string(kCaptchaUrlBase).append(kCaptchaUrlFragment);
138 } 141 }
(...skipping 11 matching lines...) Expand all
150 const GURL& url, 153 const GURL& url,
151 const std::string& results, 154 const std::string& results,
152 net::URLFetcher::RequestType request_type, 155 net::URLFetcher::RequestType request_type,
153 net::URLFetcherDelegate* d) 156 net::URLFetcherDelegate* d)
154 : net::TestURLFetcher(0, url, d) { 157 : net::TestURLFetcher(0, url, d) {
155 set_url(url); 158 set_url(url);
156 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); 159 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0));
157 set_response_code(net::HTTP_OK); 160 set_response_code(net::HTTP_OK);
158 } 161 }
159 162
160 HostedFetcher::~HostedFetcher() {} 163 HostedFetcher::~HostedFetcher() {
164 }
161 165
162 void HostedFetcher::Start() { 166 void HostedFetcher::Start() {
163 VLOG(1) << upload_data(); 167 VLOG(1) << upload_data();
164 if (upload_data().find("HOSTED") == std::string::npos) { 168 if (upload_data().find("HOSTED") == std::string::npos) {
165 VLOG(1) << "HostedFetcher failing request"; 169 VLOG(1) << "HostedFetcher failing request";
166 set_response_code(net::HTTP_FORBIDDEN); 170 set_response_code(net::HTTP_FORBIDDEN);
167 SetResponseString("Error=BadAuthentication"); 171 SetResponseString("Error=BadAuthentication");
168 } 172 }
169 delegate()->OnURLFetchComplete(this); 173 delegate()->OnURLFetchComplete(this);
170 } 174 }
171 175
172 } // namespace chromeos 176 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/login/auth/mock_url_fetchers.h ('k') | chromeos/login/auth/online_attempt.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698