| 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 "webkit/fileapi/isolated_context.h" | 5 #include "webkit/fileapi/isolated_context.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 void SetUp() { | 52 void SetUp() { |
| 53 IsolatedContext::FileInfoSet files; | 53 IsolatedContext::FileInfoSet files; |
| 54 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { | 54 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { |
| 55 std::string name; | 55 std::string name; |
| 56 ASSERT_TRUE( | 56 ASSERT_TRUE( |
| 57 files.AddPath(kTestPaths[i].NormalizePathSeparators(), &name)); | 57 files.AddPath(kTestPaths[i].NormalizePathSeparators(), &name)); |
| 58 names_.push_back(name); | 58 names_.push_back(name); |
| 59 } | 59 } |
| 60 id_ = IsolatedContext::GetInstance()->RegisterDraggedFileSystem(files); | 60 id_ = IsolatedContext::GetInstance()->RegisterDraggedFileSystem(files); |
| 61 IsolatedContext::GetInstance()->AddReference(id_); |
| 61 ASSERT_FALSE(id_.empty()); | 62 ASSERT_FALSE(id_.empty()); |
| 62 } | 63 } |
| 63 | 64 |
| 64 void TearDown() { | 65 void TearDown() { |
| 65 IsolatedContext::GetInstance()->RevokeFileSystem(id_); | 66 IsolatedContext::GetInstance()->RemoveReference(id_); |
| 66 } | 67 } |
| 67 | 68 |
| 68 IsolatedContext* isolated_context() const { | 69 IsolatedContext* isolated_context() const { |
| 69 return IsolatedContext::GetInstance(); | 70 return IsolatedContext::GetInstance(); |
| 70 } | 71 } |
| 71 | 72 |
| 72 protected: | 73 protected: |
| 73 std::string id_; | 74 std::string id_; |
| 74 std::multiset<FilePath> fileset_; | 75 std::multiset<FilePath> fileset_; |
| 75 std::vector<std::string> names_; | 76 std::vector<std::string> names_; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 102 cracked_path.value()); | 103 cracked_path.value()); |
| 103 ASSERT_EQ(id_, cracked_id); | 104 ASSERT_EQ(id_, cracked_id); |
| 104 ASSERT_EQ(kFileSystemTypeDragged, cracked_type); | 105 ASSERT_EQ(kFileSystemTypeDragged, cracked_type); |
| 105 } | 106 } |
| 106 | 107 |
| 107 // Make sure GetRegisteredPath returns false for id_ since it is | 108 // Make sure GetRegisteredPath returns false for id_ since it is |
| 108 // registered for dragged files. | 109 // registered for dragged files. |
| 109 FilePath path; | 110 FilePath path; |
| 110 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id_, &path)); | 111 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id_, &path)); |
| 111 | 112 |
| 112 // Revoking the current one and registering a new one. | 113 // Deref the current one and registering a new one. |
| 113 isolated_context()->RevokeFileSystem(id_); | 114 isolated_context()->RemoveReference(id_); |
| 115 |
| 114 std::string id2 = isolated_context()->RegisterFileSystemForPath( | 116 std::string id2 = isolated_context()->RegisterFileSystemForPath( |
| 115 kFileSystemTypeIsolated, FilePath(DRIVE FPL("/foo")), NULL); | 117 kFileSystemTypeIsolated, FilePath(DRIVE FPL("/foo")), NULL); |
| 116 | 118 |
| 117 // Make sure the GetDraggedFileInfo returns false for both ones. | 119 // Make sure the GetDraggedFileInfo returns false for both ones. |
| 118 ASSERT_FALSE(isolated_context()->GetDraggedFileInfo(id2, &toplevels)); | 120 ASSERT_FALSE(isolated_context()->GetDraggedFileInfo(id2, &toplevels)); |
| 119 ASSERT_FALSE(isolated_context()->GetDraggedFileInfo(id_, &toplevels)); | 121 ASSERT_FALSE(isolated_context()->GetDraggedFileInfo(id_, &toplevels)); |
| 120 | 122 |
| 121 // Make sure the GetRegisteredPath returns true only for the new one. | 123 // Make sure the GetRegisteredPath returns true only for the new one. |
| 124 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id_, &path)); |
| 122 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id2, &path)); | 125 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id2, &path)); |
| 123 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id_, &path)); | |
| 124 | 126 |
| 125 isolated_context()->RevokeFileSystem(id2); | 127 // Try registering two more file systems for the same path as id2. |
| 128 std::string id3 = isolated_context()->RegisterFileSystemForPath( |
| 129 kFileSystemTypeIsolated, path, NULL); |
| 130 std::string id4 = isolated_context()->RegisterFileSystemForPath( |
| 131 kFileSystemTypeIsolated, path, NULL); |
| 132 |
| 133 // Remove file system for id4. |
| 134 isolated_context()->AddReference(id4); |
| 135 isolated_context()->RemoveReference(id4); |
| 136 |
| 137 // Only id4 should become invalid now. |
| 138 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id2, &path)); |
| 139 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id3, &path)); |
| 140 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id4, &path)); |
| 141 |
| 142 // Revoke the file systems by path. |
| 143 isolated_context()->RevokeFileSystemByPath(path); |
| 144 |
| 145 // Now all the file systems associated to the path must be invalid. |
| 146 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id2, &path)); |
| 147 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id3, &path)); |
| 148 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id4, &path)); |
| 126 } | 149 } |
| 127 | 150 |
| 128 TEST_F(IsolatedContextTest, CrackWithRelativePaths) { | 151 TEST_F(IsolatedContextTest, CrackWithRelativePaths) { |
| 129 const struct { | 152 const struct { |
| 130 FilePath::StringType path; | 153 FilePath::StringType path; |
| 131 bool valid; | 154 bool valid; |
| 132 } relatives[] = { | 155 } relatives[] = { |
| 133 { FPL("foo"), true }, | 156 { FPL("foo"), true }, |
| 134 { FPL("foo/bar"), true }, | 157 { FPL("foo/bar"), true }, |
| 135 { FPL(".."), false }, | 158 { FPL(".."), false }, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 207 |
| 185 // Trying to crack "/foo" should fail (because "foo" is not the one | 208 // Trying to crack "/foo" should fail (because "foo" is not the one |
| 186 // included in the kTestPaths). | 209 // included in the kTestPaths). |
| 187 virtual_path = isolated_context()->CreateVirtualRootPath( | 210 virtual_path = isolated_context()->CreateVirtualRootPath( |
| 188 id_).AppendASCII("foo"); | 211 id_).AppendASCII("foo"); |
| 189 ASSERT_FALSE(isolated_context()->CrackIsolatedPath( | 212 ASSERT_FALSE(isolated_context()->CrackIsolatedPath( |
| 190 virtual_path, &cracked_id, NULL, &cracked_path)); | 213 virtual_path, &cracked_id, NULL, &cracked_path)); |
| 191 } | 214 } |
| 192 | 215 |
| 193 } // namespace fileapi | 216 } // namespace fileapi |
| OLD | NEW |