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

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

Issue 8416020: Handle additional feedback from http://codereview.chromium.org/8395038/. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/mock_url_fetchers.h" 5 #include "chrome/browser/chromeos/login/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.h" 10 #include "base/message_loop.h"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "chrome/common/net/http_return.h" 12 #include "chrome/common/net/http_return.h"
13 #include "content/browser/browser_thread.h" 13 #include "content/browser/browser_thread.h"
14 #include "content/public/common/url_fetcher_delegate.h" 14 #include "content/public/common/url_fetcher_delegate.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "net/url_request/url_request_status.h" 16 #include "net/url_request/url_request_status.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.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 content::URLFetcher::RequestType request_type, 25 content::URLFetcher::RequestType request_type,
26 content::URLFetcherDelegate* d) 26 content::URLFetcherDelegate* d)
27 : TestURLFetcher(0, url, request_type, d), 27 : TestURLFetcher(0, url, d),
28 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 28 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
29 } 29 }
30 30
31 ExpectCanceledFetcher::~ExpectCanceledFetcher() { 31 ExpectCanceledFetcher::~ExpectCanceledFetcher() {
32 } 32 }
33 33
34 void ExpectCanceledFetcher::Start() { 34 void ExpectCanceledFetcher::Start() {
35 MessageLoop::current()->PostDelayedTask( 35 MessageLoop::current()->PostDelayedTask(
36 FROM_HERE, 36 FROM_HERE,
37 base::Bind(&ExpectCanceledFetcher::CompleteFetch, 37 base::Bind(&ExpectCanceledFetcher::CompleteFetch,
38 weak_factory_.GetWeakPtr()), 38 weak_factory_.GetWeakPtr()),
39 100); 39 100);
40 } 40 }
41 41
42 void ExpectCanceledFetcher::CompleteFetch() { 42 void ExpectCanceledFetcher::CompleteFetch() {
43 ADD_FAILURE() << "Fetch completed in ExpectCanceledFetcher!"; 43 ADD_FAILURE() << "Fetch completed in ExpectCanceledFetcher!";
44 MessageLoop::current()->Quit(); // Allow exiting even if we mess up. 44 MessageLoop::current()->Quit(); // Allow exiting even if we mess up.
45 } 45 }
46 46
47 GotCanceledFetcher::GotCanceledFetcher( 47 GotCanceledFetcher::GotCanceledFetcher(
48 bool success, 48 bool success,
49 const GURL& url, 49 const GURL& url,
50 const std::string& results, 50 const std::string& results,
51 content::URLFetcher::RequestType request_type, 51 content::URLFetcher::RequestType request_type,
52 content::URLFetcherDelegate* d) 52 content::URLFetcherDelegate* d)
53 : TestURLFetcher(0, url, request_type, d) { 53 : TestURLFetcher(0, url, d) {
54 set_url(url); 54 set_url(url);
55 set_status(net::URLRequestStatus(net::URLRequestStatus::CANCELED, 0)); 55 set_status(net::URLRequestStatus(net::URLRequestStatus::CANCELED, 0));
56 set_response_code(RC_FORBIDDEN); 56 set_response_code(RC_FORBIDDEN);
57 } 57 }
58 58
59 GotCanceledFetcher::~GotCanceledFetcher() {} 59 GotCanceledFetcher::~GotCanceledFetcher() {}
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 content::URLFetcher::RequestType request_type, 68 content::URLFetcher::RequestType request_type,
69 content::URLFetcherDelegate* d) 69 content::URLFetcherDelegate* d)
70 : TestURLFetcher(0, url, request_type, d) { 70 : 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(RC_REQUEST_OK); 73 set_response_code(RC_REQUEST_OK);
74 } 74 }
75 75
76 SuccessFetcher::~SuccessFetcher() {} 76 SuccessFetcher::~SuccessFetcher() {}
77 77
78 void SuccessFetcher::Start() { 78 void SuccessFetcher::Start() {
79 delegate()->OnURLFetchComplete(this); 79 delegate()->OnURLFetchComplete(this);
80 } 80 }
81 81
82 FailFetcher::FailFetcher(bool success, 82 FailFetcher::FailFetcher(bool success,
83 const GURL& url, 83 const GURL& url,
84 const std::string& results, 84 const std::string& results,
85 content::URLFetcher::RequestType request_type, 85 content::URLFetcher::RequestType request_type,
86 content::URLFetcherDelegate* d) 86 content::URLFetcherDelegate* d)
87 : TestURLFetcher(0, url, request_type, d) { 87 : TestURLFetcher(0, url, d) {
88 set_url(url); 88 set_url(url);
89 set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED, ECONNRESET)); 89 set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED, ECONNRESET));
90 set_response_code(RC_REQUEST_OK); 90 set_response_code(RC_REQUEST_OK);
91 } 91 }
92 92
93 FailFetcher::~FailFetcher() {} 93 FailFetcher::~FailFetcher() {}
94 94
95 void FailFetcher::Start() { 95 void FailFetcher::Start() {
96 delegate()->OnURLFetchComplete(this); 96 delegate()->OnURLFetchComplete(this);
97 } 97 }
98 98
99 // static 99 // static
100 const char CaptchaFetcher::kCaptchaToken[] = "token"; 100 const char CaptchaFetcher::kCaptchaToken[] = "token";
101 // static 101 // static
102 const char CaptchaFetcher::kCaptchaUrlBase[] = "http://www.google.com/accounts/" ; 102 const char CaptchaFetcher::kCaptchaUrlBase[] = "http://www.google.com/accounts/" ;
103 // static 103 // static
104 const char CaptchaFetcher::kCaptchaUrlFragment[] = "fragment"; 104 const char CaptchaFetcher::kCaptchaUrlFragment[] = "fragment";
105 // static 105 // static
106 const char CaptchaFetcher::kUnlockUrl[] = "http://what.ever"; 106 const char CaptchaFetcher::kUnlockUrl[] = "http://what.ever";
107 107
108 108
109 CaptchaFetcher::CaptchaFetcher(bool success, 109 CaptchaFetcher::CaptchaFetcher(bool success,
110 const GURL& url, 110 const GURL& url,
111 const std::string& results, 111 const std::string& results,
112 content::URLFetcher::RequestType request_type, 112 content::URLFetcher::RequestType request_type,
113 content::URLFetcherDelegate* d) 113 content::URLFetcherDelegate* d)
114 : TestURLFetcher(0, url, request_type, d) { 114 : TestURLFetcher(0, url, d) {
115 set_url(url); 115 set_url(url);
116 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); 116 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0));
117 set_response_code(RC_FORBIDDEN); 117 set_response_code(RC_FORBIDDEN);
118 SetResponseString(base::StringPrintf("Error=%s\n" 118 SetResponseString(base::StringPrintf("Error=%s\n"
119 "Url=%s\n" 119 "Url=%s\n"
120 "CaptchaUrl=%s\n" 120 "CaptchaUrl=%s\n"
121 "CaptchaToken=%s\n", 121 "CaptchaToken=%s\n",
122 "CaptchaRequired", 122 "CaptchaRequired",
123 kUnlockUrl, 123 kUnlockUrl,
124 kCaptchaUrlFragment, 124 kCaptchaUrlFragment,
(...skipping 19 matching lines...) Expand all
144 144
145 void CaptchaFetcher::Start() { 145 void CaptchaFetcher::Start() {
146 delegate()->OnURLFetchComplete(this); 146 delegate()->OnURLFetchComplete(this);
147 } 147 }
148 148
149 HostedFetcher::HostedFetcher(bool success, 149 HostedFetcher::HostedFetcher(bool success,
150 const GURL& url, 150 const GURL& url,
151 const std::string& results, 151 const std::string& results,
152 content::URLFetcher::RequestType request_type, 152 content::URLFetcher::RequestType request_type,
153 content::URLFetcherDelegate* d) 153 content::URLFetcherDelegate* d)
154 : TestURLFetcher(0, url, request_type, d) { 154 : TestURLFetcher(0, url, d) {
155 set_url(url); 155 set_url(url);
156 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); 156 set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0));
157 set_response_code(RC_REQUEST_OK); 157 set_response_code(RC_REQUEST_OK);
158 } 158 }
159 159
160 HostedFetcher::~HostedFetcher() {} 160 HostedFetcher::~HostedFetcher() {}
161 161
162 void HostedFetcher::Start() { 162 void HostedFetcher::Start() {
163 VLOG(1) << upload_data(); 163 VLOG(1) << upload_data();
164 if (upload_data().find("HOSTED") == std::string::npos) { 164 if (upload_data().find("HOSTED") == std::string::npos) {
165 VLOG(1) << "HostedFetcher failing request"; 165 VLOG(1) << "HostedFetcher failing request";
166 set_response_code(RC_FORBIDDEN); 166 set_response_code(RC_FORBIDDEN);
167 SetResponseString("Error=BadAuthentication"); 167 SetResponseString("Error=BadAuthentication");
168 } 168 }
169 delegate()->OnURLFetchComplete(this); 169 delegate()->OnURLFetchComplete(this);
170 } 170 }
171 171
172 } // namespace chromeos 172 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698