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

Side by Side Diff: webkit/fileapi/isolated_file_util_unittest.cc

Issue 10810053: Enables internal filesystem types via Isolated filesystems (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: layout test crash fix Created 8 years, 5 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
« no previous file with comments | « webkit/fileapi/isolated_file_util.cc ('k') | webkit/fileapi/isolated_mount_point_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <map> 5 #include <map>
6 #include <set> 6 #include <set>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 }; 43 };
44 44
45 FilePath GetTopLevelPath(const FilePath& path) { 45 FilePath GetTopLevelPath(const FilePath& path) {
46 std::vector<FilePath::StringType> components; 46 std::vector<FilePath::StringType> components;
47 path.GetComponents(&components); 47 path.GetComponents(&components);
48 return FilePath(components[0]); 48 return FilePath(components[0]);
49 } 49 }
50 50
51 } // namespace 51 } // namespace
52 52
53 // TODO(kinuko): we should have separate tests for DraggedFileUtil and
54 // IsolatedFileUtil.
53 class IsolatedFileUtilTest : public testing::Test { 55 class IsolatedFileUtilTest : public testing::Test {
54 public: 56 public:
55 IsolatedFileUtilTest() {} 57 IsolatedFileUtilTest() {}
56 58
57 void SetUp() { 59 void SetUp() {
58 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); 60 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
59 file_util_.reset(new IsolatedFileUtil()); 61 file_util_.reset(new DraggedFileUtil());
60 62
61 // Register the files/directories of RegularTestCases (with random 63 // Register the files/directories of RegularTestCases (with random
62 // root paths) as dropped files. 64 // root paths) as dropped files.
63 SimulateDropFiles(); 65 SimulateDropFiles();
64 66
65 file_system_context_ = new FileSystemContext( 67 file_system_context_ = new FileSystemContext(
66 base::MessageLoopProxy::current(), 68 base::MessageLoopProxy::current(),
67 base::MessageLoopProxy::current(), 69 base::MessageLoopProxy::current(),
68 make_scoped_refptr(new quota::MockSpecialStoragePolicy()), 70 make_scoped_refptr(new quota::MockSpecialStoragePolicy()),
69 NULL /* quota_manager */, 71 NULL /* quota_manager */,
(...skipping 22 matching lines...) Expand all
92 } 94 }
93 FileSystemFileUtil* file_util() const { return file_util_.get(); } 95 FileSystemFileUtil* file_util() const { return file_util_.get(); }
94 FileSystemFileUtil* other_file_util() const { return other_file_util_.get(); } 96 FileSystemFileUtil* other_file_util() const { return other_file_util_.get(); }
95 std::string filesystem_id() const { return filesystem_id_; } 97 std::string filesystem_id() const { return filesystem_id_; }
96 98
97 FilePath GetTestCasePlatformPath(const FilePath::StringType& path) { 99 FilePath GetTestCasePlatformPath(const FilePath::StringType& path) {
98 return toplevel_root_map_[GetTopLevelPath(FilePath(path))].Append(path). 100 return toplevel_root_map_[GetTopLevelPath(FilePath(path))].Append(path).
99 NormalizePathSeparators(); 101 NormalizePathSeparators();
100 } 102 }
101 103
104 FilePath GetTestCaseLocalPath(const FilePath& path) {
105 FilePath relative;
106 if (data_dir_.path().AppendRelativePath(path, &relative))
107 return relative;
108 return path;
109 }
110
102 FileSystemURL GetFileSystemURL(const FilePath& path) const { 111 FileSystemURL GetFileSystemURL(const FilePath& path) const {
103 FilePath virtual_path = isolated_context()->CreateVirtualRootPath( 112 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(
104 filesystem_id()).Append(path); 113 filesystem_id()).Append(path);
105 return FileSystemURL(GURL("http://example.com"), 114 return FileSystemURL(GURL("http://example.com"),
106 kFileSystemTypeIsolated, 115 kFileSystemTypeIsolated,
107 virtual_path); 116 virtual_path);
108 } 117 }
109 118
110 FileSystemURL GetOtherFileSystemURL(const FilePath& path) { 119 FileSystemURL GetOtherFileSystemURL(const FilePath& path) {
111 return other_file_util_helper_.CreateURL(path); 120 return other_file_util_helper_.CreateURL(GetTestCaseLocalPath(path));
112 } 121 }
113 122
114 void VerifyFilesHaveSameContent(FileSystemFileUtil* file_util1, 123 void VerifyFilesHaveSameContent(FileSystemFileUtil* file_util1,
115 FileSystemFileUtil* file_util2, 124 FileSystemFileUtil* file_util2,
116 const FileSystemURL& url1, 125 const FileSystemURL& url1,
117 const FileSystemURL& url2) { 126 const FileSystemURL& url2) {
118 scoped_ptr<FileSystemOperationContext> context; 127 scoped_ptr<FileSystemOperationContext> context;
119 128
120 // Get the file info for url1. 129 // Get the file info for url1.
121 base::PlatformFileInfo info1; 130 base::PlatformFileInfo info1;
(...skipping 21 matching lines...) Expand all
143 EXPECT_TRUE(file_util::ReadFileToString(platform_path1, &content1)); 152 EXPECT_TRUE(file_util::ReadFileToString(platform_path1, &content1));
144 EXPECT_TRUE(file_util::ReadFileToString(platform_path2, &content2)); 153 EXPECT_TRUE(file_util::ReadFileToString(platform_path2, &content2));
145 EXPECT_EQ(content1, content2); 154 EXPECT_EQ(content1, content2);
146 } 155 }
147 156
148 void VerifyDirectoriesHaveSameContent(FileSystemFileUtil* file_util1, 157 void VerifyDirectoriesHaveSameContent(FileSystemFileUtil* file_util1,
149 FileSystemFileUtil* file_util2, 158 FileSystemFileUtil* file_util2,
150 const FileSystemURL& root1, 159 const FileSystemURL& root1,
151 const FileSystemURL& root2) { 160 const FileSystemURL& root2) {
152 scoped_ptr<FileSystemOperationContext> context; 161 scoped_ptr<FileSystemOperationContext> context;
162 FilePath root_path1 = root1.path();
163 FilePath root_path2 = root2.path();
153 164
154 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum1; 165 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum1;
155 context.reset(new FileSystemOperationContext(file_system_context())); 166 context.reset(new FileSystemOperationContext(file_system_context()));
156 file_enum1.reset(file_util1->CreateFileEnumerator( 167 file_enum1.reset(file_util1->CreateFileEnumerator(
157 context.get(), root1, true /* recursive */)); 168 context.get(), root1, true /* recursive */));
158 169
159 FilePath current; 170 FilePath current;
160 std::set<FilePath> file_set1; 171 std::set<FilePath> file_set1;
161 while (!(current = file_enum1->Next()).empty()) { 172 while (!(current = file_enum1->Next()).empty()) {
162 if (file_enum1->IsDirectory()) 173 if (file_enum1->IsDirectory())
163 continue; 174 continue;
164 file_set1.insert(current); 175 FilePath relative;
176 root_path1.AppendRelativePath(current, &relative);
177 file_set1.insert(relative);
165 } 178 }
166 179
167 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum2; 180 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum2;
168 context.reset(new FileSystemOperationContext(file_system_context())); 181 context.reset(new FileSystemOperationContext(file_system_context()));
169 file_enum2.reset(file_util2->CreateFileEnumerator( 182 file_enum2.reset(file_util2->CreateFileEnumerator(
170 context.get(), root2, true /* recursive */)); 183 context.get(), root2, true /* recursive */));
171 184
172 while (!(current = file_enum2->Next()).empty()) { 185 while (!(current = file_enum2->Next()).empty()) {
173 FileSystemURL url1 = root1.WithPath(current); 186 FilePath relative;
174 FileSystemURL url2 = root2.WithPath(current); 187 root_path2.AppendRelativePath(current, &relative);
188 FileSystemURL url1 = root1.WithPath(root_path1.Append(relative));
189 FileSystemURL url2 = root2.WithPath(root_path2.Append(relative));
175 if (file_enum2->IsDirectory()) { 190 if (file_enum2->IsDirectory()) {
176 FileSystemOperationContext context1(file_system_context()); 191 FileSystemOperationContext context1(file_system_context());
177 FileSystemOperationContext context2(file_system_context()); 192 FileSystemOperationContext context2(file_system_context());
178 EXPECT_EQ(file_util1->IsDirectoryEmpty(&context1, url1), 193 EXPECT_EQ(file_util1->IsDirectoryEmpty(&context1, url1),
179 file_util2->IsDirectoryEmpty(&context2, url2)); 194 file_util2->IsDirectoryEmpty(&context2, url2));
180 continue; 195 continue;
181 } 196 }
182 EXPECT_TRUE(file_set1.find(current) != file_set1.end()); 197 EXPECT_TRUE(file_set1.find(relative) != file_set1.end());
183 VerifyFilesHaveSameContent(file_util1, file_util2, url1, url2); 198 VerifyFilesHaveSameContent(file_util1, file_util2, url1, url2);
184 } 199 }
185 } 200 }
186 201
187 scoped_ptr<FileSystemOperationContext> GetOperationContext() { 202 scoped_ptr<FileSystemOperationContext> GetOperationContext() {
188 return make_scoped_ptr( 203 return make_scoped_ptr(
189 new FileSystemOperationContext(file_system_context())).Pass(); 204 new FileSystemOperationContext(file_system_context())).Pass();
190 } 205 }
191 206
192 207
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 for (size_t i = 0; i < arraysize(kUnregisteredCases); ++i) { 295 for (size_t i = 0; i < arraysize(kUnregisteredCases); ++i) {
281 SCOPED_TRACE(testing::Message() << "Creating kUnregisteredCases " << i); 296 SCOPED_TRACE(testing::Message() << "Creating kUnregisteredCases " << i);
282 const test::TestCaseRecord& test_case = kUnregisteredCases[i]; 297 const test::TestCaseRecord& test_case = kUnregisteredCases[i];
283 FileSystemURL url = GetFileSystemURL(FilePath(test_case.path)); 298 FileSystemURL url = GetFileSystemURL(FilePath(test_case.path));
284 299
285 // This should fail as the paths in kUnregisteredCases are not included 300 // This should fail as the paths in kUnregisteredCases are not included
286 // in the dropped files (i.e. the regular test cases). 301 // in the dropped files (i.e. the regular test cases).
287 base::PlatformFileInfo info; 302 base::PlatformFileInfo info;
288 FilePath platform_path; 303 FilePath platform_path;
289 FileSystemOperationContext context(file_system_context()); 304 FileSystemOperationContext context(file_system_context());
290 ASSERT_EQ(base::PLATFORM_FILE_ERROR_SECURITY, 305 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
291 file_util()->GetFileInfo(&context, url, &info, &platform_path)); 306 file_util()->GetFileInfo(&context, url, &info, &platform_path));
292 } 307 }
293 } 308 }
294 309
295 TEST_F(IsolatedFileUtilTest, ReadDirectoryTest) { 310 TEST_F(IsolatedFileUtilTest, ReadDirectoryTest) {
296 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { 311 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) {
297 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; 312 const test::TestCaseRecord& test_case = test::kRegularTestCases[i];
298 if (!test_case.is_directory) 313 if (!test_case.is_directory)
299 continue; 314 continue;
300 315
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 false /* exclusive */, 402 false /* exclusive */,
388 true /* recursive */)); 403 true /* recursive */));
389 404
390 context.reset(new FileSystemOperationContext(file_system_context())); 405 context.reset(new FileSystemOperationContext(file_system_context()));
391 ASSERT_EQ(base::PLATFORM_FILE_OK, 406 ASSERT_EQ(base::PLATFORM_FILE_OK,
392 FileUtilHelper::Copy( 407 FileUtilHelper::Copy(
393 context.get(), 408 context.get(),
394 file_util(), other_file_util(), 409 file_util(), other_file_util(),
395 src_url, dest_url)); 410 src_url, dest_url));
396 411
397 // The other way (copy-in) should not work.
398 context.reset(new FileSystemOperationContext(file_system_context()));
399 ASSERT_EQ(base::PLATFORM_FILE_ERROR_SECURITY,
400 FileUtilHelper::Copy(
401 context.get(),
402 other_file_util(), file_util(),
403 dest_url, src_url));
404
405 VerifyFilesHaveSameContent(file_util(), other_file_util(), 412 VerifyFilesHaveSameContent(file_util(), other_file_util(),
406 src_url, dest_url); 413 src_url, dest_url);
407 } 414 }
408 } 415 }
409 416
410 TEST_F(IsolatedFileUtilTest, CopyOutDirectoryTest) { 417 TEST_F(IsolatedFileUtilTest, CopyOutDirectoryTest) {
411 scoped_ptr<FileSystemOperationContext> context( 418 scoped_ptr<FileSystemOperationContext> context(
412 new FileSystemOperationContext(file_system_context())); 419 new FileSystemOperationContext(file_system_context()));
413 FileSystemURL root_url = GetFileSystemURL(FilePath()); 420 FileSystemURL root_url = GetFileSystemURL(FilePath());
414 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( 421 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum(
(...skipping 20 matching lines...) Expand all
435 false /* exclusive */, 442 false /* exclusive */,
436 true /* recursive */)); 443 true /* recursive */));
437 444
438 context.reset(new FileSystemOperationContext(file_system_context())); 445 context.reset(new FileSystemOperationContext(file_system_context()));
439 ASSERT_EQ(base::PLATFORM_FILE_OK, 446 ASSERT_EQ(base::PLATFORM_FILE_OK,
440 FileUtilHelper::Copy( 447 FileUtilHelper::Copy(
441 context.get(), 448 context.get(),
442 file_util(), other_file_util(), 449 file_util(), other_file_util(),
443 src_url, dest_url)); 450 src_url, dest_url));
444 451
445 // The other way (copy-in) should not work for two reasons:
446 // write is prohibited in the isolated filesystem, and copying directory
447 // to non-empty directory shouldn't work.
448 context.reset(new FileSystemOperationContext(file_system_context()));
449 base::PlatformFileError result = FileUtilHelper::Copy(
450 context.get(), other_file_util(), file_util(), dest_url, src_url);
451 ASSERT_TRUE(result == base::PLATFORM_FILE_ERROR_FAILED ||
452 result == base::PLATFORM_FILE_ERROR_NOT_EMPTY);
453
454 VerifyDirectoriesHaveSameContent(file_util(), other_file_util(), 452 VerifyDirectoriesHaveSameContent(file_util(), other_file_util(),
455 src_url, dest_url); 453 src_url, dest_url);
456 } 454 }
457 } 455 }
458 456
459 TEST_F(IsolatedFileUtilTest, TouchTest) { 457 TEST_F(IsolatedFileUtilTest, TouchTest) {
460 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { 458 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) {
461 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; 459 const test::TestCaseRecord& test_case = test::kRegularTestCases[i];
462 if (test_case.is_directory) 460 if (test_case.is_directory)
463 continue; 461 continue;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 EXPECT_EQ(base::PLATFORM_FILE_OK, 504 EXPECT_EQ(base::PLATFORM_FILE_OK,
507 file_util()->Truncate(GetOperationContext().get(), url, 999)); 505 file_util()->Truncate(GetOperationContext().get(), url, 999));
508 ASSERT_EQ(base::PLATFORM_FILE_OK, 506 ASSERT_EQ(base::PLATFORM_FILE_OK,
509 file_util()->GetFileInfo(GetOperationContext().get(), url, 507 file_util()->GetFileInfo(GetOperationContext().get(), url,
510 &info, &platform_path)); 508 &info, &platform_path));
511 EXPECT_EQ(999, info.size); 509 EXPECT_EQ(999, info.size);
512 } 510 }
513 } 511 }
514 512
515 } // namespace fileapi 513 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/isolated_file_util.cc ('k') | webkit/fileapi/isolated_mount_point_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698