| 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/isolated_context.h" | 10 #include "webkit/fileapi/isolated_context.h" |
| 11 | 11 |
| 12 #define FPL(x) FILE_PATH_LITERAL(x) | 12 #define FPL(x) FILE_PATH_LITERAL(x) |
| 13 | 13 |
| 14 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | 14 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 15 #define DRIVE FPL("C:") | 15 #define DRIVE FPL("C:") |
| 16 #else | 16 #else |
| 17 #define DRIVE | 17 #define DRIVE |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 namespace fileapi { | 20 namespace fileapi { |
| 21 | 21 |
| 22 typedef IsolatedContext::FileInfo FileInfo; | 22 typedef IsolatedContext::MountPointInfo FileInfo; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const FilePath kTestPaths[] = { | 26 const FilePath kTestPaths[] = { |
| 27 FilePath(DRIVE FPL("/a/b.txt")), | 27 FilePath(DRIVE FPL("/a/b.txt")), |
| 28 FilePath(DRIVE FPL("/c/d/e")), | 28 FilePath(DRIVE FPL("/c/d/e")), |
| 29 FilePath(DRIVE FPL("/h/")), | 29 FilePath(DRIVE FPL("/h/")), |
| 30 FilePath(DRIVE FPL("/")), | 30 FilePath(DRIVE FPL("/")), |
| 31 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 31 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 32 FilePath(DRIVE FPL("\\foo\\bar")), | 32 FilePath(DRIVE FPL("\\foo\\bar")), |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 105 |
| 106 // Make sure GetRegisteredPath returns false for id_ since it is | 106 // Make sure GetRegisteredPath returns false for id_ since it is |
| 107 // registered for dragged files. | 107 // registered for dragged files. |
| 108 FilePath path; | 108 FilePath path; |
| 109 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id_, &path)); | 109 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id_, &path)); |
| 110 | 110 |
| 111 // Deref the current one and registering a new one. | 111 // Deref the current one and registering a new one. |
| 112 isolated_context()->RemoveReference(id_); | 112 isolated_context()->RemoveReference(id_); |
| 113 | 113 |
| 114 std::string id2 = isolated_context()->RegisterFileSystemForPath( | 114 std::string id2 = isolated_context()->RegisterFileSystemForPath( |
| 115 kFileSystemTypeNativeLocal, FilePath(DRIVE FPL("/foo")), NULL); | 115 kFileSystemTypeIsolatedNativeLocal, FilePath(DRIVE FPL("/foo")), NULL); |
| 116 | 116 |
| 117 // Make sure the GetDraggedFileInfo returns false for both ones. | 117 // Make sure the GetDraggedFileInfo returns false for both ones. |
| 118 ASSERT_FALSE(isolated_context()->GetDraggedFileInfo(id2, &toplevels)); | 118 ASSERT_FALSE(isolated_context()->GetDraggedFileInfo(id2, &toplevels)); |
| 119 ASSERT_FALSE(isolated_context()->GetDraggedFileInfo(id_, &toplevels)); | 119 ASSERT_FALSE(isolated_context()->GetDraggedFileInfo(id_, &toplevels)); |
| 120 | 120 |
| 121 // Make sure the GetRegisteredPath returns true only for the new one. | 121 // Make sure the GetRegisteredPath returns true only for the new one. |
| 122 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id_, &path)); | 122 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id_, &path)); |
| 123 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id2, &path)); | 123 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id2, &path)); |
| 124 | 124 |
| 125 // Try registering three more file systems for the same path as id2. | 125 // Try registering three more file systems for the same path as id2. |
| 126 std::string id3 = isolated_context()->RegisterFileSystemForPath( | 126 std::string id3 = isolated_context()->RegisterFileSystemForPath( |
| 127 kFileSystemTypeNativeLocal, path, NULL); | 127 kFileSystemTypeNativeLocal, path, NULL); |
| 128 std::string id4 = isolated_context()->RegisterFileSystemForPath( | 128 std::string id4 = isolated_context()->RegisterFileSystemForPath( |
| 129 kFileSystemTypeNativeLocal, path, NULL); | 129 kFileSystemTypeIsolatedNativeLocal, path, NULL); |
| 130 std::string id5 = isolated_context()->RegisterFileSystemForPath( | 130 std::string id5 = isolated_context()->RegisterFileSystemForPath( |
| 131 kFileSystemTypeNativeLocal, path, NULL); | 131 kFileSystemTypeIsolatedNativeLocal, path, NULL); |
| 132 | 132 |
| 133 // Remove file system for id4. | 133 // Remove file system for id4. |
| 134 isolated_context()->AddReference(id4); | 134 isolated_context()->AddReference(id4); |
| 135 isolated_context()->RemoveReference(id4); | 135 isolated_context()->RemoveReference(id4); |
| 136 | 136 |
| 137 // Only id4 should become invalid now. | 137 // Only id4 should become invalid now. |
| 138 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id2, &path)); | 138 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id2, &path)); |
| 139 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id3, &path)); | 139 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id3, &path)); |
| 140 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id4, &path)); | 140 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id4, &path)); |
| 141 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id5, &path)); | 141 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id5, &path)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 221 |
| 222 // Trying to crack "/foo" should fail (because "foo" is not the one | 222 // Trying to crack "/foo" should fail (because "foo" is not the one |
| 223 // included in the kTestPaths). | 223 // included in the kTestPaths). |
| 224 virtual_path = isolated_context()->CreateVirtualRootPath( | 224 virtual_path = isolated_context()->CreateVirtualRootPath( |
| 225 id_).AppendASCII("foo"); | 225 id_).AppendASCII("foo"); |
| 226 ASSERT_FALSE(isolated_context()->CrackIsolatedPath( | 226 ASSERT_FALSE(isolated_context()->CrackIsolatedPath( |
| 227 virtual_path, &cracked_id, NULL, &cracked_path)); | 227 virtual_path, &cracked_id, NULL, &cracked_path)); |
| 228 } | 228 } |
| 229 | 229 |
| 230 } // namespace fileapi | 230 } // namespace fileapi |
| OLD | NEW |