| 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 19 matching lines...) Expand all Loading... |
| 30 uint32 LinearCongruentialGenerator::Generate() { | 30 uint32 LinearCongruentialGenerator::Generate() { |
| 31 uint64 result = current_; | 31 uint64 result = current_; |
| 32 current_ = (current_ * kA + kC) % kM; | 32 current_ = (current_ * kA + kC) % kM; |
| 33 return static_cast<uint32>(result >> 16); | 33 return static_cast<uint32>(result >> 16); |
| 34 } | 34 } |
| 35 | 35 |
| 36 std::string WebSocketStandardRequest(const std::string& path, | 36 std::string WebSocketStandardRequest(const std::string& path, |
| 37 const std::string& host, | 37 const std::string& host, |
| 38 const std::string& origin, | 38 const std::string& origin, |
| 39 const std::string& extra_headers) { | 39 const std::string& extra_headers) { |
| 40 return WebSocketStandardRequestWithCookies(path, host, origin, std::string(), |
| 41 extra_headers); |
| 42 } |
| 43 |
| 44 std::string WebSocketStandardRequestWithCookies( |
| 45 const std::string& path, |
| 46 const std::string& host, |
| 47 const std::string& origin, |
| 48 const std::string& cookies, |
| 49 const std::string& extra_headers) { |
| 40 // Unrelated changes in net/http may change the order and default-values of | 50 // Unrelated changes in net/http may change the order and default-values of |
| 41 // HTTP headers, causing WebSocket tests to fail. It is safe to update this | 51 // HTTP headers, causing WebSocket tests to fail. It is safe to update this |
| 42 // string in that case. | 52 // string in that case. |
| 43 return base::StringPrintf( | 53 return base::StringPrintf( |
| 44 "GET %s HTTP/1.1\r\n" | 54 "GET %s HTTP/1.1\r\n" |
| 45 "Host: %s\r\n" | 55 "Host: %s\r\n" |
| 46 "Connection: Upgrade\r\n" | 56 "Connection: Upgrade\r\n" |
| 47 "Pragma: no-cache\r\n" | 57 "Pragma: no-cache\r\n" |
| 48 "Cache-Control: no-cache\r\n" | 58 "Cache-Control: no-cache\r\n" |
| 49 "Upgrade: websocket\r\n" | 59 "Upgrade: websocket\r\n" |
| 50 "Origin: %s\r\n" | 60 "Origin: %s\r\n" |
| 51 "Sec-WebSocket-Version: 13\r\n" | 61 "Sec-WebSocket-Version: 13\r\n" |
| 52 "User-Agent:\r\n" | 62 "User-Agent:\r\n" |
| 53 "Accept-Encoding: gzip, deflate\r\n" | 63 "Accept-Encoding: gzip, deflate\r\n" |
| 54 "Accept-Language: en-us,fr\r\n" | 64 "Accept-Language: en-us,fr\r\n" |
| 65 "%s" |
| 55 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" | 66 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 56 "Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n" | 67 "Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n" |
| 57 "%s\r\n", | 68 "%s\r\n", |
| 58 path.c_str(), host.c_str(), origin.c_str(), extra_headers.c_str()); | 69 path.c_str(), host.c_str(), origin.c_str(), cookies.c_str(), |
| 70 extra_headers.c_str()); |
| 59 } | 71 } |
| 60 | 72 |
| 61 std::string WebSocketStandardResponse(const std::string& extra_headers) { | 73 std::string WebSocketStandardResponse(const std::string& extra_headers) { |
| 62 return base::StringPrintf( | 74 return base::StringPrintf( |
| 63 "HTTP/1.1 101 Switching Protocols\r\n" | 75 "HTTP/1.1 101 Switching Protocols\r\n" |
| 64 "Upgrade: websocket\r\n" | 76 "Upgrade: websocket\r\n" |
| 65 "Connection: Upgrade\r\n" | 77 "Connection: Upgrade\r\n" |
| 66 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" | 78 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" |
| 67 "%s\r\n", | 79 "%s\r\n", |
| 68 extra_headers.c_str()); | 80 extra_headers.c_str()); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 if (!url_request_context_initialized_) { | 176 if (!url_request_context_initialized_) { |
| 165 url_request_context_.Init(); | 177 url_request_context_.Init(); |
| 166 // A Network Delegate is required to make the URLRequest::Delegate work. | 178 // A Network Delegate is required to make the URLRequest::Delegate work. |
| 167 url_request_context_.set_network_delegate(&network_delegate_); | 179 url_request_context_.set_network_delegate(&network_delegate_); |
| 168 url_request_context_initialized_ = true; | 180 url_request_context_initialized_ = true; |
| 169 } | 181 } |
| 170 return &url_request_context_; | 182 return &url_request_context_; |
| 171 } | 183 } |
| 172 | 184 |
| 173 } // namespace net | 185 } // namespace net |
| OLD | NEW |