OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/fileapi/external_file_url_util.h" | 5 #include "chrome/browser/chromeos/fileapi/external_file_url_util.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/chromeos/drive/file_system_util.h" | 8 #include "chrome/browser/chromeos/drive/file_system_util.h" |
9 #include "chrome/test/base/testing_browser_process.h" | 9 #include "chrome/test/base/testing_browser_process.h" |
10 #include "chrome/test/base/testing_profile_manager.h" | 10 #include "chrome/test/base/testing_profile_manager.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {} | 25 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {} |
26 | 26 |
27 virtual void SetUp() OVERRIDE { | 27 virtual void SetUp() OVERRIDE { |
28 ASSERT_TRUE(testing_profile_manager_.SetUp()); | 28 ASSERT_TRUE(testing_profile_manager_.SetUp()); |
29 } | 29 } |
30 | 30 |
31 TestingProfileManager& testing_profile_manager() { | 31 TestingProfileManager& testing_profile_manager() { |
32 return testing_profile_manager_; | 32 return testing_profile_manager_; |
33 } | 33 } |
34 | 34 |
| 35 storage::FileSystemURL CreateExpectedURL(const base::FilePath& path) { |
| 36 return storage::FileSystemURL::CreateForTest( |
| 37 GURL("chrome-extension://xxx"), |
| 38 storage::kFileSystemTypeDrive, |
| 39 base::FilePath("drive-test-user-hash").Append(path)); |
| 40 } |
| 41 |
35 private: | 42 private: |
36 content::TestBrowserThreadBundle thread_bundle_; | 43 content::TestBrowserThreadBundle thread_bundle_; |
37 TestingProfileManager testing_profile_manager_; | 44 TestingProfileManager testing_profile_manager_; |
38 }; | 45 }; |
39 | 46 |
40 } // namespace | 47 } // namespace |
41 | 48 |
42 TEST(ExternalFileURLUtilTest, FilePathToExternalFileURL) { | 49 TEST_F(ExternalFileURLUtilTest, FilePathToExternalFileURL) { |
43 base::FilePath path; | 50 storage::FileSystemURL url; |
44 | 51 |
45 // Path with alphabets and numbers. | 52 // Path with alphabets and numbers. |
46 path = drive::util::GetDriveMyDriveRootPath().AppendASCII("foo/bar012.txt"); | 53 url = CreateExpectedURL(base::FilePath("foo/bar012.txt")); |
47 EXPECT_EQ(path, ExternalFileURLToFilePath(FilePathToExternalFileURL(path))); | 54 EXPECT_EQ(url.virtual_path(), |
| 55 ExternalFileURLToVirtualPath(FileSystemURLToExternalFileURL(url))); |
48 | 56 |
49 // Path with symbols. | 57 // Path with symbols. |
50 path = drive::util::GetDriveMyDriveRootPath().AppendASCII( | 58 url = CreateExpectedURL(base::FilePath(" !\"#$%&'()*+,-.:;<=>?@[\\]^_`{|}~")); |
51 " !\"#$%&'()*+,-.:;<=>?@[\\]^_`{|}~"); | 59 EXPECT_EQ(url.virtual_path(), |
52 EXPECT_EQ(path, ExternalFileURLToFilePath(FilePathToExternalFileURL(path))); | 60 ExternalFileURLToVirtualPath(FileSystemURLToExternalFileURL(url))); |
53 | 61 |
54 // Path with '%'. | 62 // Path with '%'. |
55 path = drive::util::GetDriveMyDriveRootPath().AppendASCII("%19%20%21.txt"); | 63 url = CreateExpectedURL(base::FilePath("%19%20%21.txt")); |
56 EXPECT_EQ(path, ExternalFileURLToFilePath(FilePathToExternalFileURL(path))); | 64 EXPECT_EQ(url.virtual_path(), |
| 65 ExternalFileURLToVirtualPath(FileSystemURLToExternalFileURL(url))); |
57 | 66 |
58 // Path with multi byte characters. | 67 // Path with multi byte characters. |
59 base::string16 utf16_string; | 68 base::string16 utf16_string; |
60 utf16_string.push_back(0x307b); // HIRAGANA_LETTER_HO | 69 utf16_string.push_back(0x307b); // HIRAGANA_LETTER_HO |
61 utf16_string.push_back(0x3052); // HIRAGANA_LETTER_GE | 70 utf16_string.push_back(0x3052); // HIRAGANA_LETTER_GE |
62 path = drive::util::GetDriveMyDriveRootPath().Append( | 71 url = CreateExpectedURL( |
63 base::FilePath::FromUTF8Unsafe(base::UTF16ToUTF8(utf16_string) + ".txt")); | 72 base::FilePath::FromUTF8Unsafe(base::UTF16ToUTF8(utf16_string) + ".txt")); |
64 EXPECT_EQ(path, ExternalFileURLToFilePath(FilePathToExternalFileURL(path))); | 73 EXPECT_EQ(url.virtual_path().AsUTF8Unsafe(), |
| 74 ExternalFileURLToVirtualPath(FileSystemURLToExternalFileURL(url)) |
| 75 .AsUTF8Unsafe()); |
65 } | 76 } |
66 | 77 |
67 TEST(ExternalFileURLUtilTest, ParseFileURLWithExternalFileOrigin) { | 78 TEST_F(ExternalFileURLUtilTest, ParseFileURLWithExternalFileOrigin) { |
68 // filesystem:externalfile:/*** is used only internally. It should not parsed | 79 // filesystem:externalfile:/xxx is used only internally. It should not parsed |
69 // directly. | 80 // directly. |
70 ASSERT_FALSE(storage::FileSystemURL::CreateForTest( | 81 ASSERT_FALSE(storage::FileSystemURL::CreateForTest( |
71 GURL("filesystem:externalfile:/")).is_valid()); | 82 GURL("filesystem:externalfile:/")).is_valid()); |
72 ASSERT_FALSE( | 83 ASSERT_FALSE(storage::FileSystemURL::CreateForTest( |
73 storage::FileSystemURL::CreateForTest( | 84 GURL( |
74 GURL("filesystem:externalfile:/external/drive/file.txt")).is_valid()); | 85 "filesystem:externalfile:/external/drive-test-user-hash/" |
| 86 "file.txt")).is_valid()); |
75 } | 87 } |
76 | 88 |
77 } // namespace chromeos | 89 } // namespace chromeos |
OLD | NEW |