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

Side by Side Diff: chrome/browser/sync_file_system/local/local_file_sync_context_unittest.cc

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 11 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/sync_file_system/local/local_file_sync_context.h" 5 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 const char kOrigin2[] = "http://chromium.org"; 48 const char kOrigin2[] = "http://chromium.org";
49 } 49 }
50 50
51 class LocalFileSyncContextTest : public testing::Test { 51 class LocalFileSyncContextTest : public testing::Test {
52 protected: 52 protected:
53 LocalFileSyncContextTest() 53 LocalFileSyncContextTest()
54 : thread_bundle_( 54 : thread_bundle_(
55 content::TestBrowserThreadBundle::REAL_FILE_THREAD | 55 content::TestBrowserThreadBundle::REAL_FILE_THREAD |
56 content::TestBrowserThreadBundle::REAL_IO_THREAD), 56 content::TestBrowserThreadBundle::REAL_IO_THREAD),
57 status_(SYNC_FILE_ERROR_FAILED), 57 status_(SYNC_FILE_ERROR_FAILED),
58 file_error_(base::PLATFORM_FILE_ERROR_FAILED), 58 file_error_(base::File::FILE_ERROR_FAILED),
59 async_modify_finished_(false), 59 async_modify_finished_(false),
60 has_inflight_prepare_for_sync_(false) {} 60 has_inflight_prepare_for_sync_(false) {}
61 61
62 virtual void SetUp() OVERRIDE { 62 virtual void SetUp() OVERRIDE {
63 RegisterSyncableFileSystem(); 63 RegisterSyncableFileSystem();
64 ASSERT_TRUE(dir_.CreateUniqueTempDir()); 64 ASSERT_TRUE(dir_.CreateUniqueTempDir());
65 65
66 ui_task_runner_ = base::MessageLoop::current()->message_loop_proxy(); 66 ui_task_runner_ = base::MessageLoop::current()->message_loop_proxy();
67 io_task_runner_ = BrowserThread::GetMessageLoopProxyForThread( 67 io_task_runner_ = BrowserThread::GetMessageLoopProxyForThread(
68 BrowserThread::IO); 68 BrowserThread::IO);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 if (!io_task_runner_->RunsTasksOnCurrentThread()) { 176 if (!io_task_runner_->RunsTasksOnCurrentThread()) {
177 async_modify_finished_ = false; 177 async_modify_finished_ = false;
178 ASSERT_TRUE(ui_task_runner_->RunsTasksOnCurrentThread()); 178 ASSERT_TRUE(ui_task_runner_->RunsTasksOnCurrentThread());
179 io_task_runner_->PostTask( 179 io_task_runner_->PostTask(
180 FROM_HERE, 180 FROM_HERE,
181 base::Bind(&LocalFileSyncContextTest::StartModifyFileOnIOThread, 181 base::Bind(&LocalFileSyncContextTest::StartModifyFileOnIOThread,
182 base::Unretained(this), file_system, url)); 182 base::Unretained(this), file_system, url));
183 return; 183 return;
184 } 184 }
185 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); 185 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread());
186 file_error_ = base::PLATFORM_FILE_ERROR_FAILED; 186 file_error_ = base::File::FILE_ERROR_FAILED;
187 file_system->operation_runner()->Truncate( 187 file_system->operation_runner()->Truncate(
188 url, 1, base::Bind(&LocalFileSyncContextTest::DidModifyFile, 188 url, 1, base::Bind(&LocalFileSyncContextTest::DidModifyFile,
189 base::Unretained(this))); 189 base::Unretained(this)));
190 } 190 }
191 191
192 base::PlatformFileError WaitUntilModifyFileIsDone() { 192 base::File::Error WaitUntilModifyFileIsDone() {
193 while (!async_modify_finished_) 193 while (!async_modify_finished_)
194 base::MessageLoop::current()->RunUntilIdle(); 194 base::MessageLoop::current()->RunUntilIdle();
195 return file_error_; 195 return file_error_;
196 } 196 }
197 197
198 void DidModifyFile(base::PlatformFileError error) { 198 void DidModifyFile(base::File::Error error) {
199 if (!ui_task_runner_->RunsTasksOnCurrentThread()) { 199 if (!ui_task_runner_->RunsTasksOnCurrentThread()) {
200 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); 200 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread());
201 ui_task_runner_->PostTask( 201 ui_task_runner_->PostTask(
202 FROM_HERE, 202 FROM_HERE,
203 base::Bind(&LocalFileSyncContextTest::DidModifyFile, 203 base::Bind(&LocalFileSyncContextTest::DidModifyFile,
204 base::Unretained(this), error)); 204 base::Unretained(this), error));
205 return; 205 return;
206 } 206 }
207 ASSERT_TRUE(ui_task_runner_->RunsTasksOnCurrentThread()); 207 ASSERT_TRUE(ui_task_runner_->RunsTasksOnCurrentThread());
208 file_error_ = error; 208 file_error_ = error;
(...skipping 20 matching lines...) Expand all
229 SyncStatusCode simulate_sync_finish_status) { 229 SyncStatusCode simulate_sync_finish_status) {
230 CannedSyncableFileSystem file_system(GURL(kOrigin1), 230 CannedSyncableFileSystem file_system(GURL(kOrigin1),
231 io_task_runner_.get(), 231 io_task_runner_.get(),
232 file_task_runner_.get()); 232 file_task_runner_.get());
233 file_system.SetUp(); 233 file_system.SetUp();
234 sync_context_ = new LocalFileSyncContext( 234 sync_context_ = new LocalFileSyncContext(
235 dir_.path(), ui_task_runner_.get(), io_task_runner_.get()); 235 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
236 ASSERT_EQ(SYNC_STATUS_OK, 236 ASSERT_EQ(SYNC_STATUS_OK,
237 file_system.MaybeInitializeFileSystemContext( 237 file_system.MaybeInitializeFileSystemContext(
238 sync_context_.get())); 238 sync_context_.get()));
239 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); 239 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem());
240 240
241 const FileSystemURL kFile(file_system.URL("file")); 241 const FileSystemURL kFile(file_system.URL("file"));
242 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kFile)); 242 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile));
243 243
244 SyncFileMetadata metadata; 244 SyncFileMetadata metadata;
245 FileChangeList changes; 245 FileChangeList changes;
246 EXPECT_EQ(SYNC_STATUS_OK, 246 EXPECT_EQ(SYNC_STATUS_OK,
247 PrepareForSync(file_system.file_system_context(), kFile, 247 PrepareForSync(file_system.file_system_context(), kFile,
248 sync_mode, &metadata, &changes, NULL)); 248 sync_mode, &metadata, &changes, NULL));
249 EXPECT_EQ(1U, changes.size()); 249 EXPECT_EQ(1U, changes.size());
250 EXPECT_TRUE(changes.list().back().IsFile()); 250 EXPECT_TRUE(changes.list().back().IsFile());
251 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); 251 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
252 252
(...skipping 26 matching lines...) Expand all
279 LocalFileSyncContext::SyncMode sync_mode) { 279 LocalFileSyncContext::SyncMode sync_mode) {
280 CannedSyncableFileSystem file_system(GURL(kOrigin1), 280 CannedSyncableFileSystem file_system(GURL(kOrigin1),
281 io_task_runner_.get(), 281 io_task_runner_.get(),
282 file_task_runner_.get()); 282 file_task_runner_.get());
283 file_system.SetUp(); 283 file_system.SetUp();
284 sync_context_ = new LocalFileSyncContext( 284 sync_context_ = new LocalFileSyncContext(
285 dir_.path(), ui_task_runner_.get(), io_task_runner_.get()); 285 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
286 ASSERT_EQ(SYNC_STATUS_OK, 286 ASSERT_EQ(SYNC_STATUS_OK,
287 file_system.MaybeInitializeFileSystemContext( 287 file_system.MaybeInitializeFileSystemContext(
288 sync_context_.get())); 288 sync_context_.get()));
289 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); 289 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem());
290 290
291 const FileSystemURL kFile(file_system.URL("file")); 291 const FileSystemURL kFile(file_system.URL("file"));
292 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kFile)); 292 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile));
293 293
294 SyncFileMetadata metadata; 294 SyncFileMetadata metadata;
295 FileChangeList changes; 295 FileChangeList changes;
296 webkit_blob::ScopedFile snapshot; 296 webkit_blob::ScopedFile snapshot;
297 EXPECT_EQ(SYNC_STATUS_OK, 297 EXPECT_EQ(SYNC_STATUS_OK,
298 PrepareForSync(file_system.file_system_context(), kFile, 298 PrepareForSync(file_system.file_system_context(), kFile,
299 sync_mode, &metadata, &changes, &snapshot)); 299 sync_mode, &metadata, &changes, &snapshot));
300 EXPECT_EQ(1U, changes.size()); 300 EXPECT_EQ(1U, changes.size());
301 EXPECT_TRUE(changes.list().back().IsFile()); 301 EXPECT_TRUE(changes.list().back().IsFile());
302 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); 302 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
303 303
304 EXPECT_EQ(sync_mode == LocalFileSyncContext::SYNC_SNAPSHOT, 304 EXPECT_EQ(sync_mode == LocalFileSyncContext::SYNC_SNAPSHOT,
305 !snapshot.path().empty()); 305 !snapshot.path().empty());
306 306
307 // Tracker keeps same set of changes. 307 // Tracker keeps same set of changes.
308 file_system.GetChangesForURLInTracker(kFile, &changes); 308 file_system.GetChangesForURLInTracker(kFile, &changes);
309 EXPECT_EQ(1U, changes.size()); 309 EXPECT_EQ(1U, changes.size());
310 EXPECT_TRUE(changes.list().back().IsFile()); 310 EXPECT_TRUE(changes.list().back().IsFile());
311 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); 311 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
312 312
313 StartModifyFileOnIOThread(&file_system, kFile); 313 StartModifyFileOnIOThread(&file_system, kFile);
314 314
315 if (sync_mode == LocalFileSyncContext::SYNC_SNAPSHOT) { 315 if (sync_mode == LocalFileSyncContext::SYNC_SNAPSHOT) {
316 // Write should succeed. 316 // Write should succeed.
317 EXPECT_EQ(base::PLATFORM_FILE_OK, WaitUntilModifyFileIsDone()); 317 EXPECT_EQ(base::File::FILE_OK, WaitUntilModifyFileIsDone());
318 } else { 318 } else {
319 base::MessageLoop::current()->RunUntilIdle(); 319 base::MessageLoop::current()->RunUntilIdle();
320 EXPECT_FALSE(async_modify_finished_); 320 EXPECT_FALSE(async_modify_finished_);
321 } 321 }
322 322
323 SimulateFinishSync(file_system.file_system_context(), kFile, 323 SimulateFinishSync(file_system.file_system_context(), kFile,
324 SYNC_STATUS_OK, sync_mode); 324 SYNC_STATUS_OK, sync_mode);
325 325
326 EXPECT_EQ(base::PLATFORM_FILE_OK, WaitUntilModifyFileIsDone()); 326 EXPECT_EQ(base::File::FILE_OK, WaitUntilModifyFileIsDone());
327 327
328 // Sync succeeded, but the other change that was made during or 328 // Sync succeeded, but the other change that was made during or
329 // after sync is recorded. 329 // after sync is recorded.
330 file_system.GetChangesForURLInTracker(kFile, &changes); 330 file_system.GetChangesForURLInTracker(kFile, &changes);
331 EXPECT_EQ(1U, changes.size()); 331 EXPECT_EQ(1U, changes.size());
332 EXPECT_TRUE(changes.list().back().IsFile()); 332 EXPECT_TRUE(changes.list().back().IsFile());
333 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); 333 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
334 334
335 sync_context_->ShutdownOnUIThread(); 335 sync_context_->ShutdownOnUIThread();
336 sync_context_ = NULL; 336 sync_context_ = NULL;
337 337
338 file_system.TearDown(); 338 file_system.TearDown();
339 } 339 }
340 340
341 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_; 341 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_;
342 342
343 base::ScopedTempDir dir_; 343 base::ScopedTempDir dir_;
344 344
345 // These need to remain until the very end. 345 // These need to remain until the very end.
346 content::TestBrowserThreadBundle thread_bundle_; 346 content::TestBrowserThreadBundle thread_bundle_;
347 347
348 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 348 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
349 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 349 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
350 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; 350 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
351 351
352 scoped_refptr<LocalFileSyncContext> sync_context_; 352 scoped_refptr<LocalFileSyncContext> sync_context_;
353 353
354 SyncStatusCode status_; 354 SyncStatusCode status_;
355 base::PlatformFileError file_error_; 355 base::File::Error file_error_;
356 bool async_modify_finished_; 356 bool async_modify_finished_;
357 bool has_inflight_prepare_for_sync_; 357 bool has_inflight_prepare_for_sync_;
358 }; 358 };
359 359
360 TEST_F(LocalFileSyncContextTest, ConstructAndDestruct) { 360 TEST_F(LocalFileSyncContextTest, ConstructAndDestruct) {
361 sync_context_ = 361 sync_context_ =
362 new LocalFileSyncContext( 362 new LocalFileSyncContext(
363 dir_.path(), ui_task_runner_.get(), io_task_runner_.get()); 363 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
364 sync_context_->ShutdownOnUIThread(); 364 sync_context_->ShutdownOnUIThread();
365 } 365 }
(...skipping 17 matching lines...) Expand all
383 EXPECT_TRUE(file_system.backend()->change_tracker() != NULL); 383 EXPECT_TRUE(file_system.backend()->change_tracker() != NULL);
384 EXPECT_EQ(sync_context_.get(), file_system.backend()->sync_context()); 384 EXPECT_EQ(sync_context_.get(), file_system.backend()->sync_context());
385 385
386 // Calling MaybeInitialize for the same context multiple times must be ok. 386 // Calling MaybeInitialize for the same context multiple times must be ok.
387 EXPECT_EQ(SYNC_STATUS_OK, 387 EXPECT_EQ(SYNC_STATUS_OK,
388 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); 388 file_system.MaybeInitializeFileSystemContext(sync_context_.get()));
389 EXPECT_EQ(sync_context_.get(), file_system.backend()->sync_context()); 389 EXPECT_EQ(sync_context_.get(), file_system.backend()->sync_context());
390 390
391 // Opens the file_system, perform some operation and see if the change tracker 391 // Opens the file_system, perform some operation and see if the change tracker
392 // correctly captures the change. 392 // correctly captures the change.
393 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); 393 EXPECT_EQ(base::File::FILE_OK, file_system.OpenFileSystem());
394 394
395 const FileSystemURL kURL(file_system.URL("foo")); 395 const FileSystemURL kURL(file_system.URL("foo"));
396 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kURL)); 396 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kURL));
397 397
398 FileSystemURLSet urls; 398 FileSystemURLSet urls;
399 file_system.GetChangedURLsInTracker(&urls); 399 file_system.GetChangedURLsInTracker(&urls);
400 ASSERT_EQ(1U, urls.size()); 400 ASSERT_EQ(1U, urls.size());
401 EXPECT_TRUE(ContainsKey(urls, kURL)); 401 EXPECT_TRUE(ContainsKey(urls, kURL));
402 402
403 // Finishing the test. 403 // Finishing the test.
404 sync_context_->ShutdownOnUIThread(); 404 sync_context_->ShutdownOnUIThread();
405 file_system.TearDown(); 405 file_system.TearDown();
406 } 406 }
(...skipping 10 matching lines...) Expand all
417 417
418 sync_context_ = new LocalFileSyncContext( 418 sync_context_ = new LocalFileSyncContext(
419 dir_.path(), ui_task_runner_.get(), io_task_runner_.get()); 419 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
420 420
421 // Initializes file_system1 and file_system2. 421 // Initializes file_system1 and file_system2.
422 EXPECT_EQ(SYNC_STATUS_OK, 422 EXPECT_EQ(SYNC_STATUS_OK,
423 file_system1.MaybeInitializeFileSystemContext(sync_context_.get())); 423 file_system1.MaybeInitializeFileSystemContext(sync_context_.get()));
424 EXPECT_EQ(SYNC_STATUS_OK, 424 EXPECT_EQ(SYNC_STATUS_OK,
425 file_system2.MaybeInitializeFileSystemContext(sync_context_.get())); 425 file_system2.MaybeInitializeFileSystemContext(sync_context_.get()));
426 426
427 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system1.OpenFileSystem()); 427 EXPECT_EQ(base::File::FILE_OK, file_system1.OpenFileSystem());
428 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system2.OpenFileSystem()); 428 EXPECT_EQ(base::File::FILE_OK, file_system2.OpenFileSystem());
429 429
430 const FileSystemURL kURL1(file_system1.URL("foo")); 430 const FileSystemURL kURL1(file_system1.URL("foo"));
431 const FileSystemURL kURL2(file_system2.URL("bar")); 431 const FileSystemURL kURL2(file_system2.URL("bar"));
432 432
433 // Creates a file in file_system1. 433 // Creates a file in file_system1.
434 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system1.CreateFile(kURL1)); 434 EXPECT_EQ(base::File::FILE_OK, file_system1.CreateFile(kURL1));
435 435
436 // file_system1's tracker must have recorded the change. 436 // file_system1's tracker must have recorded the change.
437 FileSystemURLSet urls; 437 FileSystemURLSet urls;
438 file_system1.GetChangedURLsInTracker(&urls); 438 file_system1.GetChangedURLsInTracker(&urls);
439 ASSERT_EQ(1U, urls.size()); 439 ASSERT_EQ(1U, urls.size());
440 EXPECT_TRUE(ContainsKey(urls, kURL1)); 440 EXPECT_TRUE(ContainsKey(urls, kURL1));
441 441
442 // file_system1's tracker must have no change. 442 // file_system1's tracker must have no change.
443 urls.clear(); 443 urls.clear();
444 file_system2.GetChangedURLsInTracker(&urls); 444 file_system2.GetChangedURLsInTracker(&urls);
445 ASSERT_TRUE(urls.empty()); 445 ASSERT_TRUE(urls.empty());
446 446
447 // Creates a directory in file_system2. 447 // Creates a directory in file_system2.
448 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system2.CreateDirectory(kURL2)); 448 EXPECT_EQ(base::File::FILE_OK, file_system2.CreateDirectory(kURL2));
449 449
450 // file_system1's tracker must have the change for kURL1 as before. 450 // file_system1's tracker must have the change for kURL1 as before.
451 urls.clear(); 451 urls.clear();
452 file_system1.GetChangedURLsInTracker(&urls); 452 file_system1.GetChangedURLsInTracker(&urls);
453 ASSERT_EQ(1U, urls.size()); 453 ASSERT_EQ(1U, urls.size());
454 EXPECT_TRUE(ContainsKey(urls, kURL1)); 454 EXPECT_TRUE(ContainsKey(urls, kURL1));
455 455
456 // file_system2's tracker now must have the change for kURL2. 456 // file_system2's tracker now must have the change for kURL2.
457 urls.clear(); 457 urls.clear();
458 file_system2.GetChangedURLsInTracker(&urls); 458 file_system2.GetChangedURLsInTracker(&urls);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 TEST_F(LocalFileSyncContextTest, DISABLED_PrepareSyncWhileWriting) { 524 TEST_F(LocalFileSyncContextTest, DISABLED_PrepareSyncWhileWriting) {
525 CannedSyncableFileSystem file_system(GURL(kOrigin1), 525 CannedSyncableFileSystem file_system(GURL(kOrigin1),
526 io_task_runner_.get(), 526 io_task_runner_.get(),
527 file_task_runner_.get()); 527 file_task_runner_.get());
528 file_system.SetUp(); 528 file_system.SetUp();
529 sync_context_ = new LocalFileSyncContext( 529 sync_context_ = new LocalFileSyncContext(
530 dir_.path(), ui_task_runner_.get(), io_task_runner_.get()); 530 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
531 EXPECT_EQ(SYNC_STATUS_OK, 531 EXPECT_EQ(SYNC_STATUS_OK,
532 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); 532 file_system.MaybeInitializeFileSystemContext(sync_context_.get()));
533 533
534 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); 534 EXPECT_EQ(base::File::FILE_OK, file_system.OpenFileSystem());
535 535
536 const FileSystemURL kURL1(file_system.URL("foo")); 536 const FileSystemURL kURL1(file_system.URL("foo"));
537 537
538 // Creates a file in file_system. 538 // Creates a file in file_system.
539 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kURL1)); 539 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kURL1));
540 540
541 // Kick file write on IO thread. 541 // Kick file write on IO thread.
542 StartModifyFileOnIOThread(&file_system, kURL1); 542 StartModifyFileOnIOThread(&file_system, kURL1);
543 543
544 // Until the operation finishes PrepareForSync should return BUSY error. 544 // Until the operation finishes PrepareForSync should return BUSY error.
545 SyncFileMetadata metadata; 545 SyncFileMetadata metadata;
546 metadata.file_type = SYNC_FILE_TYPE_UNKNOWN; 546 metadata.file_type = SYNC_FILE_TYPE_UNKNOWN;
547 FileChangeList changes; 547 FileChangeList changes;
548 EXPECT_EQ(SYNC_STATUS_FILE_BUSY, 548 EXPECT_EQ(SYNC_STATUS_FILE_BUSY,
549 PrepareForSync(file_system.file_system_context(), kURL1, 549 PrepareForSync(file_system.file_system_context(), kURL1,
550 LocalFileSyncContext::SYNC_EXCLUSIVE, 550 LocalFileSyncContext::SYNC_EXCLUSIVE,
551 &metadata, &changes, NULL)); 551 &metadata, &changes, NULL));
552 EXPECT_EQ(SYNC_FILE_TYPE_FILE, metadata.file_type); 552 EXPECT_EQ(SYNC_FILE_TYPE_FILE, metadata.file_type);
553 553
554 // Register PrepareForSync method to be invoked when kURL1 becomes 554 // Register PrepareForSync method to be invoked when kURL1 becomes
555 // syncable. (Actually this may be done after all operations are done 555 // syncable. (Actually this may be done after all operations are done
556 // on IO thread in this test.) 556 // on IO thread in this test.)
557 metadata.file_type = SYNC_FILE_TYPE_UNKNOWN; 557 metadata.file_type = SYNC_FILE_TYPE_UNKNOWN;
558 changes.clear(); 558 changes.clear();
559 sync_context_->RegisterURLForWaitingSync( 559 sync_context_->RegisterURLForWaitingSync(
560 kURL1, GetPrepareForSyncClosure(file_system.file_system_context(), kURL1, 560 kURL1, GetPrepareForSyncClosure(file_system.file_system_context(), kURL1,
561 LocalFileSyncContext::SYNC_EXCLUSIVE, 561 LocalFileSyncContext::SYNC_EXCLUSIVE,
562 &metadata, &changes, NULL)); 562 &metadata, &changes, NULL));
563 563
564 // Wait for the completion. 564 // Wait for the completion.
565 EXPECT_EQ(base::PLATFORM_FILE_OK, WaitUntilModifyFileIsDone()); 565 EXPECT_EQ(base::File::FILE_OK, WaitUntilModifyFileIsDone());
566 566
567 // The PrepareForSync must have been started; wait until DidPrepareForSync 567 // The PrepareForSync must have been started; wait until DidPrepareForSync
568 // is done. 568 // is done.
569 base::MessageLoop::current()->Run(); 569 base::MessageLoop::current()->Run();
570 ASSERT_FALSE(has_inflight_prepare_for_sync_); 570 ASSERT_FALSE(has_inflight_prepare_for_sync_);
571 571
572 // Now PrepareForSync should have run and returned OK. 572 // Now PrepareForSync should have run and returned OK.
573 EXPECT_EQ(SYNC_STATUS_OK, status_); 573 EXPECT_EQ(SYNC_STATUS_OK, status_);
574 EXPECT_EQ(1U, changes.size()); 574 EXPECT_EQ(1U, changes.size());
575 EXPECT_TRUE(changes.list().back().IsFile()); 575 EXPECT_TRUE(changes.list().back().IsFile());
576 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); 576 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
577 EXPECT_EQ(SYNC_FILE_TYPE_FILE, metadata.file_type); 577 EXPECT_EQ(SYNC_FILE_TYPE_FILE, metadata.file_type);
578 EXPECT_EQ(1, metadata.size); 578 EXPECT_EQ(1, metadata.size);
579 579
580 sync_context_->ShutdownOnUIThread(); 580 sync_context_->ShutdownOnUIThread();
581 sync_context_ = NULL; 581 sync_context_ = NULL;
582 file_system.TearDown(); 582 file_system.TearDown();
583 } 583 }
584 584
585 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForDeletion) { 585 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForDeletion) {
586 CannedSyncableFileSystem file_system(GURL(kOrigin1), 586 CannedSyncableFileSystem file_system(GURL(kOrigin1),
587 io_task_runner_.get(), 587 io_task_runner_.get(),
588 file_task_runner_.get()); 588 file_task_runner_.get());
589 file_system.SetUp(); 589 file_system.SetUp();
590 590
591 sync_context_ = new LocalFileSyncContext( 591 sync_context_ = new LocalFileSyncContext(
592 dir_.path(), ui_task_runner_.get(), io_task_runner_.get()); 592 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
593 ASSERT_EQ(SYNC_STATUS_OK, 593 ASSERT_EQ(SYNC_STATUS_OK,
594 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); 594 file_system.MaybeInitializeFileSystemContext(sync_context_.get()));
595 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); 595 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem());
596 596
597 // Record the initial usage (likely 0). 597 // Record the initial usage (likely 0).
598 int64 initial_usage = -1; 598 int64 initial_usage = -1;
599 int64 quota = -1; 599 int64 quota = -1;
600 EXPECT_EQ(quota::kQuotaStatusOk, 600 EXPECT_EQ(quota::kQuotaStatusOk,
601 file_system.GetUsageAndQuota(&initial_usage, &quota)); 601 file_system.GetUsageAndQuota(&initial_usage, &quota));
602 602
603 // Create a file and directory in the file_system. 603 // Create a file and directory in the file_system.
604 const FileSystemURL kFile(file_system.URL("file")); 604 const FileSystemURL kFile(file_system.URL("file"));
605 const FileSystemURL kDir(file_system.URL("dir")); 605 const FileSystemURL kDir(file_system.URL("dir"));
606 const FileSystemURL kChild(file_system.URL("dir/child")); 606 const FileSystemURL kChild(file_system.URL("dir/child"));
607 607
608 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kFile)); 608 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile));
609 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateDirectory(kDir)); 609 EXPECT_EQ(base::File::FILE_OK, file_system.CreateDirectory(kDir));
610 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kChild)); 610 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kChild));
611 611
612 // file_system's change tracker must have recorded the creation. 612 // file_system's change tracker must have recorded the creation.
613 FileSystemURLSet urls; 613 FileSystemURLSet urls;
614 file_system.GetChangedURLsInTracker(&urls); 614 file_system.GetChangedURLsInTracker(&urls);
615 ASSERT_EQ(3U, urls.size()); 615 ASSERT_EQ(3U, urls.size());
616 ASSERT_TRUE(ContainsKey(urls, kFile)); 616 ASSERT_TRUE(ContainsKey(urls, kFile));
617 ASSERT_TRUE(ContainsKey(urls, kDir)); 617 ASSERT_TRUE(ContainsKey(urls, kDir));
618 ASSERT_TRUE(ContainsKey(urls, kChild)); 618 ASSERT_TRUE(ContainsKey(urls, kChild));
619 for (FileSystemURLSet::iterator iter = urls.begin(); 619 for (FileSystemURLSet::iterator iter = urls.begin();
620 iter != urls.end(); ++iter) { 620 iter != urls.end(); ++iter) {
(...skipping 17 matching lines...) Expand all
638 // The implementation doesn't check file type for deletion, and it must be ok 638 // The implementation doesn't check file type for deletion, and it must be ok
639 // even if we don't know if the deletion change was for a file or a directory. 639 // even if we don't know if the deletion change was for a file or a directory.
640 change = FileChange(FileChange::FILE_CHANGE_DELETE, 640 change = FileChange(FileChange::FILE_CHANGE_DELETE,
641 SYNC_FILE_TYPE_UNKNOWN); 641 SYNC_FILE_TYPE_UNKNOWN);
642 EXPECT_EQ(SYNC_STATUS_OK, 642 EXPECT_EQ(SYNC_STATUS_OK,
643 ApplyRemoteChange(file_system.file_system_context(), 643 ApplyRemoteChange(file_system.file_system_context(),
644 change, base::FilePath(), kDir, 644 change, base::FilePath(), kDir,
645 SYNC_FILE_TYPE_DIRECTORY)); 645 SYNC_FILE_TYPE_DIRECTORY));
646 646
647 // Check the directory/files are deleted successfully. 647 // Check the directory/files are deleted successfully.
648 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 648 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
649 file_system.FileExists(kFile)); 649 file_system.FileExists(kFile));
650 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 650 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
651 file_system.DirectoryExists(kDir)); 651 file_system.DirectoryExists(kDir));
652 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 652 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
653 file_system.FileExists(kChild)); 653 file_system.FileExists(kChild));
654 654
655 // The changes applied by ApplyRemoteChange should not be recorded in 655 // The changes applied by ApplyRemoteChange should not be recorded in
656 // the change tracker. 656 // the change tracker.
657 urls.clear(); 657 urls.clear();
658 file_system.GetChangedURLsInTracker(&urls); 658 file_system.GetChangedURLsInTracker(&urls);
659 EXPECT_TRUE(urls.empty()); 659 EXPECT_TRUE(urls.empty());
660 660
661 // The quota usage data must have reflected the deletion. 661 // The quota usage data must have reflected the deletion.
662 EXPECT_EQ(quota::kQuotaStatusOk, 662 EXPECT_EQ(quota::kQuotaStatusOk,
663 file_system.GetUsageAndQuota(&new_usage, &quota)); 663 file_system.GetUsageAndQuota(&new_usage, &quota));
664 EXPECT_EQ(new_usage, initial_usage); 664 EXPECT_EQ(new_usage, initial_usage);
665 665
666 sync_context_->ShutdownOnUIThread(); 666 sync_context_->ShutdownOnUIThread();
667 sync_context_ = NULL; 667 sync_context_ = NULL;
668 file_system.TearDown(); 668 file_system.TearDown();
669 } 669 }
670 670
671 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForDeletion_ForRoot) { 671 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForDeletion_ForRoot) {
672 CannedSyncableFileSystem file_system(GURL(kOrigin1), 672 CannedSyncableFileSystem file_system(GURL(kOrigin1),
673 io_task_runner_.get(), 673 io_task_runner_.get(),
674 file_task_runner_.get()); 674 file_task_runner_.get());
675 file_system.SetUp(); 675 file_system.SetUp();
676 676
677 sync_context_ = new LocalFileSyncContext( 677 sync_context_ = new LocalFileSyncContext(
678 dir_.path(), ui_task_runner_.get(), io_task_runner_.get()); 678 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
679 ASSERT_EQ(SYNC_STATUS_OK, 679 ASSERT_EQ(SYNC_STATUS_OK,
680 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); 680 file_system.MaybeInitializeFileSystemContext(sync_context_.get()));
681 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); 681 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem());
682 682
683 // Record the initial usage (likely 0). 683 // Record the initial usage (likely 0).
684 int64 initial_usage = -1; 684 int64 initial_usage = -1;
685 int64 quota = -1; 685 int64 quota = -1;
686 EXPECT_EQ(quota::kQuotaStatusOk, 686 EXPECT_EQ(quota::kQuotaStatusOk,
687 file_system.GetUsageAndQuota(&initial_usage, &quota)); 687 file_system.GetUsageAndQuota(&initial_usage, &quota));
688 688
689 // Create a file and directory in the file_system. 689 // Create a file and directory in the file_system.
690 const FileSystemURL kFile(file_system.URL("file")); 690 const FileSystemURL kFile(file_system.URL("file"));
691 const FileSystemURL kDir(file_system.URL("dir")); 691 const FileSystemURL kDir(file_system.URL("dir"));
692 const FileSystemURL kChild(file_system.URL("dir/child")); 692 const FileSystemURL kChild(file_system.URL("dir/child"));
693 693
694 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kFile)); 694 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile));
695 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateDirectory(kDir)); 695 EXPECT_EQ(base::File::FILE_OK, file_system.CreateDirectory(kDir));
696 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kChild)); 696 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kChild));
697 697
698 // At this point the usage must be greater than the initial usage. 698 // At this point the usage must be greater than the initial usage.
699 int64 new_usage = -1; 699 int64 new_usage = -1;
700 EXPECT_EQ(quota::kQuotaStatusOk, 700 EXPECT_EQ(quota::kQuotaStatusOk,
701 file_system.GetUsageAndQuota(&new_usage, &quota)); 701 file_system.GetUsageAndQuota(&new_usage, &quota));
702 EXPECT_GT(new_usage, initial_usage); 702 EXPECT_GT(new_usage, initial_usage);
703 703
704 const FileSystemURL kRoot(file_system.URL("")); 704 const FileSystemURL kRoot(file_system.URL(""));
705 705
706 // Now let's apply remote deletion changes for the root. 706 // Now let's apply remote deletion changes for the root.
707 FileChange change(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_DIRECTORY); 707 FileChange change(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_DIRECTORY);
708 EXPECT_EQ(SYNC_STATUS_OK, 708 EXPECT_EQ(SYNC_STATUS_OK,
709 ApplyRemoteChange(file_system.file_system_context(), 709 ApplyRemoteChange(file_system.file_system_context(),
710 change, base::FilePath(), kRoot, 710 change, base::FilePath(), kRoot,
711 SYNC_FILE_TYPE_DIRECTORY)); 711 SYNC_FILE_TYPE_DIRECTORY));
712 712
713 // Check the directory/files are deleted successfully. 713 // Check the directory/files are deleted successfully.
714 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 714 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
715 file_system.FileExists(kFile)); 715 file_system.FileExists(kFile));
716 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 716 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
717 file_system.DirectoryExists(kDir)); 717 file_system.DirectoryExists(kDir));
718 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 718 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
719 file_system.FileExists(kChild)); 719 file_system.FileExists(kChild));
720 720
721 // All changes made for the previous creation must have been also reset. 721 // All changes made for the previous creation must have been also reset.
722 FileSystemURLSet urls; 722 FileSystemURLSet urls;
723 file_system.GetChangedURLsInTracker(&urls); 723 file_system.GetChangedURLsInTracker(&urls);
724 EXPECT_TRUE(urls.empty()); 724 EXPECT_TRUE(urls.empty());
725 725
726 // The quota usage data must have reflected the deletion. 726 // The quota usage data must have reflected the deletion.
727 EXPECT_EQ(quota::kQuotaStatusOk, 727 EXPECT_EQ(quota::kQuotaStatusOk,
728 file_system.GetUsageAndQuota(&new_usage, &quota)); 728 file_system.GetUsageAndQuota(&new_usage, &quota));
(...skipping 10 matching lines...) Expand all
739 739
740 CannedSyncableFileSystem file_system(GURL(kOrigin1), 740 CannedSyncableFileSystem file_system(GURL(kOrigin1),
741 io_task_runner_.get(), 741 io_task_runner_.get(),
742 file_task_runner_.get()); 742 file_task_runner_.get());
743 file_system.SetUp(); 743 file_system.SetUp();
744 744
745 sync_context_ = new LocalFileSyncContext( 745 sync_context_ = new LocalFileSyncContext(
746 dir_.path(), ui_task_runner_.get(), io_task_runner_.get()); 746 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
747 ASSERT_EQ(SYNC_STATUS_OK, 747 ASSERT_EQ(SYNC_STATUS_OK,
748 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); 748 file_system.MaybeInitializeFileSystemContext(sync_context_.get()));
749 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); 749 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem());
750 750
751 const FileSystemURL kFile1(file_system.URL("file1")); 751 const FileSystemURL kFile1(file_system.URL("file1"));
752 const FileSystemURL kFile2(file_system.URL("file2")); 752 const FileSystemURL kFile2(file_system.URL("file2"));
753 const FileSystemURL kDir(file_system.URL("dir")); 753 const FileSystemURL kDir(file_system.URL("dir"));
754 754
755 const char kTestFileData0[] = "0123456789"; 755 const char kTestFileData0[] = "0123456789";
756 const char kTestFileData1[] = "Lorem ipsum!"; 756 const char kTestFileData1[] = "Lorem ipsum!";
757 const char kTestFileData2[] = "This is sample test data."; 757 const char kTestFileData2[] = "This is sample test data.";
758 758
759 // Create kFile1 and populate it with kTestFileData0. 759 // Create kFile1 and populate it with kTestFileData0.
760 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kFile1)); 760 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile1));
761 EXPECT_EQ(static_cast<int64>(arraysize(kTestFileData0) - 1), 761 EXPECT_EQ(static_cast<int64>(arraysize(kTestFileData0) - 1),
762 file_system.WriteString(kFile1, kTestFileData0)); 762 file_system.WriteString(kFile1, kTestFileData0));
763 763
764 // kFile2 and kDir are not there yet. 764 // kFile2 and kDir are not there yet.
765 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 765 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
766 file_system.FileExists(kFile2)); 766 file_system.FileExists(kFile2));
767 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 767 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
768 file_system.DirectoryExists(kDir)); 768 file_system.DirectoryExists(kDir));
769 769
770 // file_system's change tracker must have recorded the creation. 770 // file_system's change tracker must have recorded the creation.
771 FileSystemURLSet urls; 771 FileSystemURLSet urls;
772 file_system.GetChangedURLsInTracker(&urls); 772 file_system.GetChangedURLsInTracker(&urls);
773 ASSERT_EQ(1U, urls.size()); 773 ASSERT_EQ(1U, urls.size());
774 EXPECT_TRUE(ContainsKey(urls, kFile1)); 774 EXPECT_TRUE(ContainsKey(urls, kFile1));
775 file_system.ClearChangeForURLInTracker(*urls.begin()); 775 file_system.ClearChangeForURLInTracker(*urls.begin());
776 776
777 // Prepare temporary files which represent the remote file data. 777 // Prepare temporary files which represent the remote file data.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 // Calling ApplyRemoteChange with different file type should be handled as 841 // Calling ApplyRemoteChange with different file type should be handled as
842 // overwrite. 842 // overwrite.
843 change = 843 change =
844 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE); 844 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE);
845 EXPECT_EQ(SYNC_STATUS_OK, 845 EXPECT_EQ(SYNC_STATUS_OK,
846 ApplyRemoteChange(file_system.file_system_context(), 846 ApplyRemoteChange(file_system.file_system_context(),
847 change, 847 change,
848 kFilePath1, 848 kFilePath1,
849 kDir, 849 kDir,
850 SYNC_FILE_TYPE_DIRECTORY)); 850 SYNC_FILE_TYPE_DIRECTORY));
851 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.FileExists(kDir)); 851 EXPECT_EQ(base::File::FILE_OK, file_system.FileExists(kDir));
852 852
853 change = FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, 853 change = FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
854 SYNC_FILE_TYPE_DIRECTORY); 854 SYNC_FILE_TYPE_DIRECTORY);
855 EXPECT_EQ(SYNC_STATUS_OK, 855 EXPECT_EQ(SYNC_STATUS_OK,
856 ApplyRemoteChange(file_system.file_system_context(), 856 ApplyRemoteChange(file_system.file_system_context(),
857 change, 857 change,
858 kFilePath1, 858 kFilePath1,
859 kDir, 859 kDir,
860 SYNC_FILE_TYPE_FILE)); 860 SYNC_FILE_TYPE_FILE));
861 861
862 // Creating a file/directory must have increased the usage more than 862 // Creating a file/directory must have increased the usage more than
863 // the size of kTestFileData2. 863 // the size of kTestFileData2.
864 new_usage = usage; 864 new_usage = usage;
865 EXPECT_EQ(quota::kQuotaStatusOk, 865 EXPECT_EQ(quota::kQuotaStatusOk,
866 file_system.GetUsageAndQuota(&new_usage, &quota)); 866 file_system.GetUsageAndQuota(&new_usage, &quota));
867 EXPECT_GT(new_usage, 867 EXPECT_GT(new_usage,
868 static_cast<int64>(usage + arraysize(kTestFileData2) - 1)); 868 static_cast<int64>(usage + arraysize(kTestFileData2) - 1));
869 869
870 // The changes applied by ApplyRemoteChange should not be recorded in 870 // The changes applied by ApplyRemoteChange should not be recorded in
871 // the change tracker. 871 // the change tracker.
872 urls.clear(); 872 urls.clear();
873 file_system.GetChangedURLsInTracker(&urls); 873 file_system.GetChangedURLsInTracker(&urls);
874 EXPECT_TRUE(urls.empty()); 874 EXPECT_TRUE(urls.empty());
875 875
876 // Make sure all three files/directory exist. 876 // Make sure all three files/directory exist.
877 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.FileExists(kFile1)); 877 EXPECT_EQ(base::File::FILE_OK, file_system.FileExists(kFile1));
878 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.FileExists(kFile2)); 878 EXPECT_EQ(base::File::FILE_OK, file_system.FileExists(kFile2));
879 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.DirectoryExists(kDir)); 879 EXPECT_EQ(base::File::FILE_OK, file_system.DirectoryExists(kDir));
880 880
881 sync_context_->ShutdownOnUIThread(); 881 sync_context_->ShutdownOnUIThread();
882 file_system.TearDown(); 882 file_system.TearDown();
883 } 883 }
884 884
885 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForAddOrUpdate_NoParent) { 885 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForAddOrUpdate_NoParent) {
886 base::ScopedTempDir temp_dir; 886 base::ScopedTempDir temp_dir;
887 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 887 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
888 888
889 CannedSyncableFileSystem file_system(GURL(kOrigin1), 889 CannedSyncableFileSystem file_system(GURL(kOrigin1),
890 io_task_runner_.get(), 890 io_task_runner_.get(),
891 file_task_runner_.get()); 891 file_task_runner_.get());
892 file_system.SetUp(); 892 file_system.SetUp();
893 893
894 sync_context_ = new LocalFileSyncContext( 894 sync_context_ = new LocalFileSyncContext(
895 dir_.path(), ui_task_runner_.get(), io_task_runner_.get()); 895 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
896 ASSERT_EQ(SYNC_STATUS_OK, 896 ASSERT_EQ(SYNC_STATUS_OK,
897 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); 897 file_system.MaybeInitializeFileSystemContext(sync_context_.get()));
898 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); 898 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem());
899 899
900 const char kTestFileData[] = "Lorem ipsum!"; 900 const char kTestFileData[] = "Lorem ipsum!";
901 const FileSystemURL kDir(file_system.URL("dir")); 901 const FileSystemURL kDir(file_system.URL("dir"));
902 const FileSystemURL kFile(file_system.URL("dir/file")); 902 const FileSystemURL kFile(file_system.URL("dir/file"));
903 903
904 // Either kDir or kFile not exist yet. 904 // Either kDir or kFile not exist yet.
905 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, file_system.FileExists(kDir)); 905 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, file_system.FileExists(kDir));
906 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, file_system.FileExists(kFile)); 906 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, file_system.FileExists(kFile));
907 907
908 // Prepare a temporary file which represents remote file data. 908 // Prepare a temporary file which represents remote file data.
909 const base::FilePath kFilePath(temp_dir.path().Append(FPL("file"))); 909 const base::FilePath kFilePath(temp_dir.path().Append(FPL("file")));
910 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData) - 1), 910 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData) - 1),
911 file_util::WriteFile(kFilePath, kTestFileData, 911 file_util::WriteFile(kFilePath, kTestFileData,
912 arraysize(kTestFileData) - 1)); 912 arraysize(kTestFileData) - 1));
913 913
914 // Calling ApplyChange's with kFilePath should create 914 // Calling ApplyChange's with kFilePath should create
915 // kFile along with kDir. 915 // kFile along with kDir.
916 FileChange change(FileChange::FILE_CHANGE_ADD_OR_UPDATE, 916 FileChange change(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
917 SYNC_FILE_TYPE_FILE); 917 SYNC_FILE_TYPE_FILE);
918 EXPECT_EQ(SYNC_STATUS_OK, 918 EXPECT_EQ(SYNC_STATUS_OK,
919 ApplyRemoteChange(file_system.file_system_context(), 919 ApplyRemoteChange(file_system.file_system_context(),
920 change, kFilePath, kFile, 920 change, kFilePath, kFile,
921 SYNC_FILE_TYPE_UNKNOWN)); 921 SYNC_FILE_TYPE_UNKNOWN));
922 922
923 // The changes applied by ApplyRemoteChange should not be recorded in 923 // The changes applied by ApplyRemoteChange should not be recorded in
924 // the change tracker. 924 // the change tracker.
925 FileSystemURLSet urls; 925 FileSystemURLSet urls;
926 urls.clear(); 926 urls.clear();
927 file_system.GetChangedURLsInTracker(&urls); 927 file_system.GetChangedURLsInTracker(&urls);
928 EXPECT_TRUE(urls.empty()); 928 EXPECT_TRUE(urls.empty());
929 929
930 // Make sure kDir and kFile are created by ApplyRemoteChange. 930 // Make sure kDir and kFile are created by ApplyRemoteChange.
931 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.FileExists(kFile)); 931 EXPECT_EQ(base::File::FILE_OK, file_system.FileExists(kFile));
932 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.DirectoryExists(kDir)); 932 EXPECT_EQ(base::File::FILE_OK, file_system.DirectoryExists(kDir));
933 933
934 sync_context_->ShutdownOnUIThread(); 934 sync_context_->ShutdownOnUIThread();
935 file_system.TearDown(); 935 file_system.TearDown();
936 } 936 }
937 937
938 } // namespace sync_file_system 938 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698