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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system
.h" | 9 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system
.h" |
10 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 10 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "webkit/browser/fileapi/external_mount_points.h" | 24 #include "webkit/browser/fileapi/external_mount_points.h" |
25 | 25 |
26 namespace chromeos { | 26 namespace chromeos { |
27 namespace file_system_provider { | 27 namespace file_system_provider { |
28 namespace util { | 28 namespace util { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; | 32 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; |
| 33 const char kFileSystemId[] = "camera-pictures"; |
33 const char kFileSystemName[] = "Camera Pictures"; | 34 const char kFileSystemName[] = "Camera Pictures"; |
34 | 35 |
35 // Creates a FileSystemURL for tests. | 36 // Creates a FileSystemURL for tests. |
36 fileapi::FileSystemURL CreateFileSystemURL(Profile* profile, | 37 fileapi::FileSystemURL CreateFileSystemURL( |
37 const std::string& extension_id, | 38 Profile* profile, |
38 int file_system_id, | 39 const ProvidedFileSystemInfo& file_system_info, |
39 const base::FilePath& file_path) { | 40 const base::FilePath& file_path) { |
40 const std::string origin = std::string("chrome-extension://") + kExtensionId; | 41 const std::string origin = |
41 const base::FilePath mount_path = | 42 std::string("chrome-extension://") + file_system_info.extension_id(); |
42 util::GetMountPath(profile, extension_id, file_system_id); | 43 const base::FilePath mount_path = file_system_info.mount_path(); |
43 const fileapi::ExternalMountPoints* const mount_points = | 44 const fileapi::ExternalMountPoints* const mount_points = |
44 fileapi::ExternalMountPoints::GetSystemInstance(); | 45 fileapi::ExternalMountPoints::GetSystemInstance(); |
45 DCHECK(mount_points); | 46 DCHECK(mount_points); |
46 DCHECK(file_path.IsAbsolute()); | 47 DCHECK(file_path.IsAbsolute()); |
47 base::FilePath relative_path(file_path.value().substr(1)); | 48 base::FilePath relative_path(file_path.value().substr(1)); |
48 return mount_points->CreateCrackedFileSystemURL( | 49 return mount_points->CreateCrackedFileSystemURL( |
49 GURL(origin), | 50 GURL(origin), |
50 fileapi::kFileSystemTypeExternal, | 51 fileapi::kFileSystemTypeExternal, |
51 base::FilePath(mount_path.BaseName().Append(relative_path))); | 52 base::FilePath(mount_path.BaseName().Append(relative_path))); |
52 } | 53 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 content::TestBrowserThreadBundle thread_bundle_; | 89 content::TestBrowserThreadBundle thread_bundle_; |
89 scoped_ptr<TestingProfileManager> profile_manager_; | 90 scoped_ptr<TestingProfileManager> profile_manager_; |
90 TestingProfile* profile_; // Owned by TestingProfileManager. | 91 TestingProfile* profile_; // Owned by TestingProfileManager. |
91 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; | 92 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; |
92 FakeUserManager* user_manager_; | 93 FakeUserManager* user_manager_; |
93 Service* file_system_provider_service_; // Owned by its factory. | 94 Service* file_system_provider_service_; // Owned by its factory. |
94 }; | 95 }; |
95 | 96 |
96 TEST_F(FileSystemProviderMountPathUtilTest, GetMountPath) { | 97 TEST_F(FileSystemProviderMountPathUtilTest, GetMountPath) { |
97 const std::string kExtensionId = "mbflcebpggnecokmikipoihdbecnjfoj"; | 98 const std::string kExtensionId = "mbflcebpggnecokmikipoihdbecnjfoj"; |
98 const int kFileSystemId = 1; | 99 const int index = 1; |
99 | 100 |
100 base::FilePath result = GetMountPath(profile_, kExtensionId, kFileSystemId); | 101 base::FilePath result = GetMountPath(profile_, kExtensionId, index); |
101 EXPECT_EQ("/provided/mbflcebpggnecokmikipoihdbecnjfoj-1-testing-profile-hash", | 102 EXPECT_EQ("/provided/mbflcebpggnecokmikipoihdbecnjfoj-1-testing-profile-hash", |
102 result.AsUTF8Unsafe()); | 103 result.AsUTF8Unsafe()); |
103 } | 104 } |
104 | 105 |
105 TEST_F(FileSystemProviderMountPathUtilTest, Parser) { | 106 TEST_F(FileSystemProviderMountPathUtilTest, Parser) { |
106 const int file_system_id = file_system_provider_service_->MountFileSystem( | 107 const bool result = file_system_provider_service_->MountFileSystem( |
107 kExtensionId, kFileSystemName); | 108 kExtensionId, kFileSystemId, kFileSystemName); |
108 EXPECT_LT(0, file_system_id); | 109 ASSERT_TRUE(result); |
| 110 const ProvidedFileSystemInfo file_system_info = |
| 111 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
| 112 kFileSystemId) |
| 113 ->GetFileSystemInfo(); |
109 | 114 |
110 const base::FilePath kFilePath = | 115 const base::FilePath kFilePath = |
111 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); | 116 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); |
112 const fileapi::FileSystemURL url = | 117 const fileapi::FileSystemURL url = |
113 CreateFileSystemURL(profile_, kExtensionId, file_system_id, kFilePath); | 118 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
114 EXPECT_TRUE(url.is_valid()); | 119 EXPECT_TRUE(url.is_valid()); |
115 | 120 |
116 FileSystemURLParser parser(url); | 121 FileSystemURLParser parser(url); |
117 EXPECT_TRUE(parser.Parse()); | 122 EXPECT_TRUE(parser.Parse()); |
118 | 123 |
119 ProvidedFileSystemInterface* file_system = parser.file_system(); | 124 ProvidedFileSystemInterface* file_system = parser.file_system(); |
120 ASSERT_TRUE(file_system); | 125 ASSERT_TRUE(file_system); |
121 EXPECT_EQ(file_system_id, file_system->GetFileSystemInfo().file_system_id()); | 126 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); |
122 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 127 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
123 } | 128 } |
124 | 129 |
125 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) { | 130 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) { |
126 const int file_system_id = file_system_provider_service_->MountFileSystem( | 131 const bool result = file_system_provider_service_->MountFileSystem( |
127 kExtensionId, kFileSystemName); | 132 kExtensionId, kFileSystemId, kFileSystemName); |
128 EXPECT_LT(0, file_system_id); | 133 ASSERT_TRUE(result); |
| 134 const ProvidedFileSystemInfo file_system_info = |
| 135 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
| 136 kFileSystemId) |
| 137 ->GetFileSystemInfo(); |
129 | 138 |
130 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); | 139 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); |
131 const fileapi::FileSystemURL url = | 140 const fileapi::FileSystemURL url = |
132 CreateFileSystemURL(profile_, kExtensionId, file_system_id, kFilePath); | 141 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
133 EXPECT_TRUE(url.is_valid()); | 142 EXPECT_TRUE(url.is_valid()); |
134 | 143 |
135 FileSystemURLParser parser(url); | 144 FileSystemURLParser parser(url); |
136 EXPECT_TRUE(parser.Parse()); | 145 EXPECT_TRUE(parser.Parse()); |
137 | 146 |
138 ProvidedFileSystemInterface* file_system = parser.file_system(); | 147 ProvidedFileSystemInterface* file_system = parser.file_system(); |
139 ASSERT_TRUE(file_system); | 148 ASSERT_TRUE(file_system); |
140 EXPECT_EQ(file_system_id, file_system->GetFileSystemInfo().file_system_id()); | 149 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); |
141 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 150 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
142 } | 151 } |
143 | 152 |
144 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) { | 153 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) { |
145 const int file_system_id = file_system_provider_service_->MountFileSystem( | 154 const int index = 1; |
146 kExtensionId, kFileSystemName); | 155 const ProvidedFileSystemInfo file_system_info( |
147 EXPECT_LT(0, file_system_id); | 156 kExtensionId, |
| 157 kFileSystemId, |
| 158 kFileSystemName, |
| 159 GetMountPath(profile_, kExtensionId, index)); |
148 | 160 |
149 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/hello"); | 161 const base::FilePath file_path = base::FilePath::FromUTF8Unsafe("/hello"); |
150 const fileapi::FileSystemURL url = CreateFileSystemURL( | 162 const fileapi::FileSystemURL url = |
151 profile_, kExtensionId, file_system_id + 1, kFilePath); | 163 CreateFileSystemURL(profile_, file_system_info, file_path); |
152 // It is impossible to create a cracked URL for a mount point which doesn't | 164 // It is impossible to create a cracked URL for a mount point which doesn't |
153 // exist, therefore is will always be invalid, and empty. | 165 // exist, therefore is will always be invalid, and empty. |
154 EXPECT_FALSE(url.is_valid()); | 166 EXPECT_FALSE(url.is_valid()); |
155 | 167 |
156 FileSystemURLParser parser(url); | 168 FileSystemURLParser parser(url); |
157 EXPECT_FALSE(parser.Parse()); | 169 EXPECT_FALSE(parser.Parse()); |
158 } | 170 } |
159 | 171 |
160 } // namespace util | 172 } // namespace util |
161 } // namespace file_system_provider | 173 } // namespace file_system_provider |
162 } // namespace chromeos | 174 } // namespace chromeos |
OLD | NEW |