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

Side by Side Diff: net/websockets/websocket_job_spdy2_unittest.cc

Issue 10066045: RefCounted types should not have public destructors, net/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Deprecated cookiestore fix Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/websockets/websocket_job.h" 5 #include "net/websockets/websocket_job.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 26 matching lines...) Expand all
37 #include "testing/platform_test.h" 37 #include "testing/platform_test.h"
38 38
39 using namespace net::test_spdy2; 39 using namespace net::test_spdy2;
40 40
41 namespace { 41 namespace {
42 42
43 class MockSocketStream : public net::SocketStream { 43 class MockSocketStream : public net::SocketStream {
44 public: 44 public:
45 MockSocketStream(const GURL& url, net::SocketStream::Delegate* delegate) 45 MockSocketStream(const GURL& url, net::SocketStream::Delegate* delegate)
46 : SocketStream(url, delegate) {} 46 : SocketStream(url, delegate) {}
47 virtual ~MockSocketStream() {}
48 47
49 virtual void Connect() OVERRIDE {} 48 virtual void Connect() OVERRIDE {}
50 virtual bool SendData(const char* data, int len) OVERRIDE { 49 virtual bool SendData(const char* data, int len) OVERRIDE {
51 sent_data_ += std::string(data, len); 50 sent_data_ += std::string(data, len);
52 return true; 51 return true;
53 } 52 }
54 53
55 virtual void Close() OVERRIDE {} 54 virtual void Close() OVERRIDE {}
56 virtual void RestartWithAuth( 55 virtual void RestartWithAuth(
57 const net::AuthCredentials& credentials) OVERRIDE { 56 const net::AuthCredentials& credentials) OVERRIDE {
58 } 57 }
59 58
60 virtual void DetachDelegate() OVERRIDE { 59 virtual void DetachDelegate() OVERRIDE {
61 delegate_ = NULL; 60 delegate_ = NULL;
62 } 61 }
63 62
64 const std::string& sent_data() const { 63 const std::string& sent_data() const {
65 return sent_data_; 64 return sent_data_;
66 } 65 }
67 66
67 protected:
68 virtual ~MockSocketStream() {}
69
68 private: 70 private:
69 std::string sent_data_; 71 std::string sent_data_;
70 }; 72 };
71 73
72 class MockSocketStreamDelegate : public net::SocketStream::Delegate { 74 class MockSocketStreamDelegate : public net::SocketStream::Delegate {
73 public: 75 public:
74 MockSocketStreamDelegate() 76 MockSocketStreamDelegate()
75 : amount_sent_(0), allow_all_cookies_(true) {} 77 : amount_sent_(0), allow_all_cookies_(true) {}
76 void set_allow_all_cookies(bool allow_all_cookies) { 78 void set_allow_all_cookies(bool allow_all_cookies) {
77 allow_all_cookies_ = allow_all_cookies; 79 allow_all_cookies_ = allow_all_cookies;
78 } 80 }
79 virtual ~MockSocketStreamDelegate() {} 81 virtual ~MockSocketStreamDelegate() {}
80 82
81 void SetOnStartOpenConnection(const base::Closure& callback) { 83 void SetOnStartOpenConnection(const base::Closure& callback) {
82 on_start_open_connection_ = callback; 84 on_start_open_connection_ = callback;
83 } 85 }
84 void SetOnConnected(const base::Closure& callback) { 86 void SetOnConnected(const base::Closure& callback) {
85 on_connected_ = callback; 87 on_connected_ = callback;
86 } 88 }
87 void SetOnSentData(const base::Closure& callback) { 89 void SetOnSentData(const base::Closure& callback) {
88 on_sent_data_ = callback; 90 on_sent_data_ = callback;
89 } 91 }
90 void SetOnReceivedData(const base::Closure& callback) { 92 void SetOnReceivedData(const base::Closure& callback) {
91 on_received_data_ = callback; 93 on_received_data_ = callback;
92 } 94 }
93 void SetOnClose(const base::Closure& callback) { 95 void SetOnClose(const base::Closure& callback) {
94 on_close_ = callback; 96 on_close_ = callback;
95 } 97 }
96 98
97 virtual int OnStartOpenConnection(net::SocketStream* socket, 99 virtual int OnStartOpenConnection(
98 const net::CompletionCallback& callback) { 100 net::SocketStream* socket,
101 const net::CompletionCallback& callback) OVERRIDE {
99 if (!on_start_open_connection_.is_null()) 102 if (!on_start_open_connection_.is_null())
100 on_start_open_connection_.Run(); 103 on_start_open_connection_.Run();
101 return net::OK; 104 return net::OK;
102 } 105 }
103 virtual void OnConnected(net::SocketStream* socket, 106 virtual void OnConnected(net::SocketStream* socket,
104 int max_pending_send_allowed) { 107 int max_pending_send_allowed) OVERRIDE {
105 if (!on_connected_.is_null()) 108 if (!on_connected_.is_null())
106 on_connected_.Run(); 109 on_connected_.Run();
107 } 110 }
108 virtual void OnSentData(net::SocketStream* socket, int amount_sent) { 111 virtual void OnSentData(net::SocketStream* socket,
112 int amount_sent) OVERRIDE {
109 amount_sent_ += amount_sent; 113 amount_sent_ += amount_sent;
110 if (!on_sent_data_.is_null()) 114 if (!on_sent_data_.is_null())
111 on_sent_data_.Run(); 115 on_sent_data_.Run();
112 } 116 }
113 virtual void OnReceivedData(net::SocketStream* socket, 117 virtual void OnReceivedData(net::SocketStream* socket,
114 const char* data, int len) { 118 const char* data, int len) OVERRIDE {
115 received_data_ += std::string(data, len); 119 received_data_ += std::string(data, len);
116 if (!on_received_data_.is_null()) 120 if (!on_received_data_.is_null())
117 on_received_data_.Run(); 121 on_received_data_.Run();
118 } 122 }
119 virtual void OnClose(net::SocketStream* socket) { 123 virtual void OnClose(net::SocketStream* socket) {
120 if (!on_close_.is_null()) 124 if (!on_close_.is_null())
121 on_close_.Run(); 125 on_close_.Run();
122 } 126 }
123 virtual bool CanGetCookies(net::SocketStream* socket, const GURL& url) { 127 virtual bool CanGetCookies(net::SocketStream* socket,
128 const GURL& url) OVERRIDE {
124 return allow_all_cookies_; 129 return allow_all_cookies_;
125 } 130 }
126 virtual bool CanSetCookie(net::SocketStream* request, 131 virtual bool CanSetCookie(net::SocketStream* request,
127 const GURL& url, 132 const GURL& url,
128 const std::string& cookie_line, 133 const std::string& cookie_line,
129 net::CookieOptions* options) { 134 net::CookieOptions* options) OVERRIDE {
130 return allow_all_cookies_; 135 return allow_all_cookies_;
131 } 136 }
132 137
133 size_t amount_sent() const { return amount_sent_; } 138 size_t amount_sent() const { return amount_sent_; }
134 const std::string& received_data() const { return received_data_; } 139 const std::string& received_data() const { return received_data_; }
135 140
136 private: 141 private:
137 int amount_sent_; 142 int amount_sent_;
138 bool allow_all_cookies_; 143 bool allow_all_cookies_;
139 std::string received_data_; 144 std::string received_data_;
140 base::Closure on_start_open_connection_; 145 base::Closure on_start_open_connection_;
141 base::Closure on_connected_; 146 base::Closure on_connected_;
142 base::Closure on_sent_data_; 147 base::Closure on_sent_data_;
143 base::Closure on_received_data_; 148 base::Closure on_received_data_;
144 base::Closure on_close_; 149 base::Closure on_close_;
145 }; 150 };
146 151
147 class MockCookieStore : public net::CookieStore { 152 class MockCookieStore : public net::CookieStore {
148 public: 153 public:
149 struct Entry { 154 struct Entry {
150 GURL url; 155 GURL url;
151 std::string cookie_line; 156 std::string cookie_line;
152 net::CookieOptions options; 157 net::CookieOptions options;
153 }; 158 };
159
154 MockCookieStore() {} 160 MockCookieStore() {}
155 161
156 virtual bool SetCookieWithOptions(const GURL& url, 162 bool SetCookieWithOptions(const GURL& url,
157 const std::string& cookie_line, 163 const std::string& cookie_line,
158 const net::CookieOptions& options) { 164 const net::CookieOptions& options) {
159 Entry entry; 165 Entry entry;
160 entry.url = url; 166 entry.url = url;
161 entry.cookie_line = cookie_line; 167 entry.cookie_line = cookie_line;
162 entry.options = options; 168 entry.options = options;
163 entries_.push_back(entry); 169 entries_.push_back(entry);
164 return true; 170 return true;
165 } 171 }
166 172
167 virtual void SetCookieWithOptionsAsync( 173 std::string GetCookiesWithOptions(const GURL& url,
168 const GURL& url, 174 const net::CookieOptions& options) {
169 const std::string& cookie_line,
170 const net::CookieOptions& options,
171 const SetCookiesCallback& callback) {
172 bool result = SetCookieWithOptions(url, cookie_line, options);
173 if (!callback.is_null())
174 callback.Run(result);
175 }
176 virtual std::string GetCookiesWithOptions(
177 const GURL& url,
178 const net::CookieOptions& options) {
179 std::string result; 175 std::string result;
180 for (size_t i = 0; i < entries_.size(); i++) { 176 for (size_t i = 0; i < entries_.size(); i++) {
181 Entry &entry = entries_[i]; 177 Entry &entry = entries_[i];
182 if (url == entry.url) { 178 if (url == entry.url) {
183 if (!result.empty()) { 179 if (!result.empty()) {
184 result += "; "; 180 result += "; ";
185 } 181 }
186 result += entry.cookie_line; 182 result += entry.cookie_line;
187 } 183 }
188 } 184 }
189 return result; 185 return result;
190 } 186 }
187
188 // CookieStore:
189 virtual void SetCookieWithOptionsAsync(
190 const GURL& url,
191 const std::string& cookie_line,
192 const net::CookieOptions& options,
193 const SetCookiesCallback& callback) OVERRIDE {
194 bool result = SetCookieWithOptions(url, cookie_line, options);
195 if (!callback.is_null())
196 callback.Run(result);
197 }
198
191 virtual void GetCookiesWithOptionsAsync( 199 virtual void GetCookiesWithOptionsAsync(
192 const GURL& url, 200 const GURL& url,
193 const net::CookieOptions& options, 201 const net::CookieOptions& options,
194 const GetCookiesCallback& callback) { 202 const GetCookiesCallback& callback) OVERRIDE {
195 if (!callback.is_null()) 203 if (!callback.is_null())
196 callback.Run(GetCookiesWithOptions(url, options)); 204 callback.Run(GetCookiesWithOptions(url, options));
197 } 205 }
198 virtual void GetCookiesWithInfo(const GURL& url, 206
199 const net::CookieOptions& options,
200 std::string* cookie_line,
201 std::vector<CookieInfo>* cookie_infos) {
202 ADD_FAILURE();
203 }
204 virtual void GetCookiesWithInfoAsync( 207 virtual void GetCookiesWithInfoAsync(
205 const GURL& url, 208 const GURL& url,
206 const net::CookieOptions& options, 209 const net::CookieOptions& options,
207 const GetCookieInfoCallback& callback) { 210 const GetCookieInfoCallback& callback) OVERRIDE {
208 ADD_FAILURE();
209 }
210 virtual void DeleteCookie(const GURL& url,
211 const std::string& cookie_name) {
212 ADD_FAILURE();
213 }
214 virtual void DeleteCookieAsync(const GURL& url,
215 const std::string& cookie_name,
216 const base::Closure& callback) {
217 ADD_FAILURE();
218 }
219 virtual void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin,
220 const base::Time& delete_end,
221 const DeleteCallback& callback) {
222 ADD_FAILURE();
223 }
224 virtual void DeleteSessionCookiesAsync(const DeleteCallback&) {
225 ADD_FAILURE(); 211 ADD_FAILURE();
226 } 212 }
227 213
228 virtual net::CookieMonster* GetCookieMonster() { return NULL; } 214 virtual void DeleteCookieAsync(const GURL& url,
215 const std::string& cookie_name,
216 const base::Closure& callback) OVERRIDE {
217 ADD_FAILURE();
218 }
219
220 virtual void DeleteAllCreatedBetweenAsync(
221 const base::Time& delete_begin,
222 const base::Time& delete_end,
223 const DeleteCallback& callback) OVERRIDE {
224 ADD_FAILURE();
225 }
226
227 virtual void DeleteSessionCookiesAsync(const DeleteCallback&) OVERRIDE {
228 ADD_FAILURE();
229 }
230
231 virtual net::CookieMonster* GetCookieMonster() OVERRIDE { return NULL; }
229 232
230 const std::vector<Entry>& entries() const { return entries_; } 233 const std::vector<Entry>& entries() const { return entries_; }
231 234
232 private: 235 private:
233 friend class base::RefCountedThreadSafe<MockCookieStore>; 236 friend class base::RefCountedThreadSafe<MockCookieStore>;
234 virtual ~MockCookieStore() {} 237 virtual ~MockCookieStore() {}
235 238
236 std::vector<Entry> entries_; 239 std::vector<Entry> entries_;
237 }; 240 };
238 241
239 class MockSSLConfigService : public net::SSLConfigService { 242 class MockSSLConfigService : public net::SSLConfigService {
240 public: 243 public:
241 virtual void GetSSLConfig(net::SSLConfig* config) {}; 244 virtual void GetSSLConfig(net::SSLConfig* config) OVERRIDE {}
245
246 protected:
247 virtual ~MockSSLConfigService() {}
242 }; 248 };
243 249
244 class MockURLRequestContext : public net::URLRequestContext { 250 class MockURLRequestContext : public net::URLRequestContext {
245 public: 251 public:
246 explicit MockURLRequestContext(net::CookieStore* cookie_store) 252 explicit MockURLRequestContext(net::CookieStore* cookie_store)
247 : transport_security_state_(std::string()) { 253 : transport_security_state_(std::string()) {
248 set_cookie_store(cookie_store); 254 set_cookie_store(cookie_store);
249 set_transport_security_state(&transport_security_state_); 255 set_transport_security_state(&transport_security_state_);
250 net::TransportSecurityState::DomainState state; 256 net::TransportSecurityState::DomainState state;
251 state.expiry = base::Time::Now() + base::TimeDelta::FromSeconds(1000); 257 state.expiry = base::Time::Now() + base::TimeDelta::FromSeconds(1000);
252 transport_security_state_.EnableHost("upgrademe.com", state); 258 transport_security_state_.EnableHost("upgrademe.com", state);
253 } 259 }
254 260
255 private: 261 protected:
256 friend class base::RefCountedThreadSafe<MockURLRequestContext>; 262 friend class base::RefCountedThreadSafe<MockURLRequestContext>;
257 virtual ~MockURLRequestContext() {} 263 virtual ~MockURLRequestContext() {}
258 264
265 private:
259 net::TransportSecurityState transport_security_state_; 266 net::TransportSecurityState transport_security_state_;
260 }; 267 };
261 268
262 class MockHttpTransactionFactory : public net::HttpTransactionFactory { 269 class MockHttpTransactionFactory : public net::HttpTransactionFactory {
263 public: 270 public:
264 MockHttpTransactionFactory(net::OrderedSocketData* data) { 271 MockHttpTransactionFactory(net::OrderedSocketData* data) {
265 data_ = data; 272 data_ = data;
266 net::MockConnect connect_data(net::SYNCHRONOUS, net::OK); 273 net::MockConnect connect_data(net::SYNCHRONOUS, net::OK);
267 data_->set_connect_data(connect_data); 274 data_->set_connect_data(connect_data);
268 session_deps_.reset(new SpdySessionDependencies); 275 session_deps_.reset(new SpdySessionDependencies);
(...skipping 19 matching lines...) Expand all
288 net::ClientSocketHandle* connection = new net::ClientSocketHandle; 295 net::ClientSocketHandle* connection = new net::ClientSocketHandle;
289 EXPECT_EQ(net::OK, 296 EXPECT_EQ(net::OK,
290 connection->Init(host_port_pair_.ToString(), transport_params_, 297 connection->Init(host_port_pair_.ToString(), transport_params_,
291 net::MEDIUM, net::CompletionCallback(), 298 net::MEDIUM, net::CompletionCallback(),
292 http_session_->GetTransportSocketPool( 299 http_session_->GetTransportSocketPool(
293 net::HttpNetworkSession::NORMAL_SOCKET_POOL), 300 net::HttpNetworkSession::NORMAL_SOCKET_POOL),
294 net::BoundNetLog())); 301 net::BoundNetLog()));
295 EXPECT_EQ(net::OK, 302 EXPECT_EQ(net::OK,
296 session_->InitializeWithSocket(connection, false, net::OK)); 303 session_->InitializeWithSocket(connection, false, net::OK));
297 } 304 }
298 virtual int CreateTransaction(scoped_ptr<net::HttpTransaction>* trans) { 305
306 virtual int CreateTransaction(
307 scoped_ptr<net::HttpTransaction>* trans) OVERRIDE {
299 NOTREACHED(); 308 NOTREACHED();
300 return net::ERR_UNEXPECTED; 309 return net::ERR_UNEXPECTED;
301 } 310 }
302 virtual net::HttpCache* GetCache() { 311
312 virtual net::HttpCache* GetCache() OVERRIDE {
303 NOTREACHED(); 313 NOTREACHED();
304 return NULL; 314 return NULL;
305 } 315 }
306 virtual net::HttpNetworkSession* GetSession() { 316
317 virtual net::HttpNetworkSession* GetSession() OVERRIDE {
307 return http_session_.get(); 318 return http_session_.get();
308 } 319 }
320
309 private: 321 private:
310 net::OrderedSocketData* data_; 322 net::OrderedSocketData* data_;
311 scoped_ptr<SpdySessionDependencies> session_deps_; 323 scoped_ptr<SpdySessionDependencies> session_deps_;
312 scoped_refptr<net::HttpNetworkSession> http_session_; 324 scoped_refptr<net::HttpNetworkSession> http_session_;
313 scoped_refptr<net::TransportSocketParams> transport_params_; 325 scoped_refptr<net::TransportSocketParams> transport_params_;
314 scoped_refptr<net::SpdySession> session_; 326 scoped_refptr<net::SpdySession> session_;
315 net::HostPortPair host_port_pair_; 327 net::HostPortPair host_port_pair_;
316 net::HostPortProxyPair host_port_proxy_pair_; 328 net::HostPortProxyPair host_port_proxy_pair_;
317 }; 329 };
318 } // namespace 330 } // namespace
319 331
320 namespace net { 332 namespace net {
321 333
322 class WebSocketJobSpdy2Test : public PlatformTest { 334 class WebSocketJobSpdy2Test : public PlatformTest {
323 public: 335 public:
324 virtual void SetUp() { 336 virtual void SetUp() OVERRIDE {
325 SpdySession::set_default_protocol(kProtoSPDY2); 337 SpdySession::set_default_protocol(kProtoSPDY2);
326 stream_type_ = STREAM_INVALID; 338 stream_type_ = STREAM_INVALID;
327 cookie_store_ = new MockCookieStore; 339 cookie_store_ = new MockCookieStore;
328 context_ = new MockURLRequestContext(cookie_store_.get()); 340 context_ = new MockURLRequestContext(cookie_store_.get());
329 } 341 }
330 virtual void TearDown() { 342 virtual void TearDown() OVERRIDE {
331 cookie_store_ = NULL; 343 cookie_store_ = NULL;
332 context_ = NULL; 344 context_ = NULL;
333 websocket_ = NULL; 345 websocket_ = NULL;
334 socket_ = NULL; 346 socket_ = NULL;
335 } 347 }
336 void DoSendRequest() { 348 void DoSendRequest() {
337 EXPECT_TRUE(websocket_->SendData(kHandshakeRequestWithoutCookie, 349 EXPECT_TRUE(websocket_->SendData(kHandshakeRequestWithoutCookie,
338 kHandshakeRequestWithoutCookieLength)); 350 kHandshakeRequestWithoutCookieLength));
339 } 351 }
340 void DoSendData() { 352 void DoSendData() {
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 1109
1098 TEST_F(WebSocketJobSpdy2Test, ThrottlingSpdySpdyEnabled) { 1110 TEST_F(WebSocketJobSpdy2Test, ThrottlingSpdySpdyEnabled) {
1099 WebSocketJob::set_websocket_over_spdy_enabled(true); 1111 WebSocketJob::set_websocket_over_spdy_enabled(true);
1100 TestConnectBySpdy(SPDY_ON, THROTTLING_ON); 1112 TestConnectBySpdy(SPDY_ON, THROTTLING_ON);
1101 } 1113 }
1102 1114
1103 // TODO(toyoshim): Add tests to verify throttling, SPDY stream limitation. 1115 // TODO(toyoshim): Add tests to verify throttling, SPDY stream limitation.
1104 // TODO(toyoshim,yutak): Add tests to verify closing handshake. 1116 // TODO(toyoshim,yutak): Add tests to verify closing handshake.
1105 1117
1106 } // namespace net 1118 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/view_cache_helper_unittest.cc ('k') | net/websockets/websocket_job_spdy3_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698