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

Side by Side Diff: ios/web/public/test/response_providers/response_provider.mm

Issue 2898733003: Split up ios/web:test_support. (Closed)
Patch Set: don't break downstream clients Created 3 years, 6 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/web/public/test/response_providers/response_provider.h"
6
7 #include "base/strings/stringprintf.h"
8 #include "net/http/http_response_headers.h"
9
10 namespace web {
11
12 ResponseProvider::Request::Request(const GURL& url,
13 const std::string& method,
14 const std::string& body,
15 const net::HttpRequestHeaders& headers)
16 : url(url), method(method), body(body), headers(headers) {}
17
18 ResponseProvider::Request::Request(const Request& other) = default;
19
20 ResponseProvider::Request::~Request() {}
21
22 ResponseProvider::ResponseProvider() {}
23
24 // static
25 scoped_refptr<net::HttpResponseHeaders> ResponseProvider::GetResponseHeaders(
26 const std::string& content_type,
27 net::HttpStatusCode response_code) {
28 scoped_refptr<net::HttpResponseHeaders> result(
29 new net::HttpResponseHeaders(""));
30 const std::string reason_phrase(net::GetHttpReasonPhrase(response_code));
31 const std::string status_line = base::StringPrintf(
32 "HTTP/1.1 %i %s", static_cast<int>(response_code), reason_phrase.c_str());
33 result->ReplaceStatusLine(status_line);
34 const std::string content_type_header =
35 base::StringPrintf("Content-type: %s", content_type.c_str());
36 result->AddHeader(content_type_header);
37 return result;
38 }
39
40 // static
41 scoped_refptr<net::HttpResponseHeaders> ResponseProvider::GetResponseHeaders(
42 const std::string& content_type) {
43 return GetResponseHeaders(content_type, net::HTTP_OK);
44 }
45
46 // static
47 scoped_refptr<net::HttpResponseHeaders>
48 ResponseProvider::GetDefaultResponseHeaders() {
49 return GetResponseHeaders("text/html", net::HTTP_OK);
50 }
51
52 // static
53 std::map<GURL, scoped_refptr<net::HttpResponseHeaders>>
54 ResponseProvider::GetDefaultResponseHeaders(
55 const std::map<GURL, std::pair<std::string, std::string>>& responses) {
56 std::map<GURL, scoped_refptr<net::HttpResponseHeaders>> headers;
57 for (const auto& pair : responses) {
58 std::string cookie = pair.second.first;
59 scoped_refptr<net::HttpResponseHeaders> result =
60 GetDefaultResponseHeaders();
61 if (!cookie.empty()) {
62 result->AddCookie(cookie);
63 }
64 headers.insert(std::make_pair(pair.first, result));
65 }
66 return headers;
67 }
68
69 // static
70 scoped_refptr<net::HttpResponseHeaders>
71 ResponseProvider::GetRedirectResponseHeaders(
72 const std::string& destination,
73 const net::HttpStatusCode& http_status) {
74 scoped_refptr<net::HttpResponseHeaders> headers(
75 GetResponseHeaders("text/html", http_status));
76 headers->AddHeader("Location: " + destination);
77 return headers;
78 }
79
80 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698