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

Side by Side Diff: net/proxy/proxy_config_unittest.cc

Issue 710623002: Merge to M39: Correct manual proxy selection for WebSockets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2171
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « net/proxy/proxy_config.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/proxy/proxy_config.h" 5 #include "net/proxy/proxy_config.h"
6 #include "net/proxy/proxy_config_service_common_unittest.h" 6 #include "net/proxy/proxy_config_service_common_unittest.h"
7 #include "net/proxy/proxy_info.h" 7 #include "net/proxy/proxy_info.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace net { 10 namespace net {
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 346
347 rules.Apply(GURL("http://example.org"), &result); 347 rules.Apply(GURL("http://example.org"), &result);
348 EXPECT_TRUE(result.is_direct_only()); 348 EXPECT_TRUE(result.is_direct_only());
349 EXPECT_TRUE(result.did_bypass_proxy()); 349 EXPECT_TRUE(result.did_bypass_proxy());
350 350
351 rules.Apply(GURL("http://example.com"), &result); 351 rules.Apply(GURL("http://example.com"), &result);
352 EXPECT_FALSE(result.is_direct()); 352 EXPECT_FALSE(result.is_direct());
353 EXPECT_FALSE(result.did_bypass_proxy()); 353 EXPECT_FALSE(result.did_bypass_proxy());
354 } 354 }
355 355
356 static const char kWsUrl[] = "ws://example.com/echo";
357 static const char kWssUrl[] = "wss://example.com/echo";
358
359 class ProxyConfigWebSocketTest : public ::testing::Test {
360 protected:
361 void ParseFromString(const std::string& rules) {
362 rules_.ParseFromString(rules);
363 }
364 void Apply(const GURL& gurl) { rules_.Apply(gurl, &info_); }
365 std::string ToPacString() const { return info_.ToPacString(); }
366
367 static GURL WsUrl() { return GURL(kWsUrl); }
368 static GURL WssUrl() { return GURL(kWssUrl); }
369
370 ProxyConfig::ProxyRules rules_;
371 ProxyInfo info_;
372 };
373
374 // If a single proxy is set for all protocols, WebSocket uses it.
375 TEST_F(ProxyConfigWebSocketTest, UsesProxy) {
376 ParseFromString("proxy:3128");
377 Apply(WsUrl());
378 EXPECT_EQ("PROXY proxy:3128", ToPacString());
379 }
380
381 // See RFC6455 Section 4.1. item 3, "_Proxy Usage_".
382 TEST_F(ProxyConfigWebSocketTest, PrefersSocks) {
383 ParseFromString(
384 "http=proxy:3128 ; https=sslproxy:3128 ; socks=socksproxy:1080");
385 Apply(WsUrl());
386 EXPECT_EQ("SOCKS socksproxy:1080", ToPacString());
387 }
388
389 TEST_F(ProxyConfigWebSocketTest, PrefersHttpsToHttp) {
390 ParseFromString("http=proxy:3128 ; https=sslproxy:3128");
391 Apply(WssUrl());
392 EXPECT_EQ("PROXY sslproxy:3128", ToPacString());
393 }
394
395 TEST_F(ProxyConfigWebSocketTest, PrefersHttpsEvenForWs) {
396 ParseFromString("http=proxy:3128 ; https=sslproxy:3128");
397 Apply(WsUrl());
398 EXPECT_EQ("PROXY sslproxy:3128", ToPacString());
399 }
400
401 TEST_F(ProxyConfigWebSocketTest, PrefersHttpToDirect) {
402 ParseFromString("http=proxy:3128");
403 Apply(WssUrl());
404 EXPECT_EQ("PROXY proxy:3128", ToPacString());
405 }
406
407 TEST_F(ProxyConfigWebSocketTest, IgnoresFtpProxy) {
408 ParseFromString("ftp=ftpproxy:3128");
409 Apply(WssUrl());
410 EXPECT_EQ("DIRECT", ToPacString());
411 }
412
413 TEST_F(ProxyConfigWebSocketTest, ObeysBypassRules) {
414 ParseFromString("http=proxy:3128 ; https=sslproxy:3128");
415 rules_.bypass_rules.AddRuleFromString(".chromium.org");
416 Apply(GURL("wss://codereview.chromium.org/feed"));
417 EXPECT_EQ("DIRECT", ToPacString());
418 }
419
420 TEST_F(ProxyConfigWebSocketTest, ObeysLocalBypass) {
421 ParseFromString("http=proxy:3128 ; https=sslproxy:3128");
422 rules_.bypass_rules.AddRuleFromString("<local>");
423 Apply(GURL("ws://localhost/feed"));
424 EXPECT_EQ("DIRECT", ToPacString());
425 }
426
356 } // namespace 427 } // namespace
357 } // namespace net 428 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_config.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698