Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Side by Side Diff: content/browser/fileapi/isolated_context_unittest.cc

Issue 341043008: Add FileSystemID parameter to IsolatedContext::RegisterFileSystemForPath. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/fileapi/file_system_url.h" 10 #include "webkit/browser/fileapi/file_system_url.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 95 }
96 96
97 // See if the name of each registered kTestPaths (that is what we 97 // See if the name of each registered kTestPaths (that is what we
98 // register in SetUp() by RegisterDraggedFileSystem) is properly cracked as 98 // register in SetUp() by RegisterDraggedFileSystem) is properly cracked as
99 // a valid virtual path in the isolated filesystem. 99 // a valid virtual path in the isolated filesystem.
100 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { 100 for (size_t i = 0; i < arraysize(kTestPaths); ++i) {
101 base::FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_) 101 base::FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_)
102 .AppendASCII(names_[i]); 102 .AppendASCII(names_[i]);
103 std::string cracked_id; 103 std::string cracked_id;
104 base::FilePath cracked_path; 104 base::FilePath cracked_path;
105 std::string cracked_inner_id;
105 fileapi::FileSystemType cracked_type; 106 fileapi::FileSystemType cracked_type;
106 FileSystemMountOption cracked_option; 107 FileSystemMountOption cracked_option;
107 ASSERT_TRUE(isolated_context()->CrackVirtualPath( 108 ASSERT_TRUE(isolated_context()->CrackVirtualPath(
108 virtual_path, &cracked_id, &cracked_type, &cracked_path, 109 virtual_path, &cracked_id, &cracked_type, &cracked_inner_id,
109 &cracked_option)); 110 &cracked_path, &cracked_option));
110 ASSERT_EQ(kTestPaths[i].NormalizePathSeparators().value(), 111 ASSERT_EQ(kTestPaths[i].NormalizePathSeparators().value(),
111 cracked_path.value()); 112 cracked_path.value());
112 ASSERT_EQ(id_, cracked_id); 113 ASSERT_EQ(id_, cracked_id);
113 ASSERT_EQ(kFileSystemTypeDragged, cracked_type); 114 ASSERT_EQ(kFileSystemTypeDragged, cracked_type);
115 EXPECT_TRUE(cracked_inner_id.empty());
114 } 116 }
115 117
116 // Make sure GetRegisteredPath returns false for id_ since it is 118 // Make sure GetRegisteredPath returns false for id_ since it is
117 // registered for dragged files. 119 // registered for dragged files.
118 base::FilePath path; 120 base::FilePath path;
119 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id_, &path)); 121 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id_, &path));
120 122
121 // Deref the current one and registering a new one. 123 // Deref the current one and registering a new one.
122 isolated_context()->RemoveReference(id_); 124 isolated_context()->RemoveReference(id_);
123 125
124 std::string id2 = isolated_context()->RegisterFileSystemForPath( 126 std::string id2 = isolated_context()->RegisterFileSystemForPath(
125 kFileSystemTypeNativeLocal, base::FilePath(DRIVE FPL("/foo")), NULL); 127 kFileSystemTypeNativeLocal, std::string(),
128 base::FilePath(DRIVE FPL("/foo")), NULL);
126 129
127 // Make sure the GetDraggedFileInfo returns false for both ones. 130 // Make sure the GetDraggedFileInfo returns false for both ones.
128 ASSERT_FALSE(isolated_context()->GetDraggedFileInfo(id2, &toplevels)); 131 ASSERT_FALSE(isolated_context()->GetDraggedFileInfo(id2, &toplevels));
129 ASSERT_FALSE(isolated_context()->GetDraggedFileInfo(id_, &toplevels)); 132 ASSERT_FALSE(isolated_context()->GetDraggedFileInfo(id_, &toplevels));
130 133
131 // Make sure the GetRegisteredPath returns true only for the new one. 134 // Make sure the GetRegisteredPath returns true only for the new one.
132 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id_, &path)); 135 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id_, &path));
133 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id2, &path)); 136 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id2, &path));
134 137
135 // Try registering three more file systems for the same path as id2. 138 // Try registering three more file systems for the same path as id2.
136 std::string id3 = isolated_context()->RegisterFileSystemForPath( 139 std::string id3 = isolated_context()->RegisterFileSystemForPath(
137 kFileSystemTypeNativeLocal, path, NULL); 140 kFileSystemTypeNativeLocal, std::string(), path, NULL);
138 std::string id4 = isolated_context()->RegisterFileSystemForPath( 141 std::string id4 = isolated_context()->RegisterFileSystemForPath(
139 kFileSystemTypeNativeLocal, path, NULL); 142 kFileSystemTypeNativeLocal, std::string(), path, NULL);
140 std::string id5 = isolated_context()->RegisterFileSystemForPath( 143 std::string id5 = isolated_context()->RegisterFileSystemForPath(
141 kFileSystemTypeNativeLocal, path, NULL); 144 kFileSystemTypeNativeLocal, std::string(), path, NULL);
142 145
143 // Remove file system for id4. 146 // Remove file system for id4.
144 isolated_context()->AddReference(id4); 147 isolated_context()->AddReference(id4);
145 isolated_context()->RemoveReference(id4); 148 isolated_context()->RemoveReference(id4);
146 149
147 // Only id4 should become invalid now. 150 // Only id4 should become invalid now.
148 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id2, &path)); 151 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id2, &path));
149 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id3, &path)); 152 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id3, &path));
150 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id4, &path)); 153 ASSERT_FALSE(isolated_context()->GetRegisteredPath(id4, &path));
151 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id5, &path)); 154 ASSERT_TRUE(isolated_context()->GetRegisteredPath(id5, &path));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 for (size_t i = 0; i < arraysize(kTestPaths); ++i) { 197 for (size_t i = 0; i < arraysize(kTestPaths); ++i) {
195 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(relatives); ++j) { 198 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(relatives); ++j) {
196 SCOPED_TRACE(testing::Message() << "Testing " 199 SCOPED_TRACE(testing::Message() << "Testing "
197 << kTestPaths[i].value() << " " << relatives[j].path); 200 << kTestPaths[i].value() << " " << relatives[j].path);
198 base::FilePath virtual_path = 201 base::FilePath virtual_path =
199 isolated_context()->CreateVirtualRootPath(id_).AppendASCII( 202 isolated_context()->CreateVirtualRootPath(id_).AppendASCII(
200 names_[i]).Append(relatives[j].path); 203 names_[i]).Append(relatives[j].path);
201 std::string cracked_id; 204 std::string cracked_id;
202 base::FilePath cracked_path; 205 base::FilePath cracked_path;
203 fileapi::FileSystemType cracked_type; 206 fileapi::FileSystemType cracked_type;
207 std::string cracked_inner_id;
204 FileSystemMountOption cracked_option; 208 FileSystemMountOption cracked_option;
205 if (!relatives[j].valid) { 209 if (!relatives[j].valid) {
206 ASSERT_FALSE(isolated_context()->CrackVirtualPath( 210 ASSERT_FALSE(isolated_context()->CrackVirtualPath(
207 virtual_path, &cracked_id, &cracked_type, &cracked_path, 211 virtual_path, &cracked_id, &cracked_type, &cracked_inner_id,
208 &cracked_option)); 212 &cracked_path, &cracked_option));
209 continue; 213 continue;
210 } 214 }
211 ASSERT_TRUE(isolated_context()->CrackVirtualPath( 215 ASSERT_TRUE(isolated_context()->CrackVirtualPath(
212 virtual_path, &cracked_id, &cracked_type, &cracked_path, 216 virtual_path, &cracked_id, &cracked_type, &cracked_inner_id,
213 &cracked_option)); 217 &cracked_path, &cracked_option));
214 ASSERT_EQ(kTestPaths[i].Append(relatives[j].path) 218 ASSERT_EQ(kTestPaths[i].Append(relatives[j].path)
215 .NormalizePathSeparators().value(), 219 .NormalizePathSeparators().value(),
216 cracked_path.value()); 220 cracked_path.value());
217 ASSERT_EQ(id_, cracked_id); 221 ASSERT_EQ(id_, cracked_id);
218 ASSERT_EQ(kFileSystemTypeDragged, cracked_type); 222 ASSERT_EQ(kFileSystemTypeDragged, cracked_type);
223 EXPECT_TRUE(cracked_inner_id.empty());
219 } 224 }
220 } 225 }
221 } 226 }
222 227
223 TEST_F(IsolatedContextTest, CrackURLWithRelativePaths) { 228 TEST_F(IsolatedContextTest, CrackURLWithRelativePaths) {
224 const struct { 229 const struct {
225 base::FilePath::StringType path; 230 base::FilePath::StringType path;
226 bool valid; 231 bool valid;
227 } relatives[] = { 232 } relatives[] = {
228 { FPL("foo"), true }, 233 { FPL("foo"), true },
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 TEST_F(IsolatedContextTest, TestWithVirtualRoot) { 274 TEST_F(IsolatedContextTest, TestWithVirtualRoot) {
270 std::string cracked_id; 275 std::string cracked_id;
271 base::FilePath cracked_path; 276 base::FilePath cracked_path;
272 FileSystemMountOption cracked_option; 277 FileSystemMountOption cracked_option;
273 278
274 // Trying to crack virtual root "/" returns true but with empty cracked path 279 // Trying to crack virtual root "/" returns true but with empty cracked path
275 // as "/" of the isolated filesystem is a pure virtual directory 280 // as "/" of the isolated filesystem is a pure virtual directory
276 // that has no corresponding platform directory. 281 // that has no corresponding platform directory.
277 base::FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_); 282 base::FilePath virtual_path = isolated_context()->CreateVirtualRootPath(id_);
278 ASSERT_TRUE(isolated_context()->CrackVirtualPath( 283 ASSERT_TRUE(isolated_context()->CrackVirtualPath(
279 virtual_path, &cracked_id, NULL, &cracked_path, &cracked_option)); 284 virtual_path, &cracked_id, NULL, NULL, &cracked_path, &cracked_option));
280 ASSERT_EQ(FPL(""), cracked_path.value()); 285 ASSERT_EQ(FPL(""), cracked_path.value());
281 ASSERT_EQ(id_, cracked_id); 286 ASSERT_EQ(id_, cracked_id);
282 287
283 // Trying to crack "/foo" should fail (because "foo" is not the one 288 // Trying to crack "/foo" should fail (because "foo" is not the one
284 // included in the kTestPaths). 289 // included in the kTestPaths).
285 virtual_path = isolated_context()->CreateVirtualRootPath( 290 virtual_path = isolated_context()->CreateVirtualRootPath(
286 id_).AppendASCII("foo"); 291 id_).AppendASCII("foo");
287 ASSERT_FALSE(isolated_context()->CrackVirtualPath( 292 ASSERT_FALSE(isolated_context()->CrackVirtualPath(
288 virtual_path, &cracked_id, NULL, &cracked_path, &cracked_option)); 293 virtual_path, &cracked_id, NULL, NULL, &cracked_path, &cracked_option));
289 } 294 }
290 295
291 TEST_F(IsolatedContextTest, CanHandleURL) { 296 TEST_F(IsolatedContextTest, CanHandleURL) {
292 const GURL test_origin("http://chromium.org"); 297 const GURL test_origin("http://chromium.org");
293 const base::FilePath test_path(FPL("/mount")); 298 const base::FilePath test_path(FPL("/mount"));
294 299
295 // Should handle isolated file system. 300 // Should handle isolated file system.
296 EXPECT_TRUE(isolated_context()->HandlesFileSystemMountType( 301 EXPECT_TRUE(isolated_context()->HandlesFileSystemMountType(
297 fileapi::kFileSystemTypeIsolated)); 302 fileapi::kFileSystemTypeIsolated));
298 303
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 340
336 base::FilePath test_virtual_path = 341 base::FilePath test_virtual_path =
337 base::FilePath().AppendASCII("virtualdir").AppendASCII("virtualfile.txt"); 342 base::FilePath().AppendASCII("virtualdir").AppendASCII("virtualfile.txt");
338 343
339 base::FilePath whole_virtual_path = 344 base::FilePath whole_virtual_path =
340 isolated_context()->CreateVirtualRootPath(database_fsid) 345 isolated_context()->CreateVirtualRootPath(database_fsid)
341 .AppendASCII("_").Append(test_virtual_path); 346 .AppendASCII("_").Append(test_virtual_path);
342 347
343 std::string cracked_id; 348 std::string cracked_id;
344 base::FilePath cracked_path; 349 base::FilePath cracked_path;
350 std::string cracked_inner_id;
345 FileSystemMountOption cracked_option; 351 FileSystemMountOption cracked_option;
346 ASSERT_TRUE(isolated_context()->CrackVirtualPath( 352 ASSERT_TRUE(isolated_context()->CrackVirtualPath(
347 whole_virtual_path, &cracked_id, NULL, &cracked_path, &cracked_option)); 353 whole_virtual_path, &cracked_id, NULL, &cracked_inner_id,
354 &cracked_path, &cracked_option));
348 ASSERT_EQ(database_fsid, cracked_id); 355 ASSERT_EQ(database_fsid, cracked_id);
349 ASSERT_EQ(test_virtual_path, cracked_path); 356 ASSERT_EQ(test_virtual_path, cracked_path);
357 EXPECT_TRUE(cracked_inner_id.empty());
350 } 358 }
351 359
352 } // namespace content 360 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/fileapi/file_system_context_unittest.cc ('k') | content/browser/fileapi/transient_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698