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

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

Issue 1680893002: Moving proxy resolution logic out of NetworkDelegate and into ProxyDelegate for DataReductionProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased change Created 4 years, 10 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 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 #include <string> 12 #include <string>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/bind_helpers.h" 15 #include "base/bind_helpers.h"
16 #include "base/callback.h" 16 #include "base/callback.h"
17 #include "base/location.h" 17 #include "base/location.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
20 #include "base/run_loop.h" 20 #include "base/run_loop.h"
21 #include "base/single_thread_task_runner.h" 21 #include "base/single_thread_task_runner.h"
22 #include "base/strings/string_piece.h" 22 #include "base/strings/string_piece.h"
23 #include "base/thread_task_runner_handle.h" 23 #include "base/thread_task_runner_handle.h"
24 #include "net/base/auth.h" 24 #include "net/base/auth.h"
25 #include "net/base/network_delegate.h" 25 #include "net/base/proxy_delegate.h"
26 #include "net/base/test_data_directory.h" 26 #include "net/base/test_data_directory.h"
27 #include "net/proxy/proxy_service.h" 27 #include "net/proxy/proxy_service.h"
28 #include "net/test/embedded_test_server/embedded_test_server.h" 28 #include "net/test/embedded_test_server/embedded_test_server.h"
29 #include "net/test/spawned_test_server/spawned_test_server.h" 29 #include "net/test/spawned_test_server/spawned_test_server.h"
30 #include "net/url_request/url_request_test_util.h" 30 #include "net/url_request/url_request_test_util.h"
31 #include "net/websockets/websocket_channel.h" 31 #include "net/websockets/websocket_channel.h"
32 #include "net/websockets/websocket_event_interface.h" 32 #include "net/websockets/websocket_event_interface.h"
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 #include "url/origin.h" 34 #include "url/origin.h"
35 35
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 ERR_SSL_PROTOCOL_ERROR, &ssl_info)); 188 ERR_SSL_PROTOCOL_ERROR, &ssl_info));
189 return CHANNEL_ALIVE; 189 return CHANNEL_ALIVE;
190 } 190 }
191 191
192 void ConnectTestingEventInterface::QuitNestedEventLoop() { 192 void ConnectTestingEventInterface::QuitNestedEventLoop() {
193 run_loop_.Quit(); 193 run_loop_.Quit();
194 } 194 }
195 195
196 // A subclass of TestNetworkDelegate that additionally implements the 196 // A subclass of TestNetworkDelegate that additionally implements the
197 // OnResolveProxy callback and records the information passed to it. 197 // OnResolveProxy callback and records the information passed to it.
198 class TestNetworkDelegateWithProxyInfo : public TestNetworkDelegate { 198 class TestProxyDelegateWithProxyInfo : public ProxyDelegate {
199 public: 199 public:
200 TestNetworkDelegateWithProxyInfo() {} 200 TestProxyDelegateWithProxyInfo() {}
201 201
202 struct ResolvedProxyInfo { 202 struct ResolvedProxyInfo {
203 GURL url; 203 GURL url;
204 ProxyInfo proxy_info; 204 ProxyInfo proxy_info;
205 }; 205 };
206 206
207 const ResolvedProxyInfo& resolved_proxy_info() const { 207 const ResolvedProxyInfo& resolved_proxy_info() const {
208 return resolved_proxy_info_; 208 return resolved_proxy_info_;
209 } 209 }
210 210
211 protected: 211 protected:
212 void OnResolveProxy(const GURL& url, 212 void OnResolveProxy(const GURL& url,
213 int load_flags, 213 int load_flags,
214 const ProxyService& proxy_service, 214 const ProxyService& proxy_service,
215 ProxyInfo* result) override { 215 ProxyInfo* result) override {
216 resolved_proxy_info_.url = url; 216 resolved_proxy_info_.url = url;
217 resolved_proxy_info_.proxy_info = *result; 217 resolved_proxy_info_.proxy_info = *result;
218 } 218 }
219 219
220 void OnTunnelConnectCompleted(const HostPortPair& endpoint,
221 const HostPortPair& proxy_server,
222 int net_error) override {}
223 void OnFallback(const ProxyServer& bad_proxy, int net_error) override {}
224 void OnBeforeSendHeaders(URLRequest* request,
225 const ProxyInfo& proxy_info,
226 HttpRequestHeaders* headers) override {}
227 void OnBeforeTunnelRequest(const HostPortPair& proxy_server,
228 HttpRequestHeaders* extra_headers) override {}
229 void OnTunnelHeadersReceived(
230 const HostPortPair& origin,
231 const HostPortPair& proxy_server,
232 const HttpResponseHeaders& response_headers) override {}
233 bool IsTrustedSpdyProxy(const net::ProxyServer& proxy_server) override {
234 return true;
235 }
236
220 private: 237 private:
221 ResolvedProxyInfo resolved_proxy_info_; 238 ResolvedProxyInfo resolved_proxy_info_;
222 239
223 DISALLOW_COPY_AND_ASSIGN(TestNetworkDelegateWithProxyInfo); 240 DISALLOW_COPY_AND_ASSIGN(TestProxyDelegateWithProxyInfo);
224 }; 241 };
225 242
226 class WebSocketEndToEndTest : public ::testing::Test { 243 class WebSocketEndToEndTest : public ::testing::Test {
227 protected: 244 protected:
228 WebSocketEndToEndTest() 245 WebSocketEndToEndTest()
229 : event_interface_(), 246 : event_interface_(),
230 network_delegate_(new TestNetworkDelegateWithProxyInfo), 247 proxy_delegate_(new TestProxyDelegateWithProxyInfo),
231 context_(true), 248 context_(true),
232 channel_(), 249 channel_(),
233 initialised_context_(false) {} 250 initialised_context_(false) {}
234 251
235 // Initialise the URLRequestContext. Normally done automatically by 252 // Initialise the URLRequestContext. Normally done automatically by
236 // ConnectAndWait(). This method is for the use of tests that need the 253 // ConnectAndWait(). This method is for the use of tests that need the
237 // URLRequestContext initialised before calling ConnectAndWait(). 254 // URLRequestContext initialised before calling ConnectAndWait().
238 void InitialiseContext() { 255 void InitialiseContext() {
239 context_.set_network_delegate(network_delegate_.get()); 256 context_.set_proxy_delegate(proxy_delegate_.get());
240 context_.Init(); 257 context_.Init();
241 initialised_context_ = true; 258 initialised_context_ = true;
242 } 259 }
243 260
244 // Send the connect request to |socket_url| and wait for a response. Returns 261 // Send the connect request to |socket_url| and wait for a response. Returns
245 // true if the handshake succeeded. 262 // true if the handshake succeeded.
246 bool ConnectAndWait(const GURL& socket_url) { 263 bool ConnectAndWait(const GURL& socket_url) {
247 if (!initialised_context_) { 264 if (!initialised_context_) {
248 InitialiseContext(); 265 InitialiseContext();
249 } 266 }
250 url::Origin origin(GURL("http://localhost")); 267 url::Origin origin(GURL("http://localhost"));
251 event_interface_ = new ConnectTestingEventInterface; 268 event_interface_ = new ConnectTestingEventInterface;
252 channel_.reset( 269 channel_.reset(
253 new WebSocketChannel(make_scoped_ptr(event_interface_), &context_)); 270 new WebSocketChannel(make_scoped_ptr(event_interface_), &context_));
254 channel_->SendAddChannelRequest(GURL(socket_url), sub_protocols_, origin); 271 channel_->SendAddChannelRequest(GURL(socket_url), sub_protocols_, origin);
255 event_interface_->WaitForResponse(); 272 event_interface_->WaitForResponse();
256 return !event_interface_->failed(); 273 return !event_interface_->failed();
257 } 274 }
258 275
259 ConnectTestingEventInterface* event_interface_; // owned by channel_ 276 ConnectTestingEventInterface* event_interface_; // owned by channel_
260 scoped_ptr<TestNetworkDelegateWithProxyInfo> network_delegate_; 277 scoped_ptr<TestProxyDelegateWithProxyInfo> proxy_delegate_;
261 TestURLRequestContext context_; 278 TestURLRequestContext context_;
262 scoped_ptr<WebSocketChannel> channel_; 279 scoped_ptr<WebSocketChannel> channel_;
263 std::vector<std::string> sub_protocols_; 280 std::vector<std::string> sub_protocols_;
264 bool initialised_context_; 281 bool initialised_context_;
265 }; 282 };
266 283
267 // None of these tests work on Android. 284 // None of these tests work on Android.
268 // TODO(ricea): Make these tests work on Android. See crbug.com/441711. 285 // TODO(ricea): Make these tests work on Android. See crbug.com/441711.
269 #if defined(OS_ANDROID) 286 #if defined(OS_ANDROID)
270 #define DISABLED_ON_ANDROID(test) DISABLED_##test 287 #define DISABLED_ON_ANDROID(test) DISABLED_##test
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 context_.CreateRequest(http_page, DEFAULT_PRIORITY, &delegate)); 379 context_.CreateRequest(http_page, DEFAULT_PRIORITY, &delegate));
363 request->Start(); 380 request->Start();
364 // TestDelegate exits the message loop when the request completes by 381 // TestDelegate exits the message loop when the request completes by
365 // default. 382 // default.
366 base::RunLoop().Run(); 383 base::RunLoop().Run();
367 EXPECT_TRUE(delegate.auth_required_called()); 384 EXPECT_TRUE(delegate.auth_required_called());
368 } 385 }
369 386
370 GURL ws_url = ws_server.GetURL(kEchoServer); 387 GURL ws_url = ws_server.GetURL(kEchoServer);
371 EXPECT_TRUE(ConnectAndWait(ws_url)); 388 EXPECT_TRUE(ConnectAndWait(ws_url));
372 const TestNetworkDelegateWithProxyInfo::ResolvedProxyInfo& info = 389 const TestProxyDelegateWithProxyInfo::ResolvedProxyInfo& info =
373 network_delegate_->resolved_proxy_info(); 390 proxy_delegate_->resolved_proxy_info();
374 EXPECT_EQ(ws_url, info.url); 391 EXPECT_EQ(ws_url, info.url);
375 EXPECT_TRUE(info.proxy_info.is_http()); 392 EXPECT_TRUE(info.proxy_info.is_http());
376 } 393 }
377 394
378 // This is a regression test for crbug.com/408061 Crash in 395 // This is a regression test for crbug.com/408061 Crash in
379 // net::WebSocketBasicHandshakeStream::Upgrade. 396 // net::WebSocketBasicHandshakeStream::Upgrade.
380 TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(TruncatedResponse)) { 397 TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(TruncatedResponse)) {
381 SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS, 398 SpawnedTestServer ws_server(SpawnedTestServer::TYPE_WS,
382 SpawnedTestServer::kLocalhost, 399 SpawnedTestServer::kLocalhost,
383 GetWebSocketTestDataDirectory()); 400 GetWebSocketTestDataDirectory());
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 GURL ws_url = ws_server.GetURL("header-continuation"); 510 GURL ws_url = ws_server.GetURL("header-continuation");
494 511
495 EXPECT_TRUE(ConnectAndWait(ws_url)); 512 EXPECT_TRUE(ConnectAndWait(ws_url));
496 EXPECT_EQ("permessage-deflate; server_max_window_bits=10", 513 EXPECT_EQ("permessage-deflate; server_max_window_bits=10",
497 event_interface_->extensions()); 514 event_interface_->extensions());
498 } 515 }
499 516
500 } // namespace 517 } // namespace
501 518
502 } // namespace net 519 } // namespace net
OLDNEW
« net/proxy/proxy_service_unittest.cc ('K') | « net/url_request/url_request_test_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698