| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_WEBSOCKETS_WEBSOCKET_TEST_UTIL_H_ | 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_TEST_UTIL_H_ |
| 6 #define NET_WEBSOCKETS_WEBSOCKET_TEST_UTIL_H_ | 6 #define NET_WEBSOCKETS_WEBSOCKET_TEST_UTIL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 uint32 Generate(); | 38 uint32 Generate(); |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 uint64 current_; | 41 uint64 current_; |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 // Alternate version of WebSocketStream::CreateAndConnectStream() for testing | 44 // Alternate version of WebSocketStream::CreateAndConnectStream() for testing |
| 45 // use only. The differences are the use of a |create_helper| argument in place | 45 // use only. The differences are the use of a |create_helper| argument in place |
| 46 // of |requested_subprotocols| and taking |timer| as the handshake timeout | 46 // of |requested_subprotocols| and taking |timer| as the handshake timeout |
| 47 // timer. Implemented in websocket_stream.cc. | 47 // timer. Implemented in websocket_stream.cc. |
| 48 NET_EXPORT_PRIVATE extern scoped_ptr<WebSocketStreamRequest> | 48 NET_EXPORT_PRIVATE scoped_ptr<WebSocketStreamRequest> |
| 49 CreateAndConnectStreamForTesting( | 49 CreateAndConnectStreamForTesting( |
| 50 const GURL& socket_url, | 50 const GURL& socket_url, |
| 51 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper, | 51 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper, |
| 52 const url::Origin& origin, | 52 const url::Origin& origin, |
| 53 URLRequestContext* url_request_context, | 53 URLRequestContext* url_request_context, |
| 54 const BoundNetLog& net_log, | 54 const BoundNetLog& net_log, |
| 55 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate, | 55 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate, |
| 56 scoped_ptr<base::Timer> timer); | 56 scoped_ptr<base::Timer> timer); |
| 57 | 57 |
| 58 // Generates a standard WebSocket handshake request. The challenge key used is | 58 // Generates a standard WebSocket handshake request. The challenge key used is |
| 59 // "dGhlIHNhbXBsZSBub25jZQ==". Each header in |extra_headers| must be terminated | 59 // "dGhlIHNhbXBsZSBub25jZQ==". Each header in |extra_headers| must be terminated |
| 60 // with "\r\n". | 60 // with "\r\n". |
| 61 extern std::string WebSocketStandardRequest(const std::string& path, | 61 std::string WebSocketStandardRequest(const std::string& path, |
| 62 const std::string& host, | 62 const std::string& host, |
| 63 const std::string& origin, | 63 const std::string& origin, |
| 64 const std::string& extra_headers); | 64 const std::string& extra_headers); |
| 65 |
| 66 // Generates a standard WebSocket handshake request. The challenge key used is |
| 67 // "dGhlIHNhbXBsZSBub25jZQ==". |cookies| must be empty or terminated with |
| 68 // "\r\n". Each header in |extra_headers| must be terminated with "\r\n". |
| 69 std::string WebSocketStandardRequestWithCookies( |
| 70 const std::string& path, |
| 71 const std::string& host, |
| 72 const std::string& origin, |
| 73 const std::string& cookies, |
| 74 const std::string& extra_headers); |
| 65 | 75 |
| 66 // A response with the appropriate accept header to match the above challenge | 76 // A response with the appropriate accept header to match the above challenge |
| 67 // key. Each header in |extra_headers| must be terminated with "\r\n". | 77 // key. Each header in |extra_headers| must be terminated with "\r\n". |
| 68 extern std::string WebSocketStandardResponse(const std::string& extra_headers); | 78 std::string WebSocketStandardResponse(const std::string& extra_headers); |
| 69 | 79 |
| 70 // This class provides a convenient way to construct a | 80 // This class provides a convenient way to construct a |
| 71 // DeterministicMockClientSocketFactory for WebSocket tests. | 81 // DeterministicMockClientSocketFactory for WebSocket tests. |
| 72 class WebSocketDeterministicMockClientSocketFactoryMaker { | 82 class WebSocketDeterministicMockClientSocketFactoryMaker { |
| 73 public: | 83 public: |
| 74 WebSocketDeterministicMockClientSocketFactoryMaker(); | 84 WebSocketDeterministicMockClientSocketFactoryMaker(); |
| 75 ~WebSocketDeterministicMockClientSocketFactoryMaker(); | 85 ~WebSocketDeterministicMockClientSocketFactoryMaker(); |
| 76 | 86 |
| 77 // Tell the factory to create a socket which expects |expect_written| to be | 87 // Tell the factory to create a socket which expects |expect_written| to be |
| 78 // written, and responds with |return_to_read|. The test will fail if the | 88 // written, and responds with |return_to_read|. The test will fail if the |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 TestNetworkDelegate network_delegate_; | 150 TestNetworkDelegate network_delegate_; |
| 141 scoped_ptr<ProxyService> proxy_service_; | 151 scoped_ptr<ProxyService> proxy_service_; |
| 142 bool url_request_context_initialized_; | 152 bool url_request_context_initialized_; |
| 143 | 153 |
| 144 DISALLOW_COPY_AND_ASSIGN(WebSocketTestURLRequestContextHost); | 154 DISALLOW_COPY_AND_ASSIGN(WebSocketTestURLRequestContextHost); |
| 145 }; | 155 }; |
| 146 | 156 |
| 147 } // namespace net | 157 } // namespace net |
| 148 | 158 |
| 149 #endif // NET_WEBSOCKETS_WEBSOCKET_TEST_UTIL_H_ | 159 #endif // NET_WEBSOCKETS_WEBSOCKET_TEST_UTIL_H_ |
| OLD | NEW |