| 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 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "net/test/spawned_test_server/spawned_test_server.h" | 30 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 31 #include "net/test/test_data_directory.h" | 31 #include "net/test/test_data_directory.h" |
| 32 #include "net/url_request/url_request_test_util.h" | 32 #include "net/url_request/url_request_test_util.h" |
| 33 #include "net/websockets/websocket_channel.h" | 33 #include "net/websockets/websocket_channel.h" |
| 34 #include "net/websockets/websocket_event_interface.h" | 34 #include "net/websockets/websocket_event_interface.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 36 #include "url/origin.h" | 36 #include "url/origin.h" |
| 37 | 37 |
| 38 namespace net { | 38 namespace net { |
| 39 | 39 |
| 40 class URLRequest; |
| 41 |
| 40 namespace { | 42 namespace { |
| 41 | 43 |
| 42 static const char kEchoServer[] = "echo-with-no-extension"; | 44 static const char kEchoServer[] = "echo-with-no-extension"; |
| 43 | 45 |
| 44 // Simplify changing URL schemes. | 46 // Simplify changing URL schemes. |
| 45 GURL ReplaceUrlScheme(const GURL& in_url, const base::StringPiece& scheme) { | 47 GURL ReplaceUrlScheme(const GURL& in_url, const base::StringPiece& scheme) { |
| 46 GURL::Replacements replacements; | 48 GURL::Replacements replacements; |
| 47 replacements.SetSchemeStr(scheme); | 49 replacements.SetSchemeStr(scheme); |
| 48 return in_url.ReplaceComponents(replacements); | 50 return in_url.ReplaceComponents(replacements); |
| 49 } | 51 } |
| 50 | 52 |
| 51 // An implementation of WebSocketEventInterface that waits for and records the | 53 // An implementation of WebSocketEventInterface that waits for and records the |
| 52 // results of the connect. | 54 // results of the connect. |
| 53 class ConnectTestingEventInterface : public WebSocketEventInterface { | 55 class ConnectTestingEventInterface : public WebSocketEventInterface { |
| 54 public: | 56 public: |
| 55 ConnectTestingEventInterface(); | 57 ConnectTestingEventInterface(); |
| 56 | 58 |
| 57 void WaitForResponse(); | 59 void WaitForResponse(); |
| 58 | 60 |
| 59 bool failed() const { return failed_; } | 61 bool failed() const { return failed_; } |
| 60 | 62 |
| 61 // Only set if the handshake failed, otherwise empty. | 63 // Only set if the handshake failed, otherwise empty. |
| 62 std::string failure_message() const; | 64 std::string failure_message() const; |
| 63 | 65 |
| 64 std::string selected_subprotocol() const; | 66 std::string selected_subprotocol() const; |
| 65 | 67 |
| 66 std::string extensions() const; | 68 std::string extensions() const; |
| 67 | 69 |
| 68 // Implementation of WebSocketEventInterface. | 70 // Implementation of WebSocketEventInterface. |
| 71 void OnCreateURLRequest(URLRequest* request) override {} |
| 72 |
| 69 ChannelState OnAddChannelResponse(const std::string& selected_subprotocol, | 73 ChannelState OnAddChannelResponse(const std::string& selected_subprotocol, |
| 70 const std::string& extensions) override; | 74 const std::string& extensions) override; |
| 71 | 75 |
| 72 ChannelState OnDataFrame(bool fin, | 76 ChannelState OnDataFrame(bool fin, |
| 73 WebSocketMessageType type, | 77 WebSocketMessageType type, |
| 74 scoped_refptr<IOBuffer> data, | 78 scoped_refptr<IOBuffer> data, |
| 75 size_t data_size) override; | 79 size_t data_size) override; |
| 76 | 80 |
| 77 ChannelState OnFlowControl(int64_t quota) override; | 81 ChannelState OnFlowControl(int64_t quota) override; |
| 78 | 82 |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 GURL ws_url = ws_server.GetURL("header-continuation"); | 523 GURL ws_url = ws_server.GetURL("header-continuation"); |
| 520 | 524 |
| 521 EXPECT_TRUE(ConnectAndWait(ws_url)); | 525 EXPECT_TRUE(ConnectAndWait(ws_url)); |
| 522 EXPECT_EQ("permessage-deflate; server_max_window_bits=10", | 526 EXPECT_EQ("permessage-deflate; server_max_window_bits=10", |
| 523 event_interface_->extensions()); | 527 event_interface_->extensions()); |
| 524 } | 528 } |
| 525 | 529 |
| 526 } // namespace | 530 } // namespace |
| 527 | 531 |
| 528 } // namespace net | 532 } // namespace net |
| OLD | NEW |