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 #include "net/websockets/websocket_test_util.h" | 5 #include "net/websockets/websocket_test_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 LinearCongruentialGenerator::LinearCongruentialGenerator(uint32 seed) | 26 LinearCongruentialGenerator::LinearCongruentialGenerator(uint32 seed) |
27 : current_(seed) {} | 27 : current_(seed) {} |
28 | 28 |
29 uint32 LinearCongruentialGenerator::Generate() { | 29 uint32 LinearCongruentialGenerator::Generate() { |
30 uint64 result = current_; | 30 uint64 result = current_; |
31 current_ = (current_ * kA + kC) % kM; | 31 current_ = (current_ * kA + kC) % kM; |
32 return static_cast<uint32>(result >> 16); | 32 return static_cast<uint32>(result >> 16); |
33 } | 33 } |
34 | 34 |
35 std::string WebSocketStandardRequest(const std::string& path, | 35 std::string WebSocketStandardRequest(const std::string& path, |
| 36 const std::string& host, |
36 const std::string& origin, | 37 const std::string& origin, |
37 const std::string& extra_headers) { | 38 const std::string& extra_headers) { |
38 // Unrelated changes in net/http may change the order and default-values of | 39 // Unrelated changes in net/http may change the order and default-values of |
39 // HTTP headers, causing WebSocket tests to fail. It is safe to update this | 40 // HTTP headers, causing WebSocket tests to fail. It is safe to update this |
40 // string in that case. | 41 // string in that case. |
41 return base::StringPrintf( | 42 return base::StringPrintf( |
42 "GET %s HTTP/1.1\r\n" | 43 "GET %s HTTP/1.1\r\n" |
43 "Host: localhost\r\n" | 44 "Host: %s\r\n" |
44 "Connection: Upgrade\r\n" | 45 "Connection: Upgrade\r\n" |
45 "Pragma: no-cache\r\n" | 46 "Pragma: no-cache\r\n" |
46 "Cache-Control: no-cache\r\n" | 47 "Cache-Control: no-cache\r\n" |
47 "Upgrade: websocket\r\n" | 48 "Upgrade: websocket\r\n" |
48 "Origin: %s\r\n" | 49 "Origin: %s\r\n" |
49 "Sec-WebSocket-Version: 13\r\n" | 50 "Sec-WebSocket-Version: 13\r\n" |
50 "User-Agent:\r\n" | 51 "User-Agent:\r\n" |
51 "Accept-Encoding: gzip, deflate\r\n" | 52 "Accept-Encoding: gzip, deflate\r\n" |
52 "Accept-Language: en-us,fr\r\n" | 53 "Accept-Language: en-us,fr\r\n" |
53 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" | 54 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
54 "Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n" | 55 "Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n" |
55 "%s\r\n", | 56 "%s\r\n", |
56 path.c_str(), | 57 path.c_str(), host.c_str(), origin.c_str(), extra_headers.c_str()); |
57 origin.c_str(), | |
58 extra_headers.c_str()); | |
59 } | 58 } |
60 | 59 |
61 std::string WebSocketStandardResponse(const std::string& extra_headers) { | 60 std::string WebSocketStandardResponse(const std::string& extra_headers) { |
62 return base::StringPrintf( | 61 return base::StringPrintf( |
63 "HTTP/1.1 101 Switching Protocols\r\n" | 62 "HTTP/1.1 101 Switching Protocols\r\n" |
64 "Upgrade: websocket\r\n" | 63 "Upgrade: websocket\r\n" |
65 "Connection: Upgrade\r\n" | 64 "Connection: Upgrade\r\n" |
66 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" | 65 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" |
67 "%s\r\n", | 66 "%s\r\n", |
68 extra_headers.c_str()); | 67 extra_headers.c_str()); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 if (!url_request_context_initialized_) { | 156 if (!url_request_context_initialized_) { |
158 url_request_context_.Init(); | 157 url_request_context_.Init(); |
159 // A Network Delegate is required to make the URLRequest::Delegate work. | 158 // A Network Delegate is required to make the URLRequest::Delegate work. |
160 url_request_context_.set_network_delegate(&network_delegate_); | 159 url_request_context_.set_network_delegate(&network_delegate_); |
161 url_request_context_initialized_ = true; | 160 url_request_context_initialized_ = true; |
162 } | 161 } |
163 return &url_request_context_; | 162 return &url_request_context_; |
164 } | 163 } |
165 | 164 |
166 } // namespace net | 165 } // namespace net |
OLD | NEW |