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

Side by Side Diff: net/spdy/spdy_test_util.h

Issue 3020032: Implement server push protocol 2. (Closed)
Patch Set: nits. Created 10 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
« no previous file with comments | « net/spdy/spdy_stream.cc ('k') | net/spdy/spdy_test_util.cc » ('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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #ifndef NET_SPDY_SPDY_TEST_UTIL_H_ 5 #ifndef NET_SPDY_SPDY_TEST_UTIL_H_
6 #define NET_SPDY_SPDY_TEST_UTIL_H_ 6 #define NET_SPDY_SPDY_TEST_UTIL_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "net/base/mock_host_resolver.h" 10 #include "net/base/mock_host_resolver.h"
11 #include "net/base/request_priority.h" 11 #include "net/base/request_priority.h"
12 #include "net/base/ssl_config_service_defaults.h" 12 #include "net/base/ssl_config_service_defaults.h"
13 #include "net/http/http_auth_handler_factory.h" 13 #include "net/http/http_auth_handler_factory.h"
14 #include "net/http/http_cache.h"
14 #include "net/http/http_network_session.h" 15 #include "net/http/http_network_session.h"
16 #include "net/http/http_network_layer.h"
17 #include "net/http/http_transaction_factory.h"
15 #include "net/proxy/proxy_service.h" 18 #include "net/proxy/proxy_service.h"
16 #include "net/socket/socket_test_util.h" 19 #include "net/socket/socket_test_util.h"
17 #include "net/spdy/spdy_framer.h" 20 #include "net/spdy/spdy_framer.h"
18 #include "net/spdy/spdy_session_pool.h" 21 #include "net/spdy/spdy_session_pool.h"
22 #include "net/url_request/url_request_context.h"
19 23
20 namespace net { 24 namespace net {
21 25
22 // NOTE: In GCC, on a Mac, this can't be in an anonymous namespace! 26 // NOTE: In GCC, on a Mac, this can't be in an anonymous namespace!
23 // This struct holds information used to construct spdy control and data frames. 27 // This struct holds information used to construct spdy control and data frames.
24 struct SpdyHeaderInfo { 28 struct SpdyHeaderInfo {
25 spdy::SpdyControlType kind; 29 spdy::SpdyControlType kind;
26 spdy::SpdyStreamId id; 30 spdy::SpdyStreamId id;
27 spdy::SpdyStreamId assoc_id; 31 spdy::SpdyStreamId assoc_id;
28 spdy::SpdyPriority priority; 32 spdy::SpdyPriority priority;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // will vary the most between calls. 106 // will vary the most between calls.
103 // |tail| is any (relatively constant) header-value pairs to add. 107 // |tail| is any (relatively constant) header-value pairs to add.
104 // |buffer| is the buffer we're filling in. 108 // |buffer| is the buffer we're filling in.
105 // Returns a SpdyFrame. 109 // Returns a SpdyFrame.
106 spdy::SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info, 110 spdy::SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info,
107 const char* const extra_headers[], 111 const char* const extra_headers[],
108 int extra_header_count, 112 int extra_header_count,
109 const char* const tail[], 113 const char* const tail[],
110 int tail_header_count); 114 int tail_header_count);
111 115
116 // Construct a generic SpdyControlFrame.
117 spdy::SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[],
118 int extra_header_count,
119 bool compressed,
120 int stream_id,
121 RequestPriority request_priority,
122 spdy::SpdyControlType type,
123 spdy::SpdyControlFlags flags,
124 const char* const* kHeaders,
125 int kHeadersSize);
126 spdy::SpdyFrame* ConstructSpdyControlFrame(const char* const extra_headers[],
127 int extra_header_count,
128 bool compressed,
129 int stream_id,
130 RequestPriority request_priority,
131 spdy::SpdyControlType type,
132 spdy::SpdyControlFlags flags,
133 const char* const* kHeaders,
134 int kHeadersSize,
135 int associated_stream_id);
136
112 // Construct an expected SPDY reply string. 137 // Construct an expected SPDY reply string.
113 // |extra_headers| are the extra header-value pairs, which typically 138 // |extra_headers| are the extra header-value pairs, which typically
114 // will vary the most between calls. 139 // will vary the most between calls.
115 // |buffer| is the buffer we're filling in. 140 // |buffer| is the buffer we're filling in.
116 // Returns the number of bytes written into |buffer|. 141 // Returns the number of bytes written into |buffer|.
117 int ConstructSpdyReplyString(const char* const extra_headers[], 142 int ConstructSpdyReplyString(const char* const extra_headers[],
118 int extra_header_count, 143 int extra_header_count,
119 char* buffer, 144 char* buffer,
120 int buffer_length); 145 int buffer_length);
121 146
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // Constructs a standard SPDY GET SYN packet, optionally compressed. 187 // Constructs a standard SPDY GET SYN packet, optionally compressed.
163 // |extra_headers| are the extra header-value pairs, which typically 188 // |extra_headers| are the extra header-value pairs, which typically
164 // will vary the most between calls. 189 // will vary the most between calls.
165 // Returns a SpdyFrame. 190 // Returns a SpdyFrame.
166 spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], 191 spdy::SpdyFrame* ConstructSpdyGet(const char* const extra_headers[],
167 int extra_header_count, 192 int extra_header_count,
168 bool compressed, 193 bool compressed,
169 int stream_id, 194 int stream_id,
170 RequestPriority request_priority); 195 RequestPriority request_priority);
171 196
197 // Constructs a standard SPDY push SYN packet.
198 // |extra_headers| are the extra header-value pairs, which typically
199 // will vary the most between calls.
200 // Returns a SpdyFrame.
201 spdy::SpdyFrame* ConstructSpdyPush(const char* const extra_headers[],
202 int extra_header_count,
203 int stream_id,
204 int associated_stream_id);
205 spdy::SpdyFrame* ConstructSpdyPush(const char* const extra_headers[],
206 int extra_header_count,
207 int stream_id,
208 int associated_stream_id,
209 const char* path);
210 spdy::SpdyFrame* ConstructSpdyPush(const char* const extra_headers[],
211 int extra_header_count,
212 int stream_id,
213 int associated_stream_id,
214 const char* path,
215 const char* status,
216 const char* location,
217 const char* url);
218
172 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET. 219 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET.
173 // |extra_headers| are the extra header-value pairs, which typically 220 // |extra_headers| are the extra header-value pairs, which typically
174 // will vary the most between calls. 221 // will vary the most between calls.
175 // Returns a SpdyFrame. 222 // Returns a SpdyFrame.
176 spdy::SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], 223 spdy::SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[],
177 int extra_header_count, 224 int extra_header_count,
178 int stream_id); 225 int stream_id);
179 226
227 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY GET.
228 // |extra_headers| are the extra header-value pairs, which typically
229 // will vary the most between calls.
230 // Returns a SpdyFrame.
231 spdy::SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id);
232
233
180 // Constructs a standard SPDY POST SYN packet. 234 // Constructs a standard SPDY POST SYN packet.
181 // |extra_headers| are the extra header-value pairs, which typically 235 // |extra_headers| are the extra header-value pairs, which typically
182 // will vary the most between calls. 236 // will vary the most between calls.
183 // Returns a SpdyFrame. 237 // Returns a SpdyFrame.
184 spdy::SpdyFrame* ConstructSpdyPost(int64 content_length, 238 spdy::SpdyFrame* ConstructSpdyPost(int64 content_length,
185 const char* const extra_headers[], 239 const char* const extra_headers[],
186 int extra_header_count); 240 int extra_header_count);
187 241
188 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST. 242 // Constructs a standard SPDY SYN_REPLY packet to match the SPDY POST.
189 // |extra_headers| are the extra header-value pairs, which typically 243 // |extra_headers| are the extra header-value pairs, which typically
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 session_deps->proxy_service, 308 session_deps->proxy_service,
255 &session_deps->socket_factory, 309 &session_deps->socket_factory,
256 session_deps->ssl_config_service, 310 session_deps->ssl_config_service,
257 session_deps->spdy_session_pool, 311 session_deps->spdy_session_pool,
258 session_deps->http_auth_handler_factory.get(), 312 session_deps->http_auth_handler_factory.get(),
259 NULL, 313 NULL,
260 NULL); 314 NULL);
261 } 315 }
262 }; 316 };
263 317
318 class SpdyURLRequestContext : public URLRequestContext {
319 public:
320 SpdyURLRequestContext() {
321 host_resolver_ = new MockHostResolver;
322 proxy_service_ = ProxyService::CreateNull();
323 spdy_session_pool_ = new SpdySessionPool();
324 ssl_config_service_ = new SSLConfigServiceDefaults;
325 http_auth_handler_factory_ = HttpAuthHandlerFactory::CreateDefault();
326 http_transaction_factory_ = new net::HttpCache(
327 new HttpNetworkLayer(&socket_factory_,
328 host_resolver_,
329 proxy_service_,
330 ssl_config_service_,
331 spdy_session_pool_.get(),
332 http_auth_handler_factory_,
333 network_delegate_,
334 NULL),
335 net::HttpCache::DefaultBackend::InMemory(0));
336 }
337
338 MockClientSocketFactory& socket_factory() { return socket_factory_; }
339
340 protected:
341 virtual ~SpdyURLRequestContext() {
342 delete http_transaction_factory_;
343 delete http_auth_handler_factory_;
344 }
345
346 private:
347 MockClientSocketFactory socket_factory_;
348 scoped_refptr<SpdySessionPool> spdy_session_pool_;
349 };
350
264 // This creates a proxy for testing purposes. 351 // This creates a proxy for testing purposes.
265 // |proxy| should be in the form "myproxy:70". 352 // |proxy| should be in the form "myproxy:70".
266 ProxyService* SpdyCreateFixedProxyService(const std::string& proxy); 353 ProxyService* SpdyCreateFixedProxyService(const std::string& proxy);
267 354
355 const SpdyHeaderInfo make_spdy_header(spdy::SpdyControlType type);
268 } // namespace net 356 } // namespace net
269 357
270 #endif // NET_SPDY_SPDY_TEST_UTIL_H_ 358 #endif // NET_SPDY_SPDY_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « net/spdy/spdy_stream.cc ('k') | net/spdy/spdy_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698