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

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

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 21 matching lines...) Expand all
32 using file_util::FileEnumerator; 32 using file_util::FileEnumerator;
33 33
34 namespace fileapi { 34 namespace fileapi {
35 35
36 namespace { 36 namespace {
37 37
38 // Used in IsolatedFileUtilTest::SimulateDropFiles(). 38 // Used in IsolatedFileUtilTest::SimulateDropFiles().
39 // Random root paths in which we create each file/directory of the 39 // Random root paths in which we create each file/directory of the
40 // RegularTestCases (so that we can simulate a drop with files/directories 40 // RegularTestCases (so that we can simulate a drop with files/directories
41 // from multiple directories). 41 // from multiple directories).
42 static const FilePath::CharType* kRootPaths[] = { 42 static const base::FilePath::CharType* kRootPaths[] = {
43 FILE_PATH_LITERAL("a"), 43 FILE_PATH_LITERAL("a"),
44 FILE_PATH_LITERAL("b/c"), 44 FILE_PATH_LITERAL("b/c"),
45 FILE_PATH_LITERAL("etc"), 45 FILE_PATH_LITERAL("etc"),
46 }; 46 };
47 47
48 FilePath GetTopLevelPath(const FilePath& path) { 48 base::FilePath GetTopLevelPath(const base::FilePath& path) {
49 std::vector<FilePath::StringType> components; 49 std::vector<base::FilePath::StringType> components;
50 path.GetComponents(&components); 50 path.GetComponents(&components);
51 return FilePath(components[0]); 51 return base::FilePath(components[0]);
52 } 52 }
53 53
54 bool IsDirectoryEmpty(FileSystemOperationContext* context, 54 bool IsDirectoryEmpty(FileSystemOperationContext* context,
55 FileSystemFileUtil* file_util, 55 FileSystemFileUtil* file_util,
56 const FileSystemURL& url) { 56 const FileSystemURL& url) {
57 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum = 57 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum =
58 file_util->CreateFileEnumerator(context, url, false /* recursive */); 58 file_util->CreateFileEnumerator(context, url, false /* recursive */);
59 return file_enum->Next().empty(); 59 return file_enum->Next().empty();
60 } 60 }
61 61
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 void TearDown() { 94 void TearDown() {
95 isolated_context()->RemoveReference(filesystem_id_); 95 isolated_context()->RemoveReference(filesystem_id_);
96 other_file_util_helper_.TearDown(); 96 other_file_util_helper_.TearDown();
97 } 97 }
98 98
99 protected: 99 protected:
100 IsolatedContext* isolated_context() const { 100 IsolatedContext* isolated_context() const {
101 return IsolatedContext::GetInstance(); 101 return IsolatedContext::GetInstance();
102 } 102 }
103 const FilePath& root_path() const { 103 const base::FilePath& root_path() const {
104 return data_dir_.path(); 104 return data_dir_.path();
105 } 105 }
106 FileSystemContext* file_system_context() const { 106 FileSystemContext* file_system_context() const {
107 return file_system_context_.get(); 107 return file_system_context_.get();
108 } 108 }
109 FileSystemFileUtil* file_util() const { return file_util_.get(); } 109 FileSystemFileUtil* file_util() const { return file_util_.get(); }
110 FileSystemFileUtil* other_file_util() const { 110 FileSystemFileUtil* other_file_util() const {
111 return other_file_util_helper_.file_util(); 111 return other_file_util_helper_.file_util();
112 } 112 }
113 std::string filesystem_id() const { return filesystem_id_; } 113 std::string filesystem_id() const { return filesystem_id_; }
114 114
115 FilePath GetTestCasePlatformPath(const FilePath::StringType& path) { 115 base::FilePath GetTestCasePlatformPath(const base::FilePath::StringType& path) {
116 return toplevel_root_map_[GetTopLevelPath(FilePath(path))].Append(path). 116 return toplevel_root_map_[GetTopLevelPath(base::FilePath(path))].Append(path ).
117 NormalizePathSeparators(); 117 NormalizePathSeparators();
118 } 118 }
119 119
120 FilePath GetTestCaseLocalPath(const FilePath& path) { 120 base::FilePath GetTestCaseLocalPath(const base::FilePath& path) {
121 FilePath relative; 121 base::FilePath relative;
122 if (data_dir_.path().AppendRelativePath(path, &relative)) 122 if (data_dir_.path().AppendRelativePath(path, &relative))
123 return relative; 123 return relative;
124 return path; 124 return path;
125 } 125 }
126 126
127 FileSystemURL GetFileSystemURL(const FilePath& path) const { 127 FileSystemURL GetFileSystemURL(const base::FilePath& path) const {
128 FilePath virtual_path = isolated_context()->CreateVirtualRootPath( 128 base::FilePath virtual_path = isolated_context()->CreateVirtualRootPath(
129 filesystem_id()).Append(path); 129 filesystem_id()).Append(path);
130 return file_system_context_->CreateCrackedFileSystemURL( 130 return file_system_context_->CreateCrackedFileSystemURL(
131 GURL("http://example.com"), 131 GURL("http://example.com"),
132 kFileSystemTypeIsolated, 132 kFileSystemTypeIsolated,
133 virtual_path); 133 virtual_path);
134 } 134 }
135 135
136 FileSystemURL GetOtherFileSystemURL(const FilePath& path) { 136 FileSystemURL GetOtherFileSystemURL(const base::FilePath& path) {
137 return other_file_util_helper_.CreateURL(GetTestCaseLocalPath(path)); 137 return other_file_util_helper_.CreateURL(GetTestCaseLocalPath(path));
138 } 138 }
139 139
140 void VerifyFilesHaveSameContent(FileSystemFileUtil* file_util1, 140 void VerifyFilesHaveSameContent(FileSystemFileUtil* file_util1,
141 FileSystemFileUtil* file_util2, 141 FileSystemFileUtil* file_util2,
142 const FileSystemURL& url1, 142 const FileSystemURL& url1,
143 const FileSystemURL& url2) { 143 const FileSystemURL& url2) {
144 scoped_ptr<FileSystemOperationContext> context; 144 scoped_ptr<FileSystemOperationContext> context;
145 145
146 // Get the file info for url1. 146 // Get the file info for url1.
147 base::PlatformFileInfo info1; 147 base::PlatformFileInfo info1;
148 FilePath platform_path1; 148 base::FilePath platform_path1;
149 context.reset(new FileSystemOperationContext(file_system_context())); 149 context.reset(new FileSystemOperationContext(file_system_context()));
150 ASSERT_EQ(base::PLATFORM_FILE_OK, 150 ASSERT_EQ(base::PLATFORM_FILE_OK,
151 file_util1->GetFileInfo(context.get(), url1, 151 file_util1->GetFileInfo(context.get(), url1,
152 &info1, &platform_path1)); 152 &info1, &platform_path1));
153 153
154 // Get the file info for url2. 154 // Get the file info for url2.
155 base::PlatformFileInfo info2; 155 base::PlatformFileInfo info2;
156 FilePath platform_path2; 156 base::FilePath platform_path2;
157 context.reset(new FileSystemOperationContext(file_system_context())); 157 context.reset(new FileSystemOperationContext(file_system_context()));
158 ASSERT_EQ(base::PLATFORM_FILE_OK, 158 ASSERT_EQ(base::PLATFORM_FILE_OK,
159 file_util2->GetFileInfo(context.get(), url2, 159 file_util2->GetFileInfo(context.get(), url2,
160 &info2, &platform_path2)); 160 &info2, &platform_path2));
161 161
162 // See if file info matches with the other one. 162 // See if file info matches with the other one.
163 EXPECT_EQ(info1.is_directory, info2.is_directory); 163 EXPECT_EQ(info1.is_directory, info2.is_directory);
164 EXPECT_EQ(info1.size, info2.size); 164 EXPECT_EQ(info1.size, info2.size);
165 EXPECT_EQ(info1.is_symbolic_link, info2.is_symbolic_link); 165 EXPECT_EQ(info1.is_symbolic_link, info2.is_symbolic_link);
166 EXPECT_NE(platform_path1, platform_path2); 166 EXPECT_NE(platform_path1, platform_path2);
167 167
168 std::string content1, content2; 168 std::string content1, content2;
169 EXPECT_TRUE(file_util::ReadFileToString(platform_path1, &content1)); 169 EXPECT_TRUE(file_util::ReadFileToString(platform_path1, &content1));
170 EXPECT_TRUE(file_util::ReadFileToString(platform_path2, &content2)); 170 EXPECT_TRUE(file_util::ReadFileToString(platform_path2, &content2));
171 EXPECT_EQ(content1, content2); 171 EXPECT_EQ(content1, content2);
172 } 172 }
173 173
174 void VerifyDirectoriesHaveSameContent(FileSystemFileUtil* file_util1, 174 void VerifyDirectoriesHaveSameContent(FileSystemFileUtil* file_util1,
175 FileSystemFileUtil* file_util2, 175 FileSystemFileUtil* file_util2,
176 const FileSystemURL& root1, 176 const FileSystemURL& root1,
177 const FileSystemURL& root2) { 177 const FileSystemURL& root2) {
178 scoped_ptr<FileSystemOperationContext> context; 178 scoped_ptr<FileSystemOperationContext> context;
179 FilePath root_path1 = root1.path(); 179 base::FilePath root_path1 = root1.path();
180 FilePath root_path2 = root2.path(); 180 base::FilePath root_path2 = root2.path();
181 181
182 context.reset(new FileSystemOperationContext(file_system_context())); 182 context.reset(new FileSystemOperationContext(file_system_context()));
183 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum1 = 183 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum1 =
184 file_util1->CreateFileEnumerator(context.get(), root1, 184 file_util1->CreateFileEnumerator(context.get(), root1,
185 true /* recursive */); 185 true /* recursive */);
186 186
187 FilePath current; 187 base::FilePath current;
188 std::set<FilePath> file_set1; 188 std::set<base::FilePath> file_set1;
189 while (!(current = file_enum1->Next()).empty()) { 189 while (!(current = file_enum1->Next()).empty()) {
190 if (file_enum1->IsDirectory()) 190 if (file_enum1->IsDirectory())
191 continue; 191 continue;
192 FilePath relative; 192 base::FilePath relative;
193 root_path1.AppendRelativePath(current, &relative); 193 root_path1.AppendRelativePath(current, &relative);
194 file_set1.insert(relative); 194 file_set1.insert(relative);
195 } 195 }
196 196
197 context.reset(new FileSystemOperationContext(file_system_context())); 197 context.reset(new FileSystemOperationContext(file_system_context()));
198 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum2 = 198 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum2 =
199 file_util2->CreateFileEnumerator(context.get(), root2, 199 file_util2->CreateFileEnumerator(context.get(), root2,
200 true /* recursive */); 200 true /* recursive */);
201 201
202 while (!(current = file_enum2->Next()).empty()) { 202 while (!(current = file_enum2->Next()).empty()) {
203 FilePath relative; 203 base::FilePath relative;
204 root_path2.AppendRelativePath(current, &relative); 204 root_path2.AppendRelativePath(current, &relative);
205 FileSystemURL url1 = root1.WithPath(root_path1.Append(relative)); 205 FileSystemURL url1 = root1.WithPath(root_path1.Append(relative));
206 FileSystemURL url2 = root2.WithPath(root_path2.Append(relative)); 206 FileSystemURL url2 = root2.WithPath(root_path2.Append(relative));
207 if (file_enum2->IsDirectory()) { 207 if (file_enum2->IsDirectory()) {
208 FileSystemOperationContext context1(file_system_context()); 208 FileSystemOperationContext context1(file_system_context());
209 FileSystemOperationContext context2(file_system_context()); 209 FileSystemOperationContext context2(file_system_context());
210 EXPECT_EQ(IsDirectoryEmpty(&context1, file_util1, url1), 210 EXPECT_EQ(IsDirectoryEmpty(&context1, file_util1, url1),
211 IsDirectoryEmpty(&context2, file_util2, url2)); 211 IsDirectoryEmpty(&context2, file_util2, url2));
212 continue; 212 continue;
213 } 213 }
214 EXPECT_TRUE(file_set1.find(relative) != file_set1.end()); 214 EXPECT_TRUE(file_set1.find(relative) != file_set1.end());
215 VerifyFilesHaveSameContent(file_util1, file_util2, url1, url2); 215 VerifyFilesHaveSameContent(file_util1, file_util2, url1, url2);
216 } 216 }
217 } 217 }
218 218
219 scoped_ptr<FileSystemOperationContext> GetOperationContext() { 219 scoped_ptr<FileSystemOperationContext> GetOperationContext() {
220 return make_scoped_ptr( 220 return make_scoped_ptr(
221 new FileSystemOperationContext(file_system_context())).Pass(); 221 new FileSystemOperationContext(file_system_context())).Pass();
222 } 222 }
223 223
224 224
225 private: 225 private:
226 void SimulateDropFiles() { 226 void SimulateDropFiles() {
227 size_t root_path_index = 0; 227 size_t root_path_index = 0;
228 228
229 IsolatedContext::FileInfoSet toplevels; 229 IsolatedContext::FileInfoSet toplevels;
230 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { 230 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) {
231 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; 231 const test::TestCaseRecord& test_case = test::kRegularTestCases[i];
232 FilePath path(test_case.path); 232 base::FilePath path(test_case.path);
233 FilePath toplevel = GetTopLevelPath(path); 233 base::FilePath toplevel = GetTopLevelPath(path);
234 234
235 // We create the test case files under one of the kRootPaths 235 // We create the test case files under one of the kRootPaths
236 // to simulate a drop with multiple directories. 236 // to simulate a drop with multiple directories.
237 if (toplevel_root_map_.find(toplevel) == toplevel_root_map_.end()) { 237 if (toplevel_root_map_.find(toplevel) == toplevel_root_map_.end()) {
238 FilePath root = root_path().Append( 238 base::FilePath root = root_path().Append(
239 kRootPaths[(root_path_index++) % arraysize(kRootPaths)]); 239 kRootPaths[(root_path_index++) % arraysize(kRootPaths)]);
240 toplevel_root_map_[toplevel] = root; 240 toplevel_root_map_[toplevel] = root;
241 toplevels.AddPath(root.Append(path), NULL); 241 toplevels.AddPath(root.Append(path), NULL);
242 } 242 }
243 243
244 test::SetUpOneTestCase(toplevel_root_map_[toplevel], test_case); 244 test::SetUpOneTestCase(toplevel_root_map_[toplevel], test_case);
245 } 245 }
246 246
247 // Register the toplevel entries. 247 // Register the toplevel entries.
248 filesystem_id_ = isolated_context()->RegisterDraggedFileSystem(toplevels); 248 filesystem_id_ = isolated_context()->RegisterDraggedFileSystem(toplevels);
249 } 249 }
250 250
251 base::ScopedTempDir data_dir_; 251 base::ScopedTempDir data_dir_;
252 base::ScopedTempDir partition_dir_; 252 base::ScopedTempDir partition_dir_;
253 MessageLoop message_loop_; 253 MessageLoop message_loop_;
254 std::string filesystem_id_; 254 std::string filesystem_id_;
255 scoped_refptr<FileSystemContext> file_system_context_; 255 scoped_refptr<FileSystemContext> file_system_context_;
256 std::map<FilePath, FilePath> toplevel_root_map_; 256 std::map<base::FilePath, base::FilePath> toplevel_root_map_;
257 scoped_ptr<IsolatedFileUtil> file_util_; 257 scoped_ptr<IsolatedFileUtil> file_util_;
258 LocalFileSystemTestOriginHelper other_file_util_helper_; 258 LocalFileSystemTestOriginHelper other_file_util_helper_;
259 DISALLOW_COPY_AND_ASSIGN(IsolatedFileUtilTest); 259 DISALLOW_COPY_AND_ASSIGN(IsolatedFileUtilTest);
260 }; 260 };
261 261
262 TEST_F(IsolatedFileUtilTest, BasicTest) { 262 TEST_F(IsolatedFileUtilTest, BasicTest) {
263 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { 263 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) {
264 SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i); 264 SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i);
265 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; 265 const test::TestCaseRecord& test_case = test::kRegularTestCases[i];
266 266
267 FileSystemURL url = GetFileSystemURL(FilePath(test_case.path)); 267 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path));
268 268
269 // See if we can query the file info via the isolated FileUtil. 269 // See if we can query the file info via the isolated FileUtil.
270 // (This should succeed since we have registered all the top-level 270 // (This should succeed since we have registered all the top-level
271 // entries of the test cases in SetUp()) 271 // entries of the test cases in SetUp())
272 base::PlatformFileInfo info; 272 base::PlatformFileInfo info;
273 FilePath platform_path; 273 base::FilePath platform_path;
274 FileSystemOperationContext context(file_system_context()); 274 FileSystemOperationContext context(file_system_context());
275 ASSERT_EQ(base::PLATFORM_FILE_OK, 275 ASSERT_EQ(base::PLATFORM_FILE_OK,
276 file_util()->GetFileInfo(&context, url, &info, &platform_path)); 276 file_util()->GetFileInfo(&context, url, &info, &platform_path));
277 277
278 // See if the obtained file info is correct. 278 // See if the obtained file info is correct.
279 if (!test_case.is_directory) 279 if (!test_case.is_directory)
280 ASSERT_EQ(test_case.data_file_size, info.size); 280 ASSERT_EQ(test_case.data_file_size, info.size);
281 ASSERT_EQ(test_case.is_directory, info.is_directory); 281 ASSERT_EQ(test_case.is_directory, info.is_directory);
282 ASSERT_EQ(GetTestCasePlatformPath(test_case.path), 282 ASSERT_EQ(GetTestCasePlatformPath(test_case.path),
283 platform_path.NormalizePathSeparators()); 283 platform_path.NormalizePathSeparators());
(...skipping 21 matching lines...) Expand all
305 ASSERT_TRUE(file_util::GetFileInfo( 305 ASSERT_TRUE(file_util::GetFileInfo(
306 root_path().Append(test_case.path), &info)); 306 root_path().Append(test_case.path), &info));
307 if (!test_case.is_directory) 307 if (!test_case.is_directory)
308 ASSERT_EQ(test_case.data_file_size, info.size); 308 ASSERT_EQ(test_case.data_file_size, info.size);
309 ASSERT_EQ(test_case.is_directory, info.is_directory); 309 ASSERT_EQ(test_case.is_directory, info.is_directory);
310 } 310 }
311 311
312 for (size_t i = 0; i < arraysize(kUnregisteredCases); ++i) { 312 for (size_t i = 0; i < arraysize(kUnregisteredCases); ++i) {
313 SCOPED_TRACE(testing::Message() << "Creating kUnregisteredCases " << i); 313 SCOPED_TRACE(testing::Message() << "Creating kUnregisteredCases " << i);
314 const test::TestCaseRecord& test_case = kUnregisteredCases[i]; 314 const test::TestCaseRecord& test_case = kUnregisteredCases[i];
315 FileSystemURL url = GetFileSystemURL(FilePath(test_case.path)); 315 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path));
316 316
317 // We should not be able to get the valid URL for unregistered files. 317 // We should not be able to get the valid URL for unregistered files.
318 ASSERT_FALSE(url.is_valid()); 318 ASSERT_FALSE(url.is_valid());
319 319
320 // We should not be able to create a new operation for an invalid URL. 320 // We should not be able to create a new operation for an invalid URL.
321 base::PlatformFileError error_code; 321 base::PlatformFileError error_code;
322 FileSystemOperation* operation = 322 FileSystemOperation* operation =
323 file_system_context()->CreateFileSystemOperation(url, &error_code); 323 file_system_context()->CreateFileSystemOperation(url, &error_code);
324 ASSERT_EQ(NULL, operation); 324 ASSERT_EQ(NULL, operation);
325 ASSERT_EQ(base::PLATFORM_FILE_ERROR_INVALID_URL, error_code); 325 ASSERT_EQ(base::PLATFORM_FILE_ERROR_INVALID_URL, error_code);
326 } 326 }
327 } 327 }
328 328
329 TEST_F(IsolatedFileUtilTest, ReadDirectoryTest) { 329 TEST_F(IsolatedFileUtilTest, ReadDirectoryTest) {
330 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { 330 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) {
331 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; 331 const test::TestCaseRecord& test_case = test::kRegularTestCases[i];
332 if (!test_case.is_directory) 332 if (!test_case.is_directory)
333 continue; 333 continue;
334 334
335 SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i 335 SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i
336 << ": " << test_case.path); 336 << ": " << test_case.path);
337 337
338 // Read entries in the directory to construct the expected results map. 338 // Read entries in the directory to construct the expected results map.
339 typedef std::map<FilePath::StringType, base::FileUtilProxy::Entry> EntryMap; 339 typedef std::map<base::FilePath::StringType, base::FileUtilProxy::Entry> Ent ryMap;
340 EntryMap expected_entry_map; 340 EntryMap expected_entry_map;
341 341
342 FileEnumerator file_enum( 342 FileEnumerator file_enum(
343 GetTestCasePlatformPath(test_case.path), false /* not recursive */, 343 GetTestCasePlatformPath(test_case.path), false /* not recursive */,
344 FileEnumerator::FILES | FileEnumerator::DIRECTORIES); 344 FileEnumerator::FILES | FileEnumerator::DIRECTORIES);
345 FilePath current; 345 base::FilePath current;
346 while (!(current = file_enum.Next()).empty()) { 346 while (!(current = file_enum.Next()).empty()) {
347 FileEnumerator::FindInfo file_info; 347 FileEnumerator::FindInfo file_info;
348 file_enum.GetFindInfo(&file_info); 348 file_enum.GetFindInfo(&file_info);
349 base::FileUtilProxy::Entry entry; 349 base::FileUtilProxy::Entry entry;
350 entry.is_directory = FileEnumerator::IsDirectory(file_info); 350 entry.is_directory = FileEnumerator::IsDirectory(file_info);
351 entry.name = current.BaseName().value(); 351 entry.name = current.BaseName().value();
352 entry.size = FileEnumerator::GetFilesize(file_info); 352 entry.size = FileEnumerator::GetFilesize(file_info);
353 entry.last_modified_time = FileEnumerator::GetLastModifiedTime(file_info); 353 entry.last_modified_time = FileEnumerator::GetLastModifiedTime(file_info);
354 expected_entry_map[entry.name] = entry; 354 expected_entry_map[entry.name] = entry;
355 } 355 }
356 356
357 // Perform ReadDirectory in the isolated filesystem. 357 // Perform ReadDirectory in the isolated filesystem.
358 FileSystemURL url = GetFileSystemURL(FilePath(test_case.path)); 358 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path));
359 std::vector<base::FileUtilProxy::Entry> entries; 359 std::vector<base::FileUtilProxy::Entry> entries;
360 FileSystemOperationContext context(file_system_context()); 360 FileSystemOperationContext context(file_system_context());
361 ASSERT_EQ(base::PLATFORM_FILE_OK, 361 ASSERT_EQ(base::PLATFORM_FILE_OK,
362 FileUtilHelper::ReadDirectory( 362 FileUtilHelper::ReadDirectory(
363 &context, file_util(), url, &entries)); 363 &context, file_util(), url, &entries));
364 364
365 EXPECT_EQ(expected_entry_map.size(), entries.size()); 365 EXPECT_EQ(expected_entry_map.size(), entries.size());
366 for (size_t i = 0; i < entries.size(); ++i) { 366 for (size_t i = 0; i < entries.size(); ++i) {
367 const base::FileUtilProxy::Entry& entry = entries[i]; 367 const base::FileUtilProxy::Entry& entry = entries[i];
368 EntryMap::iterator found = expected_entry_map.find(entry.name); 368 EntryMap::iterator found = expected_entry_map.find(entry.name);
369 EXPECT_TRUE(found != expected_entry_map.end()); 369 EXPECT_TRUE(found != expected_entry_map.end());
370 EXPECT_EQ(found->second.name, entry.name); 370 EXPECT_EQ(found->second.name, entry.name);
371 EXPECT_EQ(found->second.is_directory, entry.is_directory); 371 EXPECT_EQ(found->second.is_directory, entry.is_directory);
372 EXPECT_EQ(found->second.size, entry.size); 372 EXPECT_EQ(found->second.size, entry.size);
373 EXPECT_EQ(found->second.last_modified_time.ToDoubleT(), 373 EXPECT_EQ(found->second.last_modified_time.ToDoubleT(),
374 entry.last_modified_time.ToDoubleT()); 374 entry.last_modified_time.ToDoubleT());
375 } 375 }
376 } 376 }
377 } 377 }
378 378
379 TEST_F(IsolatedFileUtilTest, GetLocalFilePathTest) { 379 TEST_F(IsolatedFileUtilTest, GetLocalFilePathTest) {
380 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { 380 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) {
381 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; 381 const test::TestCaseRecord& test_case = test::kRegularTestCases[i];
382 FileSystemURL url = GetFileSystemURL(FilePath(test_case.path)); 382 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path));
383 383
384 FileSystemOperationContext context(file_system_context()); 384 FileSystemOperationContext context(file_system_context());
385 385
386 FilePath local_file_path; 386 base::FilePath local_file_path;
387 EXPECT_EQ(base::PLATFORM_FILE_OK, 387 EXPECT_EQ(base::PLATFORM_FILE_OK,
388 file_util()->GetLocalFilePath(&context, url, &local_file_path)); 388 file_util()->GetLocalFilePath(&context, url, &local_file_path));
389 EXPECT_EQ(GetTestCasePlatformPath(test_case.path).value(), 389 EXPECT_EQ(GetTestCasePlatformPath(test_case.path).value(),
390 local_file_path.value()); 390 local_file_path.value());
391 } 391 }
392 } 392 }
393 393
394 TEST_F(IsolatedFileUtilTest, CopyOutFileTest) { 394 TEST_F(IsolatedFileUtilTest, CopyOutFileTest) {
395 scoped_ptr<FileSystemOperationContext> context( 395 scoped_ptr<FileSystemOperationContext> context(
396 new FileSystemOperationContext(file_system_context())); 396 new FileSystemOperationContext(file_system_context()));
397 FileSystemURL root_url = GetFileSystemURL(FilePath()); 397 FileSystemURL root_url = GetFileSystemURL(base::FilePath());
398 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( 398 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum(
399 file_util()->CreateFileEnumerator(context.get(), 399 file_util()->CreateFileEnumerator(context.get(),
400 root_url, 400 root_url,
401 true /* recursive */)); 401 true /* recursive */));
402 FilePath current; 402 base::FilePath current;
403 while (!(current = file_enum->Next()).empty()) { 403 while (!(current = file_enum->Next()).empty()) {
404 if (file_enum->IsDirectory()) 404 if (file_enum->IsDirectory())
405 continue; 405 continue;
406 406
407 SCOPED_TRACE(testing::Message() << "Testing file copy " 407 SCOPED_TRACE(testing::Message() << "Testing file copy "
408 << current.value()); 408 << current.value());
409 409
410 FileSystemURL src_url = root_url.WithPath(current); 410 FileSystemURL src_url = root_url.WithPath(current);
411 FileSystemURL dest_url = GetOtherFileSystemURL(current); 411 FileSystemURL dest_url = GetOtherFileSystemURL(current);
412 412
(...skipping 14 matching lines...) Expand all
427 src_url, dest_url)); 427 src_url, dest_url));
428 428
429 VerifyFilesHaveSameContent(file_util(), other_file_util(), 429 VerifyFilesHaveSameContent(file_util(), other_file_util(),
430 src_url, dest_url); 430 src_url, dest_url);
431 } 431 }
432 } 432 }
433 433
434 TEST_F(IsolatedFileUtilTest, CopyOutDirectoryTest) { 434 TEST_F(IsolatedFileUtilTest, CopyOutDirectoryTest) {
435 scoped_ptr<FileSystemOperationContext> context( 435 scoped_ptr<FileSystemOperationContext> context(
436 new FileSystemOperationContext(file_system_context())); 436 new FileSystemOperationContext(file_system_context()));
437 FileSystemURL root_url = GetFileSystemURL(FilePath()); 437 FileSystemURL root_url = GetFileSystemURL(base::FilePath());
438 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( 438 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum(
439 file_util()->CreateFileEnumerator(context.get(), 439 file_util()->CreateFileEnumerator(context.get(),
440 root_url, 440 root_url,
441 false /* recursive */)); 441 false /* recursive */));
442 FilePath current; 442 base::FilePath current;
443 while (!(current = file_enum->Next()).empty()) { 443 while (!(current = file_enum->Next()).empty()) {
444 if (!file_enum->IsDirectory()) 444 if (!file_enum->IsDirectory())
445 continue; 445 continue;
446 446
447 SCOPED_TRACE(testing::Message() << "Testing directory copy " 447 SCOPED_TRACE(testing::Message() << "Testing directory copy "
448 << current.value()); 448 << current.value());
449 449
450 FileSystemURL src_url = root_url.WithPath(current); 450 FileSystemURL src_url = root_url.WithPath(current);
451 FileSystemURL dest_url = GetOtherFileSystemURL(current); 451 FileSystemURL dest_url = GetOtherFileSystemURL(current);
452 452
(...skipping 17 matching lines...) Expand all
470 src_url, dest_url); 470 src_url, dest_url);
471 } 471 }
472 } 472 }
473 473
474 TEST_F(IsolatedFileUtilTest, TouchTest) { 474 TEST_F(IsolatedFileUtilTest, TouchTest) {
475 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { 475 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) {
476 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; 476 const test::TestCaseRecord& test_case = test::kRegularTestCases[i];
477 if (test_case.is_directory) 477 if (test_case.is_directory)
478 continue; 478 continue;
479 SCOPED_TRACE(testing::Message() << test_case.path); 479 SCOPED_TRACE(testing::Message() << test_case.path);
480 FileSystemURL url = GetFileSystemURL(FilePath(test_case.path)); 480 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path));
481 481
482 base::Time last_access_time = base::Time::FromTimeT(1000); 482 base::Time last_access_time = base::Time::FromTimeT(1000);
483 base::Time last_modified_time = base::Time::FromTimeT(2000); 483 base::Time last_modified_time = base::Time::FromTimeT(2000);
484 484
485 EXPECT_EQ(base::PLATFORM_FILE_OK, 485 EXPECT_EQ(base::PLATFORM_FILE_OK,
486 file_util()->Touch(GetOperationContext().get(), url, 486 file_util()->Touch(GetOperationContext().get(), url,
487 last_access_time, 487 last_access_time,
488 last_modified_time)); 488 last_modified_time));
489 489
490 // Verification. 490 // Verification.
491 base::PlatformFileInfo info; 491 base::PlatformFileInfo info;
492 FilePath platform_path; 492 base::FilePath platform_path;
493 ASSERT_EQ(base::PLATFORM_FILE_OK, 493 ASSERT_EQ(base::PLATFORM_FILE_OK,
494 file_util()->GetFileInfo(GetOperationContext().get(), url, 494 file_util()->GetFileInfo(GetOperationContext().get(), url,
495 &info, &platform_path)); 495 &info, &platform_path));
496 EXPECT_EQ(last_access_time.ToTimeT(), info.last_accessed.ToTimeT()); 496 EXPECT_EQ(last_access_time.ToTimeT(), info.last_accessed.ToTimeT());
497 EXPECT_EQ(last_modified_time.ToTimeT(), info.last_modified.ToTimeT()); 497 EXPECT_EQ(last_modified_time.ToTimeT(), info.last_modified.ToTimeT());
498 } 498 }
499 } 499 }
500 500
501 TEST_F(IsolatedFileUtilTest, TruncateTest) { 501 TEST_F(IsolatedFileUtilTest, TruncateTest) {
502 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { 502 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) {
503 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; 503 const test::TestCaseRecord& test_case = test::kRegularTestCases[i];
504 if (test_case.is_directory) 504 if (test_case.is_directory)
505 continue; 505 continue;
506 506
507 SCOPED_TRACE(testing::Message() << test_case.path); 507 SCOPED_TRACE(testing::Message() << test_case.path);
508 FileSystemURL url = GetFileSystemURL(FilePath(test_case.path)); 508 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path));
509 509
510 // Truncate to 0. 510 // Truncate to 0.
511 base::PlatformFileInfo info; 511 base::PlatformFileInfo info;
512 FilePath platform_path; 512 base::FilePath platform_path;
513 EXPECT_EQ(base::PLATFORM_FILE_OK, 513 EXPECT_EQ(base::PLATFORM_FILE_OK,
514 file_util()->Truncate(GetOperationContext().get(), url, 0)); 514 file_util()->Truncate(GetOperationContext().get(), url, 0));
515 ASSERT_EQ(base::PLATFORM_FILE_OK, 515 ASSERT_EQ(base::PLATFORM_FILE_OK,
516 file_util()->GetFileInfo(GetOperationContext().get(), url, 516 file_util()->GetFileInfo(GetOperationContext().get(), url,
517 &info, &platform_path)); 517 &info, &platform_path));
518 EXPECT_EQ(0, info.size); 518 EXPECT_EQ(0, info.size);
519 519
520 // Truncate (extend) to 999. 520 // Truncate (extend) to 999.
521 EXPECT_EQ(base::PLATFORM_FILE_OK, 521 EXPECT_EQ(base::PLATFORM_FILE_OK,
522 file_util()->Truncate(GetOperationContext().get(), url, 999)); 522 file_util()->Truncate(GetOperationContext().get(), url, 999));
523 ASSERT_EQ(base::PLATFORM_FILE_OK, 523 ASSERT_EQ(base::PLATFORM_FILE_OK,
524 file_util()->GetFileInfo(GetOperationContext().get(), url, 524 file_util()->GetFileInfo(GetOperationContext().get(), url,
525 &info, &platform_path)); 525 &info, &platform_path));
526 EXPECT_EQ(999, info.size); 526 EXPECT_EQ(999, info.size);
527 } 527 }
528 } 528 }
529 529
530 } // namespace fileapi 530 } // 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