spdy_test_util_common.h revision a02191e04bc25c4935f804f2c080ae28663d096d
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef NET_SPDY_SPDY_TEST_UTIL_COMMON_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define NET_SPDY_SPDY_TEST_UTIL_COMMON_H_ 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include <string> 9eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include <vector> 10eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/ref_counted.h" 1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 13c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "crypto/ec_private_key.h" 14c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "crypto/ec_signature_creator.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/base/completion_callback.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/base/request_priority.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/base/test_completion_callback.h" 18c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/cert/cert_verifier.h" 19c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/dns/mock_host_resolver.h" 20c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/http/http_auth_handler_factory.h" 21c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/http/http_network_session.h" 227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "net/http/http_response_info.h" 23c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/http/http_server_properties_impl.h" 247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "net/http/transport_security_state.h" 25c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/proxy/proxy_service.h" 26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/socket/next_proto.h" 27c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/socket/socket_test_util.h" 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/spdy/spdy_protocol.h" 29c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/ssl/ssl_config_service_defaults.h" 30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/url_request/url_request_context.h" 31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/url_request/url_request_context_storage.h" 32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class GURL; 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace net { 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class BoundNetLog; 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class SpdySession; 407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass SpdySessionKey; 417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass SpdySessionPool; 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class SpdyStream; 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class SpdyStreamRequest; 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 45c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Default upload data used by both, mock objects and framer when creating 46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// data frames. 47c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kDefaultURL[] = "http://www.google.com"; 48c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kUploadData[] = "hello!"; 49c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const int kUploadDataSize = arraysize(kUploadData)-1; 50c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 51ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// SpdyNextProtos returns a vector of next protocols for negotiating 52eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// SPDY. 53ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochstd::vector<NextProto> SpdyNextProtos(); 54eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 55c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Chop a frame into an array of MockWrites. 56c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// |data| is the frame to chop. 57c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// |length| is the length of the frame to chop. 58c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// |num_chunks| is the number of chunks to create. 59c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks); 60c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 61c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Chop a SpdyFrame into an array of MockWrites. 62c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// |frame| is the frame to chop. 63c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// |num_chunks| is the number of chunks to create. 64c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)MockWrite* ChopWriteFrame(const SpdyFrame& frame, int num_chunks); 65c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 66c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Chop a frame into an array of MockReads. 67c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// |data| is the frame to chop. 68c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// |length| is the length of the frame to chop. 69c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// |num_chunks| is the number of chunks to create. 70c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)MockRead* ChopReadFrame(const char* data, int length, int num_chunks); 71c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 72c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Chop a SpdyFrame into an array of MockReads. 73c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// |frame| is the frame to chop. 74c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// |num_chunks| is the number of chunks to create. 75c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)MockRead* ChopReadFrame(const SpdyFrame& frame, int num_chunks); 76c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 77c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Adds headers and values to a map. 78c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// |extra_headers| is an array of { name, value } pairs, arranged as strings 79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// where the even entries are the header names, and the odd entries are the 80c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// header values. 81c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// |headers| gets filled in from |extra_headers|. 82c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void AppendToHeaderBlock(const char* const extra_headers[], 83c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) int extra_header_count, 84c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SpdyHeaderBlock* headers); 85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 86c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Create an async MockWrite from the given SpdyFrame. 87c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)MockWrite CreateMockWrite(const SpdyFrame& req); 88c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 89c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Create an async MockWrite from the given SpdyFrame and sequence number. 90c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)MockWrite CreateMockWrite(const SpdyFrame& req, int seq); 91c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)MockWrite CreateMockWrite(const SpdyFrame& req, int seq, IoMode mode); 93c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 94c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Create a MockRead from the given SpdyFrame. 95c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)MockRead CreateMockRead(const SpdyFrame& resp); 96c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 97c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Create a MockRead from the given SpdyFrame and sequence number. 98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)MockRead CreateMockRead(const SpdyFrame& resp, int seq); 99c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)MockRead CreateMockRead(const SpdyFrame& resp, int seq, IoMode mode); 101c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 102c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Combines the given SpdyFrames into the given char array and returns 103c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// the total length. 104c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)int CombineFrames(const SpdyFrame** frames, int num_frames, 105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) char* buff, int buff_len); 106c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Returns the SpdyPriority embedded in the given frame. Returns true 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// and fills in |priority| on success. 10990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)bool GetSpdyPriority(SpdyMajorVersion version, 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const SpdyFrame& frame, 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SpdyPriority* priority); 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Tries to create a stream in |session| synchronously. Returns NULL 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// on failure. 115a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)base::WeakPtr<SpdyStream> CreateStreamSynchronously( 11690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SpdyStreamType type, 117ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch const base::WeakPtr<SpdySession>& session, 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GURL& url, 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RequestPriority priority, 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const BoundNetLog& net_log); 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 122a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Helper class used by some tests to release a stream as soon as it's 123a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// created. 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class StreamReleaserCallback : public TestCompletionCallbackBase { 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 126a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) StreamReleaserCallback(); 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~StreamReleaserCallback(); 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 130a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // Returns a callback that releases |request|'s stream. 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CompletionCallback MakeCallback(SpdyStreamRequest* request); 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnComplete(SpdyStreamRequest* request, int result); 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 137c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const size_t kSpdyCredentialSlotUnused = 0; 138c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 139c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// This struct holds information used to construct spdy control and data frames. 140c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)struct SpdyHeaderInfo { 141c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SpdyFrameType kind; 142c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SpdyStreamId id; 143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SpdyStreamId assoc_id; 144c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SpdyPriority priority; 145c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) size_t credential_slot; // SPDY3 only 146c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SpdyControlFlags control_flags; 147c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool compressed; 148c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SpdyRstStreamStatus status; 149c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const char* data; 150c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) uint32 data_length; 151c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SpdyDataFlags data_flags; 152c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 153c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 154c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// An ECSignatureCreator that returns deterministic signatures. 155c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class MockECSignatureCreator : public crypto::ECSignatureCreator { 156c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public: 157c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) explicit MockECSignatureCreator(crypto::ECPrivateKey* key); 158c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 159c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // crypto::ECSignatureCreator 160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual bool Sign(const uint8* data, 161c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) int data_len, 162c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::vector<uint8>* signature) OVERRIDE; 163c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual bool DecodeSignature(const std::vector<uint8>& signature, 164c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::vector<uint8>* out_raw_sig) OVERRIDE; 165c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 166c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 167c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) crypto::ECPrivateKey* key_; 168c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 169c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(MockECSignatureCreator); 170c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 171c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 172c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// An ECSignatureCreatorFactory creates MockECSignatureCreator. 173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class MockECSignatureCreatorFactory : public crypto::ECSignatureCreatorFactory { 174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public: 175c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) MockECSignatureCreatorFactory(); 176c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual ~MockECSignatureCreatorFactory(); 177c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 178c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // crypto::ECSignatureCreatorFactory 179c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual crypto::ECSignatureCreator* Create( 180c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) crypto::ECPrivateKey* key) OVERRIDE; 181c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 182c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 183c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(MockECSignatureCreatorFactory); 184c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 185c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 186c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Helper to manage the lifetimes of the dependencies for a 187c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// HttpNetworkTransaction. 188c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)struct SpdySessionDependencies { 189c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Default set of dependencies -- "null" proxy service. 190c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) explicit SpdySessionDependencies(NextProto protocol); 191c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 192c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Custom proxy service dependency. 193c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SpdySessionDependencies(NextProto protocol, ProxyService* proxy_service); 194c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 195c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ~SpdySessionDependencies(); 196c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 197c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) static HttpNetworkSession* SpdyCreateSession( 198c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SpdySessionDependencies* session_deps); 199c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) static HttpNetworkSession* SpdyCreateSessionDeterministic( 200c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SpdySessionDependencies* session_deps); 201c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) static HttpNetworkSession::Params CreateSessionParams( 202c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SpdySessionDependencies* session_deps); 203c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 204c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // NOTE: host_resolver must be ordered before http_auth_handler_factory. 205c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<MockHostResolverBase> host_resolver; 206c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<CertVerifier> cert_verifier; 2077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) scoped_ptr<TransportSecurityState> transport_security_state; 208c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<ProxyService> proxy_service; 209c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_refptr<SSLConfigService> ssl_config_service; 210c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<MockClientSocketFactory> socket_factory; 211c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<DeterministicMockClientSocketFactory> deterministic_socket_factory; 212c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; 213c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) HttpServerPropertiesImpl http_server_properties; 214c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool enable_ip_pooling; 215c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool enable_compression; 216c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool enable_ping; 217c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool enable_user_alternate_protocol_ports; 218c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NextProto protocol; 219c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) size_t stream_initial_recv_window_size; 220c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SpdySession::TimeFunc time_func; 221c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string trusted_spdy_proxy; 222c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NetLog* net_log; 223c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 224c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 225c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class SpdyURLRequestContext : public URLRequestContext { 226c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public: 227c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) explicit SpdyURLRequestContext(NextProto protocol); 228c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual ~SpdyURLRequestContext(); 229c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 230c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) MockClientSocketFactory& socket_factory() { return socket_factory_; } 231c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 232c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 233c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) MockClientSocketFactory socket_factory_; 234c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) net::URLRequestContextStorage storage_; 235c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 236c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Equivalent to pool->GetIfExists(spdy_session_key, BoundNetLog()) != NULL. 2387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochbool HasSpdySession(SpdySessionPool* pool, const SpdySessionKey& key); 2397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 2407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Creates a SPDY session for the given key and puts it in the SPDY 2417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// session pool in |http_session|. A SPDY session for |key| must not 2427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// already exist. 243ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochbase::WeakPtr<SpdySession> CreateInsecureSpdySession( 2447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const scoped_refptr<HttpNetworkSession>& http_session, 2457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const SpdySessionKey& key, 2467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const BoundNetLog& net_log); 2477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 248ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// Tries to create a SPDY session for the given key but expects the 249ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// attempt to fail with the given error. A SPDY session for |key| must 250effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// not already exist. The session will be created but close in the 251effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// next event loop iteration. 252effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochbase::WeakPtr<SpdySession> TryCreateInsecureSpdySessionExpectingFailure( 253ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch const scoped_refptr<HttpNetworkSession>& http_session, 254ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch const SpdySessionKey& key, 255ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch Error expected_error, 256ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch const BoundNetLog& net_log); 257ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 2587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Like CreateInsecureSpdySession(), but uses TLS. 259ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochbase::WeakPtr<SpdySession> CreateSecureSpdySession( 2607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const scoped_refptr<HttpNetworkSession>& http_session, 2617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const SpdySessionKey& key, 2627dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const BoundNetLog& net_log); 2637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 2647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Creates an insecure SPDY session for the given key and puts it in 265ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// |pool|. The returned session will neither receive nor send any 2667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// data. A SPDY session for |key| must not already exist. 267ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochbase::WeakPtr<SpdySession> CreateFakeSpdySession(SpdySessionPool* pool, 2687dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const SpdySessionKey& key); 2697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 270ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// Tries to create an insecure SPDY session for the given key but 271ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// expects the attempt to fail with the given error. The session will 272ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// neither receive nor send any data. A SPDY session for |key| must 273effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// not already exist. The session will be created but close in the 274effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// next event loop iteration. 275effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochbase::WeakPtr<SpdySession> TryCreateFakeSpdySessionExpectingFailure( 276effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch SpdySessionPool* pool, 277effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch const SpdySessionKey& key, 278effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Error expected_error); 279ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 280c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class SpdySessionPoolPeer { 281c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public: 282b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) explicit SpdySessionPoolPeer(SpdySessionPool* pool); 283c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 28490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void RemoveAliases(const SpdySessionKey& key); 285c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void DisableDomainAuthenticationVerification(); 286a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) void SetEnableSendingInitialData(bool enabled); 287c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 288c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 289c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SpdySessionPool* const pool_; 290c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 291c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(SpdySessionPoolPeer); 292c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 293c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 294b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class SpdyTestUtil { 295b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) public: 296b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) explicit SpdyTestUtil(NextProto protocol); 297b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 298868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Add the appropriate headers to put |url| into |block|. 299868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void AddUrlToHeaderBlock(base::StringPiece url, 300868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyHeaderBlock* headers) const; 301868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 302b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) scoped_ptr<SpdyHeaderBlock> ConstructGetHeaderBlock( 303b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) base::StringPiece url) const; 3047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) scoped_ptr<SpdyHeaderBlock> ConstructGetHeaderBlockForProxy( 3057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::StringPiece url) const; 3067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) scoped_ptr<SpdyHeaderBlock> ConstructHeadHeaderBlock( 3077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::StringPiece url, 3087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) int64 content_length) const; 309b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) scoped_ptr<SpdyHeaderBlock> ConstructPostHeaderBlock( 310b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) base::StringPiece url, 311b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) int64 content_length) const; 3127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) scoped_ptr<SpdyHeaderBlock> ConstructPutHeaderBlock( 3137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::StringPiece url, 3147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) int64 content_length) const; 315b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 316b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Construct a SPDY frame. If it is a SYN_STREAM or SYN_REPLY frame (as 317b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // specified in header_info.kind), the provided headers are included in the 318b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // frame. 319b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) SpdyFrame* ConstructSpdyFrame( 320b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const SpdyHeaderInfo& header_info, 321b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) scoped_ptr<SpdyHeaderBlock> headers) const; 322b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 323b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Construct a SPDY frame. If it is a SYN_STREAM or SYN_REPLY frame (as 324b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // specified in header_info.kind), the headers provided in extra_headers and 325b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // (if non-NULL) tail_headers are concatenated and included in the frame. 326b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // (extra_headers must always be non-NULL.) 327b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) SpdyFrame* ConstructSpdyFrame(const SpdyHeaderInfo& header_info, 328b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const char* const extra_headers[], 329b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) int extra_header_count, 330b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const char* const tail_headers[], 331b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) int tail_header_count) const; 332b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 33390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Construct a generic SpdyControlFrame. 334868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyFrame* ConstructSpdyControlFrame( 335868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scoped_ptr<SpdyHeaderBlock> headers, 336868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool compressed, 337868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyStreamId stream_id, 338868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) RequestPriority request_priority, 339868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyFrameType type, 340868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyControlFlags flags, 341868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyStreamId associated_stream_id) const; 342868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 343868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Construct a generic SpdyControlFrame. 34490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // 34590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Warning: extra_header_count is the number of header-value pairs in 34690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // extra_headers (so half the number of elements), but tail_headers_size is 34790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // the actual number of elements (both keys and values) in tail_headers. 34890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // TODO(ttuttle): Fix this inconsistency. 349a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) SpdyFrame* ConstructSpdyControlFrame( 350a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) const char* const extra_headers[], 351a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) int extra_header_count, 352a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) bool compressed, 353a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) SpdyStreamId stream_id, 354a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) RequestPriority request_priority, 355a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) SpdyFrameType type, 356a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) SpdyControlFlags flags, 35790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const char* const* tail_headers, 35890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int tail_headers_size, 359a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) SpdyStreamId associated_stream_id) const; 360a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 361868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Construct an expected SPDY reply string from the given headers. 362868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) std::string ConstructSpdyReplyString(const SpdyHeaderBlock& headers) const; 36390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 36490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Construct an expected SPDY SETTINGS frame. 36590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // |settings| are the settings to set. 36690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns the constructed frame. The caller takes ownership of the frame. 36790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SpdyFrame* ConstructSpdySettings(const SettingsMap& settings) const; 36890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 36990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Construct a SPDY PING frame. 37090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns the constructed frame. The caller takes ownership of the frame. 371a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SpdyFrame* ConstructSpdyPing(uint32 ping_id, bool is_ack) const; 37290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 37390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Construct a SPDY GOAWAY frame with last_good_stream_id = 0. 37490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns the constructed frame. The caller takes ownership of the frame. 37590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SpdyFrame* ConstructSpdyGoAway() const; 37690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 37790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Construct a SPDY GOAWAY frame with the specified last_good_stream_id. 37890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns the constructed frame. The caller takes ownership of the frame. 37990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SpdyFrame* ConstructSpdyGoAway(SpdyStreamId last_good_stream_id) const; 38090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 38190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Construct a SPDY WINDOW_UPDATE frame. 38290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns the constructed frame. The caller takes ownership of the frame. 38390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SpdyFrame* ConstructSpdyWindowUpdate( 38490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SpdyStreamId stream_id, 38590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) uint32 delta_window_size) const; 38690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 38790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Construct a SPDY RST_STREAM frame. 38890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns the constructed frame. The caller takes ownership of the frame. 38990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SpdyFrame* ConstructSpdyRstStream(SpdyStreamId stream_id, 39090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SpdyRstStreamStatus status) const; 39190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 39290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Constructs a standard SPDY GET SYN frame, optionally compressed 39390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // for the url |url|. 39490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // |extra_headers| are the extra header-value pairs, which typically 39590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // will vary the most between calls. 39690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns a SpdyFrame. 39790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SpdyFrame* ConstructSpdyGet(const char* const url, 39890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool compressed, 39990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SpdyStreamId stream_id, 40090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) RequestPriority request_priority) const; 40190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 4027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) SpdyFrame* ConstructSpdyGetForProxy(const char* const url, 4037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool compressed, 4047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) SpdyStreamId stream_id, 4057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) RequestPriority request_priority) const; 4067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 40790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Constructs a standard SPDY GET SYN frame, optionally compressed. 40890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // |extra_headers| are the extra header-value pairs, which typically 40990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // will vary the most between calls. If |direct| is false, the 41090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // the full url will be used instead of simply the path. 41190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns a SpdyFrame. 41290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SpdyFrame* ConstructSpdyGet(const char* const extra_headers[], 41390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int extra_header_count, 41490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool compressed, 41590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int stream_id, 41690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) RequestPriority request_priority, 41790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool direct) const; 41890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 41990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. 42090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SpdyFrame* ConstructSpdyConnect(const char* const extra_headers[], 42190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int extra_header_count, 4223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) int stream_id, 4233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) RequestPriority priority) const; 42490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 425868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Constructs a standard SPDY push SYN frame. 426868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // |extra_headers| are the extra header-value pairs, which typically 427868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // will vary the most between calls. 428868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Returns a SpdyFrame. 429868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], 430868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int extra_header_count, 431868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int stream_id, 432868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int associated_stream_id, 433868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const char* url); 434868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyFrame* ConstructSpdyPush(const char* const extra_headers[], 435868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int extra_header_count, 436868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int stream_id, 437868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int associated_stream_id, 438868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const char* url, 439868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const char* status, 440868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const char* location); 441868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 442868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyFrame* ConstructSpdyPushHeaders(int stream_id, 443868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const char* const extra_headers[], 444868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int extra_header_count); 445868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 446868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET. 447868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // |extra_headers| are the extra header-value pairs, which typically 448868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // will vary the most between calls. 449868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Returns a SpdyFrame. 450868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyFrame* ConstructSpdyGetSynReply(const char* const extra_headers[], 451868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int extra_header_count, 452868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int stream_id); 453868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 454868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Constructs a standard SPDY SYN_REPLY frame to match the SPDY GET. 455868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // |extra_headers| are the extra header-value pairs, which typically 456868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // will vary the most between calls. 457868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Returns a SpdyFrame. 458868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyFrame* ConstructSpdyGetSynReplyRedirect(int stream_id); 459868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 460868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Constructs a standard SPDY SYN_REPLY frame with an Internal Server 461868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Error status code. 462868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Returns a SpdyFrame. 463868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyFrame* ConstructSpdySynReplyError(int stream_id); 464868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 465868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Constructs a standard SPDY SYN_REPLY frame with the specified status code. 466868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Returns a SpdyFrame. 467868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyFrame* ConstructSpdySynReplyError(const char* const status, 468868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const char* const* const extra_headers, 469868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int extra_header_count, 470868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int stream_id); 471868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 472868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Constructs a standard SPDY POST SYN frame. 473868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // |extra_headers| are the extra header-value pairs, which typically 474868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // will vary the most between calls. 475868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Returns a SpdyFrame. 476868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyFrame* ConstructSpdyPost(const char* url, 477868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyStreamId stream_id, 478868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int64 content_length, 479868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) RequestPriority priority, 480868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const char* const extra_headers[], 481868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int extra_header_count); 482868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 483868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Constructs a chunked transfer SPDY POST SYN frame. 484868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // |extra_headers| are the extra header-value pairs, which typically 485868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // will vary the most between calls. 486868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Returns a SpdyFrame. 487868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyFrame* ConstructChunkedSpdyPost(const char* const extra_headers[], 488868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int extra_header_count); 489868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 490868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Constructs a standard SPDY SYN_REPLY frame to match the SPDY POST. 491868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // |extra_headers| are the extra header-value pairs, which typically 492868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // will vary the most between calls. 493868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Returns a SpdyFrame. 494868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyFrame* ConstructSpdyPostSynReply(const char* const extra_headers[], 495868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int extra_header_count); 496868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 497868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Constructs a single SPDY data frame with the contents "hello!" 498868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyFrame* ConstructSpdyBodyFrame(int stream_id, 499868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool fin); 500868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 501868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Constructs a single SPDY data frame with the given content. 502868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyFrame* ConstructSpdyBodyFrame(int stream_id, const char* data, 503868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) uint32 len, bool fin); 504868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 505868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Wraps |frame| in the payload of a data frame in stream |stream_id|. 506868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) SpdyFrame* ConstructWrappedSpdyFrame(const scoped_ptr<SpdyFrame>& frame, 507868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int stream_id); 508868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 509868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const SpdyHeaderInfo MakeSpdyHeader(SpdyFrameType type); 510868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 511c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // For versions below SPDY4, adds the version HTTP/1.1 header. 512c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch void MaybeAddVersionHeader(SpdyFrameWithNameValueBlockIR* frame_ir) const; 513c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 514c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Maps |priority| to SPDY version priority, and sets it on |frame_ir|. 515c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch void SetPriority(RequestPriority priority, SpdySynStreamIR* frame_ir) const; 516c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 51790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) NextProto protocol() const { return protocol_; } 51890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SpdyMajorVersion spdy_version() const { return spdy_version_; } 51990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool is_spdy2() const { return protocol_ < kProtoSPDY3; } 520a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch bool include_version_header() const { return protocol_ < kProtoSPDY4; } 521c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch scoped_ptr<SpdyFramer> CreateFramer(bool compressed) const; 52290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 523868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const char* GetMethodKey() const; 524868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const char* GetStatusKey() const; 525868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const char* GetHostKey() const; 526868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const char* GetSchemeKey() const; 527868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const char* GetVersionKey() const; 528868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const char* GetPathKey() const; 529868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 530b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) private: 5317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // |content_length| may be NULL, in which case the content-length 5327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // header will be omitted. 5337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) scoped_ptr<SpdyHeaderBlock> ConstructHeaderBlock( 5347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::StringPiece method, 5357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::StringPiece url, 5367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) int64* content_length) const; 5377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 538b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const NextProto protocol_; 53990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const SpdyMajorVersion spdy_version_; 540b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}; 541b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 5422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace net 5432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // NET_SPDY_SPDY_TEST_UTIL_COMMON_H_ 545