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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc

Issue 10877005: Rename GDataCache* to DriveCache* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
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/json/json_file_value_serializer.h" 11 #include "base/json/json_file_value_serializer.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/scoped_temp_dir.h" 15 #include "base/scoped_temp_dir.h"
16 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
17 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/chromeos/cros/cros_library.h" 19 #include "chrome/browser/chromeos/cros/cros_library.h"
20 #include "chrome/browser/chromeos/gdata/drive.pb.h" 20 #include "chrome/browser/chromeos/gdata/drive.pb.h"
21 #include "chrome/browser/chromeos/gdata/drive_api_parser.h" 21 #include "chrome/browser/chromeos/gdata/drive_api_parser.h"
22 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" 22 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h"
23 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 23 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
24 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" 24 #include "chrome/browser/chromeos/gdata/gdata_test_util.h"
25 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" 25 #include "chrome/browser/chromeos/gdata/gdata_uploader.h"
26 #include "chrome/browser/chromeos/gdata/gdata_util.h" 26 #include "chrome/browser/chromeos/gdata/gdata_util.h"
27 #include "chrome/browser/chromeos/gdata/mock_directory_change_observer.h" 27 #include "chrome/browser/chromeos/gdata/mock_directory_change_observer.h"
28 #include "chrome/browser/chromeos/gdata/mock_drive_cache_observer.h"
28 #include "chrome/browser/chromeos/gdata/mock_drive_service.h" 29 #include "chrome/browser/chromeos/gdata/mock_drive_service.h"
29 #include "chrome/browser/chromeos/gdata/mock_gdata_cache_observer.h"
30 #include "chrome/common/chrome_paths.h" 30 #include "chrome/common/chrome_paths.h"
31 #include "chrome/test/base/testing_profile.h" 31 #include "chrome/test/base/testing_profile.h"
32 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
33 #include "content/public/test/test_browser_thread.h" 33 #include "content/public/test/test_browser_thread.h"
34 #include "testing/gmock/include/gmock/gmock.h" 34 #include "testing/gmock/include/gmock/gmock.h"
35 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
36 36
37 using ::testing::AtLeast; 37 using ::testing::AtLeast;
38 using ::testing::Eq; 38 using ::testing::Eq;
39 using ::testing::NotNull; 39 using ::testing::NotNull;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 GDataFileSystemTest() 207 GDataFileSystemTest()
208 : ui_thread_(content::BrowserThread::UI, &message_loop_), 208 : ui_thread_(content::BrowserThread::UI, &message_loop_),
209 io_thread_(content::BrowserThread::IO), 209 io_thread_(content::BrowserThread::IO),
210 cache_(NULL), 210 cache_(NULL),
211 file_system_(NULL), 211 file_system_(NULL),
212 mock_drive_service_(NULL), 212 mock_drive_service_(NULL),
213 mock_webapps_registry_(NULL), 213 mock_webapps_registry_(NULL),
214 num_callback_invocations_(0), 214 num_callback_invocations_(0),
215 expected_error_(GDATA_FILE_OK), 215 expected_error_(GDATA_FILE_OK),
216 expected_cache_state_(0), 216 expected_cache_state_(0),
217 expected_sub_dir_type_(GDataCache::CACHE_TYPE_META), 217 expected_sub_dir_type_(DriveCache::CACHE_TYPE_META),
218 expected_success_(true), 218 expected_success_(true),
219 expect_outgoing_symlink_(false), 219 expect_outgoing_symlink_(false),
220 root_feed_changestamp_(0) { 220 root_feed_changestamp_(0) {
221 } 221 }
222 222
223 virtual void SetUp() OVERRIDE { 223 virtual void SetUp() OVERRIDE {
224 chromeos::CrosLibrary::Initialize(true /* use_stub */); 224 chromeos::CrosLibrary::Initialize(true /* use_stub */);
225 io_thread_.StartIOThread(); 225 io_thread_.StartIOThread();
226 226
227 profile_.reset(new TestingProfile); 227 profile_.reset(new TestingProfile);
228 228
229 callback_helper_ = new CallbackHelper; 229 callback_helper_ = new CallbackHelper;
230 230
231 // Allocate and keep a pointer to the mock, and inject it into the 231 // Allocate and keep a pointer to the mock, and inject it into the
232 // GDataFileSystem object, which will own the mock object. 232 // GDataFileSystem object, which will own the mock object.
233 mock_drive_service_ = new StrictMock<MockDriveService>; 233 mock_drive_service_ = new StrictMock<MockDriveService>;
234 234
235 EXPECT_CALL(*mock_drive_service_, Initialize(profile_.get())).Times(1); 235 EXPECT_CALL(*mock_drive_service_, Initialize(profile_.get())).Times(1);
236 236
237 // Likewise, this will be owned by GDataFileSystem. 237 // Likewise, this will be owned by GDataFileSystem.
238 mock_free_disk_space_checker_ = new StrictMock<MockFreeDiskSpaceGetter>; 238 mock_free_disk_space_checker_ = new StrictMock<MockFreeDiskSpaceGetter>;
239 SetFreeDiskSpaceGetterForTesting(mock_free_disk_space_checker_); 239 SetFreeDiskSpaceGetterForTesting(mock_free_disk_space_checker_);
240 240
241 scoped_refptr<base::SequencedWorkerPool> pool = 241 scoped_refptr<base::SequencedWorkerPool> pool =
242 content::BrowserThread::GetBlockingPool(); 242 content::BrowserThread::GetBlockingPool();
243 blocking_task_runner_ = 243 blocking_task_runner_ =
244 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); 244 pool->GetSequencedTaskRunner(pool->GetSequenceToken());
245 245
246 cache_ = GDataCache::CreateGDataCacheOnUIThread( 246 cache_ = DriveCache::CreateDriveCacheOnUIThread(
247 GDataCache::GetCacheRootPath(profile_.get()), blocking_task_runner_); 247 DriveCache::GetCacheRootPath(profile_.get()), blocking_task_runner_);
248 248
249 mock_uploader_.reset(new StrictMock<MockGDataUploader>); 249 mock_uploader_.reset(new StrictMock<MockGDataUploader>);
250 mock_webapps_registry_.reset(new StrictMock<MockDriveWebAppsRegistry>); 250 mock_webapps_registry_.reset(new StrictMock<MockDriveWebAppsRegistry>);
251 251
252 ASSERT_FALSE(file_system_); 252 ASSERT_FALSE(file_system_);
253 file_system_ = new GDataFileSystem(profile_.get(), 253 file_system_ = new GDataFileSystem(profile_.get(),
254 cache_, 254 cache_,
255 mock_drive_service_, 255 mock_drive_service_,
256 mock_uploader_.get(), 256 mock_uploader_.get(),
257 mock_webapps_registry_.get(), 257 mock_webapps_registry_.get(),
258 blocking_task_runner_); 258 blocking_task_runner_);
259 259
260 mock_cache_observer_.reset(new StrictMock<MockGDataCacheObserver>); 260 mock_cache_observer_.reset(new StrictMock<MockDriveCacheObserver>);
261 cache_->AddObserver(mock_cache_observer_.get()); 261 cache_->AddObserver(mock_cache_observer_.get());
262 262
263 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>); 263 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>);
264 file_system_->AddObserver(mock_directory_observer_.get()); 264 file_system_->AddObserver(mock_directory_observer_.get());
265 265
266 file_system_->Initialize(); 266 file_system_->Initialize();
267 cache_->RequestInitializeOnUIThreadForTesting(); 267 cache_->RequestInitializeOnUIThreadForTesting();
268 test_util::RunBlockingPoolTask(); 268 test_util::RunBlockingPoolTask();
269 } 269 }
270 270
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 344
345 bool RemoveEntry(const FilePath& file_path) { 345 bool RemoveEntry(const FilePath& file_path) {
346 return file_system_->RemoveEntryAndCacheLocally(file_path) == 346 return file_system_->RemoveEntryAndCacheLocally(file_path) ==
347 GDATA_FILE_OK; 347 GDATA_FILE_OK;
348 } 348 }
349 349
350 FilePath GetCachePathForFile(const std::string& resource_id, 350 FilePath GetCachePathForFile(const std::string& resource_id,
351 const std::string& md5) { 351 const std::string& md5) {
352 return cache_->GetCacheFilePath(resource_id, 352 return cache_->GetCacheFilePath(resource_id,
353 md5, 353 md5,
354 GDataCache::CACHE_TYPE_TMP, 354 DriveCache::CACHE_TYPE_TMP,
355 GDataCache::CACHED_FILE_FROM_SERVER); 355 DriveCache::CACHED_FILE_FROM_SERVER);
356 } 356 }
357 357
358 // Gets entry info by path synchronously. 358 // Gets entry info by path synchronously.
359 scoped_ptr<DriveEntryProto> GetEntryInfoByPathSync( 359 scoped_ptr<DriveEntryProto> GetEntryInfoByPathSync(
360 const FilePath& file_path) { 360 const FilePath& file_path) {
361 file_system_->GetEntryInfoByPath( 361 file_system_->GetEntryInfoByPath(
362 file_path, 362 file_path,
363 base::Bind(&CallbackHelper::GetEntryInfoCallback, 363 base::Bind(&CallbackHelper::GetEntryInfoCallback,
364 callback_helper_.get())); 364 callback_helper_.get()));
365 test_util::RunBlockingPoolTask(); 365 test_util::RunBlockingPoolTask();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 DriveCacheEntry cache_entry; 427 DriveCacheEntry cache_entry;
428 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); 428 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry);
429 } 429 }
430 430
431 // Returns true if the cache file exists for the given resource ID and MD5. 431 // Returns true if the cache file exists for the given resource ID and MD5.
432 bool CacheFileExists(const std::string& resource_id, 432 bool CacheFileExists(const std::string& resource_id,
433 const std::string& md5) { 433 const std::string& md5) {
434 const FilePath file_path = cache_->GetCacheFilePath( 434 const FilePath file_path = cache_->GetCacheFilePath(
435 resource_id, 435 resource_id,
436 md5, 436 md5,
437 GDataCache::CACHE_TYPE_TMP, 437 DriveCache::CACHE_TYPE_TMP,
438 GDataCache::CACHED_FILE_FROM_SERVER); 438 DriveCache::CACHED_FILE_FROM_SERVER);
439 return file_util::PathExists(file_path); 439 return file_util::PathExists(file_path);
440 } 440 }
441 441
442 void TestStoreToCache( 442 void TestStoreToCache(
443 const std::string& resource_id, 443 const std::string& resource_id,
444 const std::string& md5, 444 const std::string& md5,
445 const FilePath& source_path, 445 const FilePath& source_path,
446 GDataFileError expected_error, 446 GDataFileError expected_error,
447 int expected_cache_state, 447 int expected_cache_state,
448 GDataCache::CacheSubDirectoryType expected_sub_dir_type) { 448 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
449 expected_error_ = expected_error; 449 expected_error_ = expected_error;
450 expected_cache_state_ = expected_cache_state; 450 expected_cache_state_ = expected_cache_state;
451 expected_sub_dir_type_ = expected_sub_dir_type; 451 expected_sub_dir_type_ = expected_sub_dir_type;
452 452
453 cache_->StoreOnUIThread( 453 cache_->StoreOnUIThread(
454 resource_id, md5, source_path, 454 resource_id, md5, source_path,
455 GDataCache::FILE_OPERATION_COPY, 455 DriveCache::FILE_OPERATION_COPY,
456 base::Bind(&GDataFileSystemTest::VerifyCacheFileState, 456 base::Bind(&GDataFileSystemTest::VerifyCacheFileState,
457 base::Unretained(this))); 457 base::Unretained(this)));
458 458
459 test_util::RunBlockingPoolTask(); 459 test_util::RunBlockingPoolTask();
460 } 460 }
461 461
462 void TestPin( 462 void TestPin(
463 const std::string& resource_id, 463 const std::string& resource_id,
464 const std::string& md5, 464 const std::string& md5,
465 GDataFileError expected_error, 465 GDataFileError expected_error,
466 int expected_cache_state, 466 int expected_cache_state,
467 GDataCache::CacheSubDirectoryType expected_sub_dir_type) { 467 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
468 expected_error_ = expected_error; 468 expected_error_ = expected_error;
469 expected_cache_state_ = expected_cache_state; 469 expected_cache_state_ = expected_cache_state;
470 expected_sub_dir_type_ = expected_sub_dir_type; 470 expected_sub_dir_type_ = expected_sub_dir_type;
471 471
472 cache_->PinOnUIThread( 472 cache_->PinOnUIThread(
473 resource_id, md5, 473 resource_id, md5,
474 base::Bind(&GDataFileSystemTest::VerifyCacheFileState, 474 base::Bind(&GDataFileSystemTest::VerifyCacheFileState,
475 base::Unretained(this))); 475 base::Unretained(this)));
476 476
477 test_util::RunBlockingPoolTask(); 477 test_util::RunBlockingPoolTask();
478 } 478 }
479 479
480 void TestMarkDirty( 480 void TestMarkDirty(
481 const std::string& resource_id, 481 const std::string& resource_id,
482 const std::string& md5, 482 const std::string& md5,
483 GDataFileError expected_error, 483 GDataFileError expected_error,
484 int expected_cache_state, 484 int expected_cache_state,
485 GDataCache::CacheSubDirectoryType expected_sub_dir_type) { 485 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
486 expected_error_ = expected_error; 486 expected_error_ = expected_error;
487 expected_cache_state_ = expected_cache_state; 487 expected_cache_state_ = expected_cache_state;
488 expected_sub_dir_type_ = expected_sub_dir_type; 488 expected_sub_dir_type_ = expected_sub_dir_type;
489 expect_outgoing_symlink_ = false; 489 expect_outgoing_symlink_ = false;
490 490
491 cache_->MarkDirtyOnUIThread( 491 cache_->MarkDirtyOnUIThread(
492 resource_id, md5, 492 resource_id, md5,
493 base::Bind(&GDataFileSystemTest::VerifyMarkDirty, 493 base::Bind(&GDataFileSystemTest::VerifyMarkDirty,
494 base::Unretained(this))); 494 base::Unretained(this)));
495 495
(...skipping 16 matching lines...) Expand all
512 } else { 512 } else {
513 EXPECT_TRUE(cache_file_path.empty()); 513 EXPECT_TRUE(cache_file_path.empty());
514 } 514 }
515 } 515 }
516 516
517 void TestCommitDirty( 517 void TestCommitDirty(
518 const std::string& resource_id, 518 const std::string& resource_id,
519 const std::string& md5, 519 const std::string& md5,
520 GDataFileError expected_error, 520 GDataFileError expected_error,
521 int expected_cache_state, 521 int expected_cache_state,
522 GDataCache::CacheSubDirectoryType expected_sub_dir_type) { 522 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
523 expected_error_ = expected_error; 523 expected_error_ = expected_error;
524 expected_cache_state_ = expected_cache_state; 524 expected_cache_state_ = expected_cache_state;
525 expected_sub_dir_type_ = expected_sub_dir_type; 525 expected_sub_dir_type_ = expected_sub_dir_type;
526 expect_outgoing_symlink_ = true; 526 expect_outgoing_symlink_ = true;
527 527
528 cache_->CommitDirtyOnUIThread( 528 cache_->CommitDirtyOnUIThread(
529 resource_id, md5, 529 resource_id, md5,
530 base::Bind(&GDataFileSystemTest::VerifyCacheFileState, 530 base::Bind(&GDataFileSystemTest::VerifyCacheFileState,
531 base::Unretained(this))); 531 base::Unretained(this)));
532 532
533 test_util::RunBlockingPoolTask(); 533 test_util::RunBlockingPoolTask();
534 } 534 }
535 535
536 // Verify the file identified by |resource_id| and |md5| is in the expected 536 // Verify the file identified by |resource_id| and |md5| is in the expected
537 // cache state after |OpenFile|, that is, marked dirty and has no outgoing 537 // cache state after |OpenFile|, that is, marked dirty and has no outgoing
538 // symlink, etc. 538 // symlink, etc.
539 void VerifyCacheStateAfterOpenFile(GDataFileError error, 539 void VerifyCacheStateAfterOpenFile(GDataFileError error,
540 const std::string& resource_id, 540 const std::string& resource_id,
541 const std::string& md5, 541 const std::string& md5,
542 const FilePath& cache_file_path) { 542 const FilePath& cache_file_path) {
543 expected_error_ = GDATA_FILE_OK; 543 expected_error_ = GDATA_FILE_OK;
544 expected_cache_state_ = (test_util::TEST_CACHE_STATE_PRESENT | 544 expected_cache_state_ = (test_util::TEST_CACHE_STATE_PRESENT |
545 test_util::TEST_CACHE_STATE_DIRTY | 545 test_util::TEST_CACHE_STATE_DIRTY |
546 test_util::TEST_CACHE_STATE_PERSISTENT); 546 test_util::TEST_CACHE_STATE_PERSISTENT);
547 expected_sub_dir_type_ = GDataCache::CACHE_TYPE_PERSISTENT; 547 expected_sub_dir_type_ = DriveCache::CACHE_TYPE_PERSISTENT;
548 expect_outgoing_symlink_ = false; 548 expect_outgoing_symlink_ = false;
549 VerifyMarkDirty(error, resource_id, md5, cache_file_path); 549 VerifyMarkDirty(error, resource_id, md5, cache_file_path);
550 } 550 }
551 551
552 // Verify the file identified by |resource_id| and |md5| is in the expected 552 // Verify the file identified by |resource_id| and |md5| is in the expected
553 // cache state after |CloseFile|, that is, marked dirty and has an outgoing 553 // cache state after |CloseFile|, that is, marked dirty and has an outgoing
554 // symlink, etc. 554 // symlink, etc.
555 void VerifyCacheStateAfterCloseFile(GDataFileError error, 555 void VerifyCacheStateAfterCloseFile(GDataFileError error,
556 const std::string& resource_id, 556 const std::string& resource_id,
557 const std::string& md5) { 557 const std::string& md5) {
558 expected_error_ = GDATA_FILE_OK; 558 expected_error_ = GDATA_FILE_OK;
559 expected_cache_state_ = (test_util::TEST_CACHE_STATE_PRESENT | 559 expected_cache_state_ = (test_util::TEST_CACHE_STATE_PRESENT |
560 test_util::TEST_CACHE_STATE_DIRTY | 560 test_util::TEST_CACHE_STATE_DIRTY |
561 test_util::TEST_CACHE_STATE_PERSISTENT); 561 test_util::TEST_CACHE_STATE_PERSISTENT);
562 expected_sub_dir_type_ = GDataCache::CACHE_TYPE_PERSISTENT; 562 expected_sub_dir_type_ = DriveCache::CACHE_TYPE_PERSISTENT;
563 expect_outgoing_symlink_ = true; 563 expect_outgoing_symlink_ = true;
564 VerifyCacheFileState(error, resource_id, md5); 564 VerifyCacheFileState(error, resource_id, md5);
565 } 565 }
566 566
567 void VerifyCacheFileState(GDataFileError error, 567 void VerifyCacheFileState(GDataFileError error,
568 const std::string& resource_id, 568 const std::string& resource_id,
569 const std::string& md5) { 569 const std::string& md5) {
570 ++num_callback_invocations_; 570 ++num_callback_invocations_;
571 571
572 EXPECT_EQ(expected_error_, error); 572 EXPECT_EQ(expected_error_, error);
573 573
574 // Verify cache map. 574 // Verify cache map.
575 DriveCacheEntry cache_entry; 575 DriveCacheEntry cache_entry;
576 const bool cache_entry_found = 576 const bool cache_entry_found =
577 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); 577 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry);
578 if (test_util::ToCacheEntry(expected_cache_state_).is_present() || 578 if (test_util::ToCacheEntry(expected_cache_state_).is_present() ||
579 test_util::ToCacheEntry(expected_cache_state_).is_pinned()) { 579 test_util::ToCacheEntry(expected_cache_state_).is_pinned()) {
580 ASSERT_TRUE(cache_entry_found); 580 ASSERT_TRUE(cache_entry_found);
581 EXPECT_TRUE(test_util::CacheStatesEqual( 581 EXPECT_TRUE(test_util::CacheStatesEqual(
582 test_util::ToCacheEntry(expected_cache_state_), 582 test_util::ToCacheEntry(expected_cache_state_),
583 cache_entry)); 583 cache_entry));
584 EXPECT_EQ(expected_sub_dir_type_, 584 EXPECT_EQ(expected_sub_dir_type_,
585 GDataCache::GetSubDirectoryType(cache_entry)); 585 DriveCache::GetSubDirectoryType(cache_entry));
586 } else { 586 } else {
587 EXPECT_FALSE(cache_entry_found); 587 EXPECT_FALSE(cache_entry_found);
588 } 588 }
589 589
590 // Verify actual cache file. 590 // Verify actual cache file.
591 FilePath dest_path = cache_->GetCacheFilePath( 591 FilePath dest_path = cache_->GetCacheFilePath(
592 resource_id, 592 resource_id,
593 md5, 593 md5,
594 test_util::ToCacheEntry(expected_cache_state_).is_pinned() || 594 test_util::ToCacheEntry(expected_cache_state_).is_pinned() ||
595 test_util::ToCacheEntry(expected_cache_state_).is_dirty() ? 595 test_util::ToCacheEntry(expected_cache_state_).is_dirty() ?
596 GDataCache::CACHE_TYPE_PERSISTENT : 596 DriveCache::CACHE_TYPE_PERSISTENT :
597 GDataCache::CACHE_TYPE_TMP, 597 DriveCache::CACHE_TYPE_TMP,
598 test_util::ToCacheEntry(expected_cache_state_).is_dirty() ? 598 test_util::ToCacheEntry(expected_cache_state_).is_dirty() ?
599 GDataCache::CACHED_FILE_LOCALLY_MODIFIED : 599 DriveCache::CACHED_FILE_LOCALLY_MODIFIED :
600 GDataCache::CACHED_FILE_FROM_SERVER); 600 DriveCache::CACHED_FILE_FROM_SERVER);
601 bool exists = file_util::PathExists(dest_path); 601 bool exists = file_util::PathExists(dest_path);
602 if (test_util::ToCacheEntry(expected_cache_state_).is_present()) 602 if (test_util::ToCacheEntry(expected_cache_state_).is_present())
603 EXPECT_TRUE(exists); 603 EXPECT_TRUE(exists);
604 else 604 else
605 EXPECT_FALSE(exists); 605 EXPECT_FALSE(exists);
606 606
607 // Verify symlink in pinned dir. 607 // Verify symlink in pinned dir.
608 FilePath symlink_path = cache_->GetCacheFilePath( 608 FilePath symlink_path = cache_->GetCacheFilePath(
609 resource_id, 609 resource_id,
610 std::string(), 610 std::string(),
611 GDataCache::CACHE_TYPE_PINNED, 611 DriveCache::CACHE_TYPE_PINNED,
612 GDataCache::CACHED_FILE_FROM_SERVER); 612 DriveCache::CACHED_FILE_FROM_SERVER);
613 // Check that pin symlink exists, without dereferencing to target path. 613 // Check that pin symlink exists, without dereferencing to target path.
614 exists = file_util::IsLink(symlink_path); 614 exists = file_util::IsLink(symlink_path);
615 if (test_util::ToCacheEntry(expected_cache_state_).is_pinned()) { 615 if (test_util::ToCacheEntry(expected_cache_state_).is_pinned()) {
616 EXPECT_TRUE(exists); 616 EXPECT_TRUE(exists);
617 FilePath target_path; 617 FilePath target_path;
618 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path)); 618 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path));
619 if (test_util::ToCacheEntry(expected_cache_state_).is_present()) 619 if (test_util::ToCacheEntry(expected_cache_state_).is_present())
620 EXPECT_EQ(dest_path, target_path); 620 EXPECT_EQ(dest_path, target_path);
621 else 621 else
622 EXPECT_EQ(kSymLinkToDevNull, target_path.value()); 622 EXPECT_EQ(kSymLinkToDevNull, target_path.value());
623 } else { 623 } else {
624 EXPECT_FALSE(exists); 624 EXPECT_FALSE(exists);
625 } 625 }
626 626
627 // Verify symlink in outgoing dir. 627 // Verify symlink in outgoing dir.
628 symlink_path = cache_->GetCacheFilePath( 628 symlink_path = cache_->GetCacheFilePath(
629 resource_id, 629 resource_id,
630 std::string(), 630 std::string(),
631 GDataCache::CACHE_TYPE_OUTGOING, 631 DriveCache::CACHE_TYPE_OUTGOING,
632 GDataCache::CACHED_FILE_FROM_SERVER); 632 DriveCache::CACHED_FILE_FROM_SERVER);
633 // Check that outgoing symlink exists, without dereferencing to target path. 633 // Check that outgoing symlink exists, without dereferencing to target path.
634 exists = file_util::IsLink(symlink_path); 634 exists = file_util::IsLink(symlink_path);
635 if (expect_outgoing_symlink_ && 635 if (expect_outgoing_symlink_ &&
636 test_util::ToCacheEntry(expected_cache_state_).is_dirty()) { 636 test_util::ToCacheEntry(expected_cache_state_).is_dirty()) {
637 EXPECT_TRUE(exists); 637 EXPECT_TRUE(exists);
638 FilePath target_path; 638 FilePath target_path;
639 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path)); 639 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path));
640 EXPECT_TRUE(target_path.value() != kSymLinkToDevNull); 640 EXPECT_TRUE(target_path.value() != kSymLinkToDevNull);
641 if (test_util::ToCacheEntry(expected_cache_state_).is_present()) 641 if (test_util::ToCacheEntry(expected_cache_state_).is_present())
642 EXPECT_EQ(dest_path, target_path); 642 EXPECT_EQ(dest_path, target_path);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 }; 839 };
840 840
841 MessageLoopForUI message_loop_; 841 MessageLoopForUI message_loop_;
842 // The order of the test threads is important, do not change the order. 842 // The order of the test threads is important, do not change the order.
843 // See also content/browser/browser_thread_impl.cc. 843 // See also content/browser/browser_thread_impl.cc.
844 content::TestBrowserThread ui_thread_; 844 content::TestBrowserThread ui_thread_;
845 content::TestBrowserThread io_thread_; 845 content::TestBrowserThread io_thread_;
846 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 846 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
847 scoped_ptr<TestingProfile> profile_; 847 scoped_ptr<TestingProfile> profile_;
848 scoped_refptr<CallbackHelper> callback_helper_; 848 scoped_refptr<CallbackHelper> callback_helper_;
849 GDataCache* cache_; 849 DriveCache* cache_;
850 scoped_ptr<StrictMock<MockGDataUploader> > mock_uploader_; 850 scoped_ptr<StrictMock<MockGDataUploader> > mock_uploader_;
851 GDataFileSystem* file_system_; 851 GDataFileSystem* file_system_;
852 StrictMock<MockDriveService>* mock_drive_service_; 852 StrictMock<MockDriveService>* mock_drive_service_;
853 scoped_ptr<StrictMock<MockDriveWebAppsRegistry> > mock_webapps_registry_; 853 scoped_ptr<StrictMock<MockDriveWebAppsRegistry> > mock_webapps_registry_;
854 StrictMock<MockFreeDiskSpaceGetter>* mock_free_disk_space_checker_; 854 StrictMock<MockFreeDiskSpaceGetter>* mock_free_disk_space_checker_;
855 scoped_ptr<StrictMock<MockGDataCacheObserver> > mock_cache_observer_; 855 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_;
856 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; 856 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_;
857 857
858 int num_callback_invocations_; 858 int num_callback_invocations_;
859 GDataFileError expected_error_; 859 GDataFileError expected_error_;
860 int expected_cache_state_; 860 int expected_cache_state_;
861 GDataCache::CacheSubDirectoryType expected_sub_dir_type_; 861 DriveCache::CacheSubDirectoryType expected_sub_dir_type_;
862 bool expected_success_; 862 bool expected_success_;
863 bool expect_outgoing_symlink_; 863 bool expect_outgoing_symlink_;
864 std::string expected_file_extension_; 864 std::string expected_file_extension_;
865 int root_feed_changestamp_; 865 int root_feed_changestamp_;
866 static bool cros_initialized_; 866 static bool cros_initialized_;
867 }; 867 };
868 868
869 bool GDataFileSystemTest::cros_initialized_ = false; 869 bool GDataFileSystemTest::cros_initialized_ = false;
870 870
871 void AsyncInitializationCallback( 871 void AsyncInitializationCallback(
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2064 .WillOnce(Return(0)) 2064 .WillOnce(Return(0))
2065 .WillOnce(Return(file_size + kMinFreeSpace)) 2065 .WillOnce(Return(file_size + kMinFreeSpace))
2066 .WillOnce(Return(file_size + kMinFreeSpace)); 2066 .WillOnce(Return(file_size + kMinFreeSpace));
2067 2067
2068 // Store something in the temporary cache directory. 2068 // Store something in the temporary cache directory.
2069 TestStoreToCache("<resource_id>", 2069 TestStoreToCache("<resource_id>",
2070 "<md5>", 2070 "<md5>",
2071 GetTestFilePath("root_feed.json"), 2071 GetTestFilePath("root_feed.json"),
2072 GDATA_FILE_OK, 2072 GDATA_FILE_OK,
2073 test_util::TEST_CACHE_STATE_PRESENT, 2073 test_util::TEST_CACHE_STATE_PRESENT,
2074 GDataCache::CACHE_TYPE_TMP); 2074 DriveCache::CACHE_TYPE_TMP);
2075 ASSERT_TRUE(CacheEntryExists("<resource_id>", "<md5>")); 2075 ASSERT_TRUE(CacheEntryExists("<resource_id>", "<md5>"));
2076 ASSERT_TRUE(CacheFileExists("<resource_id>", "<md5>")); 2076 ASSERT_TRUE(CacheFileExists("<resource_id>", "<md5>"));
2077 2077
2078 // Before Download starts metadata from server will be fetched. 2078 // Before Download starts metadata from server will be fetched.
2079 // We will read content url from the result. 2079 // We will read content url from the result.
2080 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json")); 2080 scoped_ptr<base::Value> document(LoadJSONFile("document_to_download.json"));
2081 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id"); 2081 SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id");
2082 2082
2083 // The file is obtained with the mock DriveService, because of we freed up the 2083 // The file is obtained with the mock DriveService, because of we freed up the
2084 // space. 2084 // space.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 FilePath downloaded_file = GetCachePathForFile( 2163 FilePath downloaded_file = GetCachePathForFile(
2164 entry_proto->resource_id(), 2164 entry_proto->resource_id(),
2165 entry_proto->file_specific_info().file_md5()); 2165 entry_proto->file_specific_info().file_md5());
2166 2166
2167 // Store something as cached version of this file. 2167 // Store something as cached version of this file.
2168 TestStoreToCache(entry_proto->resource_id(), 2168 TestStoreToCache(entry_proto->resource_id(),
2169 entry_proto->file_specific_info().file_md5(), 2169 entry_proto->file_specific_info().file_md5(),
2170 GetTestFilePath("root_feed.json"), 2170 GetTestFilePath("root_feed.json"),
2171 GDATA_FILE_OK, 2171 GDATA_FILE_OK,
2172 test_util::TEST_CACHE_STATE_PRESENT, 2172 test_util::TEST_CACHE_STATE_PRESENT,
2173 GDataCache::CACHE_TYPE_TMP); 2173 DriveCache::CACHE_TYPE_TMP);
2174 2174
2175 // Make sure we don't fetch metadata for downloading file. 2175 // Make sure we don't fetch metadata for downloading file.
2176 EXPECT_CALL(*mock_drive_service_, GetDocumentEntry(_, _)).Times(0); 2176 EXPECT_CALL(*mock_drive_service_, GetDocumentEntry(_, _)).Times(0);
2177 2177
2178 // Make sure we don't call downloads at all. 2178 // Make sure we don't call downloads at all.
2179 EXPECT_CALL(*mock_drive_service_, 2179 EXPECT_CALL(*mock_drive_service_,
2180 DownloadFile(file_in_root, 2180 DownloadFile(file_in_root,
2181 downloaded_file, 2181 downloaded_file,
2182 GURL("https://file_content_url_changed/"), 2182 GURL("https://file_content_url_changed/"),
2183 _, _)) 2183 _, _))
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2271 FilePath downloaded_file = GetCachePathForFile( 2271 FilePath downloaded_file = GetCachePathForFile(
2272 entry_proto->resource_id(), 2272 entry_proto->resource_id(),
2273 entry_proto->file_specific_info().file_md5()); 2273 entry_proto->file_specific_info().file_md5());
2274 2274
2275 // Store something as cached version of this file. 2275 // Store something as cached version of this file.
2276 TestStoreToCache(entry_proto->resource_id(), 2276 TestStoreToCache(entry_proto->resource_id(),
2277 entry_proto->file_specific_info().file_md5(), 2277 entry_proto->file_specific_info().file_md5(),
2278 GetTestFilePath("root_feed.json"), 2278 GetTestFilePath("root_feed.json"),
2279 GDATA_FILE_OK, 2279 GDATA_FILE_OK,
2280 test_util::TEST_CACHE_STATE_PRESENT, 2280 test_util::TEST_CACHE_STATE_PRESENT,
2281 GDataCache::CACHE_TYPE_TMP); 2281 DriveCache::CACHE_TYPE_TMP);
2282 2282
2283 // The file is obtained from the cache. 2283 // The file is obtained from the cache.
2284 // Make sure we don't call downloads at all. 2284 // Make sure we don't call downloads at all.
2285 EXPECT_CALL(*mock_drive_service_, DownloadFile(_, _, _, _, _)) 2285 EXPECT_CALL(*mock_drive_service_, DownloadFile(_, _, _, _, _))
2286 .Times(0); 2286 .Times(0);
2287 2287
2288 file_system_->GetFileByResourceId(entry_proto->resource_id(), 2288 file_system_->GetFileByResourceId(entry_proto->resource_id(),
2289 callback, 2289 callback,
2290 GetContentCallback()); 2290 GetContentCallback());
2291 test_util::RunBlockingPoolTask(); 2291 test_util::RunBlockingPoolTask();
(...skipping 13 matching lines...) Expand all
2305 const FilePath kFilePath(FILE_PATH_LITERAL("drive/File 1.txt")); 2305 const FilePath kFilePath(FILE_PATH_LITERAL("drive/File 1.txt"));
2306 const std::string kResourceId("file:2_file_resource_id"); 2306 const std::string kResourceId("file:2_file_resource_id");
2307 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce"); 2307 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce");
2308 2308
2309 // Pin the file so it'll be store in "persistent" directory. 2309 // Pin the file so it'll be store in "persistent" directory.
2310 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(kResourceId, kMd5)).Times(1); 2310 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(kResourceId, kMd5)).Times(1);
2311 TestPin(kResourceId, 2311 TestPin(kResourceId,
2312 kMd5, 2312 kMd5,
2313 GDATA_FILE_OK, 2313 GDATA_FILE_OK,
2314 test_util::TEST_CACHE_STATE_PINNED, 2314 test_util::TEST_CACHE_STATE_PINNED,
2315 GDataCache::CACHE_TYPE_TMP); 2315 DriveCache::CACHE_TYPE_TMP);
2316 2316
2317 // First store a file to cache. A cache file will be created at: 2317 // First store a file to cache. A cache file will be created at:
2318 // GCache/v1/persistent/<kResourceId>.<kMd5> 2318 // GCache/v1/persistent/<kResourceId>.<kMd5>
2319 const FilePath original_cache_file_path = 2319 const FilePath original_cache_file_path =
2320 GDataCache::GetCacheRootPath(profile_.get()) 2320 DriveCache::GetCacheRootPath(profile_.get())
2321 .AppendASCII("persistent") 2321 .AppendASCII("persistent")
2322 .AppendASCII(kResourceId + "." + kMd5); 2322 .AppendASCII(kResourceId + "." + kMd5);
2323 TestStoreToCache(kResourceId, 2323 TestStoreToCache(kResourceId,
2324 kMd5, 2324 kMd5,
2325 GetTestFilePath("root_feed.json"), // Anything works. 2325 GetTestFilePath("root_feed.json"), // Anything works.
2326 GDATA_FILE_OK, 2326 GDATA_FILE_OK,
2327 test_util::TEST_CACHE_STATE_PRESENT | 2327 test_util::TEST_CACHE_STATE_PRESENT |
2328 test_util::TEST_CACHE_STATE_PINNED | 2328 test_util::TEST_CACHE_STATE_PINNED |
2329 test_util::TEST_CACHE_STATE_PERSISTENT, 2329 test_util::TEST_CACHE_STATE_PERSISTENT,
2330 GDataCache::CACHE_TYPE_PERSISTENT); 2330 DriveCache::CACHE_TYPE_PERSISTENT);
2331 ASSERT_TRUE(file_util::PathExists(original_cache_file_path)); 2331 ASSERT_TRUE(file_util::PathExists(original_cache_file_path));
2332 2332
2333 // Add the dirty bit. The cache file will be renamed to 2333 // Add the dirty bit. The cache file will be renamed to
2334 // GCache/v1/persistent/<kResourceId>.local 2334 // GCache/v1/persistent/<kResourceId>.local
2335 TestMarkDirty(kResourceId, 2335 TestMarkDirty(kResourceId,
2336 kMd5, 2336 kMd5,
2337 GDATA_FILE_OK, 2337 GDATA_FILE_OK,
2338 test_util::TEST_CACHE_STATE_PRESENT | 2338 test_util::TEST_CACHE_STATE_PRESENT |
2339 test_util::TEST_CACHE_STATE_PINNED | 2339 test_util::TEST_CACHE_STATE_PINNED |
2340 test_util::TEST_CACHE_STATE_DIRTY | 2340 test_util::TEST_CACHE_STATE_DIRTY |
2341 test_util::TEST_CACHE_STATE_PERSISTENT, 2341 test_util::TEST_CACHE_STATE_PERSISTENT,
2342 GDataCache::CACHE_TYPE_PERSISTENT); 2342 DriveCache::CACHE_TYPE_PERSISTENT);
2343 const FilePath dirty_cache_file_path = 2343 const FilePath dirty_cache_file_path =
2344 GDataCache::GetCacheRootPath(profile_.get()) 2344 DriveCache::GetCacheRootPath(profile_.get())
2345 .AppendASCII("persistent") 2345 .AppendASCII("persistent")
2346 .AppendASCII(kResourceId + ".local"); 2346 .AppendASCII(kResourceId + ".local");
2347 ASSERT_FALSE(file_util::PathExists(original_cache_file_path)); 2347 ASSERT_FALSE(file_util::PathExists(original_cache_file_path));
2348 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path)); 2348 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path));
2349 2349
2350 // Modify the cached file. 2350 // Modify the cached file.
2351 const std::string kDummyCacheContent("modification to the cache"); 2351 const std::string kDummyCacheContent("modification to the cache");
2352 ASSERT_TRUE(file_util::WriteFile(dirty_cache_file_path, 2352 ASSERT_TRUE(file_util::WriteFile(dirty_cache_file_path,
2353 kDummyCacheContent.c_str(), 2353 kDummyCacheContent.c_str(),
2354 kDummyCacheContent.size())); 2354 kDummyCacheContent.size()));
2355 2355
2356 // Commit the dirty bit. The cache file name remains the same 2356 // Commit the dirty bit. The cache file name remains the same
2357 // but a symlink will be created at: 2357 // but a symlink will be created at:
2358 // GCache/v1/outgoing/<kResourceId> 2358 // GCache/v1/outgoing/<kResourceId>
2359 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(kResourceId)).Times(1); 2359 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(kResourceId)).Times(1);
2360 TestCommitDirty(kResourceId, 2360 TestCommitDirty(kResourceId,
2361 kMd5, 2361 kMd5,
2362 GDATA_FILE_OK, 2362 GDATA_FILE_OK,
2363 test_util::TEST_CACHE_STATE_PRESENT | 2363 test_util::TEST_CACHE_STATE_PRESENT |
2364 test_util::TEST_CACHE_STATE_PINNED | 2364 test_util::TEST_CACHE_STATE_PINNED |
2365 test_util::TEST_CACHE_STATE_DIRTY | 2365 test_util::TEST_CACHE_STATE_DIRTY |
2366 test_util::TEST_CACHE_STATE_PERSISTENT, 2366 test_util::TEST_CACHE_STATE_PERSISTENT,
2367 GDataCache::CACHE_TYPE_PERSISTENT); 2367 DriveCache::CACHE_TYPE_PERSISTENT);
2368 const FilePath outgoing_symlink_path = 2368 const FilePath outgoing_symlink_path =
2369 GDataCache::GetCacheRootPath(profile_.get()) 2369 DriveCache::GetCacheRootPath(profile_.get())
2370 .AppendASCII("outgoing") 2370 .AppendASCII("outgoing")
2371 .AppendASCII(kResourceId); 2371 .AppendASCII(kResourceId);
2372 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path)); 2372 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path));
2373 ASSERT_TRUE(file_util::PathExists(outgoing_symlink_path)); 2373 ASSERT_TRUE(file_util::PathExists(outgoing_symlink_path));
2374 2374
2375 // Create a DocumentEntry, which is needed to mock 2375 // Create a DocumentEntry, which is needed to mock
2376 // GDataUploaderInterface::UploadExistingFile(). 2376 // GDataUploaderInterface::UploadExistingFile().
2377 // TODO(satorux): This should be cleaned up. crbug.com/134240. 2377 // TODO(satorux): This should be cleaned up. crbug.com/134240.
2378 DocumentEntry* document_entry = NULL; 2378 DocumentEntry* document_entry = NULL;
2379 scoped_ptr<base::Value> value(LoadJSONFile("root_feed.json")); 2379 scoped_ptr<base::Value> value(LoadJSONFile("root_feed.json"));
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
2640 2640
2641 // Try to close the same file twice. 2641 // Try to close the same file twice.
2642 file_system_->CloseFile(kFileInRoot, close_file_callback); 2642 file_system_->CloseFile(kFileInRoot, close_file_callback);
2643 message_loop_.Run(); 2643 message_loop_.Run();
2644 2644
2645 // It must fail. 2645 // It must fail.
2646 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); 2646 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_);
2647 } 2647 }
2648 2648
2649 } // namespace gdata 2649 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system_interface.h ('k') | chrome/browser/chromeos/gdata/gdata_sync_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698