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

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

Issue 10698135: Revert 145933 - gdata: Remove sub_dir_type from CacheEntry for simplicity (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_cache_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <errno.h> 5 #include <errno.h>
6 #include <string> 6 #include <string>
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 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 } 659 }
660 660
661 // Verify the file identified by |resource_id| and |md5| is in the expected 661 // Verify the file identified by |resource_id| and |md5| is in the expected
662 // cache state after |OpenFile|, that is, marked dirty and has no outgoing 662 // cache state after |OpenFile|, that is, marked dirty and has no outgoing
663 // symlink, etc. 663 // symlink, etc.
664 void VerifyCacheStateAfterOpenFile(base::PlatformFileError error, 664 void VerifyCacheStateAfterOpenFile(base::PlatformFileError error,
665 const std::string& resource_id, 665 const std::string& resource_id,
666 const std::string& md5, 666 const std::string& md5,
667 const FilePath& cache_file_path) { 667 const FilePath& cache_file_path) {
668 expected_error_ = base::PLATFORM_FILE_OK; 668 expected_error_ = base::PLATFORM_FILE_OK;
669 expected_cache_state_ = (GDataCache::CACHE_STATE_PRESENT | 669 expected_cache_state_ =
670 GDataCache::CACHE_STATE_DIRTY | 670 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY;
671 GDataCache::CACHE_STATE_PERSISTENT);
672 expected_sub_dir_type_ = GDataCache::CACHE_TYPE_PERSISTENT; 671 expected_sub_dir_type_ = GDataCache::CACHE_TYPE_PERSISTENT;
673 expect_outgoing_symlink_ = false; 672 expect_outgoing_symlink_ = false;
674 VerifyMarkDirty(error, resource_id, md5, cache_file_path); 673 VerifyMarkDirty(error, resource_id, md5, cache_file_path);
675 } 674 }
676 675
677 // Verify the file identified by |resource_id| and |md5| is in the expected 676 // Verify the file identified by |resource_id| and |md5| is in the expected
678 // cache state after |CloseFile|, that is, marked dirty and has an outgoing 677 // cache state after |CloseFile|, that is, marked dirty and has an outgoing
679 // symlink, etc. 678 // symlink, etc.
680 void VerifyCacheStateAfterCloseFile(base::PlatformFileError error, 679 void VerifyCacheStateAfterCloseFile(base::PlatformFileError error,
681 const std::string& resource_id, 680 const std::string& resource_id,
682 const std::string& md5) { 681 const std::string& md5) {
683 expected_error_ = base::PLATFORM_FILE_OK; 682 expected_error_ = base::PLATFORM_FILE_OK;
684 expected_cache_state_ = (GDataCache::CACHE_STATE_PRESENT | 683 expected_cache_state_ =
685 GDataCache::CACHE_STATE_DIRTY | 684 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY;
686 GDataCache::CACHE_STATE_PERSISTENT);
687 expected_sub_dir_type_ = GDataCache::CACHE_TYPE_PERSISTENT; 685 expected_sub_dir_type_ = GDataCache::CACHE_TYPE_PERSISTENT;
688 expect_outgoing_symlink_ = true; 686 expect_outgoing_symlink_ = true;
689 VerifyCacheFileState(error, resource_id, md5); 687 VerifyCacheFileState(error, resource_id, md5);
690 } 688 }
691 689
692 void VerifyCacheFileState(base::PlatformFileError error, 690 void VerifyCacheFileState(base::PlatformFileError error,
693 const std::string& resource_id, 691 const std::string& resource_id,
694 const std::string& md5) { 692 const std::string& md5) {
695 ++num_callback_invocations_; 693 ++num_callback_invocations_;
696 694
697 EXPECT_EQ(expected_error_, error); 695 EXPECT_EQ(expected_error_, error);
698 696
699 // Verify cache map. 697 // Verify cache map.
700 scoped_ptr<GDataCache::CacheEntry> cache_entry = 698 scoped_ptr<GDataCache::CacheEntry> cache_entry =
701 GetCacheEntryFromOriginThread(resource_id, md5); 699 GetCacheEntryFromOriginThread(resource_id, md5);
702 if (GDataCache::IsCachePresent(expected_cache_state_) || 700 if (GDataCache::IsCachePresent(expected_cache_state_) ||
703 GDataCache::IsCachePinned(expected_cache_state_)) { 701 GDataCache::IsCachePinned(expected_cache_state_)) {
704 ASSERT_TRUE(cache_entry.get()); 702 ASSERT_TRUE(cache_entry.get());
705 EXPECT_EQ(expected_cache_state_, cache_entry->cache_state); 703 EXPECT_EQ(expected_cache_state_, cache_entry->cache_state);
706 EXPECT_EQ(expected_sub_dir_type_, cache_entry->GetSubDirectoryType()); 704 EXPECT_EQ(expected_sub_dir_type_, cache_entry->sub_dir_type);
707 } else { 705 } else {
708 EXPECT_FALSE(cache_entry.get()); 706 EXPECT_FALSE(cache_entry.get());
709 } 707 }
710 708
711 // Verify actual cache file. 709 // Verify actual cache file.
712 FilePath dest_path = cache_->GetCacheFilePath( 710 FilePath dest_path = cache_->GetCacheFilePath(
713 resource_id, 711 resource_id,
714 md5, 712 md5,
715 GDataCache::IsCachePinned(expected_cache_state_) || 713 GDataCache::IsCachePinned(expected_cache_state_) ||
716 GDataCache::IsCacheDirty(expected_cache_state_) ? 714 GDataCache::IsCacheDirty(expected_cache_state_) ?
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after
2371 // GCache/v1/persistent/<kResourceId>.<kMd5> 2369 // GCache/v1/persistent/<kResourceId>.<kMd5>
2372 const FilePath original_cache_file_path = 2370 const FilePath original_cache_file_path =
2373 GDataCache::GetCacheRootPath(profile_.get()) 2371 GDataCache::GetCacheRootPath(profile_.get())
2374 .AppendASCII("persistent") 2372 .AppendASCII("persistent")
2375 .AppendASCII(kResourceId + "." + kMd5); 2373 .AppendASCII(kResourceId + "." + kMd5);
2376 TestStoreToCache(kResourceId, 2374 TestStoreToCache(kResourceId,
2377 kMd5, 2375 kMd5,
2378 GetTestFilePath("root_feed.json"), // Anything works. 2376 GetTestFilePath("root_feed.json"), // Anything works.
2379 base::PLATFORM_FILE_OK, 2377 base::PLATFORM_FILE_OK,
2380 GDataCache::CACHE_STATE_PRESENT | 2378 GDataCache::CACHE_STATE_PRESENT |
2381 GDataCache::CACHE_STATE_PINNED | 2379 GDataCache::CACHE_STATE_PINNED,
2382 GDataCache::CACHE_STATE_PERSISTENT,
2383 GDataCache::CACHE_TYPE_PERSISTENT); 2380 GDataCache::CACHE_TYPE_PERSISTENT);
2384 ASSERT_TRUE(file_util::PathExists(original_cache_file_path)); 2381 ASSERT_TRUE(file_util::PathExists(original_cache_file_path));
2385 2382
2386 // Add the dirty bit. The cache file will be renamed to 2383 // Add the dirty bit. The cache file will be renamed to
2387 // GCache/v1/persistent/<kResourceId>.local 2384 // GCache/v1/persistent/<kResourceId>.local
2388 TestMarkDirty(kResourceId, 2385 TestMarkDirty(kResourceId,
2389 kMd5, 2386 kMd5,
2390 base::PLATFORM_FILE_OK, 2387 base::PLATFORM_FILE_OK,
2391 GDataCache::CACHE_STATE_PRESENT | 2388 GDataCache::CACHE_STATE_PRESENT |
2392 GDataCache::CACHE_STATE_PINNED | 2389 GDataCache::CACHE_STATE_PINNED |
2393 GDataCache::CACHE_STATE_DIRTY | 2390 GDataCache::CACHE_STATE_DIRTY,
2394 GDataCache::CACHE_STATE_PERSISTENT,
2395 GDataCache::CACHE_TYPE_PERSISTENT); 2391 GDataCache::CACHE_TYPE_PERSISTENT);
2396 const FilePath dirty_cache_file_path = 2392 const FilePath dirty_cache_file_path =
2397 GDataCache::GetCacheRootPath(profile_.get()) 2393 GDataCache::GetCacheRootPath(profile_.get())
2398 .AppendASCII("persistent") 2394 .AppendASCII("persistent")
2399 .AppendASCII(kResourceId + ".local"); 2395 .AppendASCII(kResourceId + ".local");
2400 ASSERT_FALSE(file_util::PathExists(original_cache_file_path)); 2396 ASSERT_FALSE(file_util::PathExists(original_cache_file_path));
2401 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path)); 2397 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path));
2402 2398
2403 // Commit the dirty bit. The cache file name remains the same 2399 // Commit the dirty bit. The cache file name remains the same
2404 // but a symlink will be created at: 2400 // but a symlink will be created at:
2405 // GCache/v1/outgoing/<kResourceId> 2401 // GCache/v1/outgoing/<kResourceId>
2406 EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(kResourceId)).Times(1); 2402 EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(kResourceId)).Times(1);
2407 TestCommitDirty(kResourceId, 2403 TestCommitDirty(kResourceId,
2408 kMd5, 2404 kMd5,
2409 base::PLATFORM_FILE_OK, 2405 base::PLATFORM_FILE_OK,
2410 GDataCache::CACHE_STATE_PRESENT | 2406 GDataCache::CACHE_STATE_PRESENT |
2411 GDataCache::CACHE_STATE_PINNED | 2407 GDataCache::CACHE_STATE_PINNED |
2412 GDataCache::CACHE_STATE_DIRTY | 2408 GDataCache::CACHE_STATE_DIRTY,
2413 GDataCache::CACHE_STATE_PERSISTENT,
2414 GDataCache::CACHE_TYPE_PERSISTENT); 2409 GDataCache::CACHE_TYPE_PERSISTENT);
2415 const FilePath outgoing_symlink_path = 2410 const FilePath outgoing_symlink_path =
2416 GDataCache::GetCacheRootPath(profile_.get()) 2411 GDataCache::GetCacheRootPath(profile_.get())
2417 .AppendASCII("outgoing") 2412 .AppendASCII("outgoing")
2418 .AppendASCII(kResourceId); 2413 .AppendASCII(kResourceId);
2419 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path)); 2414 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path));
2420 ASSERT_TRUE(file_util::PathExists(outgoing_symlink_path)); 2415 ASSERT_TRUE(file_util::PathExists(outgoing_symlink_path));
2421 2416
2422 // Create a DocumentEntry, which is needed to mock 2417 // Create a DocumentEntry, which is needed to mock
2423 // GDataUploaderInterface::UploadExistingFile(). 2418 // GDataUploaderInterface::UploadExistingFile().
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2626 2621
2627 // Try to close the same file twice. 2622 // Try to close the same file twice.
2628 file_system_->CloseFile(kFileInRoot, close_file_callback); 2623 file_system_->CloseFile(kFileInRoot, close_file_callback);
2629 message_loop_.Run(); 2624 message_loop_.Run();
2630 2625
2631 // It must fail. 2626 // It must fail.
2632 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); 2627 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_);
2633 } 2628 }
2634 2629
2635 } // namespace gdata 2630 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_cache_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698