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 18 matching lines...) Expand all Loading... | |
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& host, |
37 const std::string& origin, | 37 const std::string& origin, |
38 const std::string& extra_headers) { | 38 const std::string& extra_headers) { |
39 return WebSocketStandardRequestWithCookies(path, host, origin, "", | |
Ryan Sleevi
2015/02/02 20:14:43
s/""/std::string()/
yhirano
2015/02/09 10:50:16
Done.
| |
40 extra_headers); | |
41 } | |
42 | |
43 std::string WebSocketStandardRequestWithCookies( | |
44 const std::string& path, | |
45 const std::string& host, | |
46 const std::string& origin, | |
47 const std::string& cookies, | |
48 const std::string& extra_headers) { | |
39 // Unrelated changes in net/http may change the order and default-values of | 49 // Unrelated changes in net/http may change the order and default-values of |
40 // HTTP headers, causing WebSocket tests to fail. It is safe to update this | 50 // HTTP headers, causing WebSocket tests to fail. It is safe to update this |
41 // string in that case. | 51 // string in that case. |
42 return base::StringPrintf( | 52 return base::StringPrintf( |
43 "GET %s HTTP/1.1\r\n" | 53 "GET %s HTTP/1.1\r\n" |
44 "Host: %s\r\n" | 54 "Host: %s\r\n" |
45 "Connection: Upgrade\r\n" | 55 "Connection: Upgrade\r\n" |
46 "Pragma: no-cache\r\n" | 56 "Pragma: no-cache\r\n" |
47 "Cache-Control: no-cache\r\n" | 57 "Cache-Control: no-cache\r\n" |
48 "Upgrade: websocket\r\n" | 58 "Upgrade: websocket\r\n" |
49 "Origin: %s\r\n" | 59 "Origin: %s\r\n" |
50 "Sec-WebSocket-Version: 13\r\n" | 60 "Sec-WebSocket-Version: 13\r\n" |
51 "User-Agent:\r\n" | 61 "User-Agent:\r\n" |
52 "Accept-Encoding: gzip, deflate\r\n" | 62 "Accept-Encoding: gzip, deflate\r\n" |
53 "Accept-Language: en-us,fr\r\n" | 63 "Accept-Language: en-us,fr\r\n" |
64 "%s" | |
54 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" | 65 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
55 "Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n" | 66 "Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n" |
56 "%s\r\n", | 67 "%s\r\n", |
57 path.c_str(), host.c_str(), origin.c_str(), extra_headers.c_str()); | 68 path.c_str(), host.c_str(), origin.c_str(), cookies.c_str(), |
69 extra_headers.c_str()); | |
58 } | 70 } |
59 | 71 |
60 std::string WebSocketStandardResponse(const std::string& extra_headers) { | 72 std::string WebSocketStandardResponse(const std::string& extra_headers) { |
61 return base::StringPrintf( | 73 return base::StringPrintf( |
62 "HTTP/1.1 101 Switching Protocols\r\n" | 74 "HTTP/1.1 101 Switching Protocols\r\n" |
63 "Upgrade: websocket\r\n" | 75 "Upgrade: websocket\r\n" |
64 "Connection: Upgrade\r\n" | 76 "Connection: Upgrade\r\n" |
65 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" | 77 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" |
66 "%s\r\n", | 78 "%s\r\n", |
67 extra_headers.c_str()); | 79 extra_headers.c_str()); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 if (!url_request_context_initialized_) { | 168 if (!url_request_context_initialized_) { |
157 url_request_context_.Init(); | 169 url_request_context_.Init(); |
158 // A Network Delegate is required to make the URLRequest::Delegate work. | 170 // A Network Delegate is required to make the URLRequest::Delegate work. |
159 url_request_context_.set_network_delegate(&network_delegate_); | 171 url_request_context_.set_network_delegate(&network_delegate_); |
160 url_request_context_initialized_ = true; | 172 url_request_context_initialized_ = true; |
161 } | 173 } |
162 return &url_request_context_; | 174 return &url_request_context_; |
163 } | 175 } |
164 | 176 |
165 } // namespace net | 177 } // namespace net |
OLD | NEW |