| 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 28 matching lines...) Expand all Loading... |
| 39 for (size_t i = 0; i < arraysize(kTestPaths); ++i) | 39 for (size_t i = 0; i < arraysize(kTestPaths); ++i) |
| 40 fileset_.insert(kTestPaths[i].NormalizePathSeparators()); | 40 fileset_.insert(kTestPaths[i].NormalizePathSeparators()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void SetUp() { | 43 void SetUp() { |
| 44 id_ = IsolatedContext::GetInstance()->RegisterIsolatedFileSystem(fileset_); | 44 id_ = IsolatedContext::GetInstance()->RegisterIsolatedFileSystem(fileset_); |
| 45 ASSERT_FALSE(id_.empty()); | 45 ASSERT_FALSE(id_.empty()); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void TearDown() { | 48 void TearDown() { |
| 49 IsolatedContext::GetInstance()->RevokeIsolatedFileSystem(id_); | 49 IsolatedContext::GetInstance()->RemoveReference(id_); |
| 50 } | 50 } |
| 51 | 51 |
| 52 IsolatedContext* isolated_context() const { | 52 IsolatedContext* isolated_context() const { |
| 53 return IsolatedContext::GetInstance(); | 53 return IsolatedContext::GetInstance(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 protected: | 56 protected: |
| 57 std::string id_; | 57 std::string id_; |
| 58 std::set<FilePath> fileset_; | 58 std::set<FilePath> fileset_; |
| 59 | 59 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 81 ASSERT_TRUE(isolated_context()->CrackIsolatedPath( | 81 ASSERT_TRUE(isolated_context()->CrackIsolatedPath( |
| 82 virtual_path, &cracked_id, &root_path, &cracked_path)); | 82 virtual_path, &cracked_id, &root_path, &cracked_path)); |
| 83 ASSERT_EQ(kTestPaths[i].NormalizePathSeparators().value(), | 83 ASSERT_EQ(kTestPaths[i].NormalizePathSeparators().value(), |
| 84 cracked_path.value()); | 84 cracked_path.value()); |
| 85 ASSERT_TRUE(fileset_.find(root_path.NormalizePathSeparators()) | 85 ASSERT_TRUE(fileset_.find(root_path.NormalizePathSeparators()) |
| 86 != fileset_.end()); | 86 != fileset_.end()); |
| 87 ASSERT_EQ(id_, cracked_id); | 87 ASSERT_EQ(id_, cracked_id); |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Revoking the current one and registering a new (empty) one. | 90 // Revoking the current one and registering a new (empty) one. |
| 91 isolated_context()->RevokeIsolatedFileSystem(id_); | 91 isolated_context()->RemoveReference(id_); |
| 92 std::string id2 = isolated_context()->RegisterIsolatedFileSystem( | 92 std::string id2 = isolated_context()->RegisterIsolatedFileSystem( |
| 93 std::set<FilePath>()); | 93 std::set<FilePath>()); |
| 94 | 94 |
| 95 // Make sure the GetTopLevelPaths returns true only for the new one. | 95 // Make sure the GetTopLevelPaths returns true only for the new one. |
| 96 ASSERT_TRUE(isolated_context()->GetTopLevelPaths(id2, &toplevels)); | 96 ASSERT_TRUE(isolated_context()->GetTopLevelPaths(id2, &toplevels)); |
| 97 ASSERT_FALSE(isolated_context()->GetTopLevelPaths(id_, &toplevels)); | 97 ASSERT_FALSE(isolated_context()->GetTopLevelPaths(id_, &toplevels)); |
| 98 | 98 |
| 99 isolated_context()->RevokeIsolatedFileSystem(id2); | 99 isolated_context()->RemoveReference(id2); |
| 100 } | 100 } |
| 101 | 101 |
| 102 TEST_F(IsolatedContextTest, CrackWithRelativePaths) { | 102 TEST_F(IsolatedContextTest, CrackWithRelativePaths) { |
| 103 const struct { | 103 const struct { |
| 104 FilePath::StringType path; | 104 FilePath::StringType path; |
| 105 bool valid; | 105 bool valid; |
| 106 } relatives[] = { | 106 } relatives[] = { |
| 107 { FPL("foo"), true }, | 107 { FPL("foo"), true }, |
| 108 { FPL("foo/bar"), true }, | 108 { FPL("foo/bar"), true }, |
| 109 { FPL(".."), false }, | 109 { FPL(".."), false }, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 // Set writable. | 172 // Set writable. |
| 173 ASSERT_TRUE(isolated_context()->SetWritable(id_, true)); | 173 ASSERT_TRUE(isolated_context()->SetWritable(id_, true)); |
| 174 ASSERT_TRUE(isolated_context()->IsWritable(id_)); | 174 ASSERT_TRUE(isolated_context()->IsWritable(id_)); |
| 175 | 175 |
| 176 // Set non-writable. | 176 // Set non-writable. |
| 177 ASSERT_TRUE(isolated_context()->SetWritable(id_, false)); | 177 ASSERT_TRUE(isolated_context()->SetWritable(id_, false)); |
| 178 ASSERT_FALSE(isolated_context()->IsWritable(id_)); | 178 ASSERT_FALSE(isolated_context()->IsWritable(id_)); |
| 179 | 179 |
| 180 // Set writable again, and revoke the filesystem. | 180 // Set writable again, and revoke the filesystem. |
| 181 ASSERT_TRUE(isolated_context()->SetWritable(id_, true)); | 181 ASSERT_TRUE(isolated_context()->SetWritable(id_, true)); |
| 182 isolated_context()->RevokeIsolatedFileSystem(id_); | 182 isolated_context()->RemoveReference(id_); |
| 183 | 183 |
| 184 // IsWritable should return false for non-registered file system. | 184 // IsWritable should return false for non-registered file system. |
| 185 ASSERT_FALSE(isolated_context()->IsWritable(id_)); | 185 ASSERT_FALSE(isolated_context()->IsWritable(id_)); |
| 186 // SetWritable should also return false for non-registered file system | 186 // SetWritable should also return false for non-registered file system |
| 187 // (no matter what value we give). | 187 // (no matter what value we give). |
| 188 ASSERT_FALSE(isolated_context()->SetWritable(id_, true)); | 188 ASSERT_FALSE(isolated_context()->SetWritable(id_, true)); |
| 189 ASSERT_FALSE(isolated_context()->SetWritable(id_, false)); | 189 ASSERT_FALSE(isolated_context()->SetWritable(id_, false)); |
| 190 } | 190 } |
| 191 | 191 |
| 192 } // namespace fileapi | 192 } // namespace fileapi |
| OLD | NEW |