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 for (size_t i
= 0; i
< arraysize(cases
); i
++) {
348 GURL
url(cases
[i
].input
);
349 GURL origin
= url
.GetAsReferrer();
350 EXPECT_EQ(cases
[i
].expected
, origin
.spec());
354 TEST(GURLTest
, GetWithEmptyPath
) {
357 const char* expected
;
359 {"http://www.google.com", "http://www.google.com/"},
360 {"javascript:window.alert(\"hello, world\");", ""},
361 {"http://www.google.com/foo/bar.html?baz=22", "http://www.google.com/"},
362 {"filesystem:http://www.google.com/temporary/bar.html?baz=22", "filesystem:http://www.google.com/temporary/"},
363 {"filesystem:file:///temporary/bar.html?baz=22", "filesystem:file:///temporary/"},
366 for (size_t i
= 0; i
< arraysize(cases
); i
++) {
367 GURL
url(cases
[i
].input
);
368 GURL empty_path
= url
.GetWithEmptyPath();
369 EXPECT_EQ(cases
[i
].expected
, empty_path
.spec());
373 TEST(GURLTest
, Replacements
) {
374 // The url canonicalizer replacement test will handle most of these case.
375 // The most important thing to do here is to check that the proper
376 // canonicalizer gets called based on the scheme of the input.
380 const char* username
;
381 const char* password
;
387 const char* expected
;
388 } replace_cases
[] = {
389 {"http://www.google.com/foo/bar.html?foo#bar", NULL
, NULL
, NULL
, NULL
, NULL
, "/", "", "", "http://www.google.com/"},
390 {"http://www.google.com/foo/bar.html?foo#bar", "javascript", "", "", "", "", "window.open('foo');", "", "", "javascript:window.open('foo');"},
391 {"file:///C:/foo/bar.txt", "http", NULL
, NULL
, "www.google.com", "99", "/foo","search", "ref", "http://www.google.com:99/foo?search#ref"},
393 {"http://www.google.com/foo/bar.html?foo#bar", "file", "", "", "", "", "c:\\", "", "", "file:///C:/"},
395 {"filesystem:http://www.google.com/foo/bar.html?foo#bar", NULL
, NULL
, NULL
, NULL
, NULL
, "/", "", "", "filesystem:http://www.google.com/foo/"},
398 for (size_t i
= 0; i
< arraysize(replace_cases
); i
++) {
399 const ReplaceCase
& cur
= replace_cases
[i
];
401 GURL::Replacements repl
;
402 SetupReplacement(&GURL::Replacements::SetScheme
, &repl
, cur
.scheme
);
403 SetupReplacement(&GURL::Replacements::SetUsername
, &repl
, cur
.username
);
404 SetupReplacement(&GURL::Replacements::SetPassword
, &repl
, cur
.password
);
405 SetupReplacement(&GURL::Replacements::SetHost
, &repl
, cur
.host
);
406 SetupReplacement(&GURL::Replacements::SetPort
, &repl
, cur
.port
);
407 SetupReplacement(&GURL::Replacements::SetPath
, &repl
, cur
.path
);
408 SetupReplacement(&GURL::Replacements::SetQuery
, &repl
, cur
.query
);
409 SetupReplacement(&GURL::Replacements::SetRef
, &repl
, cur
.ref
);
410 GURL output
= url
.ReplaceComponents(repl
);
412 EXPECT_EQ(replace_cases
[i
].expected
, output
.spec());
413 EXPECT_EQ(output
.SchemeIsFileSystem(), output
.inner_url() != NULL
);
417 TEST(GURLTest
, ClearFragmentOnDataUrl
) {
418 // http://crbug.com/291747 - a data URL may legitimately have trailing
419 // whitespace in the spec after the ref is cleared. Test this does not trigger
420 // the Parsed importing validation DCHECK in GURL.
421 GURL
url(" data: one ? two # three ");
423 // By default the trailing whitespace will have been stripped.
424 EXPECT_EQ("data: one ? two # three", url
.spec());
425 GURL::Replacements repl
;
427 GURL url_no_ref
= url
.ReplaceComponents(repl
);
429 EXPECT_EQ("data: one ? two ", url_no_ref
.spec());
431 // Importing a parsed url via this constructor overload will retain trailing
433 GURL
import_url(url_no_ref
.spec(),
434 url_no_ref
.parsed_for_possibly_invalid_spec(),
435 url_no_ref
.is_valid());
436 EXPECT_EQ(url_no_ref
, import_url
);
437 EXPECT_EQ(import_url
.query(), " two ");
440 TEST(GURLTest
, PathForRequest
) {
443 const char* expected
;
444 const char* inner_expected
;
446 {"http://www.google.com", "/", NULL
},
447 {"http://www.google.com/", "/", NULL
},
448 {"http://www.google.com/foo/bar.html?baz=22", "/foo/bar.html?baz=22", NULL
},
449 {"http://www.google.com/foo/bar.html#ref", "/foo/bar.html", NULL
},
450 {"http://www.google.com/foo/bar.html?query#ref", "/foo/bar.html?query", NULL
},
451 {"filesystem:http://www.google.com/temporary/foo/bar.html?query#ref", "/foo/bar.html?query", "/temporary"},
452 {"filesystem:http://www.google.com/temporary/foo/bar.html?query", "/foo/bar.html?query", "/temporary"},
455 for (size_t i
= 0; i
< arraysize(cases
); i
++) {
456 GURL
url(cases
[i
].input
);
457 std::string path_request
= url
.PathForRequest();
458 EXPECT_EQ(cases
[i
].expected
, path_request
);
459 EXPECT_EQ(cases
[i
].inner_expected
== NULL
, url
.inner_url() == NULL
);
460 if (url
.inner_url() && cases
[i
].inner_expected
)
461 EXPECT_EQ(cases
[i
].inner_expected
, url
.inner_url()->PathForRequest());
465 TEST(GURLTest
, EffectiveIntPort
) {
468 int expected_int_port
;
471 {"http://www.google.com/", 80},
472 {"http://www.google.com:80/", 80},
473 {"http://www.google.com:443/", 443},
476 {"https://www.google.com/", 443},
477 {"https://www.google.com:443/", 443},
478 {"https://www.google.com:80/", 80},
481 {"ftp://www.google.com/", 21},
482 {"ftp://www.google.com:21/", 21},
483 {"ftp://www.google.com:80/", 80},
486 {"gopher://www.google.com/", 70},
487 {"gopher://www.google.com:70/", 70},
488 {"gopher://www.google.com:80/", 80},
491 {"file://www.google.com/", PORT_UNSPECIFIED
},
492 {"file://www.google.com:443/", PORT_UNSPECIFIED
},
495 {"data:www.google.com:90", PORT_UNSPECIFIED
},
496 {"data:www.google.com", PORT_UNSPECIFIED
},
498 // filesystem - no port
499 {"filesystem:http://www.google.com:90/t/foo", PORT_UNSPECIFIED
},
500 {"filesystem:file:///t/foo", PORT_UNSPECIFIED
},
503 for (size_t i
= 0; i
< arraysize(port_tests
); i
++) {
504 GURL
url(port_tests
[i
].spec
);
505 EXPECT_EQ(port_tests
[i
].expected_int_port
, url
.EffectiveIntPort());
509 TEST(GURLTest
, IPAddress
) {
514 {"http://www.google.com/", false},
515 {"http://192.168.9.1/", true},
516 {"http://192.168.9.1.2/", false},
517 {"http://192.168.m.1/", false},
518 {"http://2001:db8::1/", false},
519 {"http://[2001:db8::1]/", true},
521 {"some random input!", false},
524 for (size_t i
= 0; i
< arraysize(ip_tests
); i
++) {
525 GURL
url(ip_tests
[i
].spec
);
526 EXPECT_EQ(ip_tests
[i
].expected_ip
, url
.HostIsIPAddress());
530 TEST(GURLTest
, HostNoBrackets
) {
533 const char* expected_host
;
534 const char* expected_plainhost
;
536 {"http://www.google.com", "www.google.com", "www.google.com"},
537 {"http://[2001:db8::1]/", "[2001:db8::1]", "2001:db8::1"},
538 {"http://[::]/", "[::]", "::"},
540 // Don't require a valid URL, but don't crash either.
541 {"http://[]/", "[]", ""},
542 {"http://[x]/", "[x]", "x"},
543 {"http://[x/", "[x", "[x"},
544 {"http://x]/", "x]", "x]"},
545 {"http://[/", "[", "["},
546 {"http://]/", "]", "]"},
549 for (size_t i
= 0; i
< arraysize(cases
); i
++) {
550 GURL
url(cases
[i
].input
);
551 EXPECT_EQ(cases
[i
].expected_host
, url
.host());
552 EXPECT_EQ(cases
[i
].expected_plainhost
, url
.HostNoBrackets());
556 TEST(GURLTest
, DomainIs
) {
557 const char google_domain
[] = "google.com";
559 GURL
url_1("http://www.google.com:99/foo");
560 EXPECT_TRUE(url_1
.DomainIs(google_domain
));
562 GURL
url_2("http://google.com:99/foo");
563 EXPECT_TRUE(url_2
.DomainIs(google_domain
));
565 GURL
url_3("http://google.com./foo");
566 EXPECT_TRUE(url_3
.DomainIs(google_domain
));
568 GURL
url_4("http://google.com/foo");
569 EXPECT_FALSE(url_4
.DomainIs("google.com."));
571 GURL
url_5("http://google.com./foo");
572 EXPECT_TRUE(url_5
.DomainIs("google.com."));
574 GURL
url_6("http://www.google.com./foo");
575 EXPECT_TRUE(url_6
.DomainIs(".com."));
577 GURL
url_7("http://www.balabala.com/foo");
578 EXPECT_FALSE(url_7
.DomainIs(google_domain
));
580 GURL
url_8("http://www.google.com.cn/foo");
581 EXPECT_FALSE(url_8
.DomainIs(google_domain
));
583 GURL
url_9("http://www.iamnotgoogle.com/foo");
584 EXPECT_FALSE(url_9
.DomainIs(google_domain
));
586 GURL
url_10("http://www.iamnotgoogle.com../foo");
587 EXPECT_FALSE(url_10
.DomainIs(".com"));
589 GURL
url_11("filesystem:http://www.google.com:99/foo/");
590 EXPECT_TRUE(url_11
.DomainIs(google_domain
));
592 GURL
url_12("filesystem:http://www.iamnotgoogle.com/foo/");
593 EXPECT_FALSE(url_12
.DomainIs(google_domain
));
596 // Newlines should be stripped from inputs.
597 TEST(GURLTest
, Newlines
) {
599 GURL
url_1(" \t ht\ntp://\twww.goo\rgle.com/as\ndf \n ");
600 EXPECT_EQ("http://www.google.com/asdf", url_1
.spec());
602 // Relative path resolver.
603 GURL url_2
= url_1
.Resolve(" \n /fo\to\r ");
604 EXPECT_EQ("http://www.google.com/foo", url_2
.spec());
606 // Note that newlines are NOT stripped from ReplaceComponents.
609 TEST(GURLTest
, IsStandard
) {
610 GURL
a("http:foo/bar");
611 EXPECT_TRUE(a
.IsStandard());
613 GURL
b("foo:bar/baz");
614 EXPECT_FALSE(b
.IsStandard());
616 GURL
c("foo://bar/baz");
617 EXPECT_FALSE(c
.IsStandard());
620 TEST(GURLTest
, SchemeIsHTTPOrHTTPS
) {
621 EXPECT_TRUE(GURL("http://bar/").SchemeIsHTTPOrHTTPS());
622 EXPECT_TRUE(GURL("HTTPS://BAR").SchemeIsHTTPOrHTTPS());
623 EXPECT_FALSE(GURL("ftp://bar/").SchemeIsHTTPOrHTTPS());
626 TEST(GURLTest
, SchemeIsWSOrWSS
) {
627 EXPECT_TRUE(GURL("WS://BAR/").SchemeIsWSOrWSS());
628 EXPECT_TRUE(GURL("wss://bar/").SchemeIsWSOrWSS());
629 EXPECT_FALSE(GURL("http://bar/").SchemeIsWSOrWSS());
632 TEST(GURLTest
, SchemeIsBlob
) {
633 EXPECT_TRUE(GURL("BLOB://BAR/").SchemeIsBlob());
634 EXPECT_TRUE(GURL("blob://bar/").SchemeIsBlob());
635 EXPECT_FALSE(GURL("http://bar/").SchemeIsBlob());