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/file_system_provider/mount_path_util.h" | 5 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "webkit/browser/fileapi/isolated_context.h" | 26 #include "webkit/browser/fileapi/isolated_context.h" |
27 | 27 |
28 namespace chromeos { | 28 namespace chromeos { |
29 namespace file_system_provider { | 29 namespace file_system_provider { |
30 namespace util { | 30 namespace util { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; | 34 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; |
35 const char kFileSystemId[] = "File/System/Id"; | 35 const char kFileSystemId[] = "File/System/Id"; |
36 const char kFileSystemName[] = "Camera Pictures"; | 36 const char kDisplayName[] = "Camera Pictures"; |
37 | 37 |
38 // Creates a FileSystemURL for tests. | 38 // Creates a FileSystemURL for tests. |
39 fileapi::FileSystemURL CreateFileSystemURL( | 39 fileapi::FileSystemURL CreateFileSystemURL( |
40 Profile* profile, | 40 Profile* profile, |
41 const ProvidedFileSystemInfo& file_system_info, | 41 const ProvidedFileSystemInfo& file_system_info, |
42 const base::FilePath& file_path) { | 42 const base::FilePath& file_path) { |
43 const std::string origin = | 43 const std::string origin = |
44 std::string("chrome-extension://") + file_system_info.extension_id(); | 44 std::string("chrome-extension://") + file_system_info.extension_id(); |
45 const base::FilePath mount_path = file_system_info.mount_path(); | 45 const base::FilePath mount_path = file_system_info.mount_path(); |
46 const fileapi::ExternalMountPoints* const mount_points = | 46 const fileapi::ExternalMountPoints* const mount_points = |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 base::FilePath::FromUTF8Unsafe("provided/hello-world/test.txt"))); | 120 base::FilePath::FromUTF8Unsafe("provided/hello-world/test.txt"))); |
121 EXPECT_FALSE(IsFileSystemProviderLocalPath( | 121 EXPECT_FALSE(IsFileSystemProviderLocalPath( |
122 base::FilePath::FromUTF8Unsafe("/provided"))); | 122 base::FilePath::FromUTF8Unsafe("/provided"))); |
123 EXPECT_FALSE( | 123 EXPECT_FALSE( |
124 IsFileSystemProviderLocalPath(base::FilePath::FromUTF8Unsafe("/"))); | 124 IsFileSystemProviderLocalPath(base::FilePath::FromUTF8Unsafe("/"))); |
125 EXPECT_FALSE(IsFileSystemProviderLocalPath(base::FilePath())); | 125 EXPECT_FALSE(IsFileSystemProviderLocalPath(base::FilePath())); |
126 } | 126 } |
127 | 127 |
128 TEST_F(FileSystemProviderMountPathUtilTest, Parser) { | 128 TEST_F(FileSystemProviderMountPathUtilTest, Parser) { |
129 const bool result = file_system_provider_service_->MountFileSystem( | 129 const bool result = file_system_provider_service_->MountFileSystem( |
130 kExtensionId, kFileSystemId, kFileSystemName); | 130 kExtensionId, kFileSystemId, kDisplayName); |
131 ASSERT_TRUE(result); | 131 ASSERT_TRUE(result); |
132 const ProvidedFileSystemInfo file_system_info = | 132 const ProvidedFileSystemInfo file_system_info = |
133 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 133 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
134 kFileSystemId) | 134 kFileSystemId) |
135 ->GetFileSystemInfo(); | 135 ->GetFileSystemInfo(); |
136 | 136 |
137 const base::FilePath kFilePath = | 137 const base::FilePath kFilePath = |
138 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); | 138 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); |
139 const fileapi::FileSystemURL url = | 139 const fileapi::FileSystemURL url = |
140 CreateFileSystemURL(profile_, file_system_info, kFilePath); | 140 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
141 EXPECT_TRUE(url.is_valid()); | 141 EXPECT_TRUE(url.is_valid()); |
142 | 142 |
143 FileSystemURLParser parser(url); | 143 FileSystemURLParser parser(url); |
144 EXPECT_TRUE(parser.Parse()); | 144 EXPECT_TRUE(parser.Parse()); |
145 | 145 |
146 ProvidedFileSystemInterface* file_system = parser.file_system(); | 146 ProvidedFileSystemInterface* file_system = parser.file_system(); |
147 ASSERT_TRUE(file_system); | 147 ASSERT_TRUE(file_system); |
148 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); | 148 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); |
149 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 149 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
150 } | 150 } |
151 | 151 |
152 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) { | 152 TEST_F(FileSystemProviderMountPathUtilTest, Parser_RootPath) { |
153 const bool result = file_system_provider_service_->MountFileSystem( | 153 const bool result = file_system_provider_service_->MountFileSystem( |
154 kExtensionId, kFileSystemId, kFileSystemName); | 154 kExtensionId, kFileSystemId, kDisplayName); |
155 ASSERT_TRUE(result); | 155 ASSERT_TRUE(result); |
156 const ProvidedFileSystemInfo file_system_info = | 156 const ProvidedFileSystemInfo file_system_info = |
157 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 157 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
158 kFileSystemId) | 158 kFileSystemId) |
159 ->GetFileSystemInfo(); | 159 ->GetFileSystemInfo(); |
160 | 160 |
161 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); | 161 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); |
162 const fileapi::FileSystemURL url = | 162 const fileapi::FileSystemURL url = |
163 CreateFileSystemURL(profile_, file_system_info, kFilePath); | 163 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
164 EXPECT_TRUE(url.is_valid()); | 164 EXPECT_TRUE(url.is_valid()); |
165 | 165 |
166 FileSystemURLParser parser(url); | 166 FileSystemURLParser parser(url); |
167 EXPECT_TRUE(parser.Parse()); | 167 EXPECT_TRUE(parser.Parse()); |
168 | 168 |
169 ProvidedFileSystemInterface* file_system = parser.file_system(); | 169 ProvidedFileSystemInterface* file_system = parser.file_system(); |
170 ASSERT_TRUE(file_system); | 170 ASSERT_TRUE(file_system); |
171 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); | 171 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); |
172 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 172 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
173 } | 173 } |
174 | 174 |
175 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) { | 175 TEST_F(FileSystemProviderMountPathUtilTest, Parser_WrongUrl) { |
176 const ProvidedFileSystemInfo file_system_info( | 176 const ProvidedFileSystemInfo file_system_info( |
177 kExtensionId, | 177 kExtensionId, |
178 kFileSystemId, | 178 kFileSystemId, |
179 kFileSystemName, | 179 kDisplayName, |
180 GetMountPath(profile_, kExtensionId, kFileSystemId)); | 180 GetMountPath(profile_, kExtensionId, kFileSystemId)); |
181 | 181 |
182 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/hello"); | 182 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/hello"); |
183 const fileapi::FileSystemURL url = | 183 const fileapi::FileSystemURL url = |
184 CreateFileSystemURL(profile_, file_system_info, kFilePath); | 184 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
185 // It is impossible to create a cracked URL for a mount point which doesn't | 185 // It is impossible to create a cracked URL for a mount point which doesn't |
186 // exist, therefore is will always be invalid, and empty. | 186 // exist, therefore is will always be invalid, and empty. |
187 EXPECT_FALSE(url.is_valid()); | 187 EXPECT_FALSE(url.is_valid()); |
188 | 188 |
189 FileSystemURLParser parser(url); | 189 FileSystemURLParser parser(url); |
190 EXPECT_FALSE(parser.Parse()); | 190 EXPECT_FALSE(parser.Parse()); |
191 } | 191 } |
192 | 192 |
193 TEST_F(FileSystemProviderMountPathUtilTest, Parser_IsolatedURL) { | 193 TEST_F(FileSystemProviderMountPathUtilTest, Parser_IsolatedURL) { |
194 const bool result = file_system_provider_service_->MountFileSystem( | 194 const bool result = file_system_provider_service_->MountFileSystem( |
195 kExtensionId, kFileSystemId, kFileSystemName); | 195 kExtensionId, kFileSystemId, kDisplayName); |
196 ASSERT_TRUE(result); | 196 ASSERT_TRUE(result); |
197 const ProvidedFileSystemInfo file_system_info = | 197 const ProvidedFileSystemInfo file_system_info = |
198 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 198 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
199 kFileSystemId) | 199 kFileSystemId) |
200 ->GetFileSystemInfo(); | 200 ->GetFileSystemInfo(); |
201 | 201 |
202 const base::FilePath kFilePath = | 202 const base::FilePath kFilePath = |
203 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); | 203 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); |
204 const fileapi::FileSystemURL url = | 204 const fileapi::FileSystemURL url = |
205 CreateFileSystemURL(profile_, file_system_info, kFilePath); | 205 CreateFileSystemURL(profile_, file_system_info, kFilePath); |
(...skipping 25 matching lines...) Expand all Loading... |
231 EXPECT_TRUE(parser.Parse()); | 231 EXPECT_TRUE(parser.Parse()); |
232 | 232 |
233 ProvidedFileSystemInterface* file_system = parser.file_system(); | 233 ProvidedFileSystemInterface* file_system = parser.file_system(); |
234 ASSERT_TRUE(file_system); | 234 ASSERT_TRUE(file_system); |
235 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); | 235 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); |
236 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 236 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
237 } | 237 } |
238 | 238 |
239 TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser) { | 239 TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser) { |
240 const bool result = file_system_provider_service_->MountFileSystem( | 240 const bool result = file_system_provider_service_->MountFileSystem( |
241 kExtensionId, kFileSystemId, kFileSystemName); | 241 kExtensionId, kFileSystemId, kDisplayName); |
242 ASSERT_TRUE(result); | 242 ASSERT_TRUE(result); |
243 const ProvidedFileSystemInfo file_system_info = | 243 const ProvidedFileSystemInfo file_system_info = |
244 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 244 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
245 kFileSystemId) | 245 kFileSystemId) |
246 ->GetFileSystemInfo(); | 246 ->GetFileSystemInfo(); |
247 | 247 |
248 const base::FilePath kFilePath = | 248 const base::FilePath kFilePath = |
249 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); | 249 base::FilePath::FromUTF8Unsafe("/hello/world.txt"); |
250 const base::FilePath kLocalFilePath = file_system_info.mount_path().Append( | 250 const base::FilePath kLocalFilePath = file_system_info.mount_path().Append( |
251 base::FilePath(kFilePath.value().substr(1))); | 251 base::FilePath(kFilePath.value().substr(1))); |
252 | 252 |
253 LOG(ERROR) << kLocalFilePath.value(); | 253 LOG(ERROR) << kLocalFilePath.value(); |
254 LocalPathParser parser(profile_, kLocalFilePath); | 254 LocalPathParser parser(profile_, kLocalFilePath); |
255 EXPECT_TRUE(parser.Parse()); | 255 EXPECT_TRUE(parser.Parse()); |
256 | 256 |
257 ProvidedFileSystemInterface* file_system = parser.file_system(); | 257 ProvidedFileSystemInterface* file_system = parser.file_system(); |
258 ASSERT_TRUE(file_system); | 258 ASSERT_TRUE(file_system); |
259 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); | 259 EXPECT_EQ(kFileSystemId, file_system->GetFileSystemInfo().file_system_id()); |
260 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); | 260 EXPECT_EQ(kFilePath.AsUTF8Unsafe(), parser.file_path().AsUTF8Unsafe()); |
261 } | 261 } |
262 | 262 |
263 TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser_RootPath) { | 263 TEST_F(FileSystemProviderMountPathUtilTest, LocalPathParser_RootPath) { |
264 const bool result = file_system_provider_service_->MountFileSystem( | 264 const bool result = file_system_provider_service_->MountFileSystem( |
265 kExtensionId, kFileSystemId, kFileSystemName); | 265 kExtensionId, kFileSystemId, kDisplayName); |
266 ASSERT_TRUE(result); | 266 ASSERT_TRUE(result); |
267 const ProvidedFileSystemInfo file_system_info = | 267 const ProvidedFileSystemInfo file_system_info = |
268 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, | 268 file_system_provider_service_->GetProvidedFileSystem(kExtensionId, |
269 kFileSystemId) | 269 kFileSystemId) |
270 ->GetFileSystemInfo(); | 270 ->GetFileSystemInfo(); |
271 | 271 |
272 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); | 272 const base::FilePath kFilePath = base::FilePath::FromUTF8Unsafe("/"); |
273 const base::FilePath kLocalFilePath = file_system_info.mount_path(); | 273 const base::FilePath kLocalFilePath = file_system_info.mount_path(); |
274 | 274 |
275 LocalPathParser parser(profile_, kLocalFilePath); | 275 LocalPathParser parser(profile_, kLocalFilePath); |
(...skipping 23 matching lines...) Expand all Loading... |
299 const base::FilePath kFilePath = | 299 const base::FilePath kFilePath = |
300 base::FilePath::FromUTF8Unsafe("provided/hello/world"); | 300 base::FilePath::FromUTF8Unsafe("provided/hello/world"); |
301 LocalPathParser parser(profile_, kFilePath); | 301 LocalPathParser parser(profile_, kFilePath); |
302 EXPECT_FALSE(parser.Parse()); | 302 EXPECT_FALSE(parser.Parse()); |
303 } | 303 } |
304 } | 304 } |
305 | 305 |
306 } // namespace util | 306 } // namespace util |
307 } // namespace file_system_provider | 307 } // namespace file_system_provider |
308 } // namespace chromeos | 308 } // namespace chromeos |
OLD | NEW |