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

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

Issue 10116044: gdata: Support mounting archive files in GData cache. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: gdata: Support mounting archive files in GData cache. Created 8 years, 8 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
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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 expected_sub_dir_type_ = expected_sub_dir_type; 631 expected_sub_dir_type_ = expected_sub_dir_type;
632 expect_outgoing_symlink_ = false; 632 expect_outgoing_symlink_ = false;
633 633
634 file_system_->ClearDirtyInCache(resource_id, md5, 634 file_system_->ClearDirtyInCache(resource_id, md5,
635 base::Bind(&GDataFileSystemTest::VerifyCacheFileState, 635 base::Bind(&GDataFileSystemTest::VerifyCacheFileState,
636 base::Unretained(this))); 636 base::Unretained(this)));
637 637
638 RunAllPendingForIO(); 638 RunAllPendingForIO();
639 } 639 }
640 640
641 void VerifySetMountedState(const std::string& resource_id,
642 const std::string& md5,
643 bool to_mount,
644 base::PlatformFileError error,
645 const FilePath& file_path) {
646 ++num_callback_invocations_;
647 EXPECT_TRUE(file_util::PathExists(file_path));
648 EXPECT_TRUE(file_path == file_system_->GetCacheFilePath(
649 resource_id,
650 md5,
651 expected_sub_dir_type_,
652 to_mount ?
653 GDataFileSystemInterface::CACHED_FILE_MOUNTED :
654 GDataFileSystemInterface::CACHED_FILE_FROM_SERVER));
655 }
656
657 void TestSetMountedState(
658 const std::string& resource_id,
659 const std::string& md5,
660 const FilePath& file_path,
661 bool to_mount,
662 base::PlatformFileError expected_error,
663 int expected_cache_state,
664 GDataRootDirectory::CacheSubDirectoryType expected_sub_dir_type) {
665 expected_error_ = expected_error;
666 expected_cache_state_ = expected_cache_state;
667 expected_sub_dir_type_ = expected_sub_dir_type;
668 expect_outgoing_symlink_ = false;
669
670 file_system_->SetMountedState(file_path, to_mount,
671 base::Bind(&GDataFileSystemTest::VerifySetMountedState,
672 base::Unretained(this), resource_id, md5, to_mount));
673
674 RunAllPendingForIO();
675 }
676
641 void PrepareForInitCacheTest() { 677 void PrepareForInitCacheTest() {
642 // Create gdata cache sub directories. 678 // Create gdata cache sub directories.
643 ASSERT_TRUE(file_util::CreateDirectory( 679 ASSERT_TRUE(file_util::CreateDirectory(
644 file_system_->cache_paths_[GDataRootDirectory::CACHE_TYPE_PERSISTENT])); 680 file_system_->cache_paths_[GDataRootDirectory::CACHE_TYPE_PERSISTENT]));
645 ASSERT_TRUE(file_util::CreateDirectory( 681 ASSERT_TRUE(file_util::CreateDirectory(
646 file_system_->cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP])); 682 file_system_->cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP]));
647 ASSERT_TRUE(file_util::CreateDirectory( 683 ASSERT_TRUE(file_util::CreateDirectory(
648 file_system_->cache_paths_[GDataRootDirectory::CACHE_TYPE_PINNED])); 684 file_system_->cache_paths_[GDataRootDirectory::CACHE_TYPE_PINNED]));
649 ASSERT_TRUE(file_util::CreateDirectory( 685 ASSERT_TRUE(file_util::CreateDirectory(
650 file_system_->cache_paths_[GDataRootDirectory::CACHE_TYPE_OUTGOING])); 686 file_system_->cache_paths_[GDataRootDirectory::CACHE_TYPE_OUTGOING]));
(...skipping 2364 matching lines...) Expand 10 before | Expand all | Expand 10 after
3015 EXPECT_EQ(12345, callback_helper_->quota_bytes_total_); 3051 EXPECT_EQ(12345, callback_helper_->quota_bytes_total_);
3016 3052
3017 // Verify account meta feed is saved to cache. 3053 // Verify account meta feed is saved to cache.
3018 RunAllPendingForIO(); 3054 RunAllPendingForIO();
3019 FilePath path = file_system_->cache_paths_[ 3055 FilePath path = file_system_->cache_paths_[
3020 GDataRootDirectory::CACHE_TYPE_META].Append( 3056 GDataRootDirectory::CACHE_TYPE_META].Append(
3021 FILE_PATH_LITERAL("account_metadata.json")); 3057 FILE_PATH_LITERAL("account_metadata.json"));
3022 EXPECT_TRUE(file_util::PathExists(path)); 3058 EXPECT_TRUE(file_util::PathExists(path));
3023 } 3059 }
3024 3060
3061 TEST_F(GDataFileSystemTest, MountUnmount) {
3062 EXPECT_CALL(*mock_sync_client_, OnCacheInitialized()).Times(1);
3063
3064 FilePath file_path;
3065 std::string resource_id("pdf:1a2b");
3066 std::string md5("abcdef0123456789");
3067
3068 // First store a file to cache in the tmp subdir.
3069 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
3070 base::PLATFORM_FILE_OK, GDataFile::CACHE_STATE_PRESENT,
3071 GDataRootDirectory::CACHE_TYPE_TMP);
3072
3073 // Mark the file mounted.
3074 num_callback_invocations_ = 0;
3075 file_path = file_system_->GetCacheFilePath(
3076 resource_id, md5,
3077 GDataRootDirectory::CACHE_TYPE_TMP,
3078 GDataFileSystemInterface::CACHED_FILE_FROM_SERVER);
3079 TestSetMountedState(resource_id, md5, file_path, true,
3080 base::PLATFORM_FILE_OK,
3081 GDataFile::CACHE_STATE_PRESENT |
3082 GDataFile::CACHE_STATE_MOUNTED,
3083 GDataRootDirectory::CACHE_TYPE_PERSISTENT);
3084 EXPECT_EQ(1, num_callback_invocations_);
3085 EXPECT_TRUE(CacheEntryExists(resource_id, md5));
3086
3087 // Clear mounted state of the file.
3088 num_callback_invocations_ = 0;
3089 file_path = file_system_->GetCacheFilePath(
3090 resource_id,
3091 md5,
3092 GDataRootDirectory::CACHE_TYPE_PERSISTENT,
3093 GDataFileSystemInterface::CACHED_FILE_MOUNTED);
3094 TestSetMountedState(resource_id, md5, file_path, false,
3095 base::PLATFORM_FILE_OK,
3096 GDataFile::CACHE_STATE_PRESENT,
3097 GDataRootDirectory::CACHE_TYPE_TMP);
3098 EXPECT_EQ(1, num_callback_invocations_);
3099 EXPECT_TRUE(CacheEntryExists(resource_id, md5));
3100
3101 // Try to remove the file.
3102 num_callback_invocations_ = 0;
3103 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK);
3104 EXPECT_EQ(1, num_callback_invocations_);
3105 }
3106
3025 } // namespace gdata 3107 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698