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

Side by Side Diff: ios/web/public/test/response_providers/html_response_provider_impl.h

Issue 1890333002: Web shell test to go back and forward. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/include/import Created 4 years, 8 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 2016 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 #ifndef IOS_WEB_PUBLIC_TEST_RESPONSE_PROVIDERS_HTML_RESPONSE_PROVIDER_IMPL_H_
6 #define IOS_WEB_PUBLIC_TEST_RESPONSE_PROVIDERS_HTML_RESPONSE_PROVIDER_IMPL_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/memory/ref_counted.h"
12 #include "ios/web/public/test/response_providers/data_response_provider.h"
13 #include "ios/web/public/test/response_providers/response_provider.h"
14 #include "net/http/http_response_headers.h"
15 #include "net/http/http_status_code.h"
16 #include "url/gurl.h"
17
18 // This class encapsulates the logic needed to map a request URL to a response.
19 // The mapping -- between URL to response -- is maintained internally, use
20 // |CanHandleRequest| to check if a request can be handled and use
21 // |GetResponseHeadersAndBody| to actually handle the request.
22 class HtmlResponseProviderImpl {
23 public:
24 // Encapsulates the body and headers that make up a response.
25 struct Response {
26 Response(const std::string& body,
27 const scoped_refptr<net::HttpResponseHeaders>& headers);
28 Response(const Response&);
29 Response();
30 ~Response();
31
32 std::string body;
33 scoped_refptr<net::HttpResponseHeaders> headers;
34 };
35 // Constructs an HtmlResponseProviderImpl that does not respond to any
36 // request.
37 HtmlResponseProviderImpl();
38 // Constructs an HtmlResponseProviderImpl that generates a simple string
39 // response to a URL based on the mapping present in |responses|.
40 explicit HtmlResponseProviderImpl(
41 const std::map<GURL, std::string>& responses);
42 // Constructs an HtmlResponseProviderImpl that generates a response to a URL
43 // based on the mapping present in |responses|.
44 explicit HtmlResponseProviderImpl(const std::map<GURL, Response>& responses);
45
46 virtual ~HtmlResponseProviderImpl();
47
48 // Creates a reponse based on a redirect to |destination_url|.
49 static HtmlResponseProviderImpl::Response GetRedirectResponse(
50 const GURL& destination_url,
51 const net::HttpStatusCode& http_status);
52
53 // Creates a response with |net::HTTP_OK|.
54 static HtmlResponseProviderImpl::Response GetSimpleResponse(
55 const std::string& body);
56
57 // Returns true if the request can be handled.
58 bool CanHandleRequest(const web::ResponseProvider::Request& request);
59 // Returns the headers and the response body.
60 void GetResponseHeadersAndBody(
61 const web::ResponseProvider::Request& request,
62 scoped_refptr<net::HttpResponseHeaders>* headers,
63 std::string* response_body);
64
65 private:
66 const std::map<GURL, Response> responses_;
67 };
68
69 #endif // IOS_WEB_PUBLIC_TEST_RESPONSE_PROVIDERS_HTML_RESPONSE_PROVIDER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698