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

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

Issue 7470037: [Refactor] to rename and re-layer the file_util stack layers. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Reflected the comments and rebased. Created 9 years, 4 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/platform_file.h" 12 #include "base/platform_file.h"
13 #include "base/scoped_temp_dir.h" 13 #include "base/scoped_temp_dir.h"
14 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webkit/fileapi/file_system_context.h" 16 #include "webkit/fileapi/file_system_context.h"
17 #include "webkit/fileapi/file_system_operation_context.h" 17 #include "webkit/fileapi/file_system_operation_context.h"
18 #include "webkit/fileapi/file_system_test_helper.h" 18 #include "webkit/fileapi/file_system_test_helper.h"
19 #include "webkit/fileapi/obfuscated_file_system_file_util.h" 19 #include "webkit/fileapi/native_file_util.h"
20 #include "webkit/fileapi/obfuscated_file_util.h"
20 21
21 using namespace fileapi; 22 using namespace fileapi;
22 23
23 namespace { 24 namespace {
24 25
25 FilePath UTF8ToFilePath(const std::string& str) { 26 FilePath UTF8ToFilePath(const std::string& str) {
26 FilePath::StringType result; 27 FilePath::StringType result;
27 #if defined(OS_POSIX) 28 #if defined(OS_POSIX)
28 result = str; 29 result = str;
29 #elif defined(OS_WIN) 30 #elif defined(OS_WIN)
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 {"file://", false, true}, 115 {"file://", false, true},
115 {"http://example.com:8000", false, true}, 116 {"http://example.com:8000", false, true},
116 }; 117 };
117 118
118 } // namespace (anonymous) 119 } // namespace (anonymous)
119 120
120 // TODO(ericu): The vast majority of this and the other FSFU subclass tests 121 // TODO(ericu): The vast majority of this and the other FSFU subclass tests
121 // could theoretically be shared. It would basically be a FSFU interface 122 // could theoretically be shared. It would basically be a FSFU interface
122 // compliance test, and only the subclass-specific bits that look into the 123 // compliance test, and only the subclass-specific bits that look into the
123 // implementation would need to be written per-subclass. 124 // implementation would need to be written per-subclass.
124 class ObfuscatedFileSystemFileUtilTest : public testing::Test { 125 class ObfuscatedFileUtilTest : public testing::Test {
125 public: 126 public:
126 ObfuscatedFileSystemFileUtilTest() 127 ObfuscatedFileUtilTest()
127 : origin_(GURL("http://www.example.com")), 128 : origin_(GURL("http://www.example.com")),
128 type_(kFileSystemTypeTemporary), 129 type_(kFileSystemTypeTemporary),
129 test_helper_(origin_, type_) { 130 test_helper_(origin_, type_) {
130 } 131 }
131 132
132 void SetUp() { 133 void SetUp() {
133 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); 134 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
134 135
135 obfuscated_file_system_file_util_ = 136 obfuscated_file_util_ =
136 new ObfuscatedFileSystemFileUtil(data_dir_.path(), 137 new ObfuscatedFileUtil(data_dir_.path(), new NativeFileUtil());
137 new FileSystemFileUtil());
138 test_helper_.SetUp(data_dir_.path(), 138 test_helper_.SetUp(data_dir_.path(),
139 false, // incognito 139 false, // incognito
140 false, // unlimited quota 140 false, // unlimited quota
141 NULL, // quota::QuotaManagerProxy 141 NULL, // quota::QuotaManagerProxy
142 obfuscated_file_system_file_util_.get()); 142 obfuscated_file_util_.get());
143 } 143 }
144 144
145 FileSystemOperationContext* NewContext() { 145 FileSystemOperationContext* NewContext() {
146 FileSystemOperationContext* context = test_helper_.NewOperationContext(); 146 FileSystemOperationContext* context = test_helper_.NewOperationContext();
147 return context; 147 return context;
148 } 148 }
149 149
150 ObfuscatedFileSystemFileUtil* ofsfu() { 150 ObfuscatedFileUtil* ofu() {
151 return obfuscated_file_system_file_util_.get(); 151 return obfuscated_file_util_.get();
152 } 152 }
153 153
154 const FilePath& test_directory() const { 154 const FilePath& test_directory() const {
155 return data_dir_.path(); 155 return data_dir_.path();
156 } 156 }
157 157
158 const GURL& origin_url() const { 158 const GURL& origin_url() const {
159 return origin_; 159 return origin_;
160 } 160 }
161 161
162 fileapi::FileSystemType type() const { 162 fileapi::FileSystemType type() const {
163 return type_; 163 return type_;
164 } 164 }
165 165
166 void CheckFileAndCloseHandle( 166 void CheckFileAndCloseHandle(
167 const FilePath& virtual_path, PlatformFile file_handle) { 167 const FilePath& virtual_path, PlatformFile file_handle) {
168 scoped_ptr<FileSystemOperationContext> context(NewContext()); 168 scoped_ptr<FileSystemOperationContext> context(NewContext());
169 FilePath local_path; 169 FilePath local_path;
170 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( 170 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath(
171 context.get(), virtual_path, &local_path)); 171 context.get(), virtual_path, &local_path));
172 172
173 base::PlatformFileInfo file_info0; 173 base::PlatformFileInfo file_info0;
174 FilePath data_path; 174 FilePath data_path;
175 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( 175 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
176 context.get(), virtual_path, &file_info0, &data_path)); 176 context.get(), virtual_path, &file_info0, &data_path));
177 EXPECT_EQ(data_path, local_path); 177 EXPECT_EQ(data_path, local_path);
178 EXPECT_TRUE(FileExists(data_path)); 178 EXPECT_TRUE(FileExists(data_path));
179 EXPECT_EQ(0, GetSize(data_path)); 179 EXPECT_EQ(0, GetSize(data_path));
180 180
181 const char data[] = "test data"; 181 const char data[] = "test data";
182 const int length = arraysize(data) - 1; 182 const int length = arraysize(data) - 1;
183 183
184 if (base::kInvalidPlatformFileValue == file_handle) { 184 if (base::kInvalidPlatformFileValue == file_handle) {
185 bool created = true; 185 bool created = true;
186 PlatformFileError error; 186 PlatformFileError error;
187 file_handle = base::CreatePlatformFile( 187 file_handle = base::CreatePlatformFile(
188 data_path, 188 data_path,
189 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, 189 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE,
190 &created, 190 &created,
191 &error); 191 &error);
192 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); 192 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle);
193 ASSERT_EQ(base::PLATFORM_FILE_OK, error); 193 ASSERT_EQ(base::PLATFORM_FILE_OK, error);
194 EXPECT_FALSE(created); 194 EXPECT_FALSE(created);
195 } 195 }
196 ASSERT_EQ(length, base::WritePlatformFile(file_handle, 0, data, length)); 196 ASSERT_EQ(length, base::WritePlatformFile(file_handle, 0, data, length));
197 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); 197 EXPECT_TRUE(base::ClosePlatformFile(file_handle));
198 198
199 base::PlatformFileInfo file_info1; 199 base::PlatformFileInfo file_info1;
200 EXPECT_EQ(length, GetSize(data_path)); 200 EXPECT_EQ(length, GetSize(data_path));
201 context.reset(NewContext()); 201 context.reset(NewContext());
202 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( 202 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
203 context.get(), virtual_path, &file_info1, &data_path)); 203 context.get(), virtual_path, &file_info1, &data_path));
204 EXPECT_EQ(data_path, local_path); 204 EXPECT_EQ(data_path, local_path);
205 205
206 EXPECT_FALSE(file_info0.is_directory); 206 EXPECT_FALSE(file_info0.is_directory);
207 EXPECT_FALSE(file_info1.is_directory); 207 EXPECT_FALSE(file_info1.is_directory);
208 EXPECT_FALSE(file_info0.is_symbolic_link); 208 EXPECT_FALSE(file_info0.is_symbolic_link);
209 EXPECT_FALSE(file_info1.is_symbolic_link); 209 EXPECT_FALSE(file_info1.is_symbolic_link);
210 EXPECT_EQ(0, file_info0.size); 210 EXPECT_EQ(0, file_info0.size);
211 EXPECT_EQ(length, file_info1.size); 211 EXPECT_EQ(length, file_info1.size);
212 EXPECT_LE(file_info0.last_modified, file_info1.last_modified); 212 EXPECT_LE(file_info0.last_modified, file_info1.last_modified);
213 213
214 context.reset(NewContext()); 214 context.reset(NewContext());
215 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( 215 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate(
216 context.get(), virtual_path, length * 2)); 216 context.get(), virtual_path, length * 2));
217 EXPECT_EQ(length * 2, GetSize(data_path)); 217 EXPECT_EQ(length * 2, GetSize(data_path));
218 218
219 context.reset(NewContext()); 219 context.reset(NewContext());
220 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( 220 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate(
221 context.get(), virtual_path, 1)); 221 context.get(), virtual_path, 1));
222 EXPECT_EQ(1, GetSize(data_path)); 222 EXPECT_EQ(1, GetSize(data_path));
223 } 223 }
224 224
225 void ValidateTestDirectory( 225 void ValidateTestDirectory(
226 const FilePath& root_path, 226 const FilePath& root_path,
227 const std::set<FilePath::StringType>& files, 227 const std::set<FilePath::StringType>& files,
228 const std::set<FilePath::StringType>& directories) { 228 const std::set<FilePath::StringType>& directories) {
229 scoped_ptr<FileSystemOperationContext> context; 229 scoped_ptr<FileSystemOperationContext> context;
230 std::set<FilePath::StringType>::const_iterator iter; 230 std::set<FilePath::StringType>::const_iterator iter;
231 for (iter = files.begin(); iter != files.end(); ++iter) { 231 for (iter = files.begin(); iter != files.end(); ++iter) {
232 bool created = true; 232 bool created = true;
233 context.reset(NewContext()); 233 context.reset(NewContext());
234 ASSERT_EQ(base::PLATFORM_FILE_OK, 234 ASSERT_EQ(base::PLATFORM_FILE_OK,
235 ofsfu()->EnsureFileExists( 235 ofu()->EnsureFileExists(
236 context.get(), root_path.Append(*iter), 236 context.get(), root_path.Append(*iter),
237 &created)); 237 &created));
238 ASSERT_FALSE(created); 238 ASSERT_FALSE(created);
239 } 239 }
240 for (iter = directories.begin(); iter != directories.end(); ++iter) { 240 for (iter = directories.begin(); iter != directories.end(); ++iter) {
241 context.reset(NewContext()); 241 context.reset(NewContext());
242 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), 242 EXPECT_TRUE(ofu()->DirectoryExists(context.get(),
243 root_path.Append(*iter))); 243 root_path.Append(*iter)));
244 } 244 }
245 } 245 }
246 246
247 void FillTestDirectory( 247 void FillTestDirectory(
248 const FilePath& root_path, 248 const FilePath& root_path,
249 std::set<FilePath::StringType>* files, 249 std::set<FilePath::StringType>* files,
250 std::set<FilePath::StringType>* directories) { 250 std::set<FilePath::StringType>* directories) {
251 scoped_ptr<FileSystemOperationContext> context; 251 scoped_ptr<FileSystemOperationContext> context;
252 context.reset(NewContext()); 252 context.reset(NewContext());
253 std::vector<base::FileUtilProxy::Entry> entries; 253 std::vector<base::FileUtilProxy::Entry> entries;
254 EXPECT_EQ(base::PLATFORM_FILE_OK, 254 EXPECT_EQ(base::PLATFORM_FILE_OK,
255 ofsfu()->ReadDirectory(context.get(), root_path, &entries)); 255 ofu()->ReadDirectory(context.get(), root_path, &entries));
256 EXPECT_EQ(0UL, entries.size()); 256 EXPECT_EQ(0UL, entries.size());
257 257
258 files->clear(); 258 files->clear();
259 files->insert(FILE_PATH_LITERAL("first")); 259 files->insert(FILE_PATH_LITERAL("first"));
260 files->insert(FILE_PATH_LITERAL("second")); 260 files->insert(FILE_PATH_LITERAL("second"));
261 files->insert(FILE_PATH_LITERAL("third")); 261 files->insert(FILE_PATH_LITERAL("third"));
262 directories->clear(); 262 directories->clear();
263 directories->insert(FILE_PATH_LITERAL("fourth")); 263 directories->insert(FILE_PATH_LITERAL("fourth"));
264 directories->insert(FILE_PATH_LITERAL("fifth")); 264 directories->insert(FILE_PATH_LITERAL("fifth"));
265 directories->insert(FILE_PATH_LITERAL("sixth")); 265 directories->insert(FILE_PATH_LITERAL("sixth"));
266 std::set<FilePath::StringType>::iterator iter; 266 std::set<FilePath::StringType>::iterator iter;
267 for (iter = files->begin(); iter != files->end(); ++iter) { 267 for (iter = files->begin(); iter != files->end(); ++iter) {
268 bool created = false; 268 bool created = false;
269 context.reset(NewContext()); 269 context.reset(NewContext());
270 ASSERT_EQ(base::PLATFORM_FILE_OK, 270 ASSERT_EQ(base::PLATFORM_FILE_OK,
271 ofsfu()->EnsureFileExists( 271 ofu()->EnsureFileExists(
272 context.get(), root_path.Append(*iter), &created)); 272 context.get(), root_path.Append(*iter), &created));
273 ASSERT_TRUE(created); 273 ASSERT_TRUE(created);
274 } 274 }
275 for (iter = directories->begin(); iter != directories->end(); ++iter) { 275 for (iter = directories->begin(); iter != directories->end(); ++iter) {
276 bool exclusive = true; 276 bool exclusive = true;
277 bool recursive = false; 277 bool recursive = false;
278 context.reset(NewContext()); 278 context.reset(NewContext());
279 EXPECT_EQ(base::PLATFORM_FILE_OK, 279 EXPECT_EQ(base::PLATFORM_FILE_OK,
280 ofsfu()->CreateDirectory( 280 ofu()->CreateDirectory(
281 context.get(), root_path.Append(*iter), exclusive, recursive)); 281 context.get(), root_path.Append(*iter), exclusive, recursive));
282 } 282 }
283 ValidateTestDirectory(root_path, *files, *directories); 283 ValidateTestDirectory(root_path, *files, *directories);
284 } 284 }
285 285
286 void TestReadDirectoryHelper(const FilePath& root_path) { 286 void TestReadDirectoryHelper(const FilePath& root_path) {
287 std::set<FilePath::StringType> files; 287 std::set<FilePath::StringType> files;
288 std::set<FilePath::StringType> directories; 288 std::set<FilePath::StringType> directories;
289 FillTestDirectory(root_path, &files, &directories); 289 FillTestDirectory(root_path, &files, &directories);
290 290
291 scoped_ptr<FileSystemOperationContext> context; 291 scoped_ptr<FileSystemOperationContext> context;
292 std::vector<base::FileUtilProxy::Entry> entries; 292 std::vector<base::FileUtilProxy::Entry> entries;
293 context.reset(NewContext()); 293 context.reset(NewContext());
294 EXPECT_EQ(base::PLATFORM_FILE_OK, 294 EXPECT_EQ(base::PLATFORM_FILE_OK,
295 ofsfu()->ReadDirectory(context.get(), root_path, &entries)); 295 ofu()->ReadDirectory(context.get(), root_path, &entries));
296 std::vector<base::FileUtilProxy::Entry>::iterator entry_iter; 296 std::vector<base::FileUtilProxy::Entry>::iterator entry_iter;
297 EXPECT_EQ(files.size() + directories.size(), entries.size()); 297 EXPECT_EQ(files.size() + directories.size(), entries.size());
298 for (entry_iter = entries.begin(); entry_iter != entries.end(); 298 for (entry_iter = entries.begin(); entry_iter != entries.end();
299 ++entry_iter) { 299 ++entry_iter) {
300 const base::FileUtilProxy::Entry& entry = *entry_iter; 300 const base::FileUtilProxy::Entry& entry = *entry_iter;
301 std::set<FilePath::StringType>::iterator iter = files.find(entry.name); 301 std::set<FilePath::StringType>::iterator iter = files.find(entry.name);
302 if (iter != files.end()) { 302 if (iter != files.end()) {
303 EXPECT_FALSE(entry.is_directory); 303 EXPECT_FALSE(entry.is_directory);
304 files.erase(iter); 304 files.erase(iter);
305 continue; 305 continue;
306 } 306 }
307 iter = directories.find(entry.name); 307 iter = directories.find(entry.name);
308 EXPECT_FALSE(directories.end() == iter); 308 EXPECT_FALSE(directories.end() == iter);
309 EXPECT_TRUE(entry.is_directory); 309 EXPECT_TRUE(entry.is_directory);
310 directories.erase(iter); 310 directories.erase(iter);
311 } 311 }
312 } 312 }
313 313
314 void TestTouchHelper(const FilePath& path) { 314 void TestTouchHelper(const FilePath& path) {
315 base::Time last_access_time = base::Time::Now(); // Ignored, so not tested. 315 base::Time last_access_time = base::Time::Now(); // Ignored, so not tested.
316 base::Time last_modified_time = base::Time::Now(); 316 base::Time last_modified_time = base::Time::Now();
317 scoped_ptr<FileSystemOperationContext> context(NewContext()); 317 scoped_ptr<FileSystemOperationContext> context(NewContext());
318 EXPECT_EQ(base::PLATFORM_FILE_OK, 318 EXPECT_EQ(base::PLATFORM_FILE_OK,
319 ofsfu()->Touch( 319 ofu()->Touch(
320 context.get(), path, last_access_time, last_modified_time)); 320 context.get(), path, last_access_time, last_modified_time));
321 FilePath local_path; 321 FilePath local_path;
322 base::PlatformFileInfo file_info; 322 base::PlatformFileInfo file_info;
323 context.reset(NewContext()); 323 context.reset(NewContext());
324 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( 324 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
325 context.get(), path, &file_info, &local_path)); 325 context.get(), path, &file_info, &local_path));
326 // We compare as time_t here to lower our resolution, to avoid false 326 // We compare as time_t here to lower our resolution, to avoid false
327 // negatives caused by conversion to the local filesystem's native 327 // negatives caused by conversion to the local filesystem's native
328 // representation and back. 328 // representation and back.
329 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); 329 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT());
330 330
331 context.reset(NewContext()); 331 context.reset(NewContext());
332 last_modified_time += base::TimeDelta::FromHours(1); 332 last_modified_time += base::TimeDelta::FromHours(1);
333 EXPECT_EQ(base::PLATFORM_FILE_OK, 333 EXPECT_EQ(base::PLATFORM_FILE_OK,
334 ofsfu()->Touch( 334 ofu()->Touch(
335 context.get(), path, last_access_time, last_modified_time)); 335 context.get(), path, last_access_time, last_modified_time));
336 context.reset(NewContext()); 336 context.reset(NewContext());
337 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( 337 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
338 context.get(), path, &file_info, &local_path)); 338 context.get(), path, &file_info, &local_path));
339 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT()); 339 EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT());
340 } 340 }
341 341
342 void TestCopyInForeignFileHelper(bool overwrite) { 342 void TestCopyInForeignFileHelper(bool overwrite) {
343 ScopedTempDir source_dir; 343 ScopedTempDir source_dir;
344 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); 344 ASSERT_TRUE(source_dir.CreateUniqueTempDir());
345 FilePath root_path = source_dir.path(); 345 FilePath root_path = source_dir.path();
346 FilePath src_path = root_path.AppendASCII("file_name"); 346 FilePath src_path = root_path.AppendASCII("file_name");
347 FilePath dest_path(FILE_PATH_LITERAL("new file")); 347 FilePath dest_path(FILE_PATH_LITERAL("new file"));
348 int64 src_file_length = 87; 348 int64 src_file_length = 87;
349 349
350 base::PlatformFileError error_code; 350 base::PlatformFileError error_code;
351 bool created = false; 351 bool created = false;
352 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; 352 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE;
353 base::PlatformFile file_handle = 353 base::PlatformFile file_handle =
354 base::CreatePlatformFile( 354 base::CreatePlatformFile(
355 src_path, file_flags, &created, &error_code); 355 src_path, file_flags, &created, &error_code);
356 EXPECT_TRUE(created); 356 EXPECT_TRUE(created);
357 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); 357 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code);
358 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); 358 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle);
359 ASSERT_TRUE(base::TruncatePlatformFile(file_handle, src_file_length)); 359 ASSERT_TRUE(base::TruncatePlatformFile(file_handle, src_file_length));
360 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); 360 EXPECT_TRUE(base::ClosePlatformFile(file_handle));
361 361
362 scoped_ptr<FileSystemOperationContext> context; 362 scoped_ptr<FileSystemOperationContext> context;
363 363
364 if (overwrite) { 364 if (overwrite) {
365 context.reset(NewContext()); 365 context.reset(NewContext());
366 EXPECT_EQ(base::PLATFORM_FILE_OK, 366 EXPECT_EQ(base::PLATFORM_FILE_OK,
367 ofsfu()->EnsureFileExists(context.get(), dest_path, &created)); 367 ofu()->EnsureFileExists(context.get(), dest_path, &created));
368 EXPECT_TRUE(created); 368 EXPECT_TRUE(created);
369 } 369 }
370 370
371 context.reset(NewContext()); 371 context.reset(NewContext());
372 EXPECT_EQ(base::PLATFORM_FILE_OK, 372 EXPECT_EQ(base::PLATFORM_FILE_OK,
373 ofsfu()->CopyInForeignFile(context.get(), src_path, dest_path)); 373 ofu()->CopyInForeignFile(context.get(), src_path, dest_path));
374 context.reset(NewContext()); 374 context.reset(NewContext());
375 EXPECT_TRUE(ofsfu()->PathExists(context.get(), dest_path)); 375 EXPECT_TRUE(ofu()->PathExists(context.get(), dest_path));
376 context.reset(NewContext()); 376 context.reset(NewContext());
377 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); 377 EXPECT_FALSE(ofu()->DirectoryExists(context.get(), dest_path));
378 context.reset(NewContext()); 378 context.reset(NewContext());
379 base::PlatformFileInfo file_info; 379 base::PlatformFileInfo file_info;
380 FilePath data_path; 380 FilePath data_path;
381 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( 381 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
382 context.get(), dest_path, &file_info, &data_path)); 382 context.get(), dest_path, &file_info, &data_path));
383 EXPECT_NE(data_path, src_path); 383 EXPECT_NE(data_path, src_path);
384 EXPECT_TRUE(FileExists(data_path)); 384 EXPECT_TRUE(FileExists(data_path));
385 EXPECT_EQ(src_file_length, GetSize(data_path)); 385 EXPECT_EQ(src_file_length, GetSize(data_path));
386 386
387 EXPECT_EQ(base::PLATFORM_FILE_OK, 387 EXPECT_EQ(base::PLATFORM_FILE_OK,
388 ofsfu()->DeleteFile(context.get(), dest_path)); 388 ofu()->DeleteFile(context.get(), dest_path));
389 } 389 }
390 390
391 private: 391 private:
392 ScopedTempDir data_dir_; 392 ScopedTempDir data_dir_;
393 scoped_refptr<ObfuscatedFileSystemFileUtil> obfuscated_file_system_file_util_; 393 scoped_refptr<ObfuscatedFileUtil> obfuscated_file_util_;
394 GURL origin_; 394 GURL origin_;
395 fileapi::FileSystemType type_; 395 fileapi::FileSystemType type_;
396 FileSystemTestOriginHelper test_helper_; 396 FileSystemTestOriginHelper test_helper_;
397 397
398 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileSystemFileUtilTest); 398 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilTest);
399 }; 399 };
400 400
401 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) { 401 TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) {
402 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; 402 base::PlatformFile file_handle = base::kInvalidPlatformFileValue;
403 bool created; 403 bool created;
404 FilePath path = UTF8ToFilePath("fake/file"); 404 FilePath path = UTF8ToFilePath("fake/file");
405 scoped_ptr<FileSystemOperationContext> context(NewContext()); 405 scoped_ptr<FileSystemOperationContext> context(NewContext());
406 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; 406 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE;
407 407
408 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 408 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
409 ofsfu()->CreateOrOpen( 409 ofu()->CreateOrOpen(
410 context.get(), path, file_flags, &file_handle, 410 context.get(), path, file_flags, &file_handle,
411 &created)); 411 &created));
412 412
413 context.reset(NewContext()); 413 context.reset(NewContext());
414 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 414 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
415 ofsfu()->DeleteFile(context.get(), path)); 415 ofu()->DeleteFile(context.get(), path));
416 416
417 path = UTF8ToFilePath("test file"); 417 path = UTF8ToFilePath("test file");
418 418
419 context.reset(NewContext()); 419 context.reset(NewContext());
420 ASSERT_EQ(base::PLATFORM_FILE_OK, 420 ASSERT_EQ(base::PLATFORM_FILE_OK,
421 ofsfu()->CreateOrOpen( 421 ofu()->CreateOrOpen(
422 context.get(), path, file_flags, &file_handle, &created)); 422 context.get(), path, file_flags, &file_handle, &created));
423 ASSERT_TRUE(created); 423 ASSERT_TRUE(created);
424 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); 424 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle);
425 425
426 CheckFileAndCloseHandle(path, file_handle); 426 CheckFileAndCloseHandle(path, file_handle);
427 427
428 context.reset(NewContext()); 428 context.reset(NewContext());
429 FilePath local_path; 429 FilePath local_path;
430 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( 430 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath(
431 context.get(), path, &local_path)); 431 context.get(), path, &local_path));
432 EXPECT_TRUE(file_util::PathExists(local_path)); 432 EXPECT_TRUE(file_util::PathExists(local_path));
433 433
434 context.reset(NewContext()); 434 context.reset(NewContext());
435 EXPECT_EQ(base::PLATFORM_FILE_OK, 435 EXPECT_EQ(base::PLATFORM_FILE_OK,
436 ofsfu()->DeleteFile(context.get(), path)); 436 ofu()->DeleteFile(context.get(), path));
437 EXPECT_FALSE(file_util::PathExists(local_path)); 437 EXPECT_FALSE(file_util::PathExists(local_path));
438 438
439 context.reset(NewContext()); 439 context.reset(NewContext());
440 bool exclusive = true; 440 bool exclusive = true;
441 bool recursive = true; 441 bool recursive = true;
442 FilePath directory_path = UTF8ToFilePath("series/of/directories"); 442 FilePath directory_path = UTF8ToFilePath("series/of/directories");
443 path = directory_path.AppendASCII("file name"); 443 path = directory_path.AppendASCII("file name");
444 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( 444 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
445 context.get(), directory_path, exclusive, recursive)); 445 context.get(), directory_path, exclusive, recursive));
446 446
447 context.reset(NewContext()); 447 context.reset(NewContext());
448 file_handle = base::kInvalidPlatformFileValue; 448 file_handle = base::kInvalidPlatformFileValue;
449 ASSERT_EQ(base::PLATFORM_FILE_OK, 449 ASSERT_EQ(base::PLATFORM_FILE_OK,
450 ofsfu()->CreateOrOpen( 450 ofu()->CreateOrOpen(
451 context.get(), path, file_flags, &file_handle, &created)); 451 context.get(), path, file_flags, &file_handle, &created));
452 ASSERT_TRUE(created); 452 ASSERT_TRUE(created);
453 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); 453 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle);
454 454
455 CheckFileAndCloseHandle(path, file_handle); 455 CheckFileAndCloseHandle(path, file_handle);
456 456
457 context.reset(NewContext()); 457 context.reset(NewContext());
458 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( 458 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath(
459 context.get(), path, &local_path)); 459 context.get(), path, &local_path));
460 EXPECT_TRUE(file_util::PathExists(local_path)); 460 EXPECT_TRUE(file_util::PathExists(local_path));
461 461
462 context.reset(NewContext()); 462 context.reset(NewContext());
463 EXPECT_EQ(base::PLATFORM_FILE_OK, 463 EXPECT_EQ(base::PLATFORM_FILE_OK,
464 ofsfu()->DeleteFile(context.get(), path)); 464 ofu()->DeleteFile(context.get(), path));
465 EXPECT_FALSE(file_util::PathExists(local_path)); 465 EXPECT_FALSE(file_util::PathExists(local_path));
466 } 466 }
467 467
468 TEST_F(ObfuscatedFileSystemFileUtilTest, TestTruncate) { 468 TEST_F(ObfuscatedFileUtilTest, TestTruncate) {
469 bool created = false; 469 bool created = false;
470 FilePath path = UTF8ToFilePath("file"); 470 FilePath path = UTF8ToFilePath("file");
471 scoped_ptr<FileSystemOperationContext> context(NewContext()); 471 scoped_ptr<FileSystemOperationContext> context(NewContext());
472 472
473 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 473 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
474 ofsfu()->Truncate(context.get(), path, 4)); 474 ofu()->Truncate(context.get(), path, 4));
475 475
476 context.reset(NewContext()); 476 context.reset(NewContext());
477 ASSERT_EQ(base::PLATFORM_FILE_OK, 477 ASSERT_EQ(base::PLATFORM_FILE_OK,
478 ofsfu()->EnsureFileExists(context.get(), path, &created)); 478 ofu()->EnsureFileExists(context.get(), path, &created));
479 ASSERT_TRUE(created); 479 ASSERT_TRUE(created);
480 480
481 context.reset(NewContext()); 481 context.reset(NewContext());
482 FilePath local_path; 482 FilePath local_path;
483 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath( 483 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath(
484 context.get(), path, &local_path)); 484 context.get(), path, &local_path));
485 EXPECT_EQ(0, GetSize(local_path)); 485 EXPECT_EQ(0, GetSize(local_path));
486 486
487 context.reset(NewContext()); 487 context.reset(NewContext());
488 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( 488 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate(
489 context.get(), path, 10)); 489 context.get(), path, 10));
490 EXPECT_EQ(10, GetSize(local_path)); 490 EXPECT_EQ(10, GetSize(local_path));
491 491
492 context.reset(NewContext()); 492 context.reset(NewContext());
493 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate( 493 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->Truncate(
494 context.get(), path, 1)); 494 context.get(), path, 1));
495 EXPECT_EQ(1, GetSize(local_path)); 495 EXPECT_EQ(1, GetSize(local_path));
496 496
497 context.reset(NewContext()); 497 context.reset(NewContext());
498 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); 498 EXPECT_FALSE(ofu()->DirectoryExists(context.get(), path));
499 context.reset(NewContext()); 499 context.reset(NewContext());
500 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); 500 EXPECT_TRUE(ofu()->PathExists(context.get(), path));
501 } 501 }
502 502
503 TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnsureFileExists) { 503 TEST_F(ObfuscatedFileUtilTest, TestEnsureFileExists) {
504 FilePath path = UTF8ToFilePath("fake/file"); 504 FilePath path = UTF8ToFilePath("fake/file");
505 bool created = false; 505 bool created = false;
506 scoped_ptr<FileSystemOperationContext> context(NewContext()); 506 scoped_ptr<FileSystemOperationContext> context(NewContext());
507 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 507 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
508 ofsfu()->EnsureFileExists( 508 ofu()->EnsureFileExists(
509 context.get(), path, &created)); 509 context.get(), path, &created));
510 510
511 context.reset(NewContext()); 511 context.reset(NewContext());
512 path = UTF8ToFilePath("test file"); 512 path = UTF8ToFilePath("test file");
513 created = false; 513 created = false;
514 ASSERT_EQ(base::PLATFORM_FILE_OK, 514 ASSERT_EQ(base::PLATFORM_FILE_OK,
515 ofsfu()->EnsureFileExists(context.get(), path, &created)); 515 ofu()->EnsureFileExists(context.get(), path, &created));
516 ASSERT_TRUE(created); 516 ASSERT_TRUE(created);
517 517
518 CheckFileAndCloseHandle(path, base::kInvalidPlatformFileValue); 518 CheckFileAndCloseHandle(path, base::kInvalidPlatformFileValue);
519 519
520 context.reset(NewContext()); 520 context.reset(NewContext());
521 ASSERT_EQ(base::PLATFORM_FILE_OK, 521 ASSERT_EQ(base::PLATFORM_FILE_OK,
522 ofsfu()->EnsureFileExists(context.get(), path, &created)); 522 ofu()->EnsureFileExists(context.get(), path, &created));
523 ASSERT_FALSE(created); 523 ASSERT_FALSE(created);
524 524
525 // Also test in a subdirectory. 525 // Also test in a subdirectory.
526 path = UTF8ToFilePath("path/to/file.txt"); 526 path = UTF8ToFilePath("path/to/file.txt");
527 context.reset(NewContext()); 527 context.reset(NewContext());
528 bool exclusive = true; 528 bool exclusive = true;
529 bool recursive = true; 529 bool recursive = true;
530 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( 530 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
531 context.get(), path.DirName(), exclusive, recursive)); 531 context.get(), path.DirName(), exclusive, recursive));
532 532
533 context.reset(NewContext()); 533 context.reset(NewContext());
534 ASSERT_EQ(base::PLATFORM_FILE_OK, 534 ASSERT_EQ(base::PLATFORM_FILE_OK,
535 ofsfu()->EnsureFileExists(context.get(), path, &created)); 535 ofu()->EnsureFileExists(context.get(), path, &created));
536 ASSERT_TRUE(created); 536 ASSERT_TRUE(created);
537 context.reset(NewContext()); 537 context.reset(NewContext());
538 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); 538 EXPECT_FALSE(ofu()->DirectoryExists(context.get(), path));
539 context.reset(NewContext()); 539 context.reset(NewContext());
540 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); 540 EXPECT_TRUE(ofu()->PathExists(context.get(), path));
541 } 541 }
542 542
543 TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) { 543 TEST_F(ObfuscatedFileUtilTest, TestDirectoryOps) {
544 scoped_ptr<FileSystemOperationContext> context(NewContext()); 544 scoped_ptr<FileSystemOperationContext> context(NewContext());
545 545
546 bool exclusive = false; 546 bool exclusive = false;
547 bool recursive = false; 547 bool recursive = false;
548 FilePath path = UTF8ToFilePath("foo/bar"); 548 FilePath path = UTF8ToFilePath("foo/bar");
549 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->CreateDirectory( 549 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->CreateDirectory(
550 context.get(), path, exclusive, recursive)); 550 context.get(), path, exclusive, recursive));
551 551
552 context.reset(NewContext()); 552 context.reset(NewContext());
553 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 553 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
554 ofsfu()->DeleteSingleDirectory(context.get(), path)); 554 ofu()->DeleteSingleDirectory(context.get(), path));
555 555
556 FilePath root = UTF8ToFilePath(""); 556 FilePath root = UTF8ToFilePath("");
557 context.reset(NewContext()); 557 context.reset(NewContext());
558 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); 558 EXPECT_FALSE(ofu()->DirectoryExists(context.get(), path));
559 context.reset(NewContext()); 559 context.reset(NewContext());
560 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); 560 EXPECT_FALSE(ofu()->PathExists(context.get(), path));
561 context.reset(NewContext()); 561 context.reset(NewContext());
562 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), root)); 562 EXPECT_TRUE(ofu()->IsDirectoryEmpty(context.get(), root));
563 563
564 context.reset(NewContext()); 564 context.reset(NewContext());
565 exclusive = false; 565 exclusive = false;
566 recursive = true; 566 recursive = true;
567 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( 567 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
568 context.get(), path, exclusive, recursive)); 568 context.get(), path, exclusive, recursive));
569 569
570 context.reset(NewContext()); 570 context.reset(NewContext());
571 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); 571 EXPECT_TRUE(ofu()->DirectoryExists(context.get(), path));
572 context.reset(NewContext()); 572 context.reset(NewContext());
573 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); 573 EXPECT_TRUE(ofu()->PathExists(context.get(), path));
574 context.reset(NewContext()); 574 context.reset(NewContext());
575 EXPECT_FALSE(ofsfu()->IsDirectoryEmpty(context.get(), root)); 575 EXPECT_FALSE(ofu()->IsDirectoryEmpty(context.get(), root));
576 context.reset(NewContext()); 576 context.reset(NewContext());
577 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path.DirName())); 577 EXPECT_TRUE(ofu()->DirectoryExists(context.get(), path.DirName()));
578 context.reset(NewContext()); 578 context.reset(NewContext());
579 EXPECT_FALSE(ofsfu()->IsDirectoryEmpty(context.get(), path.DirName())); 579 EXPECT_FALSE(ofu()->IsDirectoryEmpty(context.get(), path.DirName()));
580 580
581 // Can't remove a non-empty directory. 581 // Can't remove a non-empty directory.
582 context.reset(NewContext()); 582 context.reset(NewContext());
583 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, 583 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY,
584 ofsfu()->DeleteSingleDirectory(context.get(), path.DirName())); 584 ofu()->DeleteSingleDirectory(context.get(), path.DirName()));
585 585
586 base::PlatformFileInfo file_info; 586 base::PlatformFileInfo file_info;
587 FilePath local_path; 587 FilePath local_path;
588 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( 588 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
589 context.get(), path, &file_info, &local_path)); 589 context.get(), path, &file_info, &local_path));
590 EXPECT_TRUE(local_path.empty()); 590 EXPECT_TRUE(local_path.empty());
591 EXPECT_TRUE(file_info.is_directory); 591 EXPECT_TRUE(file_info.is_directory);
592 EXPECT_FALSE(file_info.is_symbolic_link); 592 EXPECT_FALSE(file_info.is_symbolic_link);
593 593
594 // Same create again should succeed, since exclusive is false. 594 // Same create again should succeed, since exclusive is false.
595 context.reset(NewContext()); 595 context.reset(NewContext());
596 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( 596 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
597 context.get(), path, exclusive, recursive)); 597 context.get(), path, exclusive, recursive));
598 598
599 exclusive = true; 599 exclusive = true;
600 recursive = true; 600 recursive = true;
601 context.reset(NewContext()); 601 context.reset(NewContext());
602 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( 602 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory(
603 context.get(), path, exclusive, recursive)); 603 context.get(), path, exclusive, recursive));
604 604
605 context.reset(NewContext()); 605 context.reset(NewContext());
606 EXPECT_EQ(base::PLATFORM_FILE_OK, 606 EXPECT_EQ(base::PLATFORM_FILE_OK,
607 ofsfu()->DeleteSingleDirectory(context.get(), path)); 607 ofu()->DeleteSingleDirectory(context.get(), path));
608 608
609 path = UTF8ToFilePath("foo/bop"); 609 path = UTF8ToFilePath("foo/bop");
610 610
611 context.reset(NewContext()); 611 context.reset(NewContext());
612 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); 612 EXPECT_FALSE(ofu()->DirectoryExists(context.get(), path));
613 context.reset(NewContext()); 613 context.reset(NewContext());
614 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); 614 EXPECT_FALSE(ofu()->PathExists(context.get(), path));
615 context.reset(NewContext()); 615 context.reset(NewContext());
616 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), path)); 616 EXPECT_TRUE(ofu()->IsDirectoryEmpty(context.get(), path));
617 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->GetFileInfo( 617 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->GetFileInfo(
618 context.get(), path, &file_info, &local_path)); 618 context.get(), path, &file_info, &local_path));
619 619
620 exclusive = true; 620 exclusive = true;
621 recursive = false; 621 recursive = false;
622 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( 622 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
623 context.get(), path, exclusive, recursive)); 623 context.get(), path, exclusive, recursive));
624 624
625 context.reset(NewContext()); 625 context.reset(NewContext());
626 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); 626 EXPECT_TRUE(ofu()->DirectoryExists(context.get(), path));
627 context.reset(NewContext()); 627 context.reset(NewContext());
628 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); 628 EXPECT_TRUE(ofu()->PathExists(context.get(), path));
629 629
630 exclusive = true; 630 exclusive = true;
631 recursive = false; 631 recursive = false;
632 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( 632 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory(
633 context.get(), path, exclusive, recursive)); 633 context.get(), path, exclusive, recursive));
634 634
635 exclusive = true; 635 exclusive = true;
636 recursive = false; 636 recursive = false;
637 path = UTF8ToFilePath("foo"); 637 path = UTF8ToFilePath("foo");
638 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( 638 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory(
639 context.get(), path, exclusive, recursive)); 639 context.get(), path, exclusive, recursive));
640 640
641 path = UTF8ToFilePath("blah"); 641 path = UTF8ToFilePath("blah");
642 642
643 context.reset(NewContext()); 643 context.reset(NewContext());
644 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path)); 644 EXPECT_FALSE(ofu()->DirectoryExists(context.get(), path));
645 context.reset(NewContext()); 645 context.reset(NewContext());
646 EXPECT_FALSE(ofsfu()->PathExists(context.get(), path)); 646 EXPECT_FALSE(ofu()->PathExists(context.get(), path));
647 647
648 exclusive = true; 648 exclusive = true;
649 recursive = false; 649 recursive = false;
650 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( 650 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
651 context.get(), path, exclusive, recursive)); 651 context.get(), path, exclusive, recursive));
652 652
653 context.reset(NewContext()); 653 context.reset(NewContext());
654 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path)); 654 EXPECT_TRUE(ofu()->DirectoryExists(context.get(), path));
655 context.reset(NewContext()); 655 context.reset(NewContext());
656 EXPECT_TRUE(ofsfu()->PathExists(context.get(), path)); 656 EXPECT_TRUE(ofu()->PathExists(context.get(), path));
657 657
658 exclusive = true; 658 exclusive = true;
659 recursive = false; 659 recursive = false;
660 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory( 660 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofu()->CreateDirectory(
661 context.get(), path, exclusive, recursive)); 661 context.get(), path, exclusive, recursive));
662 } 662 }
663 663
664 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadDirectory) { 664 TEST_F(ObfuscatedFileUtilTest, TestReadDirectory) {
665 scoped_ptr<FileSystemOperationContext> context(NewContext()); 665 scoped_ptr<FileSystemOperationContext> context(NewContext());
666 bool exclusive = true; 666 bool exclusive = true;
667 bool recursive = true; 667 bool recursive = true;
668 FilePath path = UTF8ToFilePath("directory/to/use"); 668 FilePath path = UTF8ToFilePath("directory/to/use");
669 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( 669 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
670 context.get(), path, exclusive, recursive)); 670 context.get(), path, exclusive, recursive));
671 TestReadDirectoryHelper(path); 671 TestReadDirectoryHelper(path);
672 } 672 }
673 673
674 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadRootWithSlash) { 674 TEST_F(ObfuscatedFileUtilTest, TestReadRootWithSlash) {
675 TestReadDirectoryHelper(UTF8ToFilePath("")); 675 TestReadDirectoryHelper(UTF8ToFilePath(""));
676 } 676 }
677 677
678 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadRootWithEmptyString) { 678 TEST_F(ObfuscatedFileUtilTest, TestReadRootWithEmptyString) {
679 TestReadDirectoryHelper(UTF8ToFilePath("/")); 679 TestReadDirectoryHelper(UTF8ToFilePath("/"));
680 } 680 }
681 681
682 TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadDirectoryOnFile) { 682 TEST_F(ObfuscatedFileUtilTest, TestReadDirectoryOnFile) {
683 FilePath path = UTF8ToFilePath("file"); 683 FilePath path = UTF8ToFilePath("file");
684 scoped_ptr<FileSystemOperationContext> context(NewContext()); 684 scoped_ptr<FileSystemOperationContext> context(NewContext());
685 685
686 bool created = false; 686 bool created = false;
687 ASSERT_EQ(base::PLATFORM_FILE_OK, 687 ASSERT_EQ(base::PLATFORM_FILE_OK,
688 ofsfu()->EnsureFileExists(context.get(), path, &created)); 688 ofu()->EnsureFileExists(context.get(), path, &created));
689 ASSERT_TRUE(created); 689 ASSERT_TRUE(created);
690 690
691 context.reset(NewContext()); 691 context.reset(NewContext());
692 std::vector<base::FileUtilProxy::Entry> entries; 692 std::vector<base::FileUtilProxy::Entry> entries;
693 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 693 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
694 ofsfu()->ReadDirectory(context.get(), path, &entries)); 694 ofu()->ReadDirectory(context.get(), path, &entries));
695 695
696 EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), path)); 696 EXPECT_TRUE(ofu()->IsDirectoryEmpty(context.get(), path));
697 } 697 }
698 698
699 TEST_F(ObfuscatedFileSystemFileUtilTest, TestTouch) { 699 TEST_F(ObfuscatedFileUtilTest, TestTouch) {
700 FilePath path = UTF8ToFilePath("fake/file"); 700 FilePath path = UTF8ToFilePath("fake/file");
701 base::Time last_access_time = base::Time::Now(); // Ignored, so not tested. 701 base::Time last_access_time = base::Time::Now(); // Ignored, so not tested.
702 base::Time last_modified_time = base::Time::Now(); 702 base::Time last_modified_time = base::Time::Now();
703 scoped_ptr<FileSystemOperationContext> context(NewContext()); 703 scoped_ptr<FileSystemOperationContext> context(NewContext());
704 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 704 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
705 ofsfu()->Touch( 705 ofu()->Touch(
706 context.get(), path, last_access_time, last_modified_time)); 706 context.get(), path, last_access_time, last_modified_time));
707 707
708 // Touch will create a file if it's not there but its parent is. 708 // Touch will create a file if it's not there but its parent is.
709 path = UTF8ToFilePath("file name"); 709 path = UTF8ToFilePath("file name");
710 TestTouchHelper(path); 710 TestTouchHelper(path);
711 711
712 bool exclusive = true; 712 bool exclusive = true;
713 bool recursive = true; 713 bool recursive = true;
714 path = UTF8ToFilePath("directory/to/use"); 714 path = UTF8ToFilePath("directory/to/use");
715 context.reset(NewContext()); 715 context.reset(NewContext());
716 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( 716 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
717 context.get(), path, exclusive, recursive)); 717 context.get(), path, exclusive, recursive));
718 TestTouchHelper(path); 718 TestTouchHelper(path);
719 } 719 }
720 720
721 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileNotFound) { 721 TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileNotFound) {
722 FilePath source_path = UTF8ToFilePath("path0.txt"); 722 FilePath source_path = UTF8ToFilePath("path0.txt");
723 FilePath dest_path = UTF8ToFilePath("path1.txt"); 723 FilePath dest_path = UTF8ToFilePath("path1.txt");
724 scoped_ptr<FileSystemOperationContext> context(NewContext()); 724 scoped_ptr<FileSystemOperationContext> context(NewContext());
725 725
726 bool is_copy_not_move = false; 726 bool is_copy_not_move = false;
727 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 727 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
728 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, 728 ofu()->CopyOrMoveFile(context.get(), source_path, dest_path,
729 is_copy_not_move)); 729 is_copy_not_move));
730 context.reset(NewContext()); 730 context.reset(NewContext());
731 is_copy_not_move = true; 731 is_copy_not_move = true;
732 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 732 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
733 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, 733 ofu()->CopyOrMoveFile(context.get(), source_path, dest_path,
734 is_copy_not_move)); 734 is_copy_not_move));
735 source_path = UTF8ToFilePath("dir/dir/file"); 735 source_path = UTF8ToFilePath("dir/dir/file");
736 bool exclusive = true; 736 bool exclusive = true;
737 bool recursive = true; 737 bool recursive = true;
738 context.reset(NewContext()); 738 context.reset(NewContext());
739 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( 739 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
740 context.get(), source_path.DirName(), exclusive, recursive)); 740 context.get(), source_path.DirName(), exclusive, recursive));
741 is_copy_not_move = false; 741 is_copy_not_move = false;
742 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 742 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
743 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, 743 ofu()->CopyOrMoveFile(context.get(), source_path, dest_path,
744 is_copy_not_move)); 744 is_copy_not_move));
745 context.reset(NewContext()); 745 context.reset(NewContext());
746 is_copy_not_move = true; 746 is_copy_not_move = true;
747 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 747 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
748 ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path, 748 ofu()->CopyOrMoveFile(context.get(), source_path, dest_path,
749 is_copy_not_move)); 749 is_copy_not_move));
750 } 750 }
751 751
752 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileSuccess) { 752 TEST_F(ObfuscatedFileUtilTest, TestCopyOrMoveFileSuccess) {
753 const int64 kSourceLength = 5; 753 const int64 kSourceLength = 5;
754 const int64 kDestLength = 50; 754 const int64 kDestLength = 50;
755 755
756 for (size_t i = 0; i < arraysize(kCopyMoveTestCases); ++i) { 756 for (size_t i = 0; i < arraysize(kCopyMoveTestCases); ++i) {
757 SCOPED_TRACE(testing::Message() << "kCopyMoveTestCase " << i); 757 SCOPED_TRACE(testing::Message() << "kCopyMoveTestCase " << i);
758 const CopyMoveTestCaseRecord& test_case = kCopyMoveTestCases[i]; 758 const CopyMoveTestCaseRecord& test_case = kCopyMoveTestCases[i];
759 SCOPED_TRACE(testing::Message() << "\t is_copy_not_move " << 759 SCOPED_TRACE(testing::Message() << "\t is_copy_not_move " <<
760 test_case.is_copy_not_move); 760 test_case.is_copy_not_move);
761 SCOPED_TRACE(testing::Message() << "\t source_path " << 761 SCOPED_TRACE(testing::Message() << "\t source_path " <<
762 test_case.source_path); 762 test_case.source_path);
763 SCOPED_TRACE(testing::Message() << "\t dest_path " << 763 SCOPED_TRACE(testing::Message() << "\t dest_path " <<
764 test_case.dest_path); 764 test_case.dest_path);
765 SCOPED_TRACE(testing::Message() << "\t cause_overwrite " << 765 SCOPED_TRACE(testing::Message() << "\t cause_overwrite " <<
766 test_case.cause_overwrite); 766 test_case.cause_overwrite);
767 scoped_ptr<FileSystemOperationContext> context(NewContext()); 767 scoped_ptr<FileSystemOperationContext> context(NewContext());
768 768
769 bool exclusive = false; 769 bool exclusive = false;
770 bool recursive = true; 770 bool recursive = true;
771 FilePath source_path = UTF8ToFilePath(test_case.source_path); 771 FilePath source_path = UTF8ToFilePath(test_case.source_path);
772 FilePath dest_path = UTF8ToFilePath(test_case.dest_path); 772 FilePath dest_path = UTF8ToFilePath(test_case.dest_path);
773 773
774 context.reset(NewContext()); 774 context.reset(NewContext());
775 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( 775 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
776 context.get(), source_path.DirName(), exclusive, recursive)); 776 context.get(), source_path.DirName(), exclusive, recursive));
777 context.reset(NewContext()); 777 context.reset(NewContext());
778 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( 778 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
779 context.get(), dest_path.DirName(), exclusive, recursive)); 779 context.get(), dest_path.DirName(), exclusive, recursive));
780 780
781 bool created = false; 781 bool created = false;
782 context.reset(NewContext()); 782 context.reset(NewContext());
783 ASSERT_EQ(base::PLATFORM_FILE_OK, 783 ASSERT_EQ(base::PLATFORM_FILE_OK,
784 ofsfu()->EnsureFileExists(context.get(), source_path, &created)); 784 ofu()->EnsureFileExists(context.get(), source_path, &created));
785 ASSERT_TRUE(created); 785 ASSERT_TRUE(created);
786 context.reset(NewContext()); 786 context.reset(NewContext());
787 ASSERT_EQ(base::PLATFORM_FILE_OK, 787 ASSERT_EQ(base::PLATFORM_FILE_OK,
788 ofsfu()->Truncate(context.get(), source_path, kSourceLength)); 788 ofu()->Truncate(context.get(), source_path, kSourceLength));
789 789
790 if (test_case.cause_overwrite) { 790 if (test_case.cause_overwrite) {
791 context.reset(NewContext()); 791 context.reset(NewContext());
792 created = false; 792 created = false;
793 ASSERT_EQ(base::PLATFORM_FILE_OK, 793 ASSERT_EQ(base::PLATFORM_FILE_OK,
794 ofsfu()->EnsureFileExists(context.get(), dest_path, &created)); 794 ofu()->EnsureFileExists(context.get(), dest_path, &created));
795 ASSERT_TRUE(created); 795 ASSERT_TRUE(created);
796 context.reset(NewContext()); 796 context.reset(NewContext());
797 ASSERT_EQ(base::PLATFORM_FILE_OK, 797 ASSERT_EQ(base::PLATFORM_FILE_OK,
798 ofsfu()->Truncate(context.get(), dest_path, kDestLength)); 798 ofu()->Truncate(context.get(), dest_path, kDestLength));
799 } 799 }
800 800
801 context.reset(NewContext()); 801 context.reset(NewContext());
802 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CopyOrMoveFile(context.get(), 802 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->CopyOrMoveFile(context.get(),
803 source_path, dest_path, test_case.is_copy_not_move)); 803 source_path, dest_path, test_case.is_copy_not_move));
804 if (test_case.is_copy_not_move) { 804 if (test_case.is_copy_not_move) {
805 base::PlatformFileInfo file_info; 805 base::PlatformFileInfo file_info;
806 FilePath local_path; 806 FilePath local_path;
807 context.reset(NewContext()); 807 context.reset(NewContext());
808 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( 808 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
809 context.get(), source_path, &file_info, &local_path)); 809 context.get(), source_path, &file_info, &local_path));
810 EXPECT_EQ(kSourceLength, file_info.size); 810 EXPECT_EQ(kSourceLength, file_info.size);
811 EXPECT_EQ(base::PLATFORM_FILE_OK, 811 EXPECT_EQ(base::PLATFORM_FILE_OK,
812 ofsfu()->DeleteFile(context.get(), source_path)); 812 ofu()->DeleteFile(context.get(), source_path));
813 } else { 813 } else {
814 base::PlatformFileInfo file_info; 814 base::PlatformFileInfo file_info;
815 FilePath local_path; 815 FilePath local_path;
816 context.reset(NewContext()); 816 context.reset(NewContext());
817 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->GetFileInfo( 817 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofu()->GetFileInfo(
818 context.get(), source_path, &file_info, &local_path)); 818 context.get(), source_path, &file_info, &local_path));
819 } 819 }
820 base::PlatformFileInfo file_info; 820 base::PlatformFileInfo file_info;
821 FilePath local_path; 821 FilePath local_path;
822 EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo( 822 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetFileInfo(
823 context.get(), dest_path, &file_info, &local_path)); 823 context.get(), dest_path, &file_info, &local_path));
824 EXPECT_EQ(kSourceLength, file_info.size); 824 EXPECT_EQ(kSourceLength, file_info.size);
825 825
826 EXPECT_EQ(base::PLATFORM_FILE_OK, 826 EXPECT_EQ(base::PLATFORM_FILE_OK,
827 ofsfu()->DeleteFile(context.get(), dest_path)); 827 ofu()->DeleteFile(context.get(), dest_path));
828 } 828 }
829 } 829 }
830 830
831 TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyInForeignFile) { 831 TEST_F(ObfuscatedFileUtilTest, TestCopyInForeignFile) {
832 TestCopyInForeignFileHelper(false /* overwrite */); 832 TestCopyInForeignFileHelper(false /* overwrite */);
833 TestCopyInForeignFileHelper(true /* overwrite */); 833 TestCopyInForeignFileHelper(true /* overwrite */);
834 } 834 }
835 835
836 TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnumerator) { 836 TEST_F(ObfuscatedFileUtilTest, TestEnumerator) {
837 scoped_ptr<FileSystemOperationContext> context(NewContext()); 837 scoped_ptr<FileSystemOperationContext> context(NewContext());
838 FilePath src_path = UTF8ToFilePath("source dir"); 838 FilePath src_path = UTF8ToFilePath("source dir");
839 bool exclusive = true; 839 bool exclusive = true;
840 bool recursive = false; 840 bool recursive = false;
841 ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory( 841 ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->CreateDirectory(
842 context.get(), src_path, exclusive, recursive)); 842 context.get(), src_path, exclusive, recursive));
843 843
844 std::set<FilePath::StringType> files; 844 std::set<FilePath::StringType> files;
845 std::set<FilePath::StringType> directories; 845 std::set<FilePath::StringType> directories;
846 FillTestDirectory(src_path, &files, &directories); 846 FillTestDirectory(src_path, &files, &directories);
847 847
848 FilePath dest_path = UTF8ToFilePath("destination dir"); 848 FilePath dest_path = UTF8ToFilePath("destination dir");
849 849
850 context.reset(NewContext()); 850 context.reset(NewContext());
851 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); 851 EXPECT_FALSE(ofu()->DirectoryExists(context.get(), dest_path));
852 context.reset(NewContext()); 852 context.reset(NewContext());
853 ASSERT_EQ(base::PLATFORM_FILE_OK, 853 ASSERT_EQ(base::PLATFORM_FILE_OK,
854 ofsfu()->Copy(context.get(), src_path, dest_path)); 854 ofu()->Copy(context.get(), src_path, dest_path));
855 855
856 ValidateTestDirectory(dest_path, files, directories); 856 ValidateTestDirectory(dest_path, files, directories);
857 context.reset(NewContext()); 857 context.reset(NewContext());
858 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), src_path)); 858 EXPECT_TRUE(ofu()->DirectoryExists(context.get(), src_path));
859 context.reset(NewContext()); 859 context.reset(NewContext());
860 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), dest_path)); 860 EXPECT_TRUE(ofu()->DirectoryExists(context.get(), dest_path));
861 context.reset(NewContext()); 861 context.reset(NewContext());
862 recursive = true; 862 recursive = true;
863 ASSERT_EQ(base::PLATFORM_FILE_OK, 863 ASSERT_EQ(base::PLATFORM_FILE_OK,
864 ofsfu()->Delete(context.get(), dest_path, recursive)); 864 ofu()->Delete(context.get(), dest_path, recursive));
865 context.reset(NewContext()); 865 context.reset(NewContext());
866 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); 866 EXPECT_FALSE(ofu()->DirectoryExists(context.get(), dest_path));
867 } 867 }
868 868
869 TEST_F(ObfuscatedFileSystemFileUtilTest, TestMigration) { 869 TEST_F(ObfuscatedFileUtilTest, TestMigration) {
870 ScopedTempDir source_dir; 870 ScopedTempDir source_dir;
871 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); 871 ASSERT_TRUE(source_dir.CreateUniqueTempDir());
872 FilePath root_path = source_dir.path().AppendASCII("chrome-pLmnMWXE7NzTFRsn"); 872 FilePath root_path = source_dir.path().AppendASCII("chrome-pLmnMWXE7NzTFRsn");
873 ASSERT_TRUE(file_util::CreateDirectory(root_path)); 873 ASSERT_TRUE(file_util::CreateDirectory(root_path));
874 874
875 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { 875 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) {
876 SCOPED_TRACE(testing::Message() << "Creating kMigrationTestPath " << i); 876 SCOPED_TRACE(testing::Message() << "Creating kMigrationTestPath " << i);
877 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; 877 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i];
878 FilePath local_src_path = root_path.Append(test_case.path); 878 FilePath local_src_path = root_path.Append(test_case.path);
879 if (test_case.is_directory) { 879 if (test_case.is_directory) {
880 ASSERT_TRUE( 880 ASSERT_TRUE(
881 file_util::CreateDirectory(local_src_path)); 881 file_util::CreateDirectory(local_src_path));
882 } else { 882 } else {
883 base::PlatformFileError error_code; 883 base::PlatformFileError error_code;
884 bool created = false; 884 bool created = false;
885 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; 885 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE;
886 base::PlatformFile file_handle = 886 base::PlatformFile file_handle =
887 base::CreatePlatformFile( 887 base::CreatePlatformFile(
888 local_src_path, file_flags, &created, &error_code); 888 local_src_path, file_flags, &created, &error_code);
889 EXPECT_TRUE(created); 889 EXPECT_TRUE(created);
890 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); 890 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle);
891 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); 891 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code);
892 ASSERT_TRUE( 892 ASSERT_TRUE(
893 base::TruncatePlatformFile(file_handle, test_case.data_file_size)); 893 base::TruncatePlatformFile(file_handle, test_case.data_file_size));
894 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); 894 EXPECT_TRUE(base::ClosePlatformFile(file_handle));
895 } 895 }
896 } 896 }
897 897
898 EXPECT_TRUE(ofsfu()->MigrateFromOldSandbox(origin_url(), type(), root_path)); 898 EXPECT_TRUE(ofu()->MigrateFromOldSandbox(origin_url(), type(), root_path));
899 899
900 FilePath new_root = 900 FilePath new_root =
901 test_directory().AppendASCII("000").Append( 901 test_directory().AppendASCII("000").Append(
902 ofsfu()->GetDirectoryNameForType(type())).AppendASCII("Legacy"); 902 ofu()->GetDirectoryNameForType(type())).AppendASCII("Legacy");
903 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { 903 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) {
904 SCOPED_TRACE(testing::Message() << "Validating kMigrationTestPath " << i); 904 SCOPED_TRACE(testing::Message() << "Validating kMigrationTestPath " << i);
905 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; 905 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i];
906 FilePath local_data_path = new_root.Append(test_case.path); 906 FilePath local_data_path = new_root.Append(test_case.path);
907 #if defined(OS_WIN) 907 #if defined(OS_WIN)
908 local_data_path = local_data_path.NormalizeWindowsPathSeparators(); 908 local_data_path = local_data_path.NormalizeWindowsPathSeparators();
909 #endif 909 #endif
910 scoped_ptr<FileSystemOperationContext> context(NewContext()); 910 scoped_ptr<FileSystemOperationContext> context(NewContext());
911 base::PlatformFileInfo ofsfu_file_info; 911 base::PlatformFileInfo ofu_file_info;
912 FilePath data_path; 912 FilePath data_path;
913 SCOPED_TRACE(testing::Message() << "Path is " << test_case.path); 913 SCOPED_TRACE(testing::Message() << "Path is " << test_case.path);
914 EXPECT_EQ(base::PLATFORM_FILE_OK, 914 EXPECT_EQ(base::PLATFORM_FILE_OK,
915 ofsfu()->GetFileInfo(context.get(), FilePath(test_case.path), 915 ofu()->GetFileInfo(context.get(), FilePath(test_case.path),
916 &ofsfu_file_info, &data_path)); 916 &ofu_file_info, &data_path));
917 if (test_case.is_directory) { 917 if (test_case.is_directory) {
918 EXPECT_TRUE(ofsfu_file_info.is_directory); 918 EXPECT_TRUE(ofu_file_info.is_directory);
919 } else { 919 } else {
920 base::PlatformFileInfo platform_file_info; 920 base::PlatformFileInfo platform_file_info;
921 SCOPED_TRACE(testing::Message() << "local_data_path is " << 921 SCOPED_TRACE(testing::Message() << "local_data_path is " <<
922 local_data_path.value()); 922 local_data_path.value());
923 SCOPED_TRACE(testing::Message() << "data_path is " << data_path.value()); 923 SCOPED_TRACE(testing::Message() << "data_path is " << data_path.value());
924 ASSERT_TRUE(file_util::GetFileInfo(local_data_path, &platform_file_info)); 924 ASSERT_TRUE(file_util::GetFileInfo(local_data_path, &platform_file_info));
925 EXPECT_EQ(test_case.data_file_size, platform_file_info.size); 925 EXPECT_EQ(test_case.data_file_size, platform_file_info.size);
926 EXPECT_FALSE(platform_file_info.is_directory); 926 EXPECT_FALSE(platform_file_info.is_directory);
927 scoped_ptr<FileSystemOperationContext> context(NewContext()); 927 scoped_ptr<FileSystemOperationContext> context(NewContext());
928 EXPECT_EQ(local_data_path, data_path); 928 EXPECT_EQ(local_data_path, data_path);
929 EXPECT_EQ(platform_file_info.size, ofsfu_file_info.size); 929 EXPECT_EQ(platform_file_info.size, ofu_file_info.size);
930 EXPECT_FALSE(ofsfu_file_info.is_directory); 930 EXPECT_FALSE(ofu_file_info.is_directory);
931 } 931 }
932 } 932 }
933 } 933 }
934 934
935 TEST_F(ObfuscatedFileSystemFileUtilTest, TestOriginEnumerator) { 935 TEST_F(ObfuscatedFileUtilTest, TestOriginEnumerator) {
936 scoped_ptr<ObfuscatedFileSystemFileUtil::AbstractOriginEnumerator> 936 scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator>
937 enumerator(ofsfu()->CreateOriginEnumerator()); 937 enumerator(ofu()->CreateOriginEnumerator());
938 EXPECT_TRUE(enumerator.get()); 938 EXPECT_TRUE(enumerator.get());
939 EXPECT_EQ(GURL(), enumerator->Next()); 939 EXPECT_EQ(GURL(), enumerator->Next());
940 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypeTemporary)); 940 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypeTemporary));
941 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypePersistent)); 941 EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypePersistent));
942 942
943 std::set<GURL> origins_expected; 943 std::set<GURL> origins_expected;
944 944
945 for (size_t i = 0; i < arraysize(kOriginEnumerationTestRecords); ++i) { 945 for (size_t i = 0; i < arraysize(kOriginEnumerationTestRecords); ++i) {
946 SCOPED_TRACE(testing::Message() << 946 SCOPED_TRACE(testing::Message() <<
947 "Validating kOriginEnumerationTestRecords " << i); 947 "Validating kOriginEnumerationTestRecords " << i);
948 const OriginEnumerationTestRecord& record = 948 const OriginEnumerationTestRecord& record =
949 kOriginEnumerationTestRecords[i]; 949 kOriginEnumerationTestRecords[i];
950 GURL origin_url(record.origin_url); 950 GURL origin_url(record.origin_url);
951 origins_expected.insert(origin_url); 951 origins_expected.insert(origin_url);
952 if (record.has_temporary) { 952 if (record.has_temporary) {
953 scoped_ptr<FileSystemOperationContext> context(NewContext()); 953 scoped_ptr<FileSystemOperationContext> context(NewContext());
954 context->set_src_origin_url(origin_url); 954 context->set_src_origin_url(origin_url);
955 context->set_src_type(kFileSystemTypeTemporary); 955 context->set_src_type(kFileSystemTypeTemporary);
956 bool created = false; 956 bool created = false;
957 ASSERT_EQ(base::PLATFORM_FILE_OK, 957 ASSERT_EQ(base::PLATFORM_FILE_OK,
958 ofsfu()->EnsureFileExists(context.get(), 958 ofu()->EnsureFileExists(context.get(),
959 FilePath().AppendASCII("file"), &created)); 959 FilePath().AppendASCII("file"), &created));
960 EXPECT_TRUE(created); 960 EXPECT_TRUE(created);
961 } 961 }
962 if (record.has_persistent) { 962 if (record.has_persistent) {
963 scoped_ptr<FileSystemOperationContext> context(NewContext()); 963 scoped_ptr<FileSystemOperationContext> context(NewContext());
964 context->set_src_origin_url(origin_url); 964 context->set_src_origin_url(origin_url);
965 context->set_src_type(kFileSystemTypePersistent); 965 context->set_src_type(kFileSystemTypePersistent);
966 bool created = false; 966 bool created = false;
967 ASSERT_EQ(base::PLATFORM_FILE_OK, 967 ASSERT_EQ(base::PLATFORM_FILE_OK,
968 ofsfu()->EnsureFileExists(context.get(), 968 ofu()->EnsureFileExists(context.get(),
969 FilePath().AppendASCII("file"), &created)); 969 FilePath().AppendASCII("file"), &created));
970 EXPECT_TRUE(created); 970 EXPECT_TRUE(created);
971 } 971 }
972 } 972 }
973 enumerator.reset(ofsfu()->CreateOriginEnumerator()); 973 enumerator.reset(ofu()->CreateOriginEnumerator());
974 EXPECT_TRUE(enumerator.get()); 974 EXPECT_TRUE(enumerator.get());
975 std::set<GURL> origins_found; 975 std::set<GURL> origins_found;
976 GURL origin; 976 GURL origin;
977 while (!(origin = enumerator->Next()).is_empty()) { 977 while (!(origin = enumerator->Next()).is_empty()) {
978 origins_found.insert(origin); 978 origins_found.insert(origin);
979 SCOPED_TRACE(testing::Message() << "Handling " << origin.spec()); 979 SCOPED_TRACE(testing::Message() << "Handling " << origin.spec());
980 bool found = false; 980 bool found = false;
981 for (size_t i = 0; !found && i < arraysize(kOriginEnumerationTestRecords); 981 for (size_t i = 0; !found && i < arraysize(kOriginEnumerationTestRecords);
982 ++i) { 982 ++i) {
983 const OriginEnumerationTestRecord& record = 983 const OriginEnumerationTestRecord& record =
984 kOriginEnumerationTestRecords[i]; 984 kOriginEnumerationTestRecords[i];
985 if (GURL(record.origin_url) != origin) 985 if (GURL(record.origin_url) != origin)
986 continue; 986 continue;
987 found = true; 987 found = true;
988 EXPECT_EQ(record.has_temporary, 988 EXPECT_EQ(record.has_temporary,
989 enumerator->HasFileSystemType(kFileSystemTypeTemporary)); 989 enumerator->HasFileSystemType(kFileSystemTypeTemporary));
990 EXPECT_EQ(record.has_persistent, 990 EXPECT_EQ(record.has_persistent,
991 enumerator->HasFileSystemType(kFileSystemTypePersistent)); 991 enumerator->HasFileSystemType(kFileSystemTypePersistent));
992 } 992 }
993 EXPECT_TRUE(found); 993 EXPECT_TRUE(found);
994 } 994 }
995 995
996 std::set<GURL> diff; 996 std::set<GURL> diff;
997 std::set_symmetric_difference(origins_expected.begin(), 997 std::set_symmetric_difference(origins_expected.begin(),
998 origins_expected.end(), origins_found.begin(), origins_found.end(), 998 origins_expected.end(), origins_found.begin(), origins_found.end(),
999 inserter(diff, diff.begin())); 999 inserter(diff, diff.begin()));
1000 EXPECT_TRUE(diff.empty()); 1000 EXPECT_TRUE(diff.empty());
1001 } 1001 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698