[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 5 | #include <stddef.h> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | #include <stdlib.h> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
[email protected] | 9b5b1d60 | 2014-06-12 14:29:02 | [diff] [blame] | 8 | #include "base/base_paths.h" |
[email protected] | 9b5b1d60 | 2014-06-12 14:29:02 | [diff] [blame] | 9 | #include "base/files/file_path.h" |
thestig | 819adcc8 | 2014-09-10 22:24:53 | [diff] [blame] | 10 | #include "base/files/file_util.h" |
[email protected] | 97803e1b | 2014-07-25 01:52:14 | [diff] [blame] | 11 | #include "base/files/scoped_temp_dir.h" |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 12 | #include "base/macros.h" |
[email protected] | f9b29436 | 2013-06-10 20:22:31 | [diff] [blame] | 13 | #include "base/strings/string_util.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 14 | #include "base/strings/utf_string_conversions.h" |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 15 | #include "build/build_config.h" |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 16 | #include "components/url_formatter/url_fixer.h" |
[email protected] | d96cf75 | 2014-04-09 04:05:28 | [diff] [blame] | 17 | #include "net/base/filename_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 18 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 761fa470 | 2013-07-02 15:25:15 | [diff] [blame] | 19 | #include "url/gurl.h" |
tfarina | 018de6e | 2015-05-26 17:41:20 | [diff] [blame] | 20 | #include "url/third_party/mozilla/url_parse.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 21 | |
[email protected] | 0318f92 | 2014-04-22 00:09:23 | [diff] [blame] | 22 | namespace url { |
[email protected] | 46cf4be9 | 2010-10-01 11:23:20 | [diff] [blame] | 23 | |
| 24 | std::ostream& operator<<(std::ostream& os, const Component& part) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | return os << "(begin=" << part.begin << ", len=" << part.len << ")"; |
| 26 | } |
| 27 | |
[email protected] | 0318f92 | 2014-04-22 00:09:23 | [diff] [blame] | 28 | } // namespace url |
[email protected] | 46cf4be9 | 2010-10-01 11:23:20 | [diff] [blame] | 29 | |
[email protected] | dc7d305 | 2013-05-31 21:23:28 | [diff] [blame] | 30 | struct SegmentCase { |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 31 | const std::string input; |
| 32 | const std::string result; |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 33 | const url::Component scheme; |
| 34 | const url::Component username; |
| 35 | const url::Component password; |
| 36 | const url::Component host; |
| 37 | const url::Component port; |
| 38 | const url::Component path; |
| 39 | const url::Component query; |
| 40 | const url::Component ref; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 41 | }; |
| 42 | |
[email protected] | dc7d305 | 2013-05-31 21:23:28 | [diff] [blame] | 43 | static const SegmentCase segment_cases[] = { |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 44 | { "http://www.google.com/", "http", |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 45 | url::Component(0, 4), // scheme |
| 46 | url::Component(), // username |
| 47 | url::Component(), // password |
| 48 | url::Component(7, 14), // host |
| 49 | url::Component(), // port |
| 50 | url::Component(21, 1), // path |
| 51 | url::Component(), // query |
| 52 | url::Component(), // ref |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 53 | }, |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 54 | { "aBoUt:vErSiOn", "about", |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 55 | url::Component(0, 5), // scheme |
| 56 | url::Component(), // username |
| 57 | url::Component(), // password |
| 58 | url::Component(6, 7), // host |
| 59 | url::Component(), // port |
| 60 | url::Component(), // path |
| 61 | url::Component(), // query |
| 62 | url::Component(), // ref |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 63 | }, |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 64 | { "about:host/path?query#ref", "about", |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 65 | url::Component(0, 5), // scheme |
| 66 | url::Component(), // username |
| 67 | url::Component(), // password |
| 68 | url::Component(6, 4), // host |
| 69 | url::Component(), // port |
| 70 | url::Component(10, 5), // path |
| 71 | url::Component(16, 5), // query |
| 72 | url::Component(22, 3), // ref |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 73 | }, |
| 74 | { "about://host/path?query#ref", "about", |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 75 | url::Component(0, 5), // scheme |
| 76 | url::Component(), // username |
| 77 | url::Component(), // password |
| 78 | url::Component(8, 4), // host |
| 79 | url::Component(), // port |
| 80 | url::Component(12, 5), // path |
| 81 | url::Component(18, 5), // query |
| 82 | url::Component(24, 3), // ref |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 83 | }, |
| 84 | { "chrome:host/path?query#ref", "chrome", |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 85 | url::Component(0, 6), // scheme |
| 86 | url::Component(), // username |
| 87 | url::Component(), // password |
| 88 | url::Component(7, 4), // host |
| 89 | url::Component(), // port |
| 90 | url::Component(11, 5), // path |
| 91 | url::Component(17, 5), // query |
| 92 | url::Component(23, 3), // ref |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 93 | }, |
| 94 | { "chrome://host/path?query#ref", "chrome", |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 95 | url::Component(0, 6), // scheme |
| 96 | url::Component(), // username |
| 97 | url::Component(), // password |
| 98 | url::Component(9, 4), // host |
| 99 | url::Component(), // port |
| 100 | url::Component(13, 5), // path |
| 101 | url::Component(19, 5), // query |
| 102 | url::Component(25, 3), // ref |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 103 | }, |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 104 | { " www.google.com:124?foo#", "http", |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 105 | url::Component(), // scheme |
| 106 | url::Component(), // username |
| 107 | url::Component(), // password |
| 108 | url::Component(4, 14), // host |
| 109 | url::Component(19, 3), // port |
| 110 | url::Component(), // path |
| 111 | url::Component(23, 3), // query |
| 112 | url::Component(27, 0), // ref |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 113 | }, |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 114 | { "[email protected]", "http", |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 115 | url::Component(), // scheme |
| 116 | url::Component(0, 4), // username |
| 117 | url::Component(), // password |
| 118 | url::Component(5, 14), // host |
| 119 | url::Component(), // port |
| 120 | url::Component(), // path |
| 121 | url::Component(), // query |
| 122 | url::Component(), // ref |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 123 | }, |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 124 | { "ftp:/user:P:[email protected]...::23///pub?foo#bar", "ftp", |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 125 | url::Component(0, 3), // scheme |
| 126 | url::Component(5, 4), // username |
| 127 | url::Component(10, 7), // password |
| 128 | url::Component(18, 20), // host |
| 129 | url::Component(39, 2), // port |
| 130 | url::Component(41, 6), // path |
| 131 | url::Component(48, 3), // query |
| 132 | url::Component(52, 3), // ref |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 133 | }, |
[email protected] | 818071ce | 2009-05-18 01:25:25 | [diff] [blame] | 134 | { "[2001:db8::1]/path", "http", |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 135 | url::Component(), // scheme |
| 136 | url::Component(), // username |
| 137 | url::Component(), // password |
| 138 | url::Component(0, 13), // host |
| 139 | url::Component(), // port |
| 140 | url::Component(13, 5), // path |
| 141 | url::Component(), // query |
| 142 | url::Component(), // ref |
[email protected] | 818071ce | 2009-05-18 01:25:25 | [diff] [blame] | 143 | }, |
| 144 | { "[::1]", "http", |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 145 | url::Component(), // scheme |
| 146 | url::Component(), // username |
| 147 | url::Component(), // password |
| 148 | url::Component(0, 5), // host |
| 149 | url::Component(), // port |
| 150 | url::Component(), // path |
| 151 | url::Component(), // query |
| 152 | url::Component(), // ref |
[email protected] | 818071ce | 2009-05-18 01:25:25 | [diff] [blame] | 153 | }, |
[email protected] | c199130 | 2009-06-04 03:57:39 | [diff] [blame] | 154 | // Incomplete IPv6 addresses (will not canonicalize). |
| 155 | { "[2001:4860:", "http", |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 156 | url::Component(), // scheme |
| 157 | url::Component(), // username |
| 158 | url::Component(), // password |
| 159 | url::Component(0, 11), // host |
| 160 | url::Component(), // port |
| 161 | url::Component(), // path |
| 162 | url::Component(), // query |
| 163 | url::Component(), // ref |
[email protected] | c199130 | 2009-06-04 03:57:39 | [diff] [blame] | 164 | }, |
| 165 | { "[2001:4860:/foo", "http", |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 166 | url::Component(), // scheme |
| 167 | url::Component(), // username |
| 168 | url::Component(), // password |
| 169 | url::Component(0, 11), // host |
| 170 | url::Component(), // port |
| 171 | url::Component(11, 4), // path |
| 172 | url::Component(), // query |
| 173 | url::Component(), // ref |
[email protected] | c199130 | 2009-06-04 03:57:39 | [diff] [blame] | 174 | }, |
| 175 | { "http://:b005::68]", "http", |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 176 | url::Component(0, 4), // scheme |
| 177 | url::Component(), // username |
| 178 | url::Component(), // password |
| 179 | url::Component(7, 10), // host |
| 180 | url::Component(), // port |
| 181 | url::Component(), // path |
| 182 | url::Component(), // query |
| 183 | url::Component(), // ref |
[email protected] | c199130 | 2009-06-04 03:57:39 | [diff] [blame] | 184 | }, |
brettw | 46f9b83 | 2016-10-05 19:22:48 | [diff] [blame] | 185 | { ":b005::68]", "http", |
| 186 | url::Component(), // scheme |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 187 | url::Component(), // username |
| 188 | url::Component(), // password |
brettw | 46f9b83 | 2016-10-05 19:22:48 | [diff] [blame] | 189 | url::Component(1, 9), // host |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 190 | url::Component(), // port |
| 191 | url::Component(), // path |
| 192 | url::Component(), // query |
| 193 | url::Component(), // ref |
[email protected] | c199130 | 2009-06-04 03:57:39 | [diff] [blame] | 194 | }, |
Kevin Bailey | 13622d5 | 2018-05-10 16:25:04 | [diff] [blame] | 195 | { |
| 196 | "file://host/path/file#ref", "file", url::Component(0, 4), // scheme |
| 197 | url::Component(), // username |
| 198 | url::Component(), // password |
| 199 | url::Component(7, 4), // host |
| 200 | url::Component(), // port |
| 201 | url::Component(11, 10), // path |
| 202 | url::Component(), // query |
| 203 | url::Component(22, 3), // ref |
| 204 | }, |
| 205 | { |
| 206 | "file:///notahost/path/file#ref", "file", |
| 207 | url::Component(0, 4), // scheme |
| 208 | url::Component(), // username |
| 209 | url::Component(), // password |
| 210 | url::Component(), // host |
| 211 | url::Component(), // port |
| 212 | url::Component(7, 19), // path |
| 213 | url::Component(), // query |
| 214 | url::Component(27, 3), // ref |
| 215 | }, |
| 216 | #if defined(OS_WIN) |
| 217 | { |
| 218 | "c:/notahost/path/file#ref", "file", |
| 219 | url::Component(), // scheme |
| 220 | url::Component(), // username |
| 221 | url::Component(), // password |
| 222 | url::Component(), // host |
| 223 | url::Component(), // port |
| 224 | url::Component(0, 21), // path |
| 225 | url::Component(), // query |
| 226 | url::Component(22, 3), // ref |
| 227 | }, |
| 228 | #elif defined(OS_POSIX) |
| 229 | { |
| 230 | "~/notahost/path/file#ref", "file", |
| 231 | url::Component(), // scheme |
| 232 | url::Component(), // username |
| 233 | url::Component(), // password |
| 234 | url::Component(), // host |
| 235 | url::Component(), // port |
| 236 | url::Component(0, 20), // path |
| 237 | url::Component(), // query |
| 238 | url::Component(21, 3), // ref |
| 239 | }, |
| 240 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 241 | }; |
| 242 | |
[email protected] | 9b5b1d60 | 2014-06-12 14:29:02 | [diff] [blame] | 243 | typedef testing::Test URLFixerTest; |
[email protected] | 7897768 | 2014-05-10 18:42:25 | [diff] [blame] | 244 | |
[email protected] | 9b5b1d60 | 2014-06-12 14:29:02 | [diff] [blame] | 245 | TEST(URLFixerTest, SegmentURL) { |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 246 | std::string result; |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 247 | url::Parsed parts; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 248 | |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 249 | for (size_t i = 0; i < arraysize(segment_cases); ++i) { |
[email protected] | dc7d305 | 2013-05-31 21:23:28 | [diff] [blame] | 250 | SegmentCase value = segment_cases[i]; |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 251 | result = url_formatter::SegmentURL(value.input, &parts); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 252 | EXPECT_EQ(value.result, result); |
| 253 | EXPECT_EQ(value.scheme, parts.scheme); |
| 254 | EXPECT_EQ(value.username, parts.username); |
| 255 | EXPECT_EQ(value.password, parts.password); |
| 256 | EXPECT_EQ(value.host, parts.host); |
| 257 | EXPECT_EQ(value.port, parts.port); |
| 258 | EXPECT_EQ(value.path, parts.path); |
| 259 | EXPECT_EQ(value.query, parts.query); |
| 260 | EXPECT_EQ(value.ref, parts.ref); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | // Creates a file and returns its full name as well as the decomposed |
| 265 | // version. Example: |
| 266 | // full_path = "c:\foo\bar.txt" |
| 267 | // dir = "c:\foo" |
| 268 | // file_name = "bar.txt" |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 269 | static bool MakeTempFile(const base::FilePath& dir, |
| 270 | const base::FilePath& file_name, |
| 271 | base::FilePath* full_path) { |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 272 | *full_path = dir.Append(file_name); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 273 | return base::WriteFile(*full_path, "", 0) == 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | // Returns true if the given URL is a file: URL that matches the given file |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 277 | static bool IsMatchingFileURL(const std::string& url, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 278 | const base::FilePath& full_file_path) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 279 | if (url.length() <= 8) |
| 280 | return false; |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 281 | if (std::string("file:///") != url.substr(0, 8)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 282 | return false; // no file:/// prefix |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 283 | if (url.find('\\') != std::string::npos) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 284 | return false; // contains backslashes |
| 285 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 286 | base::FilePath derived_path; |
[email protected] | 5674185 | 2008-12-17 19:04:50 | [diff] [blame] | 287 | net::FileURLToFilePath(GURL(url), &derived_path); |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 288 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 289 | return base::FilePath::CompareEqualIgnoreCase(derived_path.value(), |
[email protected] | eccb9d1 | 2009-10-28 05:40:09 | [diff] [blame] | 290 | full_file_path.value()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 291 | } |
| 292 | |
[email protected] | dc7d305 | 2013-05-31 21:23:28 | [diff] [blame] | 293 | struct FixupCase { |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 294 | const std::string input; |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 295 | const std::string output; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 296 | } fixup_cases[] = { |
Nick Carter | ff69a10 | 2018-04-04 00:15:17 | [diff] [blame] | 297 | {"www.google.com", "http://www.google.com/"}, |
| 298 | {" www.google.com ", "http://www.google.com/"}, |
| 299 | {" foo.com/asdf bar", "http://foo.com/asdf%20%20bar"}, |
| 300 | {"..www.google.com..", "http://www.google.com./"}, |
| 301 | {"http://......", "http://....../"}, |
| 302 | {"http://host.com:ninety-two/", "http://host.com:ninety-two/"}, |
| 303 | {"http://host.com:ninety-two?foo", "http://host.com:ninety-two/?foo"}, |
| 304 | {"google.com:123", "http://google.com:123/"}, |
| 305 | {"about:", "chrome://version/"}, |
| 306 | {"about:foo", "chrome://foo/"}, |
| 307 | {"about:version", "chrome://version/"}, |
| 308 | {"about:blank", "about:blank"}, |
| 309 | {"about:usr:pwd@hst:20/pth?qry#ref", "chrome://hst/pth?qry#ref"}, |
| 310 | {"about://usr:pwd@hst/pth?qry#ref", "chrome://hst/pth?qry#ref"}, |
| 311 | {"chrome:usr:pwd@hst/pth?qry#ref", "chrome://hst/pth?qry#ref"}, |
| 312 | {"chrome://usr:pwd@hst/pth?qry#ref", "chrome://hst/pth?qry#ref"}, |
| 313 | {"www:123", "http://www:123/"}, |
| 314 | {" www:123", "http://www:123/"}, |
| 315 | {"www.google.com?foo", "http://www.google.com/?foo"}, |
| 316 | {"www.google.com#foo", "http://www.google.com/#foo"}, |
| 317 | {"www.google.com?", "http://www.google.com/?"}, |
| 318 | {"www.google.com#", "http://www.google.com/#"}, |
| 319 | {"www.google.com:123?foo#bar", "http://www.google.com:123/?foo#bar"}, |
| 320 | {"[email protected]", "http://[email protected]/"}, |
| 321 | {"\xE6\xB0\xB4.com", "http://xn--1rw.com/"}, |
| 322 | // It would be better if this next case got treated as http, but I don't see |
| 323 | // a clean way to guess this isn't the new-and-exciting "user" scheme. |
| 324 | {"user:[email protected]:8080/", "user:[email protected]:8080/"}, |
| 325 | // {"file:///c:/foo/bar%20baz.txt", "file:///C:/foo/bar%20baz.txt"}, |
| 326 | // URLs which end with 0x85 (NEL in ISO-8859). |
| 327 | {"http://foo.com/s?q=\xd0\x85", "http://foo.com/s?q=%D0%85"}, |
| 328 | {"http://foo.com/s?q=\xec\x97\x85", "http://foo.com/s?q=%EC%97%85"}, |
| 329 | {"http://foo.com/s?q=\xf0\x90\x80\x85", "http://foo.com/s?q=%F0%90%80%85"}, |
| 330 | // URLs which end with 0xA0 (non-break space in ISO-8859). |
| 331 | {"http://foo.com/s?q=\xd0\xa0", "http://foo.com/s?q=%D0%A0"}, |
| 332 | {"http://foo.com/s?q=\xec\x97\xa0", "http://foo.com/s?q=%EC%97%A0"}, |
| 333 | {"http://foo.com/s?q=\xf0\x90\x80\xa0", "http://foo.com/s?q=%F0%90%80%A0"}, |
| 334 | // URLs containing IPv6 literals. |
| 335 | {"[2001:db8::2]", "http://[2001:db8::2]/"}, |
| 336 | {"[::]:80", "http://[::]/"}, |
| 337 | {"[::]:80/path", "http://[::]/path"}, |
| 338 | {"[::]:180/path", "http://[::]:180/path"}, |
| 339 | // TODO(pmarks): Maybe we should parse bare IPv6 literals someday. Currently |
| 340 | // the first colon is treated as a scheme separator, and we default |
| 341 | // unspecified schemes to "http". |
| 342 | {"::1", "http://:1/"}, |
| 343 | // Semicolon as scheme separator for standard schemes. |
| 344 | {"http;//www.google.com/", "http://www.google.com/"}, |
| 345 | {"about;chrome", "chrome://chrome/"}, |
| 346 | // Semicolon in non-standard schemes is not replaced by colon. |
| 347 | {"whatsup;//fool", "http://whatsup%3B//fool"}, |
| 348 | // Semicolon left as-is in URL itself. |
| 349 | {"http://host/port?query;moar", "http://host/port?query;moar"}, |
| 350 | // Fewer slashes than expected. |
| 351 | {"http;www.google.com/", "http://www.google.com/"}, |
| 352 | {"http;/www.google.com/", "http://www.google.com/"}, |
| 353 | // Semicolon at start. |
| 354 | {";http://www.google.com/", "http://%3Bhttp//www.google.com/"}, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 355 | }; |
| 356 | |
[email protected] | 9b5b1d60 | 2014-06-12 14:29:02 | [diff] [blame] | 357 | TEST(URLFixerTest, FixupURL) { |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 358 | for (size_t i = 0; i < arraysize(fixup_cases); ++i) { |
[email protected] | dc7d305 | 2013-05-31 21:23:28 | [diff] [blame] | 359 | FixupCase value = fixup_cases[i]; |
[email protected] | 7897768 | 2014-05-10 18:42:25 | [diff] [blame] | 360 | EXPECT_EQ(value.output, |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 361 | url_formatter::FixupURL(value.input, "").possibly_invalid_spec()) |
[email protected] | ae8e367 | 2013-03-20 09:00:08 | [diff] [blame] | 362 | << "input: " << value.input; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 363 | } |
| 364 | |
[email protected] | 7897768 | 2014-05-10 18:42:25 | [diff] [blame] | 365 | // Check the TLD-appending functionality. |
[email protected] | dc7d305 | 2013-05-31 21:23:28 | [diff] [blame] | 366 | FixupCase tld_cases[] = { |
[email protected] | 91bf0c1 | 2014-08-12 14:49:24 | [diff] [blame] | 367 | {"somedomainthatwillnotbeagtld", |
| 368 | "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 369 | {"somedomainthatwillnotbeagtld.", |
| 370 | "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 371 | {"somedomainthatwillnotbeagtld..", |
| 372 | "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 373 | {".somedomainthatwillnotbeagtld", |
| 374 | "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 375 | {"www.somedomainthatwillnotbeagtld", |
| 376 | "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 377 | {"somedomainthatwillnotbeagtld.com", |
| 378 | "http://somedomainthatwillnotbeagtld.com/"}, |
| 379 | {"http://somedomainthatwillnotbeagtld", |
| 380 | "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 381 | {"..somedomainthatwillnotbeagtld..", |
| 382 | "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 383 | {"http://www.somedomainthatwillnotbeagtld", |
| 384 | "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 385 | {"9999999999999999", "http://www.9999999999999999.com/"}, |
| 386 | {"somedomainthatwillnotbeagtld/foo", |
| 387 | "http://www.somedomainthatwillnotbeagtld.com/foo"}, |
| 388 | {"somedomainthatwillnotbeagtld.com/foo", |
| 389 | "http://somedomainthatwillnotbeagtld.com/foo"}, |
| 390 | {"somedomainthatwillnotbeagtld/?foo=.com", |
| 391 | "http://www.somedomainthatwillnotbeagtld.com/?foo=.com"}, |
| 392 | {"www.somedomainthatwillnotbeagtld/?foo=www.", |
| 393 | "http://www.somedomainthatwillnotbeagtld.com/?foo=www."}, |
| 394 | {"somedomainthatwillnotbeagtld.com/?foo=.com", |
| 395 | "http://somedomainthatwillnotbeagtld.com/?foo=.com"}, |
| 396 | {"http://www.somedomainthatwillnotbeagtld.com", |
| 397 | "http://www.somedomainthatwillnotbeagtld.com/"}, |
| 398 | {"somedomainthatwillnotbeagtld:123", |
| 399 | "http://www.somedomainthatwillnotbeagtld.com:123/"}, |
| 400 | {"http://somedomainthatwillnotbeagtld:123", |
| 401 | "http://www.somedomainthatwillnotbeagtld.com:123/"}, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 402 | }; |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 403 | for (size_t i = 0; i < arraysize(tld_cases); ++i) { |
[email protected] | dc7d305 | 2013-05-31 21:23:28 | [diff] [blame] | 404 | FixupCase value = tld_cases[i]; |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 405 | EXPECT_EQ(value.output, url_formatter::FixupURL(value.input, "com") |
| 406 | .possibly_invalid_spec()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
| 410 | // Test different types of file inputs to URIFixerUpper::FixupURL. This |
| 411 | // doesn't go into the nice array of fixups above since the file input |
| 412 | // has to exist. |
[email protected] | 9b5b1d60 | 2014-06-12 14:29:02 | [diff] [blame] | 413 | TEST(URLFixerTest, FixupFile) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 414 | // this "original" filename is the one we tweak to get all the variations |
[email protected] | 97803e1b | 2014-07-25 01:52:14 | [diff] [blame] | 415 | base::ScopedTempDir temp_dir_; |
| 416 | ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 417 | base::FilePath original; |
[email protected] | d321644 | 2009-03-05 21:07:27 | [diff] [blame] | 418 | ASSERT_TRUE(MakeTempFile( |
vabr | 8c498ea4 | 2016-09-15 12:41:58 | [diff] [blame] | 419 | temp_dir_.GetPath(), |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 420 | base::FilePath(FILE_PATH_LITERAL("url fixer upper existing file.txt")), |
[email protected] | d321644 | 2009-03-05 21:07:27 | [diff] [blame] | 421 | &original)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 422 | |
| 423 | // reference path |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame] | 424 | GURL golden(net::FilePathToFileURL(original)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 425 | |
| 426 | // c:\foo\bar.txt -> file:///c:/foo/bar.txt (basic) |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 427 | GURL fixedup(url_formatter::FixupURL(original.AsUTF8Unsafe(), std::string())); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 428 | EXPECT_EQ(golden, fixedup); |
| 429 | |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 430 | // TODO(port): Make some equivalent tests for posix. |
| 431 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 432 | // c|/foo\bar.txt -> file:///c:/foo/bar.txt (pipe allowed instead of colon) |
[email protected] | 036a5f3 | 2013-12-25 00:26:11 | [diff] [blame] | 433 | std::string cur(base::WideToUTF8(original.value())); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 434 | EXPECT_EQ(':', cur[1]); |
| 435 | cur[1] = '|'; |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 436 | EXPECT_EQ(golden, url_formatter::FixupURL(cur, std::string())); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 437 | |
[email protected] | 7897768 | 2014-05-10 18:42:25 | [diff] [blame] | 438 | FixupCase cases[] = { |
| 439 | {"c:\\Non-existent%20file.txt", "file:///C:/Non-existent%2520file.txt"}, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 440 | |
| 441 | // \\foo\bar.txt -> file://foo/bar.txt |
| 442 | // UNC paths, this file won't exist, but since there are no escapes, it |
| 443 | // should be returned just converted to a file: URL. |
[email protected] | 7897768 | 2014-05-10 18:42:25 | [diff] [blame] | 444 | {"\\\\NonexistentHost\\foo\\bar.txt", "file://nonexistenthost/foo/bar.txt"}, |
[email protected] | 7fc13ed | 2010-03-06 05:06:20 | [diff] [blame] | 445 | // We do this strictly, like IE8, which only accepts this form using |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame] | 446 | // backslashes and not forward ones. Turning "//foo" into "http" matches |
| 447 | // Firefox and IE, silly though it may seem (it falls out of adding "http" |
| 448 | // as the default protocol if you haven't entered one). |
[email protected] | 7897768 | 2014-05-10 18:42:25 | [diff] [blame] | 449 | {"//NonexistentHost\\foo/bar.txt", "http://nonexistenthost/foo/bar.txt"}, |
| 450 | {"file:///C:/foo/bar", "file:///C:/foo/bar"}, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 451 | |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame] | 452 | // Much of the work here comes from GURL's canonicalization stage. |
[email protected] | 7897768 | 2014-05-10 18:42:25 | [diff] [blame] | 453 | {"file://C:/foo/bar", "file:///C:/foo/bar"}, |
| 454 | {"file:c:", "file:///C:/"}, |
| 455 | {"file:c:WINDOWS", "file:///C:/WINDOWS"}, |
| 456 | {"file:c|Program Files", "file:///C:/Program%20Files"}, |
| 457 | {"file:/file", "file://file/"}, |
| 458 | {"file:////////c:\\foo", "file:///C:/foo"}, |
| 459 | {"file://server/folder/file", "file://server/folder/file"}, |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame] | 460 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 461 | // These are fixups we don't do, but could consider: |
[email protected] | 7897768 | 2014-05-10 18:42:25 | [diff] [blame] | 462 | // {"file:///foo:/bar", "file://foo/bar"}, |
| 463 | // {"file:/\\/server\\folder/file", "file://server/folder/file"}, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 464 | }; |
[email protected] | ba1321d1 | 2009-04-21 22:42:29 | [diff] [blame] | 465 | #elif defined(OS_POSIX) |
[email protected] | 762c554 | 2009-10-21 16:45:38 | [diff] [blame] | 466 | |
| 467 | #if defined(OS_MACOSX) |
| 468 | #define HOME "/Users/" |
| 469 | #else |
| 470 | #define HOME "/home/" |
| 471 | #endif |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 472 | url_formatter::home_directory_override = "/foo"; |
[email protected] | 7897768 | 2014-05-10 18:42:25 | [diff] [blame] | 473 | FixupCase cases[] = { |
[email protected] | ba1321d1 | 2009-04-21 22:42:29 | [diff] [blame] | 474 | // File URLs go through GURL, which tries to escape intelligently. |
[email protected] | 7897768 | 2014-05-10 18:42:25 | [diff] [blame] | 475 | {"/A%20non-existent file.txt", "file:///A%2520non-existent%20file.txt"}, |
[email protected] | ba1321d1 | 2009-04-21 22:42:29 | [diff] [blame] | 476 | // A plain "/" refers to the root. |
[email protected] | 7897768 | 2014-05-10 18:42:25 | [diff] [blame] | 477 | {"/", "file:///"}, |
[email protected] | 762c554 | 2009-10-21 16:45:38 | [diff] [blame] | 478 | |
| 479 | // These rely on the above home_directory_override. |
[email protected] | 7897768 | 2014-05-10 18:42:25 | [diff] [blame] | 480 | {"~", "file:///foo"}, |
| 481 | {"~/bar", "file:///foo/bar"}, |
[email protected] | 762c554 | 2009-10-21 16:45:38 | [diff] [blame] | 482 | |
| 483 | // References to other users' homedirs. |
[email protected] | 7897768 | 2014-05-10 18:42:25 | [diff] [blame] | 484 | {"~foo", "file://" HOME "foo"}, |
| 485 | {"~x/blah", "file://" HOME "x/blah"}, |
[email protected] | ba1321d1 | 2009-04-21 22:42:29 | [diff] [blame] | 486 | }; |
| 487 | #endif |
[email protected] | 7897768 | 2014-05-10 18:42:25 | [diff] [blame] | 488 | |
| 489 | for (size_t i = 0; i < arraysize(cases); i++) { |
| 490 | EXPECT_EQ(cases[i].output, |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 491 | url_formatter::FixupURL(cases[i].input, std::string()) |
| 492 | .possibly_invalid_spec()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 493 | } |
| 494 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 495 | EXPECT_TRUE(base::DeleteFile(original, false)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 496 | } |
| 497 | |
[email protected] | 9b5b1d60 | 2014-06-12 14:29:02 | [diff] [blame] | 498 | TEST(URLFixerTest, FixupRelativeFile) { |
[email protected] | 97803e1b | 2014-07-25 01:52:14 | [diff] [blame] | 499 | base::FilePath full_path; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 500 | base::FilePath file_part( |
| 501 | FILE_PATH_LITERAL("url_fixer_upper_existing_file.txt")); |
[email protected] | 97803e1b | 2014-07-25 01:52:14 | [diff] [blame] | 502 | base::ScopedTempDir temp_dir_; |
| 503 | ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
vabr | 8c498ea4 | 2016-09-15 12:41:58 | [diff] [blame] | 504 | ASSERT_TRUE(MakeTempFile(temp_dir_.GetPath(), file_part, &full_path)); |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 505 | full_path = base::MakeAbsoluteFilePath(full_path); |
| 506 | ASSERT_FALSE(full_path.empty()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 507 | |
| 508 | // make sure we pass through good URLs |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 509 | for (size_t i = 0; i < arraysize(fixup_cases); ++i) { |
[email protected] | dc7d305 | 2013-05-31 21:23:28 | [diff] [blame] | 510 | FixupCase value = fixup_cases[i]; |
[email protected] | 0b58a81 | 2013-05-31 01:15:17 | [diff] [blame] | 511 | base::FilePath input = base::FilePath::FromUTF8Unsafe(value.input); |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame] | 512 | EXPECT_EQ(value.output, |
vabr | 8c498ea4 | 2016-09-15 12:41:58 | [diff] [blame] | 513 | url_formatter::FixupRelativeFile(temp_dir_.GetPath(), input) |
| 514 | .possibly_invalid_spec()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | // make sure the existing file got fixed-up to a file URL, and that there |
| 518 | // are no backslashes |
[email protected] | 9b5b1d60 | 2014-06-12 14:29:02 | [diff] [blame] | 519 | EXPECT_TRUE(IsMatchingFileURL( |
vabr | 8c498ea4 | 2016-09-15 12:41:58 | [diff] [blame] | 520 | url_formatter::FixupRelativeFile(temp_dir_.GetPath(), file_part) |
| 521 | .possibly_invalid_spec(), |
| 522 | full_path)); |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 523 | EXPECT_TRUE(base::DeleteFile(full_path, false)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 524 | |
| 525 | // create a filename we know doesn't exist and make sure it doesn't get |
| 526 | // fixed up to a file URL |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 527 | base::FilePath nonexistent_file( |
[email protected] | d321644 | 2009-03-05 21:07:27 | [diff] [blame] | 528 | FILE_PATH_LITERAL("url_fixer_upper_nonexistent_file.txt")); |
vabr | 8c498ea4 | 2016-09-15 12:41:58 | [diff] [blame] | 529 | std::string fixedup( |
| 530 | url_formatter::FixupRelativeFile(temp_dir_.GetPath(), nonexistent_file) |
| 531 | .possibly_invalid_spec()); |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 532 | EXPECT_NE(std::string("file:///"), fixedup.substr(0, 8)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 533 | EXPECT_FALSE(IsMatchingFileURL(fixedup, nonexistent_file)); |
| 534 | |
| 535 | // make a subdir to make sure relative paths with directories work, also |
[email protected] | d321644 | 2009-03-05 21:07:27 | [diff] [blame] | 536 | // test spaces: |
| 537 | // "app_dir\url fixer-upper dir\url fixer-upper existing file.txt" |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 538 | base::FilePath sub_dir(FILE_PATH_LITERAL("url fixer-upper dir")); |
| 539 | base::FilePath sub_file( |
| 540 | FILE_PATH_LITERAL("url fixer-upper existing file.txt")); |
vabr | 8c498ea4 | 2016-09-15 12:41:58 | [diff] [blame] | 541 | base::FilePath new_dir = temp_dir_.GetPath().Append(sub_dir); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 542 | base::CreateDirectory(new_dir); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 543 | ASSERT_TRUE(MakeTempFile(new_dir, sub_file, &full_path)); |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 544 | full_path = base::MakeAbsoluteFilePath(full_path); |
| 545 | ASSERT_FALSE(full_path.empty()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 546 | |
| 547 | // test file in the subdir |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 548 | base::FilePath relative_file = sub_dir.Append(sub_file); |
[email protected] | 9b5b1d60 | 2014-06-12 14:29:02 | [diff] [blame] | 549 | EXPECT_TRUE(IsMatchingFileURL( |
vabr | 8c498ea4 | 2016-09-15 12:41:58 | [diff] [blame] | 550 | url_formatter::FixupRelativeFile(temp_dir_.GetPath(), relative_file) |
| 551 | .possibly_invalid_spec(), |
| 552 | full_path)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 553 | |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 554 | // test file in the subdir with different slashes and escaping. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 555 | base::FilePath::StringType relative_file_str = sub_dir.value() + |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 556 | FILE_PATH_LITERAL("/") + sub_file.value(); |
brettw | e6dae46 | 2015-06-24 20:54:45 | [diff] [blame] | 557 | base::ReplaceSubstringsAfterOffset(&relative_file_str, 0, |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 558 | FILE_PATH_LITERAL(" "), FILE_PATH_LITERAL("%20")); |
[email protected] | 9b5b1d60 | 2014-06-12 14:29:02 | [diff] [blame] | 559 | EXPECT_TRUE(IsMatchingFileURL( |
vabr | 8c498ea4 | 2016-09-15 12:41:58 | [diff] [blame] | 560 | url_formatter::FixupRelativeFile(temp_dir_.GetPath(), |
| 561 | base::FilePath(relative_file_str)) |
| 562 | .possibly_invalid_spec(), |
| 563 | full_path)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 564 | |
| 565 | // test relative directories and duplicate slashes |
| 566 | // (should resolve to the same file as above) |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 567 | relative_file_str = sub_dir.value() + FILE_PATH_LITERAL("/../") + |
| 568 | sub_dir.value() + FILE_PATH_LITERAL("///./") + sub_file.value(); |
[email protected] | 9b5b1d60 | 2014-06-12 14:29:02 | [diff] [blame] | 569 | EXPECT_TRUE(IsMatchingFileURL( |
vabr | 8c498ea4 | 2016-09-15 12:41:58 | [diff] [blame] | 570 | url_formatter::FixupRelativeFile(temp_dir_.GetPath(), |
| 571 | base::FilePath(relative_file_str)) |
| 572 | .possibly_invalid_spec(), |
| 573 | full_path)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 574 | |
| 575 | // done with the subdir |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 576 | EXPECT_TRUE(base::DeleteFile(full_path, false)); |
| 577 | EXPECT_TRUE(base::DeleteFile(new_dir, true)); |
[email protected] | a64c3cf | 2011-08-06 05:25:55 | [diff] [blame] | 578 | |
| 579 | // Test that an obvious HTTP URL isn't accidentally treated as an absolute |
| 580 | // file path (on account of system-specific craziness). |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 581 | base::FilePath empty_path; |
| 582 | base::FilePath http_url_path(FILE_PATH_LITERAL("http://../")); |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 583 | EXPECT_TRUE(url_formatter::FixupRelativeFile(empty_path, http_url_path) |
| 584 | .SchemeIs("http")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 585 | } |