| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/utf_string_conversions.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| 10 #include "url/url_canon.h" | 11 #include "url/url_canon.h" |
| 11 #include "url/url_test_utils.h" | 12 #include "url/url_test_utils.h" |
| 12 | 13 |
| 13 namespace url { | 14 namespace url { |
| 14 | 15 |
| 15 using test_utils::WStringToUTF16; | |
| 16 using test_utils::ConvertUTF8ToUTF16; | |
| 17 | |
| 18 namespace { | 16 namespace { |
| 19 | 17 |
| 20 template<typename CHAR> | 18 template<typename CHAR> |
| 21 void SetupReplacement( | 19 void SetupReplacement( |
| 22 void (Replacements<CHAR>::*func)(const CHAR*, const Component&), | 20 void (Replacements<CHAR>::*func)(const CHAR*, const Component&), |
| 23 Replacements<CHAR>* replacements, | 21 Replacements<CHAR>* replacements, |
| 24 const CHAR* str) { | 22 const CHAR* str) { |
| 25 if (str) { | 23 if (str) { |
| 26 Component comp; | 24 Component comp; |
| 27 if (str[0]) | 25 if (str[0]) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 EXPECT_EQ("file:///Z:/foo.txt", TypesTestCase("Z|foo.txt")); | 58 EXPECT_EQ("file:///Z:/foo.txt", TypesTestCase("Z|foo.txt")); |
| 61 EXPECT_EQ("file://server/foo.txt", TypesTestCase("\\\\server\\foo.txt")); | 59 EXPECT_EQ("file://server/foo.txt", TypesTestCase("\\\\server\\foo.txt")); |
| 62 EXPECT_EQ("file://server/foo.txt", TypesTestCase("//server/foo.txt")); | 60 EXPECT_EQ("file://server/foo.txt", TypesTestCase("//server/foo.txt")); |
| 63 #endif | 61 #endif |
| 64 } | 62 } |
| 65 | 63 |
| 66 // Test the basic creation and querying of components in a GURL. We assume that | 64 // Test the basic creation and querying of components in a GURL. We assume that |
| 67 // 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 |
| 68 // object does the right thing with the results. | 66 // object does the right thing with the results. |
| 69 TEST(GURLTest, Components) { | 67 TEST(GURLTest, Components) { |
| 70 GURL empty_url(WStringToUTF16(L"")); | 68 GURL empty_url(base::UTF8ToUTF16("")); |
| 71 EXPECT_TRUE(empty_url.is_empty()); | 69 EXPECT_TRUE(empty_url.is_empty()); |
| 72 EXPECT_FALSE(empty_url.is_valid()); | 70 EXPECT_FALSE(empty_url.is_valid()); |
| 73 | 71 |
| 74 GURL url(WStringToUTF16(L"http://user:pass@google.com:99/foo;bar?q=a#ref")); | 72 GURL url(base::UTF8ToUTF16("http://user:pass@google.com:99/foo;bar?q=a#ref")); |
| 75 EXPECT_FALSE(url.is_empty()); | 73 EXPECT_FALSE(url.is_empty()); |
| 76 EXPECT_TRUE(url.is_valid()); | 74 EXPECT_TRUE(url.is_valid()); |
| 77 EXPECT_TRUE(url.SchemeIs("http")); | 75 EXPECT_TRUE(url.SchemeIs("http")); |
| 78 EXPECT_FALSE(url.SchemeIsFile()); | 76 EXPECT_FALSE(url.SchemeIsFile()); |
| 79 | 77 |
| 80 // This is the narrow version of the URL, which should match the wide input. | 78 // This is the narrow version of the URL, which should match the wide input. |
| 81 EXPECT_EQ("http://user:pass@google.com:99/foo;bar?q=a#ref", url.spec()); | 79 EXPECT_EQ("http://user:pass@google.com:99/foo;bar?q=a#ref", url.spec()); |
| 82 | 80 |
| 83 EXPECT_EQ("http", url.scheme()); | 81 EXPECT_EQ("http", url.scheme()); |
| 84 EXPECT_EQ("user", url.username()); | 82 EXPECT_EQ("user", url.username()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 109 EXPECT_EQ("", url.password()); | 107 EXPECT_EQ("", url.password()); |
| 110 EXPECT_EQ("", url.host()); | 108 EXPECT_EQ("", url.host()); |
| 111 EXPECT_EQ("", url.port()); | 109 EXPECT_EQ("", url.port()); |
| 112 EXPECT_EQ(PORT_UNSPECIFIED, url.IntPort()); | 110 EXPECT_EQ(PORT_UNSPECIFIED, url.IntPort()); |
| 113 EXPECT_EQ("", url.path()); | 111 EXPECT_EQ("", url.path()); |
| 114 EXPECT_EQ("", url.query()); | 112 EXPECT_EQ("", url.query()); |
| 115 EXPECT_EQ("", url.ref()); | 113 EXPECT_EQ("", url.ref()); |
| 116 } | 114 } |
| 117 | 115 |
| 118 TEST(GURLTest, Copy) { | 116 TEST(GURLTest, Copy) { |
| 119 GURL url(WStringToUTF16(L"http://user:pass@google.com:99/foo;bar?q=a#ref")); | 117 GURL url(base::UTF8ToUTF16( |
| 118 "http://user:pass@google.com:99/foo;bar?q=a#ref")); |
| 120 | 119 |
| 121 GURL url2(url); | 120 GURL url2(url); |
| 122 EXPECT_TRUE(url2.is_valid()); | 121 EXPECT_TRUE(url2.is_valid()); |
| 123 | 122 |
| 124 EXPECT_EQ("http://user:pass@google.com:99/foo;bar?q=a#ref", url2.spec()); | 123 EXPECT_EQ("http://user:pass@google.com:99/foo;bar?q=a#ref", url2.spec()); |
| 125 EXPECT_EQ("http", url2.scheme()); | 124 EXPECT_EQ("http", url2.scheme()); |
| 126 EXPECT_EQ("user", url2.username()); | 125 EXPECT_EQ("user", url2.username()); |
| 127 EXPECT_EQ("pass", url2.password()); | 126 EXPECT_EQ("pass", url2.password()); |
| 128 EXPECT_EQ("google.com", url2.host()); | 127 EXPECT_EQ("google.com", url2.host()); |
| 129 EXPECT_EQ("99", url2.port()); | 128 EXPECT_EQ("99", url2.port()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 142 EXPECT_EQ("", invalid2.password()); | 141 EXPECT_EQ("", invalid2.password()); |
| 143 EXPECT_EQ("", invalid2.host()); | 142 EXPECT_EQ("", invalid2.host()); |
| 144 EXPECT_EQ("", invalid2.port()); | 143 EXPECT_EQ("", invalid2.port()); |
| 145 EXPECT_EQ(PORT_UNSPECIFIED, invalid2.IntPort()); | 144 EXPECT_EQ(PORT_UNSPECIFIED, invalid2.IntPort()); |
| 146 EXPECT_EQ("", invalid2.path()); | 145 EXPECT_EQ("", invalid2.path()); |
| 147 EXPECT_EQ("", invalid2.query()); | 146 EXPECT_EQ("", invalid2.query()); |
| 148 EXPECT_EQ("", invalid2.ref()); | 147 EXPECT_EQ("", invalid2.ref()); |
| 149 } | 148 } |
| 150 | 149 |
| 151 TEST(GURLTest, Assign) { | 150 TEST(GURLTest, Assign) { |
| 152 GURL url(WStringToUTF16(L"http://user:pass@google.com:99/foo;bar?q=a#ref")); | 151 GURL url(base::UTF8ToUTF16( |
| 152 "http://user:pass@google.com:99/foo;bar?q=a#ref")); |
| 153 | 153 |
| 154 GURL url2; | 154 GURL url2; |
| 155 url2 = url; | 155 url2 = url; |
| 156 EXPECT_TRUE(url2.is_valid()); | 156 EXPECT_TRUE(url2.is_valid()); |
| 157 | 157 |
| 158 EXPECT_EQ("http://user:pass@google.com:99/foo;bar?q=a#ref", url2.spec()); | 158 EXPECT_EQ("http://user:pass@google.com:99/foo;bar?q=a#ref", url2.spec()); |
| 159 EXPECT_EQ("http", url2.scheme()); | 159 EXPECT_EQ("http", url2.scheme()); |
| 160 EXPECT_EQ("user", url2.username()); | 160 EXPECT_EQ("user", url2.username()); |
| 161 EXPECT_EQ("pass", url2.password()); | 161 EXPECT_EQ("pass", url2.password()); |
| 162 EXPECT_EQ("google.com", url2.host()); | 162 EXPECT_EQ("google.com", url2.host()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 184 } | 184 } |
| 185 | 185 |
| 186 // This is a regression test for http://crbug.com/309975. | 186 // This is a regression test for http://crbug.com/309975. |
| 187 TEST(GURLTest, SelfAssign) { | 187 TEST(GURLTest, SelfAssign) { |
| 188 GURL a("filesystem:http://example.com/temporary/"); | 188 GURL a("filesystem:http://example.com/temporary/"); |
| 189 // This should not crash. | 189 // This should not crash. |
| 190 a = a; | 190 a = a; |
| 191 } | 191 } |
| 192 | 192 |
| 193 TEST(GURLTest, CopyFileSystem) { | 193 TEST(GURLTest, CopyFileSystem) { |
| 194 GURL url(WStringToUTF16(L"filesystem:https://user:pass@google.com:99/t/foo;bar
?q=a#ref")); | 194 GURL url(base::UTF8ToUTF16( |
| 195 "filesystem:https://user:pass@google.com:99/t/foo;bar?q=a#ref")); |
| 195 | 196 |
| 196 GURL url2(url); | 197 GURL url2(url); |
| 197 EXPECT_TRUE(url2.is_valid()); | 198 EXPECT_TRUE(url2.is_valid()); |
| 198 | 199 |
| 199 EXPECT_EQ("filesystem:https://user:pass@google.com:99/t/foo;bar?q=a#ref", url2
.spec()); | 200 EXPECT_EQ("filesystem:https://user:pass@google.com:99/t/foo;bar?q=a#ref", url2
.spec()); |
| 200 EXPECT_EQ("filesystem", url2.scheme()); | 201 EXPECT_EQ("filesystem", url2.scheme()); |
| 201 EXPECT_EQ("", url2.username()); | 202 EXPECT_EQ("", url2.username()); |
| 202 EXPECT_EQ("", url2.password()); | 203 EXPECT_EQ("", url2.password()); |
| 203 EXPECT_EQ("", url2.host()); | 204 EXPECT_EQ("", url2.host()); |
| 204 EXPECT_EQ("", url2.port()); | 205 EXPECT_EQ("", url2.port()); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 307 |
| 307 for (size_t i = 0; i < arraysize(resolve_cases); i++) { | 308 for (size_t i = 0; i < arraysize(resolve_cases); i++) { |
| 308 // 8-bit code path. | 309 // 8-bit code path. |
| 309 GURL input(resolve_cases[i].base); | 310 GURL input(resolve_cases[i].base); |
| 310 GURL output = input.Resolve(resolve_cases[i].relative); | 311 GURL output = input.Resolve(resolve_cases[i].relative); |
| 311 EXPECT_EQ(resolve_cases[i].expected_valid, output.is_valid()) << i; | 312 EXPECT_EQ(resolve_cases[i].expected_valid, output.is_valid()) << i; |
| 312 EXPECT_EQ(resolve_cases[i].expected, output.spec()) << i; | 313 EXPECT_EQ(resolve_cases[i].expected, output.spec()) << i; |
| 313 EXPECT_EQ(output.SchemeIsFileSystem(), output.inner_url() != NULL); | 314 EXPECT_EQ(output.SchemeIsFileSystem(), output.inner_url() != NULL); |
| 314 | 315 |
| 315 // Wide code path. | 316 // Wide code path. |
| 316 GURL inputw(ConvertUTF8ToUTF16(resolve_cases[i].base)); | 317 GURL inputw(base::UTF8ToUTF16(resolve_cases[i].base)); |
| 317 GURL outputw = | 318 GURL outputw = |
| 318 input.Resolve(ConvertUTF8ToUTF16(resolve_cases[i].relative)); | 319 input.Resolve(base::UTF8ToUTF16(resolve_cases[i].relative)); |
| 319 EXPECT_EQ(resolve_cases[i].expected_valid, outputw.is_valid()) << i; | 320 EXPECT_EQ(resolve_cases[i].expected_valid, outputw.is_valid()) << i; |
| 320 EXPECT_EQ(resolve_cases[i].expected, outputw.spec()) << i; | 321 EXPECT_EQ(resolve_cases[i].expected, outputw.spec()) << i; |
| 321 EXPECT_EQ(outputw.SchemeIsFileSystem(), outputw.inner_url() != NULL); | 322 EXPECT_EQ(outputw.SchemeIsFileSystem(), outputw.inner_url() != NULL); |
| 322 } | 323 } |
| 323 } | 324 } |
| 324 | 325 |
| 325 TEST(GURLTest, GetOrigin) { | 326 TEST(GURLTest, GetOrigin) { |
| 326 struct TestCase { | 327 struct TestCase { |
| 327 const char* input; | 328 const char* input; |
| 328 const char* expected; | 329 const char* expected; |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 }; | 733 }; |
| 733 | 734 |
| 734 for (const auto& test : cases) { | 735 for (const auto& test : cases) { |
| 735 GURL url(test.url); | 736 GURL url(test.url); |
| 736 EXPECT_EQ(test.expected, url.path()) << test.url; | 737 EXPECT_EQ(test.expected, url.path()) << test.url; |
| 737 EXPECT_EQ(test.expected, url.GetContent()) << test.url; | 738 EXPECT_EQ(test.expected, url.GetContent()) << test.url; |
| 738 } | 739 } |
| 739 } | 740 } |
| 740 | 741 |
| 741 } // namespace url | 742 } // namespace url |
| OLD | NEW |