| Index: chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc
|
| diff --git a/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc b/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc
|
| index 339d6a501f13a82bef6c9a81beb38225cd69dc7e..c0cc9e6270d3bcc9b216eb9e563077bff00172ad 100644
|
| --- a/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc
|
| +++ b/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc
|
| @@ -71,7 +71,7 @@ struct InitialCacheResource {
|
| // Cache resource in tmp dir, i.e. not pinned or dirty, with resource_id
|
| // containing non-alphanumeric characters, to test resource_id is escaped and
|
| // unescaped correctly.
|
| - { "subdir_feed.json", "tmp:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?",
|
| + { "subdir_feed.json", "tmp:`~!@#$%^&*()-_=+[{|]}\\;',<>/?",
|
| "md5_tmp_non_alphanumeric",
|
| gdata::GDataFile::CACHE_STATE_PRESENT,
|
| "md5_tmp_non_alphanumeric", gdata::GDataRootDirectory::CACHE_TYPE_TMP },
|
| @@ -638,6 +638,42 @@ class GDataFileSystemTest : public testing::Test {
|
| RunAllPendingForIO();
|
| }
|
|
|
| + void VerifySetMountedState(const std::string& resource_id,
|
| + const std::string& md5,
|
| + bool to_mount,
|
| + base::PlatformFileError error,
|
| + const FilePath& file_path) {
|
| + ++num_callback_invocations_;
|
| + EXPECT_TRUE(file_util::PathExists(file_path));
|
| + EXPECT_TRUE(file_path == file_system_->GetCacheFilePath(
|
| + resource_id,
|
| + md5,
|
| + expected_sub_dir_type_,
|
| + to_mount ?
|
| + GDataFileSystemInterface::CACHED_FILE_MOUNTED :
|
| + GDataFileSystemInterface::CACHED_FILE_FROM_SERVER));
|
| + }
|
| +
|
| + void TestSetMountedState(
|
| + const std::string& resource_id,
|
| + const std::string& md5,
|
| + const FilePath& file_path,
|
| + bool to_mount,
|
| + base::PlatformFileError expected_error,
|
| + int expected_cache_state,
|
| + GDataRootDirectory::CacheSubDirectoryType expected_sub_dir_type) {
|
| + expected_error_ = expected_error;
|
| + expected_cache_state_ = expected_cache_state;
|
| + expected_sub_dir_type_ = expected_sub_dir_type;
|
| + expect_outgoing_symlink_ = false;
|
| +
|
| + file_system_->SetMountedState(file_path, to_mount,
|
| + base::Bind(&GDataFileSystemTest::VerifySetMountedState,
|
| + base::Unretained(this), resource_id, md5, to_mount));
|
| +
|
| + RunAllPendingForIO();
|
| + }
|
| +
|
| void PrepareForInitCacheTest() {
|
| // Create gdata cache sub directories.
|
| ASSERT_TRUE(file_util::CreateDirectory(
|
| @@ -3022,4 +3058,50 @@ TEST_F(GDataFileSystemTest, GetAvailableSpace) {
|
| EXPECT_TRUE(file_util::PathExists(path));
|
| }
|
|
|
| +TEST_F(GDataFileSystemTest, MountUnmount) {
|
| + EXPECT_CALL(*mock_sync_client_, OnCacheInitialized()).Times(1);
|
| +
|
| + FilePath file_path;
|
| + std::string resource_id("pdf:1a2b");
|
| + std::string md5("abcdef0123456789");
|
| +
|
| + // First store a file to cache in the tmp subdir.
|
| + TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
|
| + base::PLATFORM_FILE_OK, GDataFile::CACHE_STATE_PRESENT,
|
| + GDataRootDirectory::CACHE_TYPE_TMP);
|
| +
|
| + // Mark the file mounted.
|
| + num_callback_invocations_ = 0;
|
| + file_path = file_system_->GetCacheFilePath(
|
| + resource_id, md5,
|
| + GDataRootDirectory::CACHE_TYPE_TMP,
|
| + GDataFileSystemInterface::CACHED_FILE_FROM_SERVER);
|
| + TestSetMountedState(resource_id, md5, file_path, true,
|
| + base::PLATFORM_FILE_OK,
|
| + GDataFile::CACHE_STATE_PRESENT |
|
| + GDataFile::CACHE_STATE_MOUNTED,
|
| + GDataRootDirectory::CACHE_TYPE_PERSISTENT);
|
| + EXPECT_EQ(1, num_callback_invocations_);
|
| + EXPECT_TRUE(CacheEntryExists(resource_id, md5));
|
| +
|
| + // Clear mounted state of the file.
|
| + num_callback_invocations_ = 0;
|
| + file_path = file_system_->GetCacheFilePath(
|
| + resource_id,
|
| + md5,
|
| + GDataRootDirectory::CACHE_TYPE_PERSISTENT,
|
| + GDataFileSystemInterface::CACHED_FILE_MOUNTED);
|
| + TestSetMountedState(resource_id, md5, file_path, false,
|
| + base::PLATFORM_FILE_OK,
|
| + GDataFile::CACHE_STATE_PRESENT,
|
| + GDataRootDirectory::CACHE_TYPE_TMP);
|
| + EXPECT_EQ(1, num_callback_invocations_);
|
| + EXPECT_TRUE(CacheEntryExists(resource_id, md5));
|
| +
|
| + // Try to remove the file.
|
| + num_callback_invocations_ = 0;
|
| + TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK);
|
| + EXPECT_EQ(1, num_callback_invocations_);
|
| +}
|
| +
|
| } // namespace gdata
|
|
|