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

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

Issue 10713007: Make isolated file system works for a device root (e.g. X:\\) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased 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.cc » ('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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 NULL /* quota_manager */, 69 NULL /* quota_manager */,
70 data_dir_.path(), 70 data_dir_.path(),
71 CreateAllowFileAccessOptions()); 71 CreateAllowFileAccessOptions());
72 72
73 // For cross-FileUtil copy/move tests. 73 // For cross-FileUtil copy/move tests.
74 other_file_util_.reset(new LocalFileUtil()); 74 other_file_util_.reset(new LocalFileUtil());
75 other_file_util_helper_.SetUp(file_system_context_, other_file_util_.get()); 75 other_file_util_helper_.SetUp(file_system_context_, other_file_util_.get());
76 } 76 }
77 77
78 void TearDown() { 78 void TearDown() {
79 isolated_context()->RevokeIsolatedFileSystem(filesystem_id_); 79 isolated_context()->RevokeFileSystem(filesystem_id_);
80 other_file_util_helper_.TearDown(); 80 other_file_util_helper_.TearDown();
81 } 81 }
82 82
83 protected: 83 protected:
84 IsolatedContext* isolated_context() const { 84 IsolatedContext* isolated_context() const {
85 return IsolatedContext::GetInstance(); 85 return IsolatedContext::GetInstance();
86 } 86 }
87 const FilePath& root_path() const { 87 const FilePath& root_path() const {
88 return data_dir_.path(); 88 return data_dir_.path();
89 } 89 }
90 FileSystemContext* file_system_context() const { 90 FileSystemContext* file_system_context() const {
91 return file_system_context_.get(); 91 return file_system_context_.get();
92 } 92 }
93 FileSystemFileUtil* file_util() const { return file_util_.get(); } 93 FileSystemFileUtil* file_util() const { return file_util_.get(); }
94 FileSystemFileUtil* other_file_util() const { return other_file_util_.get(); } 94 FileSystemFileUtil* other_file_util() const { return other_file_util_.get(); }
95 std::string filesystem_id() const { return filesystem_id_; } 95 std::string filesystem_id() const { return filesystem_id_; }
96 96
97 FilePath GetTestCasePlatformPath(const FilePath::StringType& path) { 97 FilePath GetTestCasePlatformPath(const FilePath::StringType& path) {
98 return toplevel_root_map_[GetTopLevelPath(FilePath(path))].Append(path). 98 return toplevel_root_map_[GetTopLevelPath(FilePath(path))].Append(path).
99 NormalizePathSeparators(); 99 NormalizePathSeparators();
100 } 100 }
101 101
102 FileSystemURL GetFileSystemURL(const FilePath& path) const { 102 FileSystemURL GetFileSystemURL(const FilePath& path) const {
103 FilePath virtual_path = isolated_context()->CreateVirtualPath( 103 FilePath virtual_path = isolated_context()->CreateVirtualRootPath(
104 filesystem_id(), path); 104 filesystem_id()).Append(path);
105 return FileSystemURL(GURL("http://example.com"), 105 return FileSystemURL(GURL("http://example.com"),
106 kFileSystemTypeIsolated, 106 kFileSystemTypeIsolated,
107 virtual_path); 107 virtual_path);
108 } 108 }
109 109
110 FileSystemURL GetOtherFileSystemURL(const FilePath& path) { 110 FileSystemURL GetOtherFileSystemURL(const FilePath& path) {
111 return other_file_util_helper_.CreateURL(path); 111 return other_file_util_helper_.CreateURL(path);
112 } 112 }
113 113
114 void VerifyFilesHaveSameContent(FileSystemFileUtil* file_util1, 114 void VerifyFilesHaveSameContent(FileSystemFileUtil* file_util1,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 scoped_ptr<FileSystemOperationContext> GetOperationContext() { 187 scoped_ptr<FileSystemOperationContext> GetOperationContext() {
188 return make_scoped_ptr( 188 return make_scoped_ptr(
189 new FileSystemOperationContext(file_system_context())).Pass(); 189 new FileSystemOperationContext(file_system_context())).Pass();
190 } 190 }
191 191
192 192
193 private: 193 private:
194 void SimulateDropFiles() { 194 void SimulateDropFiles() {
195 size_t root_path_index = 0; 195 size_t root_path_index = 0;
196 196
197 std::set<FilePath> toplevels; 197 IsolatedContext::FileInfoSet toplevels;
198 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { 198 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) {
199 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; 199 const test::TestCaseRecord& test_case = test::kRegularTestCases[i];
200 FilePath path(test_case.path); 200 FilePath path(test_case.path);
201 FilePath toplevel = GetTopLevelPath(path); 201 FilePath toplevel = GetTopLevelPath(path);
202 202
203 // We create the test case files under one of the kRootPaths 203 // We create the test case files under one of the kRootPaths
204 // to simulate a drop with multiple directories. 204 // to simulate a drop with multiple directories.
205 if (toplevel_root_map_.find(toplevel) == toplevel_root_map_.end()) { 205 if (toplevel_root_map_.find(toplevel) == toplevel_root_map_.end()) {
206 FilePath root = root_path().Append( 206 FilePath root = root_path().Append(
207 kRootPaths[(root_path_index++) % arraysize(kRootPaths)]); 207 kRootPaths[(root_path_index++) % arraysize(kRootPaths)]);
208 toplevel_root_map_[toplevel] = root; 208 toplevel_root_map_[toplevel] = root;
209 toplevels.insert(root.Append(path)); 209 toplevels.AddPath(root.Append(path));
210 } 210 }
211 211
212 test::SetUpOneTestCase(toplevel_root_map_[toplevel], test_case); 212 test::SetUpOneTestCase(toplevel_root_map_[toplevel], test_case);
213 } 213 }
214 214
215 // Register the toplevel entries. 215 // Register the toplevel entries.
216 filesystem_id_ = isolated_context()->RegisterIsolatedFileSystem(toplevels); 216 filesystem_id_ = isolated_context()->RegisterFileSystem(toplevels);
217 } 217 }
218 218
219 ScopedTempDir data_dir_; 219 ScopedTempDir data_dir_;
220 MessageLoop message_loop_; 220 MessageLoop message_loop_;
221 std::string filesystem_id_; 221 std::string filesystem_id_;
222 scoped_refptr<FileSystemContext> file_system_context_; 222 scoped_refptr<FileSystemContext> file_system_context_;
223 std::map<FilePath, FilePath> toplevel_root_map_; 223 std::map<FilePath, FilePath> toplevel_root_map_;
224 scoped_ptr<IsolatedFileUtil> file_util_; 224 scoped_ptr<IsolatedFileUtil> file_util_;
225 scoped_ptr<LocalFileUtil> other_file_util_; 225 scoped_ptr<LocalFileUtil> other_file_util_;
226 FileSystemTestOriginHelper other_file_util_helper_; 226 FileSystemTestOriginHelper other_file_util_helper_;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 TEST_F(IsolatedFileUtilTest, GetLocalFilePathTest) { 347 TEST_F(IsolatedFileUtilTest, GetLocalFilePathTest) {
348 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { 348 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) {
349 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; 349 const test::TestCaseRecord& test_case = test::kRegularTestCases[i];
350 FileSystemURL url = GetFileSystemURL(FilePath(test_case.path)); 350 FileSystemURL url = GetFileSystemURL(FilePath(test_case.path));
351 351
352 FileSystemOperationContext context(file_system_context()); 352 FileSystemOperationContext context(file_system_context());
353 353
354 FilePath local_file_path; 354 FilePath local_file_path;
355 EXPECT_EQ(base::PLATFORM_FILE_OK, 355 EXPECT_EQ(base::PLATFORM_FILE_OK,
356 file_util()->GetLocalFilePath(&context, url, &local_file_path)); 356 file_util()->GetLocalFilePath(&context, url, &local_file_path));
357 EXPECT_EQ(GetTestCasePlatformPath(test_case.path), local_file_path); 357 EXPECT_EQ(GetTestCasePlatformPath(test_case.path).value(),
358 local_file_path.value());
358 } 359 }
359 } 360 }
360 361
361 TEST_F(IsolatedFileUtilTest, CopyOutFileTest) { 362 TEST_F(IsolatedFileUtilTest, CopyOutFileTest) {
362 scoped_ptr<FileSystemOperationContext> context( 363 scoped_ptr<FileSystemOperationContext> context(
363 new FileSystemOperationContext(file_system_context())); 364 new FileSystemOperationContext(file_system_context()));
364 FileSystemURL root_url = GetFileSystemURL(FilePath()); 365 FileSystemURL root_url = GetFileSystemURL(FilePath());
365 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( 366 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum(
366 file_util()->CreateFileEnumerator(context.get(), 367 file_util()->CreateFileEnumerator(context.get(),
367 root_url, 368 root_url,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 EXPECT_EQ(base::PLATFORM_FILE_OK, 506 EXPECT_EQ(base::PLATFORM_FILE_OK,
506 file_util()->Truncate(GetOperationContext().get(), url, 999)); 507 file_util()->Truncate(GetOperationContext().get(), url, 999));
507 ASSERT_EQ(base::PLATFORM_FILE_OK, 508 ASSERT_EQ(base::PLATFORM_FILE_OK,
508 file_util()->GetFileInfo(GetOperationContext().get(), url, 509 file_util()->GetFileInfo(GetOperationContext().get(), url,
509 &info, &platform_path)); 510 &info, &platform_path));
510 EXPECT_EQ(999, info.size); 511 EXPECT_EQ(999, info.size);
511 } 512 }
512 } 513 }
513 514
514 } // namespace fileapi 515 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/isolated_file_util.cc ('k') | webkit/fileapi/isolated_mount_point_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698