| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "webkit/fileapi/file_system_url.h" |
| 10 #include "webkit/fileapi/isolated_context.h" | 11 #include "webkit/fileapi/isolated_context.h" |
| 11 | 12 |
| 12 #define FPL(x) FILE_PATH_LITERAL(x) | 13 #define FPL(x) FILE_PATH_LITERAL(x) |
| 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 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 }; | 183 }; |
| 183 | 184 |
| 184 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { | 185 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { |
| 185 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(relatives); ++j) { | 186 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(relatives); ++j) { |
| 186 SCOPED_TRACE(testing::Message() << "Testing " | 187 SCOPED_TRACE(testing::Message() << "Testing " |
| 187 << kTestPaths[i].value() << " " << relatives[j].path); | 188 << kTestPaths[i].value() << " " << relatives[j].path); |
| 188 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_) | 189 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_) |
| 189 .AppendASCII(names_[i]).Append(relatives[j].path); | 190 .AppendASCII(names_[i]).Append(relatives[j].path); |
| 190 std::string cracked_id; | 191 std::string cracked_id; |
| 191 FilePath cracked_path; | 192 FilePath cracked_path; |
| 192 FileSystemType cracked_type; | 193 FileSystemType cracked_type; |
| 193 if (!relatives[j].valid) { | 194 if (!relatives[j].valid) { |
| 194 ASSERT_FALSE(isolated_context()->CrackVirtualPath( | 195 ASSERT_FALSE(isolated_context()->CrackVirtualPath( |
| 195 virtual_path, &cracked_id, &cracked_type, &cracked_path)); | 196 virtual_path, &cracked_id, &cracked_type, &cracked_path)); |
| 196 continue; | 197 continue; |
| 197 } | 198 } |
| 198 ASSERT_TRUE(isolated_context()->CrackVirtualPath( | 199 ASSERT_TRUE(isolated_context()->CrackVirtualPath( |
| 199 virtual_path, &cracked_id, &cracked_type, &cracked_path)); | 200 virtual_path, &cracked_id, &cracked_type, &cracked_path)); |
| 200 ASSERT_EQ(kTestPaths[i].Append(relatives[j].path) | 201 ASSERT_EQ(kTestPaths[i].Append(relatives[j].path) |
| 201 .NormalizePathSeparators().value(), | 202 .NormalizePathSeparators().value(), |
| 202 cracked_path.value()); | 203 cracked_path.value()); |
| 203 ASSERT_EQ(id_, cracked_id); | 204 ASSERT_EQ(id_, cracked_id); |
| 204 ASSERT_EQ(kFileSystemTypeDragged, cracked_type); | 205 ASSERT_EQ(kFileSystemTypeDragged, cracked_type); |
| 205 } | 206 } |
| 206 } | 207 } |
| 207 } | 208 } |
| 208 | 209 |
| 210 TEST_F(IsolatedContextTest, CrackURLWithRelativePaths) { |
| 211 const struct { |
| 212 FilePath::StringType path; |
| 213 bool valid; |
| 214 } relatives[] = { |
| 215 { FPL("foo"), true }, |
| 216 { FPL("foo/bar"), true }, |
| 217 { FPL(".."), false }, |
| 218 { FPL("foo/.."), false }, |
| 219 { FPL("foo/../bar"), false }, |
| 220 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 221 # define SHOULD_FAIL_WITH_WIN_SEPARATORS false |
| 222 #else |
| 223 # define SHOULD_FAIL_WITH_WIN_SEPARATORS true |
| 224 #endif |
| 225 { FPL("foo\\..\\baz"), SHOULD_FAIL_WITH_WIN_SEPARATORS }, |
| 226 { FPL("foo/..\\baz"), SHOULD_FAIL_WITH_WIN_SEPARATORS }, |
| 227 }; |
| 228 |
| 229 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { |
| 230 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(relatives); ++j) { |
| 231 SCOPED_TRACE(testing::Message() << "Testing " |
| 232 << kTestPaths[i].value() << " " << relatives[j].path); |
| 233 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_) |
| 234 .AppendASCII(names_[i]).Append(relatives[j].path); |
| 235 |
| 236 FileSystemURL cracked = isolated_context()->CrackFileSystemURL( |
| 237 FileSystemURL::CreateForTest(GURL("http://chromium.org"), |
| 238 kFileSystemTypeIsolated, |
| 239 virtual_path)); |
| 240 |
| 241 ASSERT_EQ(relatives[j].valid, cracked.is_valid()); |
| 242 |
| 243 if (!relatives[j].valid) |
| 244 continue; |
| 245 ASSERT_EQ(GURL("http://chromium.org"), cracked.origin()); |
| 246 ASSERT_EQ(kTestPaths[i].Append(relatives[j].path) |
| 247 .NormalizePathSeparators().value(), |
| 248 cracked.path().value()); |
| 249 ASSERT_EQ(virtual_path.NormalizePathSeparators(), cracked.virtual_path()); |
| 250 ASSERT_EQ(id_, cracked.filesystem_id()); |
| 251 ASSERT_EQ(kFileSystemTypeDragged, cracked.type()); |
| 252 ASSERT_EQ(kFileSystemTypeIsolated, cracked.mount_type()); |
| 253 } |
| 254 } |
| 255 } |
| 256 |
| 209 TEST_F(IsolatedContextTest, TestWithVirtualRoot) { | 257 TEST_F(IsolatedContextTest, TestWithVirtualRoot) { |
| 210 std::string cracked_id; | 258 std::string cracked_id; |
| 211 FilePath cracked_path; | 259 FilePath cracked_path; |
| 212 | 260 |
| 213 // Trying to crack virtual root "/" returns true but with empty cracked path | 261 // Trying to crack virtual root "/" returns true but with empty cracked path |
| 214 // as "/" of the isolated filesystem is a pure virtual directory | 262 // as "/" of the isolated filesystem is a pure virtual directory |
| 215 // that has no corresponding platform directory. | 263 // that has no corresponding platform directory. |
| 216 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_); | 264 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_); |
| 217 ASSERT_TRUE(isolated_context()->CrackVirtualPath( | 265 ASSERT_TRUE(isolated_context()->CrackVirtualPath( |
| 218 virtual_path, &cracked_id, NULL, &cracked_path)); | 266 virtual_path, &cracked_id, NULL, &cracked_path)); |
| 219 ASSERT_EQ(FPL(""), cracked_path.value()); | 267 ASSERT_EQ(FPL(""), cracked_path.value()); |
| 220 ASSERT_EQ(id_, cracked_id); | 268 ASSERT_EQ(id_, cracked_id); |
| 221 | 269 |
| 222 // Trying to crack "/foo" should fail (because "foo" is not the one | 270 // Trying to crack "/foo" should fail (because "foo" is not the one |
| 223 // included in the kTestPaths). | 271 // included in the kTestPaths). |
| 224 virtual_path = isolated_context()->CreateVirtualRootPath( | 272 virtual_path = isolated_context()->CreateVirtualRootPath( |
| 225 id_).AppendASCII("foo"); | 273 id_).AppendASCII("foo"); |
| 226 ASSERT_FALSE(isolated_context()->CrackVirtualPath( | 274 ASSERT_FALSE(isolated_context()->CrackVirtualPath( |
| 227 virtual_path, &cracked_id, NULL, &cracked_path)); | 275 virtual_path, &cracked_id, NULL, &cracked_path)); |
| 228 } | 276 } |
| 229 | 277 |
| 278 TEST_F(IsolatedContextTest, CanHandleURL) { |
| 279 const GURL test_origin("http://chromium.org"); |
| 280 const FilePath test_path(FPL("/mount")); |
| 281 |
| 282 // Shouldn't handle invalid URL. |
| 283 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL())); |
| 284 |
| 285 // Should handle Isolated File System. |
| 286 EXPECT_TRUE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
| 287 test_origin, fileapi::kFileSystemTypeIsolated, test_path))); |
| 288 |
| 289 // Shouldn't handle the rest. |
| 290 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
| 291 test_origin, fileapi::kFileSystemTypeExternal, test_path))); |
| 292 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
| 293 test_origin, fileapi::kFileSystemTypeTemporary, test_path))); |
| 294 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
| 295 test_origin, fileapi::kFileSystemTypePersistent, test_path))); |
| 296 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
| 297 test_origin, fileapi::kFileSystemTypeTest, test_path))); |
| 298 // Not even if it's isolated subtype. |
| 299 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
| 300 test_origin, fileapi::kFileSystemTypeNativeLocal, test_path))); |
| 301 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
| 302 test_origin, fileapi::kFileSystemTypeDragged, test_path))); |
| 303 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
| 304 test_origin, fileapi::kFileSystemTypeNativeMedia, test_path))); |
| 305 EXPECT_FALSE(isolated_context()->CanHandleURL(FileSystemURL::CreateForTest( |
| 306 test_origin, fileapi::kFileSystemTypeDeviceMedia, test_path))); |
| 307 } |
| 308 |
| 230 } // namespace fileapi | 309 } // namespace fileapi |
| OLD | NEW |