Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Side by Side Diff: net/websockets/websocket_test_util.h

Issue 304093003: Support recovery from SSL errors for new WebSocket implementation (Closed) Base URL: http://git.chromium.org/chromium/src.git@master-for-pool-throttling
Patch Set: Add DCHECKs to websocket_host.cc Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef NET_WEBSOCKETS_WEBSOCKET_TEST_UTIL_H_ 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_TEST_UTIL_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_TEST_UTIL_H_ 6 #define NET_WEBSOCKETS_WEBSOCKET_TEST_UTIL_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "net/url_request/url_request_test_util.h" 12 #include "net/url_request/url_request_test_util.h"
13 #include "net/websockets/websocket_stream.h" 13 #include "net/websockets/websocket_stream.h"
14 14
15 class GURL; 15 class GURL;
16 16
17 namespace url { 17 namespace url {
18 class Origin; 18 class Origin;
19 } // namespace url 19 } // namespace url
20 20
21 namespace net { 21 namespace net {
22 22
23 class BoundNetLog; 23 class BoundNetLog;
24 class DeterministicMockClientSocketFactory;
24 class DeterministicSocketData; 25 class DeterministicSocketData;
25 class URLRequestContext; 26 class URLRequestContext;
26 class WebSocketHandshakeStreamCreateHelper; 27 class WebSocketHandshakeStreamCreateHelper;
27 class DeterministicMockClientSocketFactory; 28 struct SSLSocketDataProvider;
28 29
29 class LinearCongruentialGenerator { 30 class LinearCongruentialGenerator {
30 public: 31 public:
31 explicit LinearCongruentialGenerator(uint32 seed); 32 explicit LinearCongruentialGenerator(uint32 seed);
32 uint32 Generate(); 33 uint32 Generate();
33 34
34 private: 35 private:
35 uint64 current_; 36 uint64 current_;
36 }; 37 };
37 38
(...skipping 23 matching lines...) Expand all
61 // This class provides a convenient way to construct a 62 // This class provides a convenient way to construct a
62 // DeterministicMockClientSocketFactory for WebSocket tests. 63 // DeterministicMockClientSocketFactory for WebSocket tests.
63 class WebSocketDeterministicMockClientSocketFactoryMaker { 64 class WebSocketDeterministicMockClientSocketFactoryMaker {
64 public: 65 public:
65 WebSocketDeterministicMockClientSocketFactoryMaker(); 66 WebSocketDeterministicMockClientSocketFactoryMaker();
66 ~WebSocketDeterministicMockClientSocketFactoryMaker(); 67 ~WebSocketDeterministicMockClientSocketFactoryMaker();
67 68
68 // The socket created by the factory will expect |expect_written| to be 69 // The socket created by the factory will expect |expect_written| to be
69 // written to the socket, and will respond with |return_to_read|. The test 70 // written to the socket, and will respond with |return_to_read|. The test
70 // will fail if the expected text is not written, or all the bytes are not 71 // will fail if the expected text is not written, or all the bytes are not
71 // read. 72 // read.
tyoshino (SeeGerritForStatus) 2014/06/03 12:11:59 write some comment to say that this method "adds"
Adam Rice 2014/06/03 12:59:51 Done.
72 void SetExpectations(const std::string& expect_written, 73 void SetExpectations(const std::string& expect_written,
73 const std::string& return_to_read); 74 const std::string& return_to_read);
74 75
75 // A low-level interface to permit arbitrary expectations to be set. 76 // A low-level interface to permit arbitrary expectations to be added.
76 void SetRawExpectations(scoped_ptr<DeterministicSocketData> socket_data); 77 void AddRawExpectations(scoped_ptr<DeterministicSocketData> socket_data);
78
79 // Allow an SSL socket data provider to be added.
80 void AddSSLSocketDataProvider(
81 scoped_ptr<SSLSocketDataProvider> ssl_socket_data);
77 82
78 // Call to get a pointer to the factory, which remains owned by this object. 83 // Call to get a pointer to the factory, which remains owned by this object.
79 DeterministicMockClientSocketFactory* factory(); 84 DeterministicMockClientSocketFactory* factory();
80 85
81 private: 86 private:
82 struct Detail; 87 struct Detail;
83 scoped_ptr<Detail> detail_; 88 scoped_ptr<Detail> detail_;
84 89
85 DISALLOW_COPY_AND_ASSIGN(WebSocketDeterministicMockClientSocketFactoryMaker); 90 DISALLOW_COPY_AND_ASSIGN(WebSocketDeterministicMockClientSocketFactoryMaker);
86 }; 91 };
87 92
88 // This class encapsulates the details of creating a 93 // This class encapsulates the details of creating a
89 // TestURLRequestContext that returns mock ClientSocketHandles that do what is 94 // TestURLRequestContext that returns mock ClientSocketHandles that do what is
90 // required by the tests. 95 // required by the tests.
91 struct WebSocketTestURLRequestContextHost { 96 struct WebSocketTestURLRequestContextHost {
92 public: 97 public:
93 WebSocketTestURLRequestContextHost(); 98 WebSocketTestURLRequestContextHost();
94 ~WebSocketTestURLRequestContextHost(); 99 ~WebSocketTestURLRequestContextHost();
95 100
96 void SetExpectations(const std::string& expect_written, 101 void SetExpectations(const std::string& expect_written,
97 const std::string& return_to_read) { 102 const std::string& return_to_read) {
98 maker_.SetExpectations(expect_written, return_to_read); 103 maker_.SetExpectations(expect_written, return_to_read);
99 } 104 }
100 105
101 void SetRawExpectations(scoped_ptr<DeterministicSocketData> socket_data); 106 void AddRawExpectations(scoped_ptr<DeterministicSocketData> socket_data);
107
108 // Allow an SSL socket data provider to be added.
109 void AddSSLSocketDataProvider(
110 scoped_ptr<SSLSocketDataProvider> ssl_socket_data);
102 111
103 // Call after calling one of SetExpections() or SetRawExpectations(). The 112 // Call after calling one of SetExpections() or SetRawExpectations(). The
104 // returned pointer remains owned by this object. This should only be called 113 // returned pointer remains owned by this object. This should only be called
105 // once. 114 // once.
106 TestURLRequestContext* GetURLRequestContext(); 115 TestURLRequestContext* GetURLRequestContext();
107 116
108 private: 117 private:
109 WebSocketDeterministicMockClientSocketFactoryMaker maker_; 118 WebSocketDeterministicMockClientSocketFactoryMaker maker_;
110 TestURLRequestContext url_request_context_; 119 TestURLRequestContext url_request_context_;
111 TestNetworkDelegate network_delegate_; 120 TestNetworkDelegate network_delegate_;
112 121
113 DISALLOW_COPY_AND_ASSIGN(WebSocketTestURLRequestContextHost); 122 DISALLOW_COPY_AND_ASSIGN(WebSocketTestURLRequestContextHost);
114 }; 123 };
115 124
116 } // namespace net 125 } // namespace net
117 126
118 #endif // NET_WEBSOCKETS_WEBSOCKET_TEST_UTIL_H_ 127 #endif // NET_WEBSOCKETS_WEBSOCKET_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698