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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 class IsolatedContextTest : public testing::Test { | 45 class IsolatedContextTest : public testing::Test { |
46 public: | 46 public: |
47 IsolatedContextTest() { | 47 IsolatedContextTest() { |
48 for (size_t i = 0; i < arraysize(kTestPaths); ++i) | 48 for (size_t i = 0; i < arraysize(kTestPaths); ++i) |
49 fileset_.insert(kTestPaths[i].NormalizePathSeparators()); | 49 fileset_.insert(kTestPaths[i].NormalizePathSeparators()); |
50 } | 50 } |
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 names_.push_back(files.AddPath(kTestPaths[i].NormalizePathSeparators())); | 55 std::string name; |
56 id_ = IsolatedContext::GetInstance()->RegisterFileSystem(files); | 56 ASSERT_TRUE( |
| 57 files.AddPath(kTestPaths[i].NormalizePathSeparators(), &name)); |
| 58 names_.push_back(name); |
| 59 } |
| 60 id_ = IsolatedContext::GetInstance()->RegisterDraggedFileSystem(files); |
57 ASSERT_FALSE(id_.empty()); | 61 ASSERT_FALSE(id_.empty()); |
58 } | 62 } |
59 | 63 |
60 void TearDown() { | 64 void TearDown() { |
61 IsolatedContext::GetInstance()->RevokeFileSystem(id_); | 65 IsolatedContext::GetInstance()->RevokeFileSystem(id_); |
62 } | 66 } |
63 | 67 |
64 IsolatedContext* isolated_context() const { | 68 IsolatedContext* isolated_context() const { |
65 return IsolatedContext::GetInstance(); | 69 return IsolatedContext::GetInstance(); |
66 } | 70 } |
67 | 71 |
68 protected: | 72 protected: |
69 std::string id_; | 73 std::string id_; |
70 std::multiset<FilePath> fileset_; | 74 std::multiset<FilePath> fileset_; |
71 std::vector<std::string> names_; | 75 std::vector<std::string> names_; |
72 | 76 |
73 private: | 77 private: |
74 DISALLOW_COPY_AND_ASSIGN(IsolatedContextTest); | 78 DISALLOW_COPY_AND_ASSIGN(IsolatedContextTest); |
75 }; | 79 }; |
76 | 80 |
77 TEST_F(IsolatedContextTest, RegisterAndRevokeTest) { | 81 TEST_F(IsolatedContextTest, RegisterAndRevokeTest) { |
78 // See if the returned top-level entries match with what we registered. | 82 // See if the returned top-level entries match with what we registered. |
79 std::vector<FileInfo> toplevels; | 83 std::vector<FileInfo> toplevels; |
80 ASSERT_TRUE(isolated_context()->GetRegisteredFileInfo(id_, &toplevels)); | 84 ASSERT_TRUE(isolated_context()->GetDraggedFileInfo(id_, &toplevels)); |
81 ASSERT_EQ(fileset_.size(), toplevels.size()); | 85 ASSERT_EQ(fileset_.size(), toplevels.size()); |
82 for (size_t i = 0; i < toplevels.size(); ++i) { | 86 for (size_t i = 0; i < toplevels.size(); ++i) { |
83 ASSERT_TRUE(fileset_.find(toplevels[i].path) != fileset_.end()); | 87 ASSERT_TRUE(fileset_.find(toplevels[i].path) != fileset_.end()); |
84 } | 88 } |
85 | 89 |
86 // See if the name of each registered kTestPaths (that is what we | 90 // See if the name of each registered kTestPaths (that is what we |
87 // register in SetUp() by RegisterFileSystem) is properly cracked as | 91 // register in SetUp() by RegisterDraggedFileSystem) is properly cracked as |
88 // a valid virtual path in the isolated filesystem. | 92 // a valid virtual path in the isolated filesystem. |
89 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { | 93 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { |
90 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_) | 94 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_) |
91 .AppendASCII(names_[i]); | 95 .AppendASCII(names_[i]); |
92 std::string cracked_id; | 96 std::string cracked_id; |
93 FileInfo root_info; | 97 FileInfo root_info; |
94 FilePath cracked_path; | 98 FilePath cracked_path; |
95 ASSERT_TRUE(isolated_context()->CrackIsolatedPath( | 99 ASSERT_TRUE(isolated_context()->CrackIsolatedPath( |
96 virtual_path, &cracked_id, &root_info, &cracked_path)); | 100 virtual_path, &cracked_id, &root_info, &cracked_path)); |
97 ASSERT_EQ(kTestPaths[i].NormalizePathSeparators().value(), | 101 ASSERT_EQ(kTestPaths[i].NormalizePathSeparators().value(), |
98 cracked_path.value()); | 102 cracked_path.value()); |
99 ASSERT_TRUE(fileset_.find(root_info.path.NormalizePathSeparators()) | 103 ASSERT_TRUE(fileset_.find(root_info.path.NormalizePathSeparators()) |
100 != fileset_.end()); | 104 != fileset_.end()); |
101 ASSERT_EQ(id_, cracked_id); | 105 ASSERT_EQ(id_, cracked_id); |
102 } | 106 } |
103 | 107 |
104 // Revoking the current one and registering a new (empty) one. | 108 // Make sure GetRegisteredPath returns false for id_ since it is |
| 109 // registered for dragged files. |
| 110 FilePath path; |
| 111 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id_, &path)); |
| 112 |
| 113 // Revoking the current one and registering a new one. |
105 isolated_context()->RevokeFileSystem(id_); | 114 isolated_context()->RevokeFileSystem(id_); |
106 std::string id2 = isolated_context()->RegisterFileSystem( | 115 std::string id2 = isolated_context()->RegisterFileSystemForPath( |
107 IsolatedContext::FileInfoSet()); | 116 kFileSystemTypeIsolated, FilePath(DRIVE FPL("/foo")), NULL); |
108 | 117 |
109 // Make sure the GetRegisteredFileInfo returns true only for the new one. | 118 // Make sure the GetDraggedFileInfo returns false for both ones. |
110 ASSERT_TRUE(isolated_context()->GetRegisteredFileInfo(id2, &toplevels)); | 119 ASSERT_FALSE(isolated_context()->GetDraggedFileInfo(id2, &toplevels)); |
111 ASSERT_FALSE(isolated_context()->GetRegisteredFileInfo(id_, &toplevels)); | 120 ASSERT_FALSE(isolated_context()->GetDraggedFileInfo(id_, &toplevels)); |
| 121 |
| 122 // Make sure the GetRegisteredPath returns true only for the new one. |
| 123 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id2, &path)); |
| 124 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id_, &path)); |
112 | 125 |
113 isolated_context()->RevokeFileSystem(id2); | 126 isolated_context()->RevokeFileSystem(id2); |
114 } | 127 } |
115 | 128 |
116 TEST_F(IsolatedContextTest, CrackWithRelativePaths) { | 129 TEST_F(IsolatedContextTest, CrackWithRelativePaths) { |
117 const struct { | 130 const struct { |
118 FilePath::StringType path; | 131 FilePath::StringType path; |
119 bool valid; | 132 bool valid; |
120 } relatives[] = { | 133 } relatives[] = { |
121 { FPL("foo"), true }, | 134 { FPL("foo"), true }, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 186 |
174 // Trying to crack "/foo" should fail (because "foo" is not the one | 187 // Trying to crack "/foo" should fail (because "foo" is not the one |
175 // included in the kTestPaths). | 188 // included in the kTestPaths). |
176 virtual_path = isolated_context()->CreateVirtualRootPath( | 189 virtual_path = isolated_context()->CreateVirtualRootPath( |
177 id_).AppendASCII("foo"); | 190 id_).AppendASCII("foo"); |
178 ASSERT_FALSE(isolated_context()->CrackIsolatedPath( | 191 ASSERT_FALSE(isolated_context()->CrackIsolatedPath( |
179 virtual_path, &cracked_id, NULL, &cracked_path)); | 192 virtual_path, &cracked_id, NULL, &cracked_path)); |
180 } | 193 } |
181 | 194 |
182 } // namespace fileapi | 195 } // namespace fileapi |
OLD | NEW |