OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // End-to-end tests for WebSocket. | 5 // End-to-end tests for WebSocket. |
6 // | 6 // |
7 // A python server is (re)started for each test, which is moderately | 7 // A python server is (re)started for each test, which is moderately |
8 // inefficient. However, it makes these tests a good fit for scenarios which | 8 // inefficient. However, it makes these tests a good fit for scenarios which |
9 // require special server configurations. | 9 // require special server configurations. |
10 | 10 |
11 #include <stdint.h> | 11 #include <stdint.h> |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/bind_helpers.h" | 17 #include "base/bind_helpers.h" |
18 #include "base/callback.h" | 18 #include "base/callback.h" |
19 #include "base/location.h" | 19 #include "base/location.h" |
20 #include "base/macros.h" | 20 #include "base/macros.h" |
21 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
| 22 #include "base/message_loop/message_loop.h" |
22 #include "base/run_loop.h" | 23 #include "base/run_loop.h" |
23 #include "base/single_thread_task_runner.h" | 24 #include "base/single_thread_task_runner.h" |
24 #include "base/strings/string_piece.h" | 25 #include "base/strings/string_piece.h" |
| 26 #include "base/test/scoped_task_scheduler.h" |
25 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
26 #include "net/base/auth.h" | 28 #include "net/base/auth.h" |
27 #include "net/base/proxy_delegate.h" | 29 #include "net/base/proxy_delegate.h" |
28 #include "net/proxy/proxy_service.h" | 30 #include "net/proxy/proxy_service.h" |
29 #include "net/test/embedded_test_server/embedded_test_server.h" | 31 #include "net/test/embedded_test_server/embedded_test_server.h" |
30 #include "net/test/spawned_test_server/spawned_test_server.h" | 32 #include "net/test/spawned_test_server/spawned_test_server.h" |
31 #include "net/test/test_data_directory.h" | 33 #include "net/test/test_data_directory.h" |
32 #include "net/url_request/url_request_test_util.h" | 34 #include "net/url_request/url_request_test_util.h" |
33 #include "net/websockets/websocket_channel.h" | 35 #include "net/websockets/websocket_channel.h" |
34 #include "net/websockets/websocket_event_interface.h" | 36 #include "net/websockets/websocket_event_interface.h" |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 | 252 |
251 private: | 253 private: |
252 ResolvedProxyInfo resolved_proxy_info_; | 254 ResolvedProxyInfo resolved_proxy_info_; |
253 | 255 |
254 DISALLOW_COPY_AND_ASSIGN(TestProxyDelegateWithProxyInfo); | 256 DISALLOW_COPY_AND_ASSIGN(TestProxyDelegateWithProxyInfo); |
255 }; | 257 }; |
256 | 258 |
257 class WebSocketEndToEndTest : public ::testing::Test { | 259 class WebSocketEndToEndTest : public ::testing::Test { |
258 protected: | 260 protected: |
259 WebSocketEndToEndTest() | 261 WebSocketEndToEndTest() |
260 : event_interface_(), | 262 : scoped_task_scheduler_(base::MessageLoop::current()), |
| 263 event_interface_(), |
261 proxy_delegate_(new TestProxyDelegateWithProxyInfo), | 264 proxy_delegate_(new TestProxyDelegateWithProxyInfo), |
262 context_(true), | 265 context_(true), |
263 channel_(), | 266 channel_(), |
264 initialised_context_(false) {} | 267 initialised_context_(false) {} |
265 | 268 |
266 // Initialise the URLRequestContext. Normally done automatically by | 269 // Initialise the URLRequestContext. Normally done automatically by |
267 // ConnectAndWait(). This method is for the use of tests that need the | 270 // ConnectAndWait(). This method is for the use of tests that need the |
268 // URLRequestContext initialised before calling ConnectAndWait(). | 271 // URLRequestContext initialised before calling ConnectAndWait(). |
269 void InitialiseContext() { | 272 void InitialiseContext() { |
270 context_.set_proxy_delegate(proxy_delegate_.get()); | 273 context_.set_proxy_delegate(proxy_delegate_.get()); |
(...skipping 11 matching lines...) Expand all Loading... |
282 GURL first_party_for_cookies("http://localhost/"); | 285 GURL first_party_for_cookies("http://localhost/"); |
283 event_interface_ = new ConnectTestingEventInterface; | 286 event_interface_ = new ConnectTestingEventInterface; |
284 channel_.reset( | 287 channel_.reset( |
285 new WebSocketChannel(base::WrapUnique(event_interface_), &context_)); | 288 new WebSocketChannel(base::WrapUnique(event_interface_), &context_)); |
286 channel_->SendAddChannelRequest(GURL(socket_url), sub_protocols_, origin, | 289 channel_->SendAddChannelRequest(GURL(socket_url), sub_protocols_, origin, |
287 first_party_for_cookies, ""); | 290 first_party_for_cookies, ""); |
288 event_interface_->WaitForResponse(); | 291 event_interface_->WaitForResponse(); |
289 return !event_interface_->failed(); | 292 return !event_interface_->failed(); |
290 } | 293 } |
291 | 294 |
| 295 base::test::ScopedTaskScheduler scoped_task_scheduler_; |
292 ConnectTestingEventInterface* event_interface_; // owned by channel_ | 296 ConnectTestingEventInterface* event_interface_; // owned by channel_ |
293 std::unique_ptr<TestProxyDelegateWithProxyInfo> proxy_delegate_; | 297 std::unique_ptr<TestProxyDelegateWithProxyInfo> proxy_delegate_; |
294 TestURLRequestContext context_; | 298 TestURLRequestContext context_; |
295 std::unique_ptr<WebSocketChannel> channel_; | 299 std::unique_ptr<WebSocketChannel> channel_; |
296 std::vector<std::string> sub_protocols_; | 300 std::vector<std::string> sub_protocols_; |
297 bool initialised_context_; | 301 bool initialised_context_; |
298 }; | 302 }; |
299 | 303 |
300 // None of these tests work on Android. | 304 // None of these tests work on Android. |
301 // TODO(ricea): Make these tests work on Android. See crbug.com/441711. | 305 // TODO(ricea): Make these tests work on Android. See crbug.com/441711. |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 GURL ws_url = ws_server.GetURL("header-continuation"); | 530 GURL ws_url = ws_server.GetURL("header-continuation"); |
527 | 531 |
528 EXPECT_TRUE(ConnectAndWait(ws_url)); | 532 EXPECT_TRUE(ConnectAndWait(ws_url)); |
529 EXPECT_EQ("permessage-deflate; server_max_window_bits=10", | 533 EXPECT_EQ("permessage-deflate; server_max_window_bits=10", |
530 event_interface_->extensions()); | 534 event_interface_->extensions()); |
531 } | 535 } |
532 | 536 |
533 } // namespace | 537 } // namespace |
534 | 538 |
535 } // namespace net | 539 } // namespace net |
OLD | NEW |