Index: webkit/fileapi/isolated_context_unittest.cc |
diff --git a/webkit/fileapi/isolated_context_unittest.cc b/webkit/fileapi/isolated_context_unittest.cc |
index bf36df91886856386c6e26d624e20cf96de290e0..e6dfd9a1beaffd9e7a3cef6af9f036934ce64ed5 100644 |
--- a/webkit/fileapi/isolated_context_unittest.cc |
+++ b/webkit/fileapi/isolated_context_unittest.cc |
@@ -7,6 +7,7 @@ |
#include "base/basictypes.h" |
#include "base/logging.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "webkit/fileapi/file_system_url.h" |
#include "webkit/fileapi/isolated_context.h" |
#define FPL(x) FILE_PATH_LITERAL(x) |
@@ -189,7 +190,7 @@ TEST_F(IsolatedContextTest, CrackWithRelativePaths) { |
.AppendASCII(names_[i]).Append(relatives[j].path); |
std::string cracked_id; |
FilePath cracked_path; |
- FileSystemType cracked_type; |
+ FileSystemType cracked_type; |
if (!relatives[j].valid) { |
ASSERT_FALSE(isolated_context()->CrackVirtualPath( |
virtual_path, &cracked_id, &cracked_type, &cracked_path)); |
@@ -206,6 +207,53 @@ TEST_F(IsolatedContextTest, CrackWithRelativePaths) { |
} |
} |
+TEST_F(IsolatedContextTest, CrackURLWithRelativePaths) { |
+ const struct { |
+ FilePath::StringType path; |
+ bool valid; |
+ } relatives[] = { |
+ { FPL("foo"), true }, |
+ { FPL("foo/bar"), true }, |
+ { FPL(".."), false }, |
+ { FPL("foo/.."), false }, |
+ { FPL("foo/../bar"), false }, |
+#if defined(FILE_PATH_USES_WIN_SEPARATORS) |
+# define SHOULD_FAIL_WITH_WIN_SEPARATORS false |
+#else |
+# define SHOULD_FAIL_WITH_WIN_SEPARATORS true |
+#endif |
+ { FPL("foo\\..\\baz"), SHOULD_FAIL_WITH_WIN_SEPARATORS }, |
+ { FPL("foo/..\\baz"), SHOULD_FAIL_WITH_WIN_SEPARATORS }, |
+ }; |
+ |
+ for (size_t i = 0; i < arraysize(kTestPaths); ++i) { |
+ for (size_t j = 0; j < ARRAYSIZE_UNSAFE(relatives); ++j) { |
+ SCOPED_TRACE(testing::Message() << "Testing " |
+ << kTestPaths[i].value() << " " << relatives[j].path); |
+ FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_) |
+ .AppendASCII(names_[i]).Append(relatives[j].path); |
+ |
+ FileSystemURL cracked = isolated_context()->CrackFileSystemURL( |
+ FileSystemURL::CreateForTest(GURL("http://chromium.org"), |
+ kFileSystemTypeIsolated, |
+ virtual_path)); |
+ |
+ ASSERT_EQ(relatives[j].valid, cracked.is_valid()); |
+ |
+ if (!relatives[j].valid) |
+ continue; |
+ ASSERT_EQ(GURL("http://chromium.org"), cracked.origin()); |
+ ASSERT_EQ(kTestPaths[i].Append(relatives[j].path) |
+ .NormalizePathSeparators().value(), |
+ cracked.path().value()); |
+ ASSERT_EQ(virtual_path.NormalizePathSeparators(), cracked.virtual_path()); |
+ ASSERT_EQ(id_, cracked.filesystem_id()); |
+ ASSERT_EQ(kFileSystemTypeDragged, cracked.type()); |
+ ASSERT_EQ(kFileSystemTypeIsolated, cracked.mount_type()); |
+ } |
+ } |
+} |
+ |
TEST_F(IsolatedContextTest, TestWithVirtualRoot) { |
std::string cracked_id; |
FilePath cracked_path; |
@@ -227,4 +275,35 @@ TEST_F(IsolatedContextTest, TestWithVirtualRoot) { |
virtual_path, &cracked_id, NULL, &cracked_path)); |
} |
+TEST_F(IsolatedContextTest, CanHandleURL) { |
+ const GURL test_origin("http://chromium.org"); |
+ const FilePath test_path(FPL("/mount")); |
+ |
+ // Shouldn't handle invalid URL. |
+ EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL())); |
+ |
+ // Should handle Isolated File System. |
+ EXPECT_TRUE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
+ test_origin, fileapi::kFileSystemTypeIsolated, test_path))); |
+ |
+ // Shouldn't handle the rest. |
+ EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
+ test_origin, fileapi::kFileSystemTypeExternal, test_path))); |
+ EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
+ test_origin, fileapi::kFileSystemTypeTemporary, test_path))); |
+ EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
+ test_origin, fileapi::kFileSystemTypePersistent, test_path))); |
+ EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
+ test_origin, fileapi::kFileSystemTypeTest, test_path))); |
+ // Not even if it's isolated subtype. |
+ EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
+ test_origin, fileapi::kFileSystemTypeNativeLocal, test_path))); |
+ EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
+ test_origin, fileapi::kFileSystemTypeDragged, test_path))); |
+ EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
+ test_origin, fileapi::kFileSystemTypeNativeMedia, test_path))); |
+ EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
+ test_origin, fileapi::kFileSystemTypeDeviceMedia, test_path))); |
+} |
+ |
} // namespace fileapi |