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

Side by Side Diff: url/gurl_unittest.cc

Issue 1270443006: Proof-read comments in src/url/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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
« url/gurl.h ('K') | « url/gurl.cc ('k') | url/origin.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/macros.h" 5 #include "base/macros.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "url/gurl.h" 7 #include "url/gurl.h"
8 #include "url/url_canon.h" 8 #include "url/url_canon.h"
9 #include "url/url_test_utils.h" 9 #include "url/url_test_utils.h"
10 10
(...skipping 27 matching lines...) Expand all
38 } // namespace 38 } // namespace
39 39
40 // Different types of URLs should be handled differently, and handed off to 40 // Different types of URLs should be handled differently, and handed off to
41 // different canonicalizers. 41 // different canonicalizers.
42 TEST(GURLTest, Types) { 42 TEST(GURLTest, Types) {
43 // URLs with unknown schemes should be treated as path URLs, even when they 43 // URLs with unknown schemes should be treated as path URLs, even when they
44 // have things like "://". 44 // have things like "://".
45 EXPECT_EQ("something:///HOSTNAME.com/", 45 EXPECT_EQ("something:///HOSTNAME.com/",
46 TypesTestCase("something:///HOSTNAME.com/")); 46 TypesTestCase("something:///HOSTNAME.com/"));
47 47
48 // In the reverse, known schemes should always trigger standard URL handling. 48 // Conversely, URLs with known schemes should always trigger standard URL
49 // handling.
49 EXPECT_EQ("http://hostname.com/", TypesTestCase("http:HOSTNAME.com")); 50 EXPECT_EQ("http://hostname.com/", TypesTestCase("http:HOSTNAME.com"));
50 EXPECT_EQ("http://hostname.com/", TypesTestCase("http:/HOSTNAME.com")); 51 EXPECT_EQ("http://hostname.com/", TypesTestCase("http:/HOSTNAME.com"));
51 EXPECT_EQ("http://hostname.com/", TypesTestCase("http://HOSTNAME.com")); 52 EXPECT_EQ("http://hostname.com/", TypesTestCase("http://HOSTNAME.com"));
52 EXPECT_EQ("http://hostname.com/", TypesTestCase("http:///HOSTNAME.com")); 53 EXPECT_EQ("http://hostname.com/", TypesTestCase("http:///HOSTNAME.com"));
53 54
54 #ifdef WIN32 55 #ifdef WIN32
55 // URLs that look like absolute Windows drive specs. 56 // URLs that look like Windows absolute path specs.
56 EXPECT_EQ("file:///C:/foo.txt", TypesTestCase("c:\\foo.txt")); 57 EXPECT_EQ("file:///C:/foo.txt", TypesTestCase("c:\\foo.txt"));
57 EXPECT_EQ("file:///Z:/foo.txt", TypesTestCase("Z|foo.txt")); 58 EXPECT_EQ("file:///Z:/foo.txt", TypesTestCase("Z|foo.txt"));
58 EXPECT_EQ("file://server/foo.txt", TypesTestCase("\\\\server\\foo.txt")); 59 EXPECT_EQ("file://server/foo.txt", TypesTestCase("\\\\server\\foo.txt"));
59 EXPECT_EQ("file://server/foo.txt", TypesTestCase("//server/foo.txt")); 60 EXPECT_EQ("file://server/foo.txt", TypesTestCase("//server/foo.txt"));
60 #endif 61 #endif
61 } 62 }
62 63
63 // Test the basic creation and querying of components in a GURL. We assume 64 // Test the basic creation and querying of components in a GURL. We assume that
64 // the parser is already tested and works, so we are mostly interested if the 65 // the parser is already tested and works, so we are mostly interested if the
65 // object does the right thing with the results. 66 // object does the right thing with the results.
66 TEST(GURLTest, Components) { 67 TEST(GURLTest, Components) {
67 GURL url(WStringToUTF16(L"http://user:pass@google.com:99/foo;bar?q=a#ref")); 68 GURL url(WStringToUTF16(L"http://user:pass@google.com:99/foo;bar?q=a#ref"));
68 EXPECT_TRUE(url.is_valid()); 69 EXPECT_TRUE(url.is_valid());
69 EXPECT_TRUE(url.SchemeIs("http")); 70 EXPECT_TRUE(url.SchemeIs("http"));
70 EXPECT_FALSE(url.SchemeIsFile()); 71 EXPECT_FALSE(url.SchemeIsFile());
71 72
72 // This is the narrow version of the URL, which should match the wide input. 73 // This is the narrow version of the URL, which should match the wide input.
73 EXPECT_EQ("http://user:pass@google.com:99/foo;bar?q=a#ref", url.spec()); 74 EXPECT_EQ("http://user:pass@google.com:99/foo;bar?q=a#ref", url.spec());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 EXPECT_EQ("", invalid2.username()); 169 EXPECT_EQ("", invalid2.username());
169 EXPECT_EQ("", invalid2.password()); 170 EXPECT_EQ("", invalid2.password());
170 EXPECT_EQ("", invalid2.host()); 171 EXPECT_EQ("", invalid2.host());
171 EXPECT_EQ("", invalid2.port()); 172 EXPECT_EQ("", invalid2.port());
172 EXPECT_EQ(PORT_UNSPECIFIED, invalid2.IntPort()); 173 EXPECT_EQ(PORT_UNSPECIFIED, invalid2.IntPort());
173 EXPECT_EQ("", invalid2.path()); 174 EXPECT_EQ("", invalid2.path());
174 EXPECT_EQ("", invalid2.query()); 175 EXPECT_EQ("", invalid2.query());
175 EXPECT_EQ("", invalid2.ref()); 176 EXPECT_EQ("", invalid2.ref());
176 } 177 }
177 178
178 // This is a regression test for http://crbug.com/309975 . 179 // This is a regression test for http://crbug.com/309975.
179 TEST(GURLTest, SelfAssign) { 180 TEST(GURLTest, SelfAssign) {
180 GURL a("filesystem:http://example.com/temporary/"); 181 GURL a("filesystem:http://example.com/temporary/");
181 // This should not crash. 182 // This should not crash.
182 a = a; 183 a = a;
183 } 184 }
184 185
185 TEST(GURLTest, CopyFileSystem) { 186 TEST(GURLTest, CopyFileSystem) {
186 GURL url(WStringToUTF16(L"filesystem:https://user:pass@google.com:99/t/foo;bar ?q=a#ref")); 187 GURL url(WStringToUTF16(L"filesystem:https://user:pass@google.com:99/t/foo;bar ?q=a#ref"));
187 188
188 GURL url2(url); 189 GURL url2(url);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 "http://google.com:12three45", 239 "http://google.com:12three45",
239 "path", 240 "path",
240 }; 241 };
241 for (size_t i = 0; i < arraysize(invalid_cases); i++) { 242 for (size_t i = 0; i < arraysize(invalid_cases); i++) {
242 EXPECT_FALSE(GURL(invalid_cases[i]).is_valid()) 243 EXPECT_FALSE(GURL(invalid_cases[i]).is_valid())
243 << "Case: " << invalid_cases[i]; 244 << "Case: " << invalid_cases[i];
244 } 245 }
245 } 246 }
246 247
247 TEST(GURLTest, ExtraSlashesBeforeAuthority) { 248 TEST(GURLTest, ExtraSlashesBeforeAuthority) {
248 // According to RFC3986, the hier-part for URI with an authority must use only 249 // According to RFC3986, the hierarchical part for URI with an authority
249 // two slashes, GURL intentionally just ignores slashes more than 2 and parses 250 // must use only two slashes; GURL intentionally just ignores extra slashes
250 // the following part as an authority. 251 // if there are more than 2, and parses the following part as an authority.
251 GURL url("http:///host"); 252 GURL url("http:///host");
252 EXPECT_EQ("host", url.host()); 253 EXPECT_EQ("host", url.host());
253 EXPECT_EQ("/", url.path()); 254 EXPECT_EQ("/", url.path());
254 } 255 }
255 256
256 // Given an invalid URL, we should still get most of the components. 257 // Given an invalid URL, we should still get most of the components.
257 TEST(GURLTest, ComponentGettersWorkEvenForInvalidURL) { 258 TEST(GURLTest, ComponentGettersWorkEvenForInvalidURL) {
258 GURL url("http:google.com:foo"); 259 GURL url("http:google.com:foo");
259 EXPECT_FALSE(url.is_valid()); 260 EXPECT_FALSE(url.is_valid());
260 EXPECT_EQ("http://google.com:foo/", url.possibly_invalid_spec()); 261 EXPECT_EQ("http://google.com:foo/", url.possibly_invalid_spec());
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 }; 372 };
372 373
373 for (size_t i = 0; i < arraysize(cases); i++) { 374 for (size_t i = 0; i < arraysize(cases); i++) {
374 GURL url(cases[i].input); 375 GURL url(cases[i].input);
375 GURL empty_path = url.GetWithEmptyPath(); 376 GURL empty_path = url.GetWithEmptyPath();
376 EXPECT_EQ(cases[i].expected, empty_path.spec()); 377 EXPECT_EQ(cases[i].expected, empty_path.spec());
377 } 378 }
378 } 379 }
379 380
380 TEST(GURLTest, Replacements) { 381 TEST(GURLTest, Replacements) {
381 // The url canonicalizer replacement test will handle most of these case. 382 // The URL canonicalizer replacement test will handle most of these case.
382 // The most important thing to do here is to check that the proper 383 // The most important thing to do here is to check that the proper
383 // canonicalizer gets called based on the scheme of the input. 384 // canonicalizer gets called based on the scheme of the input.
384 struct ReplaceCase { 385 struct ReplaceCase {
385 const char* base; 386 const char* base;
386 const char* scheme; 387 const char* scheme;
387 const char* username; 388 const char* username;
388 const char* password; 389 const char* password;
389 const char* host; 390 const char* host;
390 const char* port; 391 const char* port;
391 const char* path; 392 const char* path;
392 const char* query; 393 const char* query;
393 const char* ref; 394 const char* ref;
394 const char* expected; 395 const char* expected;
395 } replace_cases[] = { 396 } replace_cases[] = {
396 {"http://www.google.com/foo/bar.html?foo#bar", NULL, NULL, NULL, NULL, NULL, "/", "", "", "http://www.google.com/"}, 397 {"http://www.google.com/foo/bar.html?foo#bar", NULL, NULL, NULL, NULL, NULL, "/", "", "", "http://www.google.com/"},
397 {"http://www.google.com/foo/bar.html?foo#bar", "javascript", "", "", "", "", "window.open('foo');", "", "", "javascript:window.open('foo');"}, 398 {"http://www.google.com/foo/bar.html?foo#bar", "javascript", "", "", "", "", "window.open('foo');", "", "", "javascript:window.open('foo');"},
398 {"file:///C:/foo/bar.txt", "http", NULL, NULL, "www.google.com", "99", "/foo ","search", "ref", "http://www.google.com:99/foo?search#ref"}, 399 {"file:///C:/foo/bar.txt", "http", NULL, NULL, "www.google.com", "99", "/foo ", "search", "ref", "http://www.google.com:99/foo?search#ref"},
399 #ifdef WIN32 400 #ifdef WIN32
400 {"http://www.google.com/foo/bar.html?foo#bar", "file", "", "", "", "", "c:\\ ", "", "", "file:///C:/"}, 401 {"http://www.google.com/foo/bar.html?foo#bar", "file", "", "", "", "", "c:\\ ", "", "", "file:///C:/"},
401 #endif 402 #endif
402 {"filesystem:http://www.google.com/foo/bar.html?foo#bar", NULL, NULL, NULL, NULL, NULL, "/", "", "", "filesystem:http://www.google.com/foo/"}, 403 {"filesystem:http://www.google.com/foo/bar.html?foo#bar", NULL, NULL, NULL, NULL, NULL, "/", "", "", "filesystem:http://www.google.com/foo/"},
403 }; 404 };
404 405
405 for (size_t i = 0; i < arraysize(replace_cases); i++) { 406 for (size_t i = 0; i < arraysize(replace_cases); i++) {
406 const ReplaceCase& cur = replace_cases[i]; 407 const ReplaceCase& cur = replace_cases[i];
407 GURL url(cur.base); 408 GURL url(cur.base);
408 GURL::Replacements repl; 409 GURL::Replacements repl;
(...skipping 19 matching lines...) Expand all
428 GURL url(" data: one ? two # three "); 429 GURL url(" data: one ? two # three ");
429 430
430 // By default the trailing whitespace will have been stripped. 431 // By default the trailing whitespace will have been stripped.
431 EXPECT_EQ("data: one ? two # three", url.spec()); 432 EXPECT_EQ("data: one ? two # three", url.spec());
432 GURL::Replacements repl; 433 GURL::Replacements repl;
433 repl.ClearRef(); 434 repl.ClearRef();
434 GURL url_no_ref = url.ReplaceComponents(repl); 435 GURL url_no_ref = url.ReplaceComponents(repl);
435 436
436 EXPECT_EQ("data: one ? two ", url_no_ref.spec()); 437 EXPECT_EQ("data: one ? two ", url_no_ref.spec());
437 438
438 // Importing a parsed url via this constructor overload will retain trailing 439 // Importing a parsed URL via this constructor overload will retain trailing
439 // whitespace. 440 // whitespace.
440 GURL import_url(url_no_ref.spec(), 441 GURL import_url(url_no_ref.spec(),
441 url_no_ref.parsed_for_possibly_invalid_spec(), 442 url_no_ref.parsed_for_possibly_invalid_spec(),
442 url_no_ref.is_valid()); 443 url_no_ref.is_valid());
443 EXPECT_EQ(url_no_ref, import_url); 444 EXPECT_EQ(url_no_ref, import_url);
444 EXPECT_EQ(import_url.query(), " two "); 445 EXPECT_EQ(import_url.query(), " two ");
445 } 446 }
446 447
447 TEST(GURLTest, PathForRequest) { 448 TEST(GURLTest, PathForRequest) {
448 struct TestCase { 449 struct TestCase {
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 }; 675 };
675 676
676 for (const auto& test : cases) { 677 for (const auto& test : cases) {
677 GURL url(test.url); 678 GURL url(test.url);
678 EXPECT_EQ(test.expected, url.path()) << test.url; 679 EXPECT_EQ(test.expected, url.path()) << test.url;
679 EXPECT_EQ(test.expected, url.GetContent()) << test.url; 680 EXPECT_EQ(test.expected, url.GetContent()) << test.url;
680 } 681 }
681 } 682 }
682 683
683 } // namespace url 684 } // namespace url
OLDNEW
« url/gurl.h ('K') | « url/gurl.cc ('k') | url/origin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698