Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: webkit/fileapi/external_mount_points_unittest.cc

Issue 11787028: New FileSystemURL cracking (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Couple of nits I noticed Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "webkit/fileapi/external_mount_points.h" 5 #include "webkit/fileapi/external_mount_points.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "webkit/fileapi/file_system_url.h"
11 12
12 #define FPL FILE_PATH_LITERAL 13 #define FPL FILE_PATH_LITERAL
13 14
14 #if defined(FILE_PATH_USES_DRIVE_LETTERS) 15 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
15 #define DRIVE FPL("C:") 16 #define DRIVE FPL("C:")
16 #else 17 #else
17 #define DRIVE 18 #define DRIVE
18 #endif 19 #endif
19 20
21 using fileapi::FileSystemURL;
22
20 namespace { 23 namespace {
21 24
22 TEST(ExternalMountPointsTest, AddMountPoint) { 25 TEST(ExternalMountPointsTest, AddMountPoint) {
23 scoped_refptr<fileapi::ExternalMountPoints> mount_points( 26 scoped_refptr<fileapi::ExternalMountPoints> mount_points(
24 fileapi::ExternalMountPoints::CreateRefCounted()); 27 fileapi::ExternalMountPoints::CreateRefCounted());
25 28
26 struct TestCase { 29 struct TestCase {
27 // The mount point's name. 30 // The mount point's name.
28 const char* const name; 31 const char* const name;
29 // The mount point's path. 32 // The mount point's path.
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // fails. 219 // fails.
217 if (!kTestCases[i].success) 220 if (!kTestCases[i].success)
218 continue; 221 continue;
219 222
220 FilePath expected_virtual_path(kTestCases[i].virtual_path); 223 FilePath expected_virtual_path(kTestCases[i].virtual_path);
221 EXPECT_EQ(expected_virtual_path.NormalizePathSeparators(), virtual_path) 224 EXPECT_EQ(expected_virtual_path.NormalizePathSeparators(), virtual_path)
222 << "Resolving " << kTestCases[i].local_path; 225 << "Resolving " << kTestCases[i].local_path;
223 } 226 }
224 } 227 }
225 228
229 TEST(ExternalMountPointsTest, CanHandleURL) {
230 scoped_refptr<fileapi::ExternalMountPoints> mount_points(
231 fileapi::ExternalMountPoints::CreateRefCounted());
232
233 const GURL test_origin("http://chromium.org");
234 const FilePath test_path(FPL("/mount"));
235
236 // Shouldn't handle invalid URL.
237 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL()));
238
239 // Should handle External File System.
240 EXPECT_TRUE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
241 test_origin, fileapi::kFileSystemTypeExternal, test_path)));
242
243 // Shouldn't handle the rest.
244 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
245 test_origin, fileapi::kFileSystemTypeIsolated, test_path)));
246 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
247 test_origin, fileapi::kFileSystemTypeTemporary, test_path)));
248 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
249 test_origin, fileapi::kFileSystemTypePersistent, test_path)));
250 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
251 test_origin, fileapi::kFileSystemTypeTest, test_path)));
252 // Not even if it's external subtype.
253 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
254 test_origin, fileapi::kFileSystemTypeNativeLocal, test_path)));
255 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
256 test_origin, fileapi::kFileSystemTypeRestrictedNativeLocal, test_path)));
257 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
258 test_origin, fileapi::kFileSystemTypeDrive, test_path)));
259 EXPECT_FALSE(mount_points->CanHandleURL(FileSystemURL::CreateForTest(
260 test_origin, fileapi::kFileSystemTypeSyncable, test_path)));
261 }
262
263 TEST(ExternalMountPointsTest, CrackURL) {
264 scoped_refptr<fileapi::ExternalMountPoints> mount_points(
265 fileapi::ExternalMountPoints::CreateRefCounted());
266
267 const GURL kTestOrigin("http://chromium.org");
268
269 mount_points->RegisterFileSystem("c",
270 fileapi::kFileSystemTypeNativeLocal,
271 FilePath(DRIVE FPL("/a/b/c")));
272 mount_points->RegisterFileSystem("c(1)",
273 fileapi::kFileSystemTypeDrive,
274 FilePath(DRIVE FPL("/a/b/c(1)")));
275 mount_points->RegisterFileSystem("empty_path",
276 fileapi::kFileSystemTypeSyncable,
277 FilePath(FPL("")));
278 mount_points->RegisterFileSystem("mount",
279 fileapi::kFileSystemTypeDrive,
280 FilePath(DRIVE FPL("/root")));
281
282 // Try cracking isolated path.
283 FileSystemURL isolated = mount_points->CrackFileSystemURL(
284 FileSystemURL::CreateForTest(kTestOrigin,
285 fileapi::kFileSystemTypeIsolated,
286 FilePath(FPL("c"))));
287 EXPECT_FALSE(isolated.is_valid());
288
289 // Try native local which is no tcracked.
290 FileSystemURL native_local = mount_points->CrackFileSystemURL(
291 FileSystemURL::CreateForTest(kTestOrigin,
292 fileapi::kFileSystemTypeNativeLocal,
293 FilePath(FPL("c"))));
294 EXPECT_FALSE(native_local.is_valid());
295
296 struct TestCase {
297 const FilePath::CharType* const path;
298 bool expect_valid;
299 fileapi::FileSystemType expect_type;
300 const FilePath::CharType* const expect_path;
301 const char* const expect_fs_id;
302 };
303
304 const TestCase kTestCases[] = {
305 { FPL("c/d/e"),
306 true, fileapi::kFileSystemTypeNativeLocal, DRIVE FPL("/a/b/c/d/e"), "c" },
307 { FPL("c(1)/d/e"),
308 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)/d/e"), "c(1)" },
309 { FPL("c(1)"),
310 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)"), "c(1)" },
311 { FPL("empty_path/a"),
312 true, fileapi::kFileSystemTypeSyncable, FPL("a"), "empty_path" },
313 { FPL("empty_path"),
314 true, fileapi::kFileSystemTypeSyncable, FPL(""), "empty_path" },
315 { FPL("mount/a/b"),
316 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root/a/b"), "mount" },
317 { FPL("mount"),
318 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root"), "mount" },
319 { FPL("cc"),
320 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
321 { FPL(""),
322 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
323 { FPL(".."),
324 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
325 // Absolte paths.
326 { FPL("/c/d/e"),
327 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
328 { FPL("/c(1)/d/e"),
329 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
330 { FPL("/empty_path"),
331 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
332 // PAth references parent.
333 { FPL("c/d/../e"),
334 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
335 { FPL("/empty_path/a/../b"),
336 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
337 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
338 { FPL("c/d\\e"),
339 true, fileapi::kFileSystemTypeNativeLocal, DRIVE FPL("/a/b/c/d/e"), "c" },
340 { FPL("mount\\a\\b"),
341 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root/a/b"), "mount" },
342 #endif
343 };
344
345 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
346 FileSystemURL cracked = mount_points->CrackFileSystemURL(
347 FileSystemURL::CreateForTest(kTestOrigin,
348 fileapi::kFileSystemTypeExternal,
349 FilePath(kTestCases[i].path)));
350
351 EXPECT_EQ(kTestCases[i].expect_valid, cracked.is_valid())
352 << "Test case index: " << i;
353
354 if (!kTestCases[i].expect_valid)
355 continue;
356
357 EXPECT_EQ(kTestOrigin, cracked.origin())
358 << "Test case index: " << i;
359 EXPECT_EQ(kTestCases[i].expect_type, cracked.type())
360 << "Test case index: " << i;
361 EXPECT_EQ(FilePath(kTestCases[i].expect_path).NormalizePathSeparators(),
362 cracked.path())
363 << "Test case index: " << i;
364 EXPECT_EQ(FilePath(kTestCases[i].path).NormalizePathSeparators(),
365 cracked.virtual_path())
366 << "Test case index: " << i;
367 EXPECT_EQ(kTestCases[i].expect_fs_id, cracked.filesystem_id())
368 << "Test case index: " << i;
369 EXPECT_EQ(fileapi::kFileSystemTypeExternal, cracked.mount_type())
370 << "Test case index: " << i;
371 }
372 }
373
374 TEST(ExternalMountPointsTest, CrackVirtualPath) {
375 scoped_refptr<fileapi::ExternalMountPoints> mount_points(
376 fileapi::ExternalMountPoints::CreateRefCounted());
377
378 const GURL kTestOrigin("http://chromium.org");
379
380 mount_points->RegisterFileSystem("c",
381 fileapi::kFileSystemTypeNativeLocal,
382 FilePath(DRIVE FPL("/a/b/c")));
383 mount_points->RegisterFileSystem("c(1)",
384 fileapi::kFileSystemTypeDrive,
385 FilePath(DRIVE FPL("/a/b/c(1)")));
386 mount_points->RegisterFileSystem("empty_path",
387 fileapi::kFileSystemTypeSyncable,
388 FilePath(FPL("")));
389 mount_points->RegisterFileSystem("mount",
390 fileapi::kFileSystemTypeDrive,
391 FilePath(DRIVE FPL("/root")));
392
393 struct TestCase {
394 const FilePath::CharType* const path;
395 bool expect_valid;
396 fileapi::FileSystemType expect_type;
397 const FilePath::CharType* const expect_path;
398 const char* const expect_name;
399 };
400
401 const TestCase kTestCases[] = {
402 { FPL("c/d/e"),
403 true, fileapi::kFileSystemTypeNativeLocal, DRIVE FPL("/a/b/c/d/e"), "c" },
404 { FPL("c(1)/d/e"),
405 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)/d/e"), "c(1)" },
406 { FPL("c(1)"),
407 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/a/b/c(1)"), "c(1)" },
408 { FPL("empty_path/a"),
409 true, fileapi::kFileSystemTypeSyncable, FPL("a"), "empty_path" },
410 { FPL("empty_path"),
411 true, fileapi::kFileSystemTypeSyncable, FPL(""), "empty_path" },
412 { FPL("mount/a/b"),
413 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root/a/b"), "mount" },
414 { FPL("mount"),
415 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root"), "mount" },
416 { FPL("cc"),
417 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
418 { FPL(""),
419 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
420 { FPL(".."),
421 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
422 // Absolte paths.
423 { FPL("/c/d/e"),
424 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
425 { FPL("/c(1)/d/e"),
426 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
427 { FPL("/empty_path"),
428 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
429 // PAth references parent.
430 { FPL("c/d/../e"),
431 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
432 { FPL("/empty_path/a/../b"),
433 false, fileapi::kFileSystemTypeUnknown, FPL(""), "" },
434 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
435 { FPL("c/d\\e"),
436 true, fileapi::kFileSystemTypeNativeLocal, DRIVE FPL("/a/b/c/d/e"), "c" },
437 { FPL("mount\\a\\b"),
438 true, fileapi::kFileSystemTypeDrive, DRIVE FPL("/root/a/b"), "mount" },
439 #endif
440 };
441
442 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
443 std::string cracked_name;
444 fileapi::FileSystemType cracked_type;
445 FilePath cracked_path;
446 EXPECT_EQ(kTestCases[i].expect_valid,
447 mount_points->CrackVirtualPath(FilePath(kTestCases[i].path),
448 &cracked_name, &cracked_type, &cracked_path))
449 << "Test case index: " << i;
450
451 if (!kTestCases[i].expect_valid)
452 continue;
453
454 EXPECT_EQ(kTestCases[i].expect_type, cracked_type)
455 << "Test case index: " << i;
456 EXPECT_EQ(FilePath(kTestCases[i].expect_path).NormalizePathSeparators(),
457 cracked_path)
458 << "Test case index: " << i;
459 EXPECT_EQ(kTestCases[i].expect_name, cracked_name)
460 << "Test case index: " << i;
461 }
462 }
463
226 } // namespace 464 } // namespace
227 465
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698