OLD | NEW |
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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "url/gurl.h" | 6 #include "url/gurl.h" |
7 #include "url/url_canon.h" | 7 #include "url/url_canon.h" |
8 #include "url/url_test_utils.h" | 8 #include "url/url_test_utils.h" |
9 | 9 |
10 // Some implementations of base/basictypes.h may define ARRAYSIZE. | 10 // Some implementations of base/basictypes.h may define ARRAYSIZE. |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 {"filesystem:http://www.google.com/temp/foo?q#b", "http://www.google.com/"}, | 280 {"filesystem:http://www.google.com/temp/foo?q#b", "http://www.google.com/"}, |
281 {"filesystem:http://user:pass@google.com:21/blah#baz", "http://google.com:21
/"}, | 281 {"filesystem:http://user:pass@google.com:21/blah#baz", "http://google.com:21
/"}, |
282 }; | 282 }; |
283 for (size_t i = 0; i < ARRAYSIZE(cases); i++) { | 283 for (size_t i = 0; i < ARRAYSIZE(cases); i++) { |
284 GURL url(cases[i].input); | 284 GURL url(cases[i].input); |
285 GURL origin = url.GetOrigin(); | 285 GURL origin = url.GetOrigin(); |
286 EXPECT_EQ(cases[i].expected, origin.spec()); | 286 EXPECT_EQ(cases[i].expected, origin.spec()); |
287 } | 287 } |
288 } | 288 } |
289 | 289 |
| 290 TEST(GURLTest, GetAsReferrer) { |
| 291 struct TestCase { |
| 292 const char* input; |
| 293 const char* expected; |
| 294 } cases[] = { |
| 295 {"http://www.google.com", "http://www.google.com/"}, |
| 296 {"http://user:pass@www.google.com:21/blah#baz", "http://www.google.com:21/bl
ah"}, |
| 297 {"http://user@www.google.com", "http://www.google.com/"}, |
| 298 {"http://:pass@www.google.com", "http://www.google.com/"}, |
| 299 {"http://:@www.google.com", "http://www.google.com/"}, |
| 300 {"http://www.google.com/temp/foo?q#b", "http://www.google.com/temp/foo?q"}, |
| 301 }; |
| 302 for (size_t i = 0; i < ARRAYSIZE(cases); i++) { |
| 303 GURL url(cases[i].input); |
| 304 GURL origin = url.GetAsReferrer(); |
| 305 EXPECT_EQ(cases[i].expected, origin.spec()); |
| 306 } |
| 307 } |
| 308 |
290 TEST(GURLTest, GetWithEmptyPath) { | 309 TEST(GURLTest, GetWithEmptyPath) { |
291 struct TestCase { | 310 struct TestCase { |
292 const char* input; | 311 const char* input; |
293 const char* expected; | 312 const char* expected; |
294 } cases[] = { | 313 } cases[] = { |
295 {"http://www.google.com", "http://www.google.com/"}, | 314 {"http://www.google.com", "http://www.google.com/"}, |
296 {"javascript:window.alert(\"hello, world\");", ""}, | 315 {"javascript:window.alert(\"hello, world\");", ""}, |
297 {"http://www.google.com/foo/bar.html?baz=22", "http://www.google.com/"}, | 316 {"http://www.google.com/foo/bar.html?baz=22", "http://www.google.com/"}, |
298 {"filesystem:http://www.google.com/temporary/bar.html?baz=22", "filesystem:h
ttp://www.google.com/temporary/"}, | 317 {"filesystem:http://www.google.com/temporary/bar.html?baz=22", "filesystem:h
ttp://www.google.com/temporary/"}, |
299 {"filesystem:file:///temporary/bar.html?baz=22", "filesystem:file:///tempora
ry/"}, | 318 {"filesystem:file:///temporary/bar.html?baz=22", "filesystem:file:///tempora
ry/"}, |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 EXPECT_TRUE(GURL("http://bar/").SchemeIsHTTPOrHTTPS()); | 576 EXPECT_TRUE(GURL("http://bar/").SchemeIsHTTPOrHTTPS()); |
558 EXPECT_TRUE(GURL("HTTPS://BAR").SchemeIsHTTPOrHTTPS()); | 577 EXPECT_TRUE(GURL("HTTPS://BAR").SchemeIsHTTPOrHTTPS()); |
559 EXPECT_FALSE(GURL("ftp://bar/").SchemeIsHTTPOrHTTPS()); | 578 EXPECT_FALSE(GURL("ftp://bar/").SchemeIsHTTPOrHTTPS()); |
560 } | 579 } |
561 | 580 |
562 TEST(GURLTest, SchemeIsWSOrWSS) { | 581 TEST(GURLTest, SchemeIsWSOrWSS) { |
563 EXPECT_TRUE(GURL("WS://BAR/").SchemeIsWSOrWSS()); | 582 EXPECT_TRUE(GURL("WS://BAR/").SchemeIsWSOrWSS()); |
564 EXPECT_TRUE(GURL("wss://bar/").SchemeIsWSOrWSS()); | 583 EXPECT_TRUE(GURL("wss://bar/").SchemeIsWSOrWSS()); |
565 EXPECT_FALSE(GURL("http://bar/").SchemeIsWSOrWSS()); | 584 EXPECT_FALSE(GURL("http://bar/").SchemeIsWSOrWSS()); |
566 } | 585 } |
OLD | NEW |