OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "net/base/completion_callback.h" | 9 #include "net/base/completion_callback.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 }; | 150 }; |
151 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | 151 StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
152 data_writes, arraysize(data_writes)); | 152 data_writes, arraysize(data_writes)); |
153 mock_socket_factory.AddSocketDataProvider(&data); | 153 mock_socket_factory.AddSocketDataProvider(&data); |
154 | 154 |
155 WebSocket::Request* request( | 155 WebSocket::Request* request( |
156 new WebSocket::Request(GURL("ws://example.com/demo"), | 156 new WebSocket::Request(GURL("ws://example.com/demo"), |
157 "sample", | 157 "sample", |
158 "http://example.com", | 158 "http://example.com", |
159 "ws://example.com/demo", | 159 "ws://example.com/demo", |
| 160 WebSocket::DRAFT75, |
160 new TestURLRequestContext())); | 161 new TestURLRequestContext())); |
161 request->SetHostResolver(new MockHostResolver()); | 162 request->SetHostResolver(new MockHostResolver()); |
162 request->SetClientSocketFactory(&mock_socket_factory); | 163 request->SetClientSocketFactory(&mock_socket_factory); |
163 | 164 |
164 TestCompletionCallback callback; | 165 TestCompletionCallback callback; |
165 | 166 |
166 scoped_ptr<WebSocketEventRecorder> delegate( | 167 scoped_ptr<WebSocketEventRecorder> delegate( |
167 new WebSocketEventRecorder(&callback)); | 168 new WebSocketEventRecorder(&callback)); |
168 delegate->SetOnOpen(NewCallback(delegate.get(), | 169 delegate->SetOnOpen(NewCallback(delegate.get(), |
169 &WebSocketEventRecorder::DoClose)); | 170 &WebSocketEventRecorder::DoClose)); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 }; | 212 }; |
212 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | 213 StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
213 data_writes, arraysize(data_writes)); | 214 data_writes, arraysize(data_writes)); |
214 mock_socket_factory.AddSocketDataProvider(&data); | 215 mock_socket_factory.AddSocketDataProvider(&data); |
215 | 216 |
216 WebSocket::Request* request( | 217 WebSocket::Request* request( |
217 new WebSocket::Request(GURL("ws://example.com/demo"), | 218 new WebSocket::Request(GURL("ws://example.com/demo"), |
218 "sample", | 219 "sample", |
219 "http://example.com", | 220 "http://example.com", |
220 "ws://example.com/demo", | 221 "ws://example.com/demo", |
| 222 WebSocket::DRAFT75, |
221 new TestURLRequestContext())); | 223 new TestURLRequestContext())); |
222 request->SetHostResolver(new MockHostResolver()); | 224 request->SetHostResolver(new MockHostResolver()); |
223 request->SetClientSocketFactory(&mock_socket_factory); | 225 request->SetClientSocketFactory(&mock_socket_factory); |
224 | 226 |
225 TestCompletionCallback callback; | 227 TestCompletionCallback callback; |
226 | 228 |
227 scoped_ptr<WebSocketEventRecorder> delegate( | 229 scoped_ptr<WebSocketEventRecorder> delegate( |
228 new WebSocketEventRecorder(&callback)); | 230 new WebSocketEventRecorder(&callback)); |
229 delegate->SetOnMessage(NewCallback(delegate.get(), | 231 delegate->SetOnMessage(NewCallback(delegate.get(), |
230 &WebSocketEventRecorder::DoClose)); | 232 &WebSocketEventRecorder::DoClose)); |
(...skipping 14 matching lines...) Expand all Loading... |
245 EXPECT_EQ(kMessage, events[1].msg); | 247 EXPECT_EQ(kMessage, events[1].msg); |
246 EXPECT_EQ(WebSocketEvent::EVENT_CLOSE, events[2].event_type); | 248 EXPECT_EQ(WebSocketEvent::EVENT_CLOSE, events[2].event_type); |
247 } | 249 } |
248 | 250 |
249 TEST_F(WebSocketTest, ProcessFrameDataForLengthCalculation) { | 251 TEST_F(WebSocketTest, ProcessFrameDataForLengthCalculation) { |
250 WebSocket::Request* request( | 252 WebSocket::Request* request( |
251 new WebSocket::Request(GURL("ws://example.com/demo"), | 253 new WebSocket::Request(GURL("ws://example.com/demo"), |
252 "sample", | 254 "sample", |
253 "http://example.com", | 255 "http://example.com", |
254 "ws://example.com/demo", | 256 "ws://example.com/demo", |
| 257 WebSocket::DRAFT75, |
255 new TestURLRequestContext())); | 258 new TestURLRequestContext())); |
256 TestCompletionCallback callback; | 259 TestCompletionCallback callback; |
257 scoped_ptr<WebSocketEventRecorder> delegate( | 260 scoped_ptr<WebSocketEventRecorder> delegate( |
258 new WebSocketEventRecorder(&callback)); | 261 new WebSocketEventRecorder(&callback)); |
259 | 262 |
260 scoped_refptr<WebSocket> websocket( | 263 scoped_refptr<WebSocket> websocket( |
261 new WebSocket(request, delegate.get())); | 264 new WebSocket(request, delegate.get())); |
262 | 265 |
263 // Frame data: skip length 1 ('x'), and try to skip length 129 | 266 // Frame data: skip length 1 ('x'), and try to skip length 129 |
264 // (1 * 128 + 1) bytes after \x81\x01, but buffer is too short to skip. | 267 // (1 * 128 + 1) bytes after \x81\x01, but buffer is too short to skip. |
(...skipping 15 matching lines...) Expand all Loading... |
280 | 283 |
281 websocket->DetachDelegate(); | 284 websocket->DetachDelegate(); |
282 } | 285 } |
283 | 286 |
284 TEST_F(WebSocketTest, ProcessFrameDataForUnterminatedString) { | 287 TEST_F(WebSocketTest, ProcessFrameDataForUnterminatedString) { |
285 WebSocket::Request* request( | 288 WebSocket::Request* request( |
286 new WebSocket::Request(GURL("ws://example.com/demo"), | 289 new WebSocket::Request(GURL("ws://example.com/demo"), |
287 "sample", | 290 "sample", |
288 "http://example.com", | 291 "http://example.com", |
289 "ws://example.com/demo", | 292 "ws://example.com/demo", |
| 293 WebSocket::DRAFT75, |
290 new TestURLRequestContext())); | 294 new TestURLRequestContext())); |
291 TestCompletionCallback callback; | 295 TestCompletionCallback callback; |
292 scoped_ptr<WebSocketEventRecorder> delegate( | 296 scoped_ptr<WebSocketEventRecorder> delegate( |
293 new WebSocketEventRecorder(&callback)); | 297 new WebSocketEventRecorder(&callback)); |
294 | 298 |
295 scoped_refptr<WebSocket> websocket( | 299 scoped_refptr<WebSocket> websocket( |
296 new WebSocket(request, delegate.get())); | 300 new WebSocket(request, delegate.get())); |
297 | 301 |
298 static const char kTestUnterminatedFrame[] = | 302 static const char kTestUnterminatedFrame[] = |
299 "\x00unterminated frame"; | 303 "\x00unterminated frame"; |
(...skipping 23 matching lines...) Expand all Loading... |
323 EXPECT_EQ(1U, events.size()); | 327 EXPECT_EQ(1U, events.size()); |
324 | 328 |
325 EXPECT_EQ(WebSocketEvent::EVENT_MESSAGE, events[0].event_type); | 329 EXPECT_EQ(WebSocketEvent::EVENT_MESSAGE, events[0].event_type); |
326 EXPECT_EQ(kExpectedMsg, events[0].msg); | 330 EXPECT_EQ(kExpectedMsg, events[0].msg); |
327 } | 331 } |
328 | 332 |
329 websocket->DetachDelegate(); | 333 websocket->DetachDelegate(); |
330 } | 334 } |
331 | 335 |
332 } // namespace net | 336 } // namespace net |
OLD | NEW |