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

Side by Side Diff: src/gurl_unittest.cc

Issue 113187: GURL: add a HostNoBrackets() method for bracketless IPv6 literals. (Closed) Base URL: http://google-url.googlecode.com/svn/trunk/
Patch Set: '' Created 11 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
« no previous file with comments | « src/gurl.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 2007 Google Inc. All Rights Reserved. 1 // Copyright 2007 Google Inc. All Rights Reserved.
2 // Author: brettw@google.com (Brett Wilson) 2 // Author: brettw@google.com (Brett Wilson)
3 3
4 #include "googleurl/src/gurl.h" 4 #include "googleurl/src/gurl.h"
5 #include "googleurl/src/url_canon.h" 5 #include "googleurl/src/url_canon.h"
6 #include "googleurl/src/url_test_utils.h" 6 #include "googleurl/src/url_test_utils.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 // Some implementations of base/basictypes.h may define ARRAYSIZE. 9 // Some implementations of base/basictypes.h may define ARRAYSIZE.
10 // If it's not defined, we define it to the ARRAYSIZE_UNSAFE macro 10 // If it's not defined, we define it to the ARRAYSIZE_UNSAFE macro
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 329
330 TEST(GURLTest, IPAddress) { 330 TEST(GURLTest, IPAddress) {
331 struct IPTest { 331 struct IPTest {
332 const char* spec; 332 const char* spec;
333 bool expected_ip; 333 bool expected_ip;
334 } ip_tests[] = { 334 } ip_tests[] = {
335 {"http://www.google.com/", false}, 335 {"http://www.google.com/", false},
336 {"http://192.168.9.1/", true}, 336 {"http://192.168.9.1/", true},
337 {"http://192.168.9.1.2/", false}, 337 {"http://192.168.9.1.2/", false},
338 {"http://192.168.m.1/", false}, 338 {"http://192.168.m.1/", false},
339 {"http://2001:db8::1/", false},
340 {"http://[2001:db8::1]/", true},
339 {"", false}, 341 {"", false},
340 {"some random input!", false}, 342 {"some random input!", false},
341 }; 343 };
342 344
343 for (size_t i = 0; i < ARRAYSIZE(ip_tests); i++) { 345 for (size_t i = 0; i < ARRAYSIZE(ip_tests); i++) {
344 GURL url(ip_tests[i].spec); 346 GURL url(ip_tests[i].spec);
345 EXPECT_EQ(ip_tests[i].expected_ip, url.HostIsIPAddress()); 347 EXPECT_EQ(ip_tests[i].expected_ip, url.HostIsIPAddress());
346 } 348 }
347 } 349 }
348 350
351 TEST(GURLTest, HostNoBrackets) {
352 struct TestCase {
353 const char* input;
354 const char* expected_host;
355 const char* expected_plainhost;
356 } cases[] = {
357 {"http://www.google.com", "www.google.com", "www.google.com"},
358 {"http://[2001:db8::1]/", "[2001:db8::1]", "2001:db8::1"},
359 {"http://[::]/", "[::]", "::"},
360
361 // Don't require a valid URL, but don't crash either.
362 {"http://[]/", "[]", ""},
363 {"http://[x]/", "[x]", "x"},
364 {"http://[x/", "[x", "[x"},
365 {"http://x]/", "x]", "x]"},
366 {"http://[/", "[", "["},
367 {"http://]/", "]", "]"},
368 {"", "", ""},
369 };
370 for (size_t i = 0; i < ARRAYSIZE(cases); i++) {
371 GURL url(cases[i].input);
372 EXPECT_EQ(cases[i].expected_host, url.host());
373 EXPECT_EQ(cases[i].expected_plainhost, url.HostNoBrackets());
374 }
375 }
376
349 TEST(GURLTest, DomainIs) { 377 TEST(GURLTest, DomainIs) {
350 const char google_domain[] = "google.com"; 378 const char google_domain[] = "google.com";
351 379
352 GURL url_1("http://www.google.com:99/foo"); 380 GURL url_1("http://www.google.com:99/foo");
353 EXPECT_TRUE(url_1.DomainIs(google_domain)); 381 EXPECT_TRUE(url_1.DomainIs(google_domain));
354 382
355 GURL url_2("http://google.com:99/foo"); 383 GURL url_2("http://google.com:99/foo");
356 EXPECT_TRUE(url_2.DomainIs(google_domain)); 384 EXPECT_TRUE(url_2.DomainIs(google_domain));
357 385
358 GURL url_3("http://google.com./foo"); 386 GURL url_3("http://google.com./foo");
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 TEST(GURLTest, IsStandard) { 424 TEST(GURLTest, IsStandard) {
397 GURL a("http:foo/bar"); 425 GURL a("http:foo/bar");
398 EXPECT_TRUE(a.IsStandard()); 426 EXPECT_TRUE(a.IsStandard());
399 427
400 GURL b("foo:bar/baz"); 428 GURL b("foo:bar/baz");
401 EXPECT_FALSE(b.IsStandard()); 429 EXPECT_FALSE(b.IsStandard());
402 430
403 GURL c("foo://bar/baz"); 431 GURL c("foo://bar/baz");
404 EXPECT_TRUE(c.IsStandard()); 432 EXPECT_TRUE(c.IsStandard());
405 } 433 }
OLDNEW
« no previous file with comments | « src/gurl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698