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

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

Issue 10702133: gdata: Remove sub_dir_type from CacheEntry for simplicity (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: the fix 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_ = 669 expected_cache_state_ = (GDataCache::CACHE_STATE_PRESENT |
670 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY; 670 GDataCache::CACHE_STATE_DIRTY |
671 GDataCache::CACHE_STATE_PERSISTENT);
671 expected_sub_dir_type_ = GDataCache::CACHE_TYPE_PERSISTENT; 672 expected_sub_dir_type_ = GDataCache::CACHE_TYPE_PERSISTENT;
672 expect_outgoing_symlink_ = false; 673 expect_outgoing_symlink_ = false;
673 VerifyMarkDirty(error, resource_id, md5, cache_file_path); 674 VerifyMarkDirty(error, resource_id, md5, cache_file_path);
674 } 675 }
675 676
676 // Verify the file identified by |resource_id| and |md5| is in the expected 677 // Verify the file identified by |resource_id| and |md5| is in the expected
677 // cache state after |CloseFile|, that is, marked dirty and has an outgoing 678 // cache state after |CloseFile|, that is, marked dirty and has an outgoing
678 // symlink, etc. 679 // symlink, etc.
679 void VerifyCacheStateAfterCloseFile(base::PlatformFileError error, 680 void VerifyCacheStateAfterCloseFile(base::PlatformFileError error,
680 const std::string& resource_id, 681 const std::string& resource_id,
681 const std::string& md5) { 682 const std::string& md5) {
682 expected_error_ = base::PLATFORM_FILE_OK; 683 expected_error_ = base::PLATFORM_FILE_OK;
683 expected_cache_state_ = 684 expected_cache_state_ = (GDataCache::CACHE_STATE_PRESENT |
684 GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY; 685 GDataCache::CACHE_STATE_DIRTY |
686 GDataCache::CACHE_STATE_PERSISTENT);
685 expected_sub_dir_type_ = GDataCache::CACHE_TYPE_PERSISTENT; 687 expected_sub_dir_type_ = GDataCache::CACHE_TYPE_PERSISTENT;
686 expect_outgoing_symlink_ = true; 688 expect_outgoing_symlink_ = true;
687 VerifyCacheFileState(error, resource_id, md5); 689 VerifyCacheFileState(error, resource_id, md5);
688 } 690 }
689 691
690 void VerifyCacheFileState(base::PlatformFileError error, 692 void VerifyCacheFileState(base::PlatformFileError error,
691 const std::string& resource_id, 693 const std::string& resource_id,
692 const std::string& md5) { 694 const std::string& md5) {
693 ++num_callback_invocations_; 695 ++num_callback_invocations_;
694 696
695 EXPECT_EQ(expected_error_, error); 697 EXPECT_EQ(expected_error_, error);
696 698
697 // Verify cache map. 699 // Verify cache map.
698 scoped_ptr<GDataCache::CacheEntry> cache_entry = 700 scoped_ptr<GDataCache::CacheEntry> cache_entry =
699 GetCacheEntryFromOriginThread(resource_id, md5); 701 GetCacheEntryFromOriginThread(resource_id, md5);
700 if (GDataCache::IsCachePresent(expected_cache_state_) || 702 if (GDataCache::IsCachePresent(expected_cache_state_) ||
701 GDataCache::IsCachePinned(expected_cache_state_)) { 703 GDataCache::IsCachePinned(expected_cache_state_)) {
702 ASSERT_TRUE(cache_entry.get()); 704 ASSERT_TRUE(cache_entry.get());
703 EXPECT_EQ(expected_cache_state_, cache_entry->cache_state); 705 EXPECT_EQ(expected_cache_state_, cache_entry->cache_state);
704 EXPECT_EQ(expected_sub_dir_type_, cache_entry->sub_dir_type); 706 EXPECT_EQ(expected_sub_dir_type_, cache_entry->GetSubDirectoryType());
705 } else { 707 } else {
706 EXPECT_FALSE(cache_entry.get()); 708 EXPECT_FALSE(cache_entry.get());
707 } 709 }
708 710
709 // Verify actual cache file. 711 // Verify actual cache file.
710 FilePath dest_path = cache_->GetCacheFilePath( 712 FilePath dest_path = cache_->GetCacheFilePath(
711 resource_id, 713 resource_id,
712 md5, 714 md5,
713 GDataCache::IsCachePinned(expected_cache_state_) || 715 GDataCache::IsCachePinned(expected_cache_state_) ||
714 GDataCache::IsCacheDirty(expected_cache_state_) ? 716 GDataCache::IsCacheDirty(expected_cache_state_) ?
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after
2369 // GCache/v1/persistent/<kResourceId>.<kMd5> 2371 // GCache/v1/persistent/<kResourceId>.<kMd5>
2370 const FilePath original_cache_file_path = 2372 const FilePath original_cache_file_path =
2371 GDataCache::GetCacheRootPath(profile_.get()) 2373 GDataCache::GetCacheRootPath(profile_.get())
2372 .AppendASCII("persistent") 2374 .AppendASCII("persistent")
2373 .AppendASCII(kResourceId + "." + kMd5); 2375 .AppendASCII(kResourceId + "." + kMd5);
2374 TestStoreToCache(kResourceId, 2376 TestStoreToCache(kResourceId,
2375 kMd5, 2377 kMd5,
2376 GetTestFilePath("root_feed.json"), // Anything works. 2378 GetTestFilePath("root_feed.json"), // Anything works.
2377 base::PLATFORM_FILE_OK, 2379 base::PLATFORM_FILE_OK,
2378 GDataCache::CACHE_STATE_PRESENT | 2380 GDataCache::CACHE_STATE_PRESENT |
2379 GDataCache::CACHE_STATE_PINNED, 2381 GDataCache::CACHE_STATE_PINNED |
2382 GDataCache::CACHE_STATE_PERSISTENT,
2380 GDataCache::CACHE_TYPE_PERSISTENT); 2383 GDataCache::CACHE_TYPE_PERSISTENT);
2381 ASSERT_TRUE(file_util::PathExists(original_cache_file_path)); 2384 ASSERT_TRUE(file_util::PathExists(original_cache_file_path));
2382 2385
2383 // Add the dirty bit. The cache file will be renamed to 2386 // Add the dirty bit. The cache file will be renamed to
2384 // GCache/v1/persistent/<kResourceId>.local 2387 // GCache/v1/persistent/<kResourceId>.local
2385 TestMarkDirty(kResourceId, 2388 TestMarkDirty(kResourceId,
2386 kMd5, 2389 kMd5,
2387 base::PLATFORM_FILE_OK, 2390 base::PLATFORM_FILE_OK,
2388 GDataCache::CACHE_STATE_PRESENT | 2391 GDataCache::CACHE_STATE_PRESENT |
2389 GDataCache::CACHE_STATE_PINNED | 2392 GDataCache::CACHE_STATE_PINNED |
2390 GDataCache::CACHE_STATE_DIRTY, 2393 GDataCache::CACHE_STATE_DIRTY |
2394 GDataCache::CACHE_STATE_PERSISTENT,
2391 GDataCache::CACHE_TYPE_PERSISTENT); 2395 GDataCache::CACHE_TYPE_PERSISTENT);
2392 const FilePath dirty_cache_file_path = 2396 const FilePath dirty_cache_file_path =
2393 GDataCache::GetCacheRootPath(profile_.get()) 2397 GDataCache::GetCacheRootPath(profile_.get())
2394 .AppendASCII("persistent") 2398 .AppendASCII("persistent")
2395 .AppendASCII(kResourceId + ".local"); 2399 .AppendASCII(kResourceId + ".local");
2396 ASSERT_FALSE(file_util::PathExists(original_cache_file_path)); 2400 ASSERT_FALSE(file_util::PathExists(original_cache_file_path));
2397 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path)); 2401 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path));
2398 2402
2399 // Commit the dirty bit. The cache file name remains the same 2403 // Commit the dirty bit. The cache file name remains the same
2400 // but a symlink will be created at: 2404 // but a symlink will be created at:
2401 // GCache/v1/outgoing/<kResourceId> 2405 // GCache/v1/outgoing/<kResourceId>
2402 EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(kResourceId)).Times(1); 2406 EXPECT_CALL(*mock_sync_client_, OnCacheCommitted(kResourceId)).Times(1);
2403 TestCommitDirty(kResourceId, 2407 TestCommitDirty(kResourceId,
2404 kMd5, 2408 kMd5,
2405 base::PLATFORM_FILE_OK, 2409 base::PLATFORM_FILE_OK,
2406 GDataCache::CACHE_STATE_PRESENT | 2410 GDataCache::CACHE_STATE_PRESENT |
2407 GDataCache::CACHE_STATE_PINNED | 2411 GDataCache::CACHE_STATE_PINNED |
2408 GDataCache::CACHE_STATE_DIRTY, 2412 GDataCache::CACHE_STATE_DIRTY |
2413 GDataCache::CACHE_STATE_PERSISTENT,
2409 GDataCache::CACHE_TYPE_PERSISTENT); 2414 GDataCache::CACHE_TYPE_PERSISTENT);
2410 const FilePath outgoing_symlink_path = 2415 const FilePath outgoing_symlink_path =
2411 GDataCache::GetCacheRootPath(profile_.get()) 2416 GDataCache::GetCacheRootPath(profile_.get())
2412 .AppendASCII("outgoing") 2417 .AppendASCII("outgoing")
2413 .AppendASCII(kResourceId); 2418 .AppendASCII(kResourceId);
2414 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path)); 2419 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path));
2415 ASSERT_TRUE(file_util::PathExists(outgoing_symlink_path)); 2420 ASSERT_TRUE(file_util::PathExists(outgoing_symlink_path));
2416 2421
2417 // Create a DocumentEntry, which is needed to mock 2422 // Create a DocumentEntry, which is needed to mock
2418 // GDataUploaderInterface::UploadExistingFile(). 2423 // GDataUploaderInterface::UploadExistingFile().
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2621 2626
2622 // Try to close the same file twice. 2627 // Try to close the same file twice.
2623 file_system_->CloseFile(kFileInRoot, close_file_callback); 2628 file_system_->CloseFile(kFileInRoot, close_file_callback);
2624 message_loop_.Run(); 2629 message_loop_.Run();
2625 2630
2626 // It must fail. 2631 // It must fail.
2627 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); 2632 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_);
2628 } 2633 }
2629 2634
2630 } // namespace gdata 2635 } // 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