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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_bypass_rules.h" 5 #include "net/proxy/proxy_bypass_rules.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "net/proxy/proxy_config_service_common_unittest.h" 9 #include "net/proxy/proxy_config_service_common_unittest.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 236
237 EXPECT_FALSE(rules1.Equals(rules2)); 237 EXPECT_FALSE(rules1.Equals(rules2));
238 EXPECT_FALSE(rules2.Equals(rules1)); 238 EXPECT_FALSE(rules2.Equals(rules1));
239 } 239 }
240 240
241 TEST(ProxyBypassRulesTest, BypassLocalNames) { 241 TEST(ProxyBypassRulesTest, BypassLocalNames) {
242 const struct { 242 const struct {
243 const char* url; 243 const char* url;
244 bool expected_is_local; 244 bool expected_is_local;
245 } tests[] = { 245 } tests[] = {
246 // Single-component hostnames are considered local. 246 // Single-component hostnames are considered local.
247 {"http://localhost/x", true}, 247 {"http://localhost/x", true},
248 {"http://www", true}, 248 {"http://www", true},
249 249
250 // IPv4 loopback interface. 250 // IPv4 loopback interface.
251 {"http://127.0.0.1/x", true}, 251 {"http://127.0.0.1/x", true},
252 {"http://127.0.0.1:80/x", true}, 252 {"http://127.0.0.1:80/x", true},
253 253
254 // IPv6 loopback interface. 254 // IPv6 loopback interface.
255 {"http://[::1]:80/x", true}, 255 {"http://[::1]:80/x", true},
256 {"http://[0:0::1]:6233/x", true}, 256 {"http://[0:0::1]:6233/x", true},
257 {"http://[0:0:0:0:0:0:0:1]/x", true}, 257 {"http://[0:0:0:0:0:0:0:1]/x", true},
258 258
259 // Non-local URLs. 259 // Non-local URLs.
260 {"http://foo.com/", false}, 260 {"http://foo.com/", false},
261 {"http://localhost.i/", false}, 261 {"http://localhost.i/", false},
262 {"http://www.google.com/", false}, 262 {"http://www.google.com/", false},
263 {"http://192.168.0.1/", false}, 263 {"http://192.168.0.1/", false},
264 264
265 // Try with different protocols. 265 // Try with different protocols.
266 {"ftp://127.0.0.1/x", true}, 266 {"ftp://127.0.0.1/x", true},
267 {"ftp://foobar.com/x", false}, 267 {"ftp://foobar.com/x", false},
268 268
269 // This is a bit of a gray-area, but GURL does not strip trailing dots 269 // This is a bit of a gray-area, but GURL does not strip trailing dots
270 // in host-names, so the following are considered non-local. 270 // in host-names, so the following are considered non-local.
271 {"http://www./x", false}, 271 {"http://www./x", false},
272 {"http://localhost./x", false}, 272 {"http://localhost./x", false},
273 }; 273 };
274 274
275 ProxyBypassRules rules; 275 ProxyBypassRules rules;
276 rules.ParseFromString("<local>"); 276 rules.ParseFromString("<local>");
277 277
278 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 278 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
279 SCOPED_TRACE(base::StringPrintf( 279 SCOPED_TRACE(
280 "Test[%d]: %s", static_cast<int>(i), tests[i].url)); 280 base::StringPrintf("Test[%d]: %s", static_cast<int>(i), tests[i].url));
281 EXPECT_EQ(tests[i].expected_is_local, rules.Matches(GURL(tests[i].url))); 281 EXPECT_EQ(tests[i].expected_is_local, rules.Matches(GURL(tests[i].url)));
282 } 282 }
283 } 283 }
284 284
285 TEST(ProxyBypassRulesTest, ParseAndMatchCIDR_IPv4) { 285 TEST(ProxyBypassRulesTest, ParseAndMatchCIDR_IPv4) {
286 ProxyBypassRules rules; 286 ProxyBypassRules rules;
287 rules.ParseFromString("192.168.1.1/16"); 287 rules.ParseFromString("192.168.1.1/16");
288 ASSERT_EQ(1u, rules.rules().size()); 288 ASSERT_EQ(1u, rules.rules().size());
289 EXPECT_EQ("192.168.1.1/16", rules.rules()[0]->ToString()); 289 EXPECT_EQ("192.168.1.1/16", rules.rules()[0]->ToString());
290 290
(...skipping 15 matching lines...) Expand all
306 EXPECT_EQ("a:b:c:d::/48", rules.rules()[0]->ToString()); 306 EXPECT_EQ("a:b:c:d::/48", rules.rules()[0]->ToString());
307 307
308 EXPECT_TRUE(rules.Matches(GURL("http://[A:b:C:9::]"))); 308 EXPECT_TRUE(rules.Matches(GURL("http://[A:b:C:9::]")));
309 EXPECT_FALSE(rules.Matches(GURL("http://foobar.com"))); 309 EXPECT_FALSE(rules.Matches(GURL("http://foobar.com")));
310 EXPECT_FALSE(rules.Matches(GURL("http://192.169.1.1"))); 310 EXPECT_FALSE(rules.Matches(GURL("http://192.169.1.1")));
311 } 311 }
312 312
313 } // namespace 313 } // namespace
314 314
315 } // namespace net 315 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698