| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "net/socket/socket_test_util.h" | 9 #include "net/socket/socket_test_util.h" |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 "GET %s HTTP/1.1\r\n" | 37 "GET %s HTTP/1.1\r\n" |
| 38 "Host: localhost\r\n" | 38 "Host: localhost\r\n" |
| 39 "Connection: Upgrade\r\n" | 39 "Connection: Upgrade\r\n" |
| 40 "Upgrade: websocket\r\n" | 40 "Upgrade: websocket\r\n" |
| 41 "Origin: %s\r\n" | 41 "Origin: %s\r\n" |
| 42 "Sec-WebSocket-Version: 13\r\n" | 42 "Sec-WebSocket-Version: 13\r\n" |
| 43 "User-Agent:\r\n" | 43 "User-Agent:\r\n" |
| 44 "Accept-Encoding: gzip,deflate\r\n" | 44 "Accept-Encoding: gzip,deflate\r\n" |
| 45 "Accept-Language: en-us,fr\r\n" | 45 "Accept-Language: en-us,fr\r\n" |
| 46 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" | 46 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 47 "Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n" |
| 47 "%s\r\n", | 48 "%s\r\n", |
| 48 path.c_str(), | 49 path.c_str(), |
| 49 origin.c_str(), | 50 origin.c_str(), |
| 50 extra_headers.c_str()); | 51 extra_headers.c_str()); |
| 51 } | 52 } |
| 52 | 53 |
| 53 std::string WebSocketStandardResponse(const std::string& extra_headers) { | 54 std::string WebSocketStandardResponse(const std::string& extra_headers) { |
| 54 return base::StringPrintf( | 55 return base::StringPrintf( |
| 55 "HTTP/1.1 101 Switching Protocols\r\n" | 56 "HTTP/1.1 101 Switching Protocols\r\n" |
| 56 "Upgrade: websocket\r\n" | 57 "Upgrade: websocket\r\n" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 80 WebSocketDeterministicMockClientSocketFactoryMaker::factory() { | 81 WebSocketDeterministicMockClientSocketFactoryMaker::factory() { |
| 81 return &detail_->factory; | 82 return &detail_->factory; |
| 82 } | 83 } |
| 83 | 84 |
| 84 void WebSocketDeterministicMockClientSocketFactoryMaker::SetExpectations( | 85 void WebSocketDeterministicMockClientSocketFactoryMaker::SetExpectations( |
| 85 const std::string& expect_written, | 86 const std::string& expect_written, |
| 86 const std::string& return_to_read) { | 87 const std::string& return_to_read) { |
| 87 // We need to extend the lifetime of these strings. | 88 // We need to extend the lifetime of these strings. |
| 88 detail_->expect_written = expect_written; | 89 detail_->expect_written = expect_written; |
| 89 detail_->return_to_read = return_to_read; | 90 detail_->return_to_read = return_to_read; |
| 90 detail_->write = MockWrite(SYNCHRONOUS, 0, detail_->expect_written.c_str()); | 91 detail_->write = MockWrite(SYNCHRONOUS, |
| 91 detail_->read = MockRead(SYNCHRONOUS, 1, detail_->return_to_read.c_str()); | 92 detail_->expect_written.data(), |
| 93 detail_->expect_written.size(), |
| 94 0); |
| 95 detail_->read = MockRead(SYNCHRONOUS, |
| 96 detail_->return_to_read.data(), |
| 97 detail_->return_to_read.size(), |
| 98 1); |
| 92 scoped_ptr<DeterministicSocketData> socket_data( | 99 scoped_ptr<DeterministicSocketData> socket_data( |
| 93 new DeterministicSocketData(&detail_->read, 1, &detail_->write, 1)); | 100 new DeterministicSocketData(&detail_->read, 1, &detail_->write, 1)); |
| 94 socket_data->set_connect_data(MockConnect(SYNCHRONOUS, OK)); | 101 socket_data->set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
| 95 socket_data->SetStop(2); | 102 socket_data->SetStop(2); |
| 96 SetRawExpectations(socket_data.Pass()); | 103 SetRawExpectations(socket_data.Pass()); |
| 97 } | 104 } |
| 98 | 105 |
| 99 void WebSocketDeterministicMockClientSocketFactoryMaker::SetRawExpectations( | 106 void WebSocketDeterministicMockClientSocketFactoryMaker::SetRawExpectations( |
| 100 scoped_ptr<DeterministicSocketData> socket_data) { | 107 scoped_ptr<DeterministicSocketData> socket_data) { |
| 101 detail_->data = socket_data.Pass(); | 108 detail_->data = socket_data.Pass(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 116 | 123 |
| 117 TestURLRequestContext* | 124 TestURLRequestContext* |
| 118 WebSocketTestURLRequestContextHost::GetURLRequestContext() { | 125 WebSocketTestURLRequestContextHost::GetURLRequestContext() { |
| 119 url_request_context_.Init(); | 126 url_request_context_.Init(); |
| 120 // A Network Delegate is required to make the URLRequest::Delegate work. | 127 // A Network Delegate is required to make the URLRequest::Delegate work. |
| 121 url_request_context_.set_network_delegate(&network_delegate_); | 128 url_request_context_.set_network_delegate(&network_delegate_); |
| 122 return &url_request_context_; | 129 return &url_request_context_; |
| 123 } | 130 } |
| 124 | 131 |
| 125 } // namespace net | 132 } // namespace net |
| OLD | NEW |