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

Side by Side Diff: headless/public/util/testing/generic_url_request_mocks.h

Issue 2260793002: Headless utility classes for making deterministic protocol handlers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments Created 4 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
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 HEADLESS_PUBLIC_UTIL_TESTING_GENERIC_URL_REQUEST_MOCKS_H_
6 #define HEADLESS_PUBLIC_UTIL_TESTING_GENERIC_URL_REQUEST_MOCKS_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/macros.h"
12 #include "headless/public/util/generic_url_request_job.h"
13 #include "headless/public/util/testing/generic_url_request_mocks.h"
14 #include "net/cookies/cookie_store.h"
15 #include "net/url_request/url_request.h"
16 #include "net/url_request/url_request_context.h"
17 #include "net/url_request/url_request_job_factory.h"
18
19 namespace net {
20 class URLRequestJob;
21 } // namespace net
22
23 namespace htmlrender_webkit_headless_proto {
24 class Resource;
25 } // htmlrender_webkit_headless_proto net
26
27 namespace headless {
28
29 class MockGenericURLRequestJobDelegate : public GenericURLRequestJob::Delegate {
30 public:
31 MockGenericURLRequestJobDelegate();
32 ~MockGenericURLRequestJobDelegate() override;
33
34 bool BlockOrRewriteRequest(
35 const GURL& url,
36 const std::string& referrer,
37 GenericURLRequestJob::RewriteCallback callback) override;
38
39 const GenericURLRequestJob::HttpResponse* MaybeMatchResource(
40 const GURL& url,
41 const net::HttpRequestHeaders& request_headers) override;
42
43 void OnResourceLoadComplete(const GURL& final_url,
44 const std::string& mime_type,
45 int http_response_code) override;
46
47 private:
48 DISALLOW_COPY_AND_ASSIGN(MockGenericURLRequestJobDelegate);
49 };
50
51 // TODO(alexclarke): We may be able to replace this with the CookieMonster.
52 class MockCookieStore : public net::CookieStore {
53 public:
54 MockCookieStore();
55 ~MockCookieStore() override;
56
57 // net::CookieStore implementation:
58 void SetCookieWithOptionsAsync(const GURL& url,
59 const std::string& cookie_line,
60 const net::CookieOptions& options,
61 const SetCookiesCallback& callback) override;
62
63 void SetCookieWithDetailsAsync(const GURL& url,
64 const std::string& name,
65 const std::string& value,
66 const std::string& domain,
67 const std::string& path,
68 base::Time creation_time,
69 base::Time expiration_time,
70 base::Time last_access_time,
71 bool secure,
72 bool http_only,
73 net::CookieSameSite same_site,
74 bool enforce_strict_secure,
75 net::CookiePriority priority,
76 const SetCookiesCallback& callback) override;
77
78 void GetCookiesWithOptionsAsync(const GURL& url,
79 const net::CookieOptions& options,
80 const GetCookiesCallback& callback) override;
81
82 void GetCookieListWithOptionsAsync(
83 const GURL& url,
84 const net::CookieOptions& options,
85 const GetCookieListCallback& callback) override;
86
87 void GetAllCookiesAsync(const GetCookieListCallback& callback) override;
88
89 void DeleteCookieAsync(const GURL& url,
90 const std::string& cookie_name,
91 const base::Closure& callback) override;
92
93 void DeleteCanonicalCookieAsync(const net::CanonicalCookie& cookie,
94 const DeleteCallback& callback) override;
95
96 void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin,
97 const base::Time& delete_end,
98 const DeleteCallback& callback) override;
99
100 void DeleteAllCreatedBetweenWithPredicateAsync(
101 const base::Time& delete_begin,
102 const base::Time& delete_end,
103 const CookiePredicate& predicate,
104 const DeleteCallback& callback) override;
105
106 void DeleteSessionCookiesAsync(const DeleteCallback&) override;
107
108 void FlushStore(const base::Closure& callback) override;
109
110 void SetForceKeepSessionState() override;
111
112 std::unique_ptr<CookieChangedSubscription> AddCallbackForCookie(
113 const GURL& url,
114 const std::string& name,
115 const CookieChangedCallback& callback) override;
116
117 bool IsEphemeral() override;
118
119 net::CookieList* cookies() { return &cookies_; }
120
121 private:
122 void SendCookies(const GURL& url,
123 const net::CookieOptions& options,
124 const GetCookieListCallback& callback);
125
126 net::CookieList cookies_;
127
128 DISALLOW_COPY_AND_ASSIGN(MockCookieStore);
129 };
130
131 class MockURLRequestDelegate : public net::URLRequest::Delegate {
132 public:
133 MockURLRequestDelegate();
134 ~MockURLRequestDelegate() override;
135
136 void OnResponseStarted(net::URLRequest* request) override;
137 void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
138 const std::string& response_data() const;
139 const net::IOBufferWithSize* metadata() const;
140
141 private:
142 std::string response_data_;
143
144 DISALLOW_COPY_AND_ASSIGN(MockURLRequestDelegate);
145 };
146
147 } // namespace headless
148
149 #endif // HEADLESS_PUBLIC_UTIL_TESTING_GENERIC_URL_REQUEST_MOCKS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698