OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 218 |
219 // Creates a file and returns its full name as well as the decomposed | 219 // Creates a file and returns its full name as well as the decomposed |
220 // version. Example: | 220 // version. Example: |
221 // full_path = "c:\foo\bar.txt" | 221 // full_path = "c:\foo\bar.txt" |
222 // dir = "c:\foo" | 222 // dir = "c:\foo" |
223 // file_name = "bar.txt" | 223 // file_name = "bar.txt" |
224 static bool MakeTempFile(const base::FilePath& dir, | 224 static bool MakeTempFile(const base::FilePath& dir, |
225 const base::FilePath& file_name, | 225 const base::FilePath& file_name, |
226 base::FilePath* full_path) { | 226 base::FilePath* full_path) { |
227 *full_path = dir.Append(file_name); | 227 *full_path = dir.Append(file_name); |
228 return file_util::WriteFile(*full_path, "", 0) == 0; | 228 return base::WriteFile(*full_path, "", 0) == 0; |
229 } | 229 } |
230 | 230 |
231 // Returns true if the given URL is a file: URL that matches the given file | 231 // Returns true if the given URL is a file: URL that matches the given file |
232 static bool IsMatchingFileURL(const std::string& url, | 232 static bool IsMatchingFileURL(const std::string& url, |
233 const base::FilePath& full_file_path) { | 233 const base::FilePath& full_file_path) { |
234 if (url.length() <= 8) | 234 if (url.length() <= 8) |
235 return false; | 235 return false; |
236 if (std::string("file:///") != url.substr(0, 8)) | 236 if (std::string("file:///") != url.substr(0, 8)) |
237 return false; // no file:/// prefix | 237 return false; // no file:/// prefix |
238 if (url.find('\\') != std::string::npos) | 238 if (url.find('\\') != std::string::npos) |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 EXPECT_TRUE(base::DeleteFile(full_path, false)); | 530 EXPECT_TRUE(base::DeleteFile(full_path, false)); |
531 EXPECT_TRUE(base::DeleteFile(new_dir, true)); | 531 EXPECT_TRUE(base::DeleteFile(new_dir, true)); |
532 | 532 |
533 // Test that an obvious HTTP URL isn't accidentally treated as an absolute | 533 // Test that an obvious HTTP URL isn't accidentally treated as an absolute |
534 // file path (on account of system-specific craziness). | 534 // file path (on account of system-specific craziness). |
535 base::FilePath empty_path; | 535 base::FilePath empty_path; |
536 base::FilePath http_url_path(FILE_PATH_LITERAL("http://../")); | 536 base::FilePath http_url_path(FILE_PATH_LITERAL("http://../")); |
537 EXPECT_TRUE(URLFixerUpper::FixupRelativeFile( | 537 EXPECT_TRUE(URLFixerUpper::FixupRelativeFile( |
538 empty_path, http_url_path).SchemeIs("http")); | 538 empty_path, http_url_path).SchemeIs("http")); |
539 } | 539 } |
OLD | NEW |