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
3 // found in the LICENSE file.
5 #include "base/macros.h"
6 #include "testing/gtest/include/gtest/gtest.h"
8 #include "url/url_canon.h"
9 #include "url/url_test_utils.h"
13 using test_utils::WStringToUTF16
;
14 using test_utils::ConvertUTF8ToUTF16
;
18 template<typename CHAR
>
19 void SetupReplacement(
20 void (Replacements
<CHAR
>::*func
)(const CHAR
*, const Component
&),
21 Replacements
<CHAR
>* replacements
,
26 comp
.len
= static_cast<int>(strlen(str
));
27 (replacements
->*func
)(str
, comp
);
31 // Returns the canonicalized string for the given URL string for the
32 // GURLTest.Types test.
33 std::string
TypesTestCase(const char* src
) {
35 return gurl
.possibly_invalid_spec();
40 // Different types of URLs should be handled differently, and handed off to
41 // different canonicalizers.
42 TEST(GURLTest
, Types
) {
43 // URLs with unknown schemes should be treated as path URLs, even when they
44 // have things like "://".
45 EXPECT_EQ("something:///HOSTNAME.com/",
46 TypesTestCase("something:///HOSTNAME.com/"));
48 // In the reverse, known schemes should always trigger standard URL handling.
49 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"));
52 EXPECT_EQ("http://hostname.com/", TypesTestCase("http:///HOSTNAME.com"));
55 // URLs that look like absolute Windows drive specs.
56 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://server/foo.txt", TypesTestCase("\\\\server\\foo.txt"));
59 EXPECT_EQ("file://server/foo.txt", TypesTestCase("//server/foo.txt"));
63 // Test the basic creation and querying of components in a GURL. We assume
64 // the parser is already tested and works, so we are mostly interested if the
65 // object does the right thing with the results.
66 TEST(GURLTest
, Components
) {
67 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
.SchemeIs("http"));
70 EXPECT_FALSE(url
.SchemeIsFile());
72 // 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());
75 EXPECT_EQ("http", url
.scheme());
76 EXPECT_EQ("user", url
.username());
77 EXPECT_EQ("pass", url
.password());
78 EXPECT_EQ("google.com", url
.host());
79 EXPECT_EQ("99", url
.port());
80 EXPECT_EQ(99, url
.IntPort());
81 EXPECT_EQ("/foo;bar", url
.path());
82 EXPECT_EQ("q=a", url
.query());
83 EXPECT_EQ("ref", url
.ref());
85 // Test parsing userinfo with special characters.
86 GURL
url_special_pass("http://user:%40!$&'()*+,;=:@google.com:12345");
87 EXPECT_TRUE(url_special_pass
.is_valid());
88 // GURL canonicalizes some delimiters.
89 EXPECT_EQ("%40!$&%27()*+,%3B%3D%3A", url_special_pass
.password());
90 EXPECT_EQ("google.com", url_special_pass
.host());
91 EXPECT_EQ("12345", url_special_pass
.port());
94 TEST(GURLTest
, Empty
) {
96 EXPECT_FALSE(url
.is_valid());
97 EXPECT_EQ("", url
.spec());
99 EXPECT_EQ("", url
.scheme());
100 EXPECT_EQ("", url
.username());
101 EXPECT_EQ("", url
.password());
102 EXPECT_EQ("", url
.host());
103 EXPECT_EQ("", url
.port());
104 EXPECT_EQ(PORT_UNSPECIFIED
, url
.IntPort());
105 EXPECT_EQ("", url
.path());
106 EXPECT_EQ("", url
.query());
107 EXPECT_EQ("", url
.ref());
110 TEST(GURLTest
, Copy
) {
111 GURL
url(WStringToUTF16(L
"http://user:pass@google.com:99/foo;bar?q=a#ref"));
114 EXPECT_TRUE(url2
.is_valid());
116 EXPECT_EQ("http://user:pass@google.com:99/foo;bar?q=a#ref", url2
.spec());
117 EXPECT_EQ("http", url2
.scheme());
118 EXPECT_EQ("user", url2
.username());
119 EXPECT_EQ("pass", url2
.password());
120 EXPECT_EQ("google.com", url2
.host());
121 EXPECT_EQ("99", url2
.port());
122 EXPECT_EQ(99, url2
.IntPort());
123 EXPECT_EQ("/foo;bar", url2
.path());
124 EXPECT_EQ("q=a", url2
.query());
125 EXPECT_EQ("ref", url2
.ref());
127 // Copying of invalid URL should be invalid
129 GURL
invalid2(invalid
);
130 EXPECT_FALSE(invalid2
.is_valid());
131 EXPECT_EQ("", invalid2
.spec());
132 EXPECT_EQ("", invalid2
.scheme());
133 EXPECT_EQ("", invalid2
.username());
134 EXPECT_EQ("", invalid2
.password());
135 EXPECT_EQ("", invalid2
.host());
136 EXPECT_EQ("", invalid2
.port());
137 EXPECT_EQ(PORT_UNSPECIFIED
, invalid2
.IntPort());
138 EXPECT_EQ("", invalid2
.path());
139 EXPECT_EQ("", invalid2
.query());
140 EXPECT_EQ("", invalid2
.ref());
143 TEST(GURLTest
, Assign
) {
144 GURL
url(WStringToUTF16(L
"http://user:pass@google.com:99/foo;bar?q=a#ref"));
148 EXPECT_TRUE(url2
.is_valid());
150 EXPECT_EQ("http://user:pass@google.com:99/foo;bar?q=a#ref", url2
.spec());
151 EXPECT_EQ("http", url2
.scheme());
152 EXPECT_EQ("user", url2
.username());
153 EXPECT_EQ("pass", url2
.password());
154 EXPECT_EQ("google.com", url2
.host());
155 EXPECT_EQ("99", url2
.port());
156 EXPECT_EQ(99, url2
.IntPort());
157 EXPECT_EQ("/foo;bar", url2
.path());
158 EXPECT_EQ("q=a", url2
.query());
159 EXPECT_EQ("ref", url2
.ref());
161 // Assignment of invalid URL should be invalid
165 EXPECT_FALSE(invalid2
.is_valid());
166 EXPECT_EQ("", invalid2
.spec());
167 EXPECT_EQ("", invalid2
.scheme());
168 EXPECT_EQ("", invalid2
.username());
169 EXPECT_EQ("", invalid2
.password());
170 EXPECT_EQ("", invalid2
.host());
171 EXPECT_EQ("", invalid2
.port());
172 EXPECT_EQ(PORT_UNSPECIFIED
, invalid2
.IntPort());
173 EXPECT_EQ("", invalid2
.path());
174 EXPECT_EQ("", invalid2
.query());
175 EXPECT_EQ("", invalid2
.ref());
178 // This is a regression test for http://crbug.com/309975 .
179 TEST(GURLTest
, SelfAssign
) {
180 GURL
a("filesystem:http://example.com/temporary/");
181 // This should not crash.
185 TEST(GURLTest
, CopyFileSystem
) {
186 GURL
url(WStringToUTF16(L
"filesystem:https://user:pass@google.com:99/t/foo;bar?q=a#ref"));
189 EXPECT_TRUE(url2
.is_valid());
191 EXPECT_EQ("filesystem:https://user:pass@google.com:99/t/foo;bar?q=a#ref", url2
.spec());
192 EXPECT_EQ("filesystem", url2
.scheme());
193 EXPECT_EQ("", url2
.username());
194 EXPECT_EQ("", url2
.password());
195 EXPECT_EQ("", url2
.host());
196 EXPECT_EQ("", url2
.port());
197 EXPECT_EQ(PORT_UNSPECIFIED
, url2
.IntPort());
198 EXPECT_EQ("/foo;bar", url2
.path());
199 EXPECT_EQ("q=a", url2
.query());
200 EXPECT_EQ("ref", url2
.ref());
202 const GURL
* inner
= url2
.inner_url();
204 EXPECT_EQ("https", inner
->scheme());
205 EXPECT_EQ("user", inner
->username());
206 EXPECT_EQ("pass", inner
->password());
207 EXPECT_EQ("google.com", inner
->host());
208 EXPECT_EQ("99", inner
->port());
209 EXPECT_EQ(99, inner
->IntPort());
210 EXPECT_EQ("/t", inner
->path());
211 EXPECT_EQ("", inner
->query());
212 EXPECT_EQ("", inner
->ref());
215 TEST(GURLTest
, IsValid
) {
216 const char* valid_cases
[] = {
218 "unknown://google.com",
219 "http://user:pass@google.com",
220 "http://google.com:12345",
221 "http://google.com/path",
222 "http://google.com//path",
223 "http://google.com?k=v#fragment",
224 "http://user:pass@google.com:12345/path?k=v#fragment",
229 for (size_t i
= 0; i
< arraysize(valid_cases
); i
++) {
230 EXPECT_TRUE(GURL(valid_cases
[i
]).is_valid())
231 << "Case: " << valid_cases
[i
];
234 const char* invalid_cases
[] = {
236 "http:://google.com",
238 "http://google.com:12three45",
241 for (size_t i
= 0; i
< arraysize(invalid_cases
); i
++) {
242 EXPECT_FALSE(GURL(invalid_cases
[i
]).is_valid())
243 << "Case: " << invalid_cases
[i
];
247 TEST(GURLTest
, ExtraSlashesBeforeAuthority
) {
248 // According to RFC3986, the hier-part for URI with an authority must use only
249 // two slashes, GURL intentionally just ignores slashes more than 2 and parses
250 // the following part as an authority.
251 GURL
url("http:///host");
252 EXPECT_EQ("host", url
.host());
253 EXPECT_EQ("/", url
.path());
256 // Given an invalid URL, we should still get most of the components.
257 TEST(GURLTest
, ComponentGettersWorkEvenForInvalidURL
) {
258 GURL
url("http:google.com:foo");
259 EXPECT_FALSE(url
.is_valid());
260 EXPECT_EQ("http://google.com:foo/", url
.possibly_invalid_spec());
262 EXPECT_EQ("http", url
.scheme());
263 EXPECT_EQ("", url
.username());
264 EXPECT_EQ("", url
.password());
265 EXPECT_EQ("google.com", url
.host());
266 EXPECT_EQ("foo", url
.port());
267 EXPECT_EQ(PORT_INVALID
, url
.IntPort());
268 EXPECT_EQ("/", url
.path());
269 EXPECT_EQ("", url
.query());
270 EXPECT_EQ("", url
.ref());
273 TEST(GURLTest
, Resolve
) {
274 // The tricky cases for relative URL resolving are tested in the
275 // canonicalizer unit test. Here, we just test that the GURL integration
279 const char* relative
;
281 const char* expected
;
282 } resolve_cases
[] = {
283 {"http://www.google.com/", "foo.html", true, "http://www.google.com/foo.html"},
284 {"http://www.google.com/", "http://images.google.com/foo.html", true, "http://images.google.com/foo.html"},
285 {"http://www.google.com/blah/bloo?c#d", "../../../hello/./world.html?a#b", true, "http://www.google.com/hello/world.html?a#b"},
286 {"http://www.google.com/foo#bar", "#com", true, "http://www.google.com/foo#com"},
287 {"http://www.google.com/", "Https:images.google.com", true, "https://images.google.com/"},
288 // A non-standard base can be replaced with a standard absolute URL.
289 {"data:blahblah", "http://google.com/", true, "http://google.com/"},
290 {"data:blahblah", "http:google.com", true, "http://google.com/"},
291 // Filesystem URLs have different paths to test.
292 {"filesystem:http://www.google.com/type/", "foo.html", true, "filesystem:http://www.google.com/type/foo.html"},
293 {"filesystem:http://www.google.com/type/", "../foo.html", true, "filesystem:http://www.google.com/type/foo.html"},
296 for (size_t i
= 0; i
< arraysize(resolve_cases
); i
++) {
298 GURL
input(resolve_cases
[i
].base
);
299 GURL output
= input
.Resolve(resolve_cases
[i
].relative
);
300 EXPECT_EQ(resolve_cases
[i
].expected_valid
, output
.is_valid()) << i
;
301 EXPECT_EQ(resolve_cases
[i
].expected
, output
.spec()) << i
;
302 EXPECT_EQ(output
.SchemeIsFileSystem(), output
.inner_url() != NULL
);
305 GURL
inputw(ConvertUTF8ToUTF16(resolve_cases
[i
].base
));
307 input
.Resolve(ConvertUTF8ToUTF16(resolve_cases
[i
].relative
));
308 EXPECT_EQ(resolve_cases
[i
].expected_valid
, outputw
.is_valid()) << i
;
309 EXPECT_EQ(resolve_cases
[i
].expected
, outputw
.spec()) << i
;
310 EXPECT_EQ(outputw
.SchemeIsFileSystem(), outputw
.inner_url() != NULL
);
314 TEST(GURLTest
, GetOrigin
) {
317 const char* expected
;
319 {"http://www.google.com", "http://www.google.com/"},
320 {"javascript:window.alert(\"hello,world\");", ""},
321 {"http://user:pass@www.google.com:21/blah#baz", "http://www.google.com:21/"},
322 {"http://user@www.google.com", "http://www.google.com/"},
323 {"http://:pass@www.google.com", "http://www.google.com/"},
324 {"http://:@www.google.com", "http://www.google.com/"},
325 {"filesystem:http://www.google.com/temp/foo?q#b", "http://www.google.com/"},
326 {"filesystem:http://user:pass@google.com:21/blah#baz", "http://google.com:21/"},
328 for (size_t i
= 0; i
< arraysize(cases
); i
++) {
329 GURL
url(cases
[i
].input
);
330 GURL origin
= url
.GetOrigin();
331 EXPECT_EQ(cases
[i
].expected
, origin
.spec());
335 TEST(GURLTest
, GetAsReferrer
) {
338 const char* expected
;
340 {"http://www.google.com", "http://www.google.com/"},
341 {"http://user:pass@www.google.com:21/blah#baz", "http://www.google.com:21/blah"},
342 {"http://user@www.google.com", "http://www.google.com/"},
343 {"http://:pass@www.google.com", "http://www.google.com/"},
344 {"http://:@www.google.com", "http://www.google.com/"},
345 {"http://www.google.com/temp/foo?q#b", "http://www.google.com/temp/foo?q"},
347 {"unknown-scheme://foo.html", ""},
348 {"file:///tmp/test.html", ""},
349 {"https://www.google.com", "https://www.google.com/"},
351 for (size_t i
= 0; i
< arraysize(cases
); i
++) {
352 GURL
url(cases
[i
].input
);
353 GURL origin
= url
.GetAsReferrer();
354 EXPECT_EQ(cases
[i
].expected
, origin
.spec());
358 TEST(GURLTest
, GetWithEmptyPath
) {
361 const char* expected
;
363 {"http://www.google.com", "http://www.google.com/"},
364 {"javascript:window.alert(\"hello, world\");", ""},
365 {"http://www.google.com/foo/bar.html?baz=22", "http://www.google.com/"},
366 {"filesystem:http://www.google.com/temporary/bar.html?baz=22", "filesystem:http://www.google.com/temporary/"},
367 {"filesystem:file:///temporary/bar.html?baz=22", "filesystem:file:///temporary/"},
370 for (size_t i
= 0; i
< arraysize(cases
); i
++) {
371 GURL
url(cases
[i
].input
);
372 GURL empty_path
= url
.GetWithEmptyPath();
373 EXPECT_EQ(cases
[i
].expected
, empty_path
.spec());
377 TEST(GURLTest
, Replacements
) {
378 // The url canonicalizer replacement test will handle most of these case.
379 // The most important thing to do here is to check that the proper
380 // canonicalizer gets called based on the scheme of the input.
384 const char* username
;
385 const char* password
;
391 const char* expected
;
392 } replace_cases
[] = {
393 {"http://www.google.com/foo/bar.html?foo#bar", NULL
, NULL
, NULL
, NULL
, NULL
, "/", "", "", "http://www.google.com/"},
394 {"http://www.google.com/foo/bar.html?foo#bar", "javascript", "", "", "", "", "window.open('foo');", "", "", "javascript:window.open('foo');"},
395 {"file:///C:/foo/bar.txt", "http", NULL
, NULL
, "www.google.com", "99", "/foo","search", "ref", "http://www.google.com:99/foo?search#ref"},
397 {"http://www.google.com/foo/bar.html?foo#bar", "file", "", "", "", "", "c:\\", "", "", "file:///C:/"},
399 {"filesystem:http://www.google.com/foo/bar.html?foo#bar", NULL
, NULL
, NULL
, NULL
, NULL
, "/", "", "", "filesystem:http://www.google.com/foo/"},
402 for (size_t i
= 0; i
< arraysize(replace_cases
); i
++) {
403 const ReplaceCase
& cur
= replace_cases
[i
];
405 GURL::Replacements repl
;
406 SetupReplacement(&GURL::Replacements::SetScheme
, &repl
, cur
.scheme
);
407 SetupReplacement(&GURL::Replacements::SetUsername
, &repl
, cur
.username
);
408 SetupReplacement(&GURL::Replacements::SetPassword
, &repl
, cur
.password
);
409 SetupReplacement(&GURL::Replacements::SetHost
, &repl
, cur
.host
);
410 SetupReplacement(&GURL::Replacements::SetPort
, &repl
, cur
.port
);
411 SetupReplacement(&GURL::Replacements::SetPath
, &repl
, cur
.path
);
412 SetupReplacement(&GURL::Replacements::SetQuery
, &repl
, cur
.query
);
413 SetupReplacement(&GURL::Replacements::SetRef
, &repl
, cur
.ref
);
414 GURL output
= url
.ReplaceComponents(repl
);
416 EXPECT_EQ(replace_cases
[i
].expected
, output
.spec());
417 EXPECT_EQ(output
.SchemeIsFileSystem(), output
.inner_url() != NULL
);
421 TEST(GURLTest
, ClearFragmentOnDataUrl
) {
422 // http://crbug.com/291747 - a data URL may legitimately have trailing
423 // whitespace in the spec after the ref is cleared. Test this does not trigger
424 // the Parsed importing validation DCHECK in GURL.
425 GURL
url(" data: one ? two # three ");
427 // By default the trailing whitespace will have been stripped.
428 EXPECT_EQ("data: one ? two # three", url
.spec());
429 GURL::Replacements repl
;
431 GURL url_no_ref
= url
.ReplaceComponents(repl
);
433 EXPECT_EQ("data: one ? two ", url_no_ref
.spec());
435 // Importing a parsed url via this constructor overload will retain trailing
437 GURL
import_url(url_no_ref
.spec(),
438 url_no_ref
.parsed_for_possibly_invalid_spec(),
439 url_no_ref
.is_valid());
440 EXPECT_EQ(url_no_ref
, import_url
);
441 EXPECT_EQ(import_url
.query(), " two ");
444 TEST(GURLTest
, PathForRequest
) {
447 const char* expected
;
448 const char* inner_expected
;
450 {"http://www.google.com", "/", NULL
},
451 {"http://www.google.com/", "/", NULL
},
452 {"http://www.google.com/foo/bar.html?baz=22", "/foo/bar.html?baz=22", NULL
},
453 {"http://www.google.com/foo/bar.html#ref", "/foo/bar.html", NULL
},
454 {"http://www.google.com/foo/bar.html?query#ref", "/foo/bar.html?query", NULL
},
455 {"filesystem:http://www.google.com/temporary/foo/bar.html?query#ref", "/foo/bar.html?query", "/temporary"},
456 {"filesystem:http://www.google.com/temporary/foo/bar.html?query", "/foo/bar.html?query", "/temporary"},
459 for (size_t i
= 0; i
< arraysize(cases
); i
++) {
460 GURL
url(cases
[i
].input
);
461 std::string path_request
= url
.PathForRequest();
462 EXPECT_EQ(cases
[i
].expected
, path_request
);
463 EXPECT_EQ(cases
[i
].inner_expected
== NULL
, url
.inner_url() == NULL
);
464 if (url
.inner_url() && cases
[i
].inner_expected
)
465 EXPECT_EQ(cases
[i
].inner_expected
, url
.inner_url()->PathForRequest());
469 TEST(GURLTest
, EffectiveIntPort
) {
472 int expected_int_port
;
475 {"http://www.google.com/", 80},
476 {"http://www.google.com:80/", 80},
477 {"http://www.google.com:443/", 443},
480 {"https://www.google.com/", 443},
481 {"https://www.google.com:443/", 443},
482 {"https://www.google.com:80/", 80},
485 {"ftp://www.google.com/", 21},
486 {"ftp://www.google.com:21/", 21},
487 {"ftp://www.google.com:80/", 80},
490 {"gopher://www.google.com/", 70},
491 {"gopher://www.google.com:70/", 70},
492 {"gopher://www.google.com:80/", 80},
495 {"file://www.google.com/", PORT_UNSPECIFIED
},
496 {"file://www.google.com:443/", PORT_UNSPECIFIED
},
499 {"data:www.google.com:90", PORT_UNSPECIFIED
},
500 {"data:www.google.com", PORT_UNSPECIFIED
},
502 // filesystem - no port
503 {"filesystem:http://www.google.com:90/t/foo", PORT_UNSPECIFIED
},
504 {"filesystem:file:///t/foo", PORT_UNSPECIFIED
},
507 for (size_t i
= 0; i
< arraysize(port_tests
); i
++) {
508 GURL
url(port_tests
[i
].spec
);
509 EXPECT_EQ(port_tests
[i
].expected_int_port
, url
.EffectiveIntPort());
513 TEST(GURLTest
, IPAddress
) {
518 {"http://www.google.com/", false},
519 {"http://192.168.9.1/", true},
520 {"http://192.168.9.1.2/", false},
521 {"http://192.168.m.1/", false},
522 {"http://2001:db8::1/", false},
523 {"http://[2001:db8::1]/", true},
525 {"some random input!", false},
528 for (size_t i
= 0; i
< arraysize(ip_tests
); i
++) {
529 GURL
url(ip_tests
[i
].spec
);
530 EXPECT_EQ(ip_tests
[i
].expected_ip
, url
.HostIsIPAddress());
534 TEST(GURLTest
, HostNoBrackets
) {
537 const char* expected_host
;
538 const char* expected_plainhost
;
540 {"http://www.google.com", "www.google.com", "www.google.com"},
541 {"http://[2001:db8::1]/", "[2001:db8::1]", "2001:db8::1"},
542 {"http://[::]/", "[::]", "::"},
544 // Don't require a valid URL, but don't crash either.
545 {"http://[]/", "[]", ""},
546 {"http://[x]/", "[x]", "x"},
547 {"http://[x/", "[x", "[x"},
548 {"http://x]/", "x]", "x]"},
549 {"http://[/", "[", "["},
550 {"http://]/", "]", "]"},
553 for (size_t i
= 0; i
< arraysize(cases
); i
++) {
554 GURL
url(cases
[i
].input
);
555 EXPECT_EQ(cases
[i
].expected_host
, url
.host());
556 EXPECT_EQ(cases
[i
].expected_plainhost
, url
.HostNoBrackets());
560 TEST(GURLTest
, DomainIs
) {
561 const char google_domain
[] = "google.com";
563 GURL
url_1("http://www.google.com:99/foo");
564 EXPECT_TRUE(url_1
.DomainIs(google_domain
));
566 GURL
url_2("http://google.com:99/foo");
567 EXPECT_TRUE(url_2
.DomainIs(google_domain
));
569 GURL
url_3("http://google.com./foo");
570 EXPECT_TRUE(url_3
.DomainIs(google_domain
));
572 GURL
url_4("http://google.com/foo");
573 EXPECT_FALSE(url_4
.DomainIs("google.com."));
575 GURL
url_5("http://google.com./foo");
576 EXPECT_TRUE(url_5
.DomainIs("google.com."));
578 GURL
url_6("http://www.google.com./foo");
579 EXPECT_TRUE(url_6
.DomainIs(".com."));
581 GURL
url_7("http://www.balabala.com/foo");
582 EXPECT_FALSE(url_7
.DomainIs(google_domain
));
584 GURL
url_8("http://www.google.com.cn/foo");
585 EXPECT_FALSE(url_8
.DomainIs(google_domain
));
587 GURL
url_9("http://www.iamnotgoogle.com/foo");
588 EXPECT_FALSE(url_9
.DomainIs(google_domain
));
590 GURL
url_10("http://www.iamnotgoogle.com../foo");
591 EXPECT_FALSE(url_10
.DomainIs(".com"));
593 GURL
url_11("filesystem:http://www.google.com:99/foo/");
594 EXPECT_TRUE(url_11
.DomainIs(google_domain
));
596 GURL
url_12("filesystem:http://www.iamnotgoogle.com/foo/");
597 EXPECT_FALSE(url_12
.DomainIs(google_domain
));
600 // Newlines should be stripped from inputs.
601 TEST(GURLTest
, Newlines
) {
603 GURL
url_1(" \t ht\ntp://\twww.goo\rgle.com/as\ndf \n ");
604 EXPECT_EQ("http://www.google.com/asdf", url_1
.spec());
606 // Relative path resolver.
607 GURL url_2
= url_1
.Resolve(" \n /fo\to\r ");
608 EXPECT_EQ("http://www.google.com/foo", url_2
.spec());
610 // Note that newlines are NOT stripped from ReplaceComponents.
613 TEST(GURLTest
, IsStandard
) {
614 GURL
a("http:foo/bar");
615 EXPECT_TRUE(a
.IsStandard());
617 GURL
b("foo:bar/baz");
618 EXPECT_FALSE(b
.IsStandard());
620 GURL
c("foo://bar/baz");
621 EXPECT_FALSE(c
.IsStandard());
624 TEST(GURLTest
, SchemeIsHTTPOrHTTPS
) {
625 EXPECT_TRUE(GURL("http://bar/").SchemeIsHTTPOrHTTPS());
626 EXPECT_TRUE(GURL("HTTPS://BAR").SchemeIsHTTPOrHTTPS());
627 EXPECT_FALSE(GURL("ftp://bar/").SchemeIsHTTPOrHTTPS());
630 TEST(GURLTest
, SchemeIsWSOrWSS
) {
631 EXPECT_TRUE(GURL("WS://BAR/").SchemeIsWSOrWSS());
632 EXPECT_TRUE(GURL("wss://bar/").SchemeIsWSOrWSS());
633 EXPECT_FALSE(GURL("http://bar/").SchemeIsWSOrWSS());
636 TEST(GURLTest
, SchemeIsBlob
) {
637 EXPECT_TRUE(GURL("BLOB://BAR/").SchemeIsBlob());
638 EXPECT_TRUE(GURL("blob://bar/").SchemeIsBlob());
639 EXPECT_FALSE(GURL("http://bar/").SchemeIsBlob());