OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_WEBSOCKETS_WEBSOCKET_STREAM_CREATE_TEST_BASE_H_ | |
6 #define NET_WEBSOCKETS_WEBSOCKET_STREAM_CREATE_TEST_BASE_H_ | |
7 | |
8 #include <string> | |
9 #include <utility> | |
10 #include <vector> | |
11 | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/memory/scoped_vector.h" | |
14 #include "base/run_loop.h" | |
15 #include "base/timer/timer.h" | |
16 #include "net/base/net_export.h" | |
17 #include "net/socket/socket_test_util.h" | |
18 #include "net/ssl/ssl_info.h" | |
19 #include "net/websockets/websocket_event_interface.h" | |
20 #include "net/websockets/websocket_test_util.h" | |
21 | |
22 namespace net { | |
23 | |
24 class HttpRequestHeaders; | |
25 class HttpResponseHeaders; | |
26 class WebSocketStream; | |
27 class WebSocketStreamRequest; | |
28 struct WebSocketHandshakeRequestInfo; | |
29 struct WebSocketHandshakeResponseInfo; | |
30 | |
31 class WebSocketStreamCreateTestBase { | |
32 public: | |
33 using HeaderKeyValuePair = std::pair<std::string, std::string>; | |
34 | |
35 WebSocketStreamCreateTestBase(); | |
36 virtual ~WebSocketStreamCreateTestBase(); | |
37 | |
38 // A wrapper for CreateAndConnectStreamForTesting that knows about our default | |
39 // parameters. | |
40 void CreateAndConnectStream(const std::string& socket_url, | |
41 const std::vector<std::string>& sub_protocols, | |
42 const std::string& origin, | |
43 scoped_ptr<base::Timer> timer); | |
44 | |
45 static std::vector<HeaderKeyValuePair> RequestHeadersToVector( | |
46 const HttpRequestHeaders& headers); | |
47 static std::vector<HeaderKeyValuePair> ResponseHeadersToVector( | |
48 const HttpResponseHeaders& headers); | |
49 | |
50 const std::string& failure_message() const { return failure_message_; } | |
51 bool has_failed() const { return has_failed_; } | |
52 | |
53 // Runs |connect_run_loop_|. It will stop when the connection establishes or | |
54 // fails. | |
55 void WaitUntilConnectDone(); | |
56 | |
57 // A simple function to make the tests more readable. | |
58 std::vector<std::string> NoSubProtocols(); | |
59 | |
60 protected: | |
61 WebSocketTestURLRequestContextHost url_request_context_host_; | |
62 scoped_ptr<WebSocketStreamRequest> stream_request_; | |
63 // Only set if the connection succeeded. | |
64 scoped_ptr<WebSocketStream> stream_; | |
65 // Only set if the connection failed. | |
66 std::string failure_message_; | |
67 bool has_failed_; | |
68 scoped_ptr<WebSocketHandshakeRequestInfo> request_info_; | |
69 scoped_ptr<WebSocketHandshakeResponseInfo> response_info_; | |
70 scoped_ptr<WebSocketEventInterface::SSLErrorCallbacks> ssl_error_callbacks_; | |
71 SSLInfo ssl_info_; | |
72 bool ssl_fatal_; | |
73 ScopedVector<SSLSocketDataProvider> ssl_data_; | |
74 | |
75 // This temporarily sets WebSocketEndpointLockManager unlock delay to zero | |
76 // during tests. | |
77 ScopedWebSocketEndpointZeroUnlockDelay zero_unlock_delay_; | |
78 base::RunLoop connect_run_loop_; | |
79 | |
80 private: | |
81 class TestConnectDelegate; | |
82 DISALLOW_COPY_AND_ASSIGN(WebSocketStreamCreateTestBase); | |
83 }; | |
84 | |
85 } // namespace net | |
86 | |
87 #endif // NET_WEBSOCKETS_WEBSOCKET_STREAM_CREATE_TEST_BASE_H_ | |
OLD | NEW |