| OLD | NEW |
| 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 "chrome/browser/chromeos/drive/drive_cache.h" | 5 #include "chrome/browser/chromeos/drive/drive_cache.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 using ::testing::AtLeast; | 25 using ::testing::AtLeast; |
| 26 using ::testing::Return; | 26 using ::testing::Return; |
| 27 using ::testing::StrictMock; | 27 using ::testing::StrictMock; |
| 28 | 28 |
| 29 namespace drive { | 29 namespace drive { |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 const char kSymLinkToDevNull[] = "/dev/null"; | 32 const char kSymLinkToDevNull[] = "/dev/null"; |
| 33 | 33 |
| 34 struct InitialCacheResource { | 34 struct TestCacheResource { |
| 35 const char* source_file; // Source file to be used for cache. | 35 const char* source_file; |
| 36 const char* resource_id; // Resource id of cache file. | 36 const char* resource_id; |
| 37 const char* md5; // MD5 of cache file. | 37 const char* md5; |
| 38 int cache_state; // Cache state of cache file. | 38 bool is_pinned; |
| 39 const char* expected_file_extension; // Expected extension of cached file. | 39 bool is_dirty; |
| 40 // Expected CacheSubDirectoryType of cached file. | 40 } const test_cache_resources[] = { |
| 41 DriveCache::CacheSubDirectoryType expected_sub_dir_type; | |
| 42 } const initial_cache_resources[] = { | |
| 43 // Cache resource in tmp dir, i.e. not pinned or dirty. | 41 // Cache resource in tmp dir, i.e. not pinned or dirty. |
| 44 { "gdata/root_feed.json", "tmp:resource_id", "md5_tmp_alphanumeric", | 42 { "gdata/root_feed.json", "tmp:resource_id", "md5_tmp_alphanumeric", |
| 45 test_util::TEST_CACHE_STATE_PRESENT, | 43 false, false }, |
| 46 "md5_tmp_alphanumeric", DriveCache::CACHE_TYPE_TMP }, | |
| 47 // Cache resource in tmp dir, i.e. not pinned or dirty, with resource_id | 44 // Cache resource in tmp dir, i.e. not pinned or dirty, with resource_id |
| 48 // containing non-alphanumeric characters, to test resource_id is escaped and | 45 // containing non-alphanumeric characters. |
| 49 // unescaped correctly. | |
| 50 { "gdata/subdir_feed.json", "tmp:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?", | 46 { "gdata/subdir_feed.json", "tmp:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?", |
| 51 "md5_tmp_non_alphanumeric", | 47 "md5_tmp_non_alphanumeric", false, false }, |
| 52 test_util::TEST_CACHE_STATE_PRESENT, | 48 // Cache resource that is pinned and persistent. |
| 53 "md5_tmp_non_alphanumeric", DriveCache::CACHE_TYPE_TMP }, | |
| 54 // Cache resource that is pinned, to test a pinned file is in persistent dir | |
| 55 // with a symlink in pinned dir referencing it. | |
| 56 { "gdata/directory_entry_atom.json", "pinned:existing", "md5_pinned_existing", | 49 { "gdata/directory_entry_atom.json", "pinned:existing", "md5_pinned_existing", |
| 57 test_util::TEST_CACHE_STATE_PRESENT | | 50 true, false }, |
| 58 test_util::TEST_CACHE_STATE_PINNED | | 51 // Cache resource with a non-existent source file that is pinned. |
| 59 test_util::TEST_CACHE_STATE_PERSISTENT, | 52 { "", "pinned:non-existent", "md5_pinned_non_existent", true, false }, |
| 60 "md5_pinned_existing", DriveCache::CACHE_TYPE_PERSISTENT }, | 53 // Cache resource that is dirty. |
| 61 // Cache resource with a non-existent source file that is pinned, to test that | |
| 62 // a pinned file can reference a non-existent file. | |
| 63 { "", "pinned:non-existent", "md5_pinned_non_existent", | |
| 64 test_util::TEST_CACHE_STATE_PINNED, | |
| 65 "md5_pinned_non_existent", DriveCache::CACHE_TYPE_TMP }, | |
| 66 // Cache resource that is dirty, to test a dirty file is in persistent dir | |
| 67 // with a symlink in outgoing dir referencing it. | |
| 68 { "gdata/account_metadata.json", "dirty:existing", "md5_dirty_existing", | 54 { "gdata/account_metadata.json", "dirty:existing", "md5_dirty_existing", |
| 69 test_util::TEST_CACHE_STATE_PRESENT | | 55 false, true }, |
| 70 test_util::TEST_CACHE_STATE_DIRTY | | 56 // Cache resource that is pinned and dirty. |
| 71 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 72 "local", DriveCache::CACHE_TYPE_PERSISTENT }, | |
| 73 // Cache resource that is pinned and dirty, to test a dirty pinned file is in | |
| 74 // persistent dir with symlink in pinned and outgoing dirs referencing it. | |
| 75 { "gdata/basic_feed.json", "dirty_and_pinned:existing", | 57 { "gdata/basic_feed.json", "dirty_and_pinned:existing", |
| 76 "md5_dirty_and_pinned_existing", | 58 "md5_dirty_and_pinned_existing", true, true }, |
| 77 test_util::TEST_CACHE_STATE_PRESENT | | |
| 78 test_util::TEST_CACHE_STATE_PINNED | | |
| 79 test_util::TEST_CACHE_STATE_DIRTY | | |
| 80 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 81 "local", DriveCache::CACHE_TYPE_PERSISTENT }, | |
| 82 }; | 59 }; |
| 83 | 60 |
| 84 const int64 kLotsOfSpace = kMinFreeSpace * 10; | 61 const int64 kLotsOfSpace = kMinFreeSpace * 10; |
| 85 | 62 |
| 86 struct PathToVerify { | 63 struct PathToVerify { |
| 87 PathToVerify(const FilePath& in_path_to_scan, | 64 PathToVerify(const FilePath& in_path_to_scan, |
| 88 const FilePath& in_expected_existing_path) : | 65 const FilePath& in_expected_existing_path) : |
| 89 path_to_scan(in_path_to_scan), | 66 path_to_scan(in_path_to_scan), |
| 90 expected_existing_path(in_expected_existing_path) { | 67 expected_existing_path(in_expected_existing_path) { |
| 91 } | 68 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 112 // Called upon completion of Iterate(). | 89 // Called upon completion of Iterate(). |
| 113 void OnIterateCompleted(bool* out_is_called) { | 90 void OnIterateCompleted(bool* out_is_called) { |
| 114 *out_is_called = true; | 91 *out_is_called = true; |
| 115 } | 92 } |
| 116 | 93 |
| 117 // Copies results from ClearAll. | 94 // Copies results from ClearAll. |
| 118 void OnClearAll(bool* out_success, bool success) { | 95 void OnClearAll(bool* out_success, bool success) { |
| 119 *out_success = success; | 96 *out_success = success; |
| 120 } | 97 } |
| 121 | 98 |
| 99 // Used as a CacheOperationCallback to copy results from DriveCache methods. |
| 100 void OnCacheOperation(DriveFileError* out_error, |
| 101 std::string* out_resource_id, |
| 102 std::string* out_md5, |
| 103 DriveFileError error, |
| 104 const std::string& resource_id, |
| 105 const std::string& md5) { |
| 106 *out_error = error; |
| 107 *out_resource_id = resource_id; |
| 108 *out_md5 = md5; |
| 109 } |
| 110 |
| 111 // Used as a GetFileFromCacheCallback to copy results from DriveCache methods. |
| 112 void OnGetFile(DriveFileError* out_error, |
| 113 FilePath* out_cache_file_path, |
| 114 DriveFileError error, |
| 115 const FilePath& cache_file_path) { |
| 116 *out_error = error; |
| 117 *out_cache_file_path = cache_file_path; |
| 118 } |
| 119 |
| 122 } // namespace | 120 } // namespace |
| 123 | 121 |
| 124 class DriveCacheTest : public testing::Test { | 122 class DriveCacheTest : public testing::Test { |
| 125 protected: | 123 protected: |
| 126 DriveCacheTest() | 124 DriveCacheTest() |
| 127 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 125 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 128 io_thread_(content::BrowserThread::IO), | 126 io_thread_(content::BrowserThread::IO), |
| 129 cache_(NULL), | 127 cache_(NULL), |
| 130 num_callback_invocations_(0), | 128 num_callback_invocations_(0), |
| 131 expected_error_(DRIVE_FILE_OK), | 129 expected_error_(DRIVE_FILE_OK), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 162 |
| 165 virtual void TearDown() OVERRIDE { | 163 virtual void TearDown() OVERRIDE { |
| 166 SetFreeDiskSpaceGetterForTesting(NULL); | 164 SetFreeDiskSpaceGetterForTesting(NULL); |
| 167 cache_->Destroy(); | 165 cache_->Destroy(); |
| 168 // The cache destruction requires to post a task to the blocking pool. | 166 // The cache destruction requires to post a task to the blocking pool. |
| 169 google_apis::test_util::RunBlockingPoolTask(); | 167 google_apis::test_util::RunBlockingPoolTask(); |
| 170 | 168 |
| 171 profile_.reset(NULL); | 169 profile_.reset(NULL); |
| 172 } | 170 } |
| 173 | 171 |
| 174 void PrepareForInitCacheTest() { | 172 void PrepareTestCacheResources() { |
| 175 DVLOG(1) << "PrepareForInitCacheTest start"; | 173 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
| 176 // Create drive cache sub directories. | 174 .WillRepeatedly(Return(kLotsOfSpace)); |
| 177 ASSERT_TRUE(file_util::CreateDirectory( | |
| 178 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_PERSISTENT))); | |
| 179 ASSERT_TRUE(file_util::CreateDirectory( | |
| 180 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_TMP))); | |
| 181 ASSERT_TRUE(file_util::CreateDirectory( | |
| 182 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_PINNED))); | |
| 183 ASSERT_TRUE(file_util::CreateDirectory( | |
| 184 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_OUTGOING))); | |
| 185 | 175 |
| 186 // Dump some files into cache dirs so that | 176 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cache_resources); ++i) { |
| 187 // DriveFileSystem::InitializeCacheOnBlockingPool would scan through them | 177 const struct TestCacheResource& resource = test_cache_resources[i]; |
| 188 // and populate cache map accordingly. | 178 // Copy file from data dir to cache. |
| 189 | 179 if (!std::string(resource.source_file).empty()) { |
| 190 // Copy files from data dir to cache dir to act as cached files. | |
| 191 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(initial_cache_resources); ++i) { | |
| 192 const struct InitialCacheResource& resource = initial_cache_resources[i]; | |
| 193 // Determine drive cache file absolute path according to cache state. | |
| 194 FilePath dest_path = cache_->GetCacheFilePath( | |
| 195 resource.resource_id, | |
| 196 resource.md5, | |
| 197 test_util::ToCacheEntry(resource.cache_state).is_pinned() || | |
| 198 test_util::ToCacheEntry(resource.cache_state).is_dirty() ? | |
| 199 DriveCache::CACHE_TYPE_PERSISTENT : | |
| 200 DriveCache::CACHE_TYPE_TMP, | |
| 201 test_util::ToCacheEntry(resource.cache_state).is_dirty() ? | |
| 202 DriveCache::CACHED_FILE_LOCALLY_MODIFIED : | |
| 203 DriveCache::CACHED_FILE_FROM_SERVER); | |
| 204 | |
| 205 // Copy file from data dir to cache subdir, naming it per cache files | |
| 206 // convention. | |
| 207 if (test_util::ToCacheEntry(resource.cache_state).is_present()) { | |
| 208 FilePath source_path = | 180 FilePath source_path = |
| 209 google_apis::test_util::GetTestFilePath(resource.source_file); | 181 google_apis::test_util::GetTestFilePath(resource.source_file); |
| 210 ASSERT_TRUE(file_util::CopyFile(source_path, dest_path)); | 182 |
| 211 } else { | 183 DriveFileError error = DRIVE_FILE_OK; |
| 212 dest_path = FilePath(FILE_PATH_LITERAL(kSymLinkToDevNull)); | 184 std::string resource_id; |
| 185 std::string md5; |
| 186 cache_->Store(resource.resource_id, |
| 187 resource.md5, |
| 188 source_path, |
| 189 DriveCache::FILE_OPERATION_COPY, |
| 190 base::Bind(&OnCacheOperation, |
| 191 &error, &resource_id, &md5)); |
| 192 google_apis::test_util::RunBlockingPoolTask(); |
| 193 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 194 EXPECT_EQ(resource.resource_id, resource_id); |
| 195 EXPECT_EQ(resource.md5, md5); |
| 213 } | 196 } |
| 197 // Pin. |
| 198 if (resource.is_pinned) { |
| 199 DriveFileError error = DRIVE_FILE_OK; |
| 200 std::string resource_id; |
| 201 std::string md5; |
| 202 EXPECT_CALL(*mock_cache_observer_, |
| 203 OnCachePinned(resource.resource_id, resource.md5)).Times(1); |
| 204 cache_->Pin(resource.resource_id, |
| 205 resource.md5, |
| 206 base::Bind(&OnCacheOperation, |
| 207 &error, &resource_id, &md5)); |
| 208 google_apis::test_util::RunBlockingPoolTask(); |
| 209 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 210 EXPECT_EQ(resource.resource_id, resource_id); |
| 211 EXPECT_EQ(resource.md5, md5); |
| 212 } |
| 213 // Mark dirty. |
| 214 if (resource.is_dirty) { |
| 215 DriveFileError error = DRIVE_FILE_OK; |
| 216 FilePath cache_file_path; |
| 217 cache_->MarkDirty(resource.resource_id, |
| 218 resource.md5, |
| 219 base::Bind(&OnGetFile, &error, &cache_file_path)); |
| 220 google_apis::test_util::RunBlockingPoolTask(); |
| 221 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 214 | 222 |
| 215 // Create symbolic link in pinned dir, naming it per cache files | 223 std::string resource_id; |
| 216 // convention. | 224 std::string md5; |
| 217 if (test_util::ToCacheEntry(resource.cache_state).is_pinned()) { | 225 EXPECT_CALL(*mock_cache_observer_, |
| 218 FilePath link_path = cache_->GetCacheFilePath( | 226 OnCacheCommitted(resource.resource_id)).Times(1); |
| 219 resource.resource_id, | 227 cache_->CommitDirty(resource.resource_id, |
| 220 "", | 228 resource.md5, |
| 221 DriveCache::CACHE_TYPE_PINNED, | 229 base::Bind(&OnCacheOperation, |
| 222 DriveCache::CACHED_FILE_FROM_SERVER); | 230 &error, &resource_id, &md5)); |
| 223 ASSERT_TRUE(file_util::CreateSymbolicLink(dest_path, link_path)); | 231 google_apis::test_util::RunBlockingPoolTask(); |
| 232 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 233 EXPECT_EQ(resource.resource_id, resource_id); |
| 234 EXPECT_EQ(resource.md5, md5); |
| 224 } | 235 } |
| 225 | |
| 226 // Create symbolic link in outgoing dir, naming it per cache files | |
| 227 // convention. | |
| 228 if (test_util::ToCacheEntry(resource.cache_state).is_dirty()) { | |
| 229 FilePath link_path = cache_->GetCacheFilePath( | |
| 230 resource.resource_id, | |
| 231 "", | |
| 232 DriveCache::CACHE_TYPE_OUTGOING, | |
| 233 DriveCache::CACHED_FILE_FROM_SERVER); | |
| 234 ASSERT_TRUE(file_util::CreateSymbolicLink(dest_path, link_path)); | |
| 235 } | |
| 236 } | |
| 237 | |
| 238 DVLOG(1) << "PrepareForInitCacheTest finished"; | |
| 239 cache_->ForceRescanForTesting(); | |
| 240 google_apis::test_util::RunBlockingPoolTask(); | |
| 241 } | |
| 242 | |
| 243 void TestInitializeCache() { | |
| 244 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(initial_cache_resources); ++i) { | |
| 245 const struct InitialCacheResource& resource = initial_cache_resources[i]; | |
| 246 // Check cache file. | |
| 247 num_callback_invocations_ = 0; | |
| 248 TestGetFileFromCacheByResourceIdAndMd5( | |
| 249 resource.resource_id, | |
| 250 resource.md5, | |
| 251 test_util::ToCacheEntry(resource.cache_state).is_present() ? | |
| 252 DRIVE_FILE_OK : | |
| 253 DRIVE_FILE_ERROR_NOT_FOUND, | |
| 254 resource.expected_file_extension); | |
| 255 EXPECT_EQ(1, num_callback_invocations_); | |
| 256 | |
| 257 // Verify cache state. | |
| 258 std::string md5; | |
| 259 if (test_util::ToCacheEntry(resource.cache_state).is_present()) | |
| 260 md5 = resource.md5; | |
| 261 DriveCacheEntry cache_entry; | |
| 262 ASSERT_TRUE(GetCacheEntryFromOriginThread( | |
| 263 resource.resource_id, md5, &cache_entry)); | |
| 264 EXPECT_TRUE(test_util::CacheStatesEqual( | |
| 265 test_util::ToCacheEntry(resource.cache_state), | |
| 266 cache_entry)); | |
| 267 EXPECT_EQ(resource.expected_sub_dir_type, | |
| 268 DriveCache::GetSubDirectoryType(cache_entry)); | |
| 269 } | 236 } |
| 270 } | 237 } |
| 271 | 238 |
| 272 void TestGetFileFromCacheByResourceIdAndMd5( | 239 void TestGetFileFromCacheByResourceIdAndMd5( |
| 273 const std::string& resource_id, | 240 const std::string& resource_id, |
| 274 const std::string& md5, | 241 const std::string& md5, |
| 275 DriveFileError expected_error, | 242 DriveFileError expected_error, |
| 276 const std::string& expected_file_extension) { | 243 const std::string& expected_file_extension) { |
| 277 expected_error_ = expected_error; | 244 expected_error_ = expected_error; |
| 278 expected_file_extension_ = expected_file_extension; | 245 expected_file_extension_ = expected_file_extension; |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 int num_callback_invocations_; | 729 int num_callback_invocations_; |
| 763 DriveFileError expected_error_; | 730 DriveFileError expected_error_; |
| 764 int expected_cache_state_; | 731 int expected_cache_state_; |
| 765 DriveCache::CacheSubDirectoryType expected_sub_dir_type_; | 732 DriveCache::CacheSubDirectoryType expected_sub_dir_type_; |
| 766 bool expected_success_; | 733 bool expected_success_; |
| 767 bool expect_outgoing_symlink_; | 734 bool expect_outgoing_symlink_; |
| 768 std::string expected_file_extension_; | 735 std::string expected_file_extension_; |
| 769 int root_feed_changestamp_; | 736 int root_feed_changestamp_; |
| 770 }; | 737 }; |
| 771 | 738 |
| 772 TEST_F(DriveCacheTest, InitializeCache) { | |
| 773 PrepareForInitCacheTest(); | |
| 774 TestInitializeCache(); | |
| 775 } | |
| 776 | |
| 777 TEST_F(DriveCacheTest, GetCacheFilePath) { | 739 TEST_F(DriveCacheTest, GetCacheFilePath) { |
| 778 // Use alphanumeric characters for resource id. | 740 // Use alphanumeric characters for resource id. |
| 779 std::string resource_id("pdf:1a2b"); | 741 std::string resource_id("pdf:1a2b"); |
| 780 std::string md5("abcdef0123456789"); | 742 std::string md5("abcdef0123456789"); |
| 781 TestGetCacheFilePath(resource_id, md5, | 743 TestGetCacheFilePath(resource_id, md5, |
| 782 resource_id + FilePath::kExtensionSeparator + md5); | 744 resource_id + FilePath::kExtensionSeparator + md5); |
| 783 EXPECT_EQ(0, num_callback_invocations_); | 745 EXPECT_EQ(0, num_callback_invocations_); |
| 784 | 746 |
| 785 // Use non-alphanumeric characters for resource id, including '.' which is an | 747 // Use non-alphanumeric characters for resource id, including '.' which is an |
| 786 // extension separator, to test that the characters are escaped and unescaped | 748 // extension separator, to test that the characters are escaped and unescaped |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1477 EXPECT_EQ(1, num_callback_invocations_); | 1439 EXPECT_EQ(1, num_callback_invocations_); |
| 1478 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); | 1440 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); |
| 1479 | 1441 |
| 1480 // Try to remove the file. | 1442 // Try to remove the file. |
| 1481 num_callback_invocations_ = 0; | 1443 num_callback_invocations_ = 0; |
| 1482 TestRemoveFromCache(resource_id, DRIVE_FILE_OK); | 1444 TestRemoveFromCache(resource_id, DRIVE_FILE_OK); |
| 1483 EXPECT_EQ(1, num_callback_invocations_); | 1445 EXPECT_EQ(1, num_callback_invocations_); |
| 1484 } | 1446 } |
| 1485 | 1447 |
| 1486 TEST_F(DriveCacheTest, Iterate) { | 1448 TEST_F(DriveCacheTest, Iterate) { |
| 1487 PrepareForInitCacheTest(); | 1449 PrepareTestCacheResources(); |
| 1488 | 1450 |
| 1489 std::vector<std::string> resource_ids; | 1451 std::vector<std::string> resource_ids; |
| 1490 std::vector<DriveCacheEntry> cache_entries; | 1452 std::vector<DriveCacheEntry> cache_entries; |
| 1491 bool completed = false; | 1453 bool completed = false; |
| 1492 cache_->Iterate( | 1454 cache_->Iterate( |
| 1493 base::Bind(&OnIterate, &resource_ids, &cache_entries), | 1455 base::Bind(&OnIterate, &resource_ids, &cache_entries), |
| 1494 base::Bind(&OnIterateCompleted, &completed)); | 1456 base::Bind(&OnIterateCompleted, &completed)); |
| 1495 google_apis::test_util::RunBlockingPoolTask(); | 1457 google_apis::test_util::RunBlockingPoolTask(); |
| 1496 | 1458 |
| 1497 ASSERT_TRUE(completed); | 1459 ASSERT_TRUE(completed); |
| 1498 | 1460 |
| 1499 sort(resource_ids.begin(), resource_ids.end()); | 1461 sort(resource_ids.begin(), resource_ids.end()); |
| 1500 ASSERT_EQ(6U, resource_ids.size()); | 1462 ASSERT_EQ(6U, resource_ids.size()); |
| 1501 EXPECT_EQ("dirty:existing", resource_ids[0]); | 1463 EXPECT_EQ("dirty:existing", resource_ids[0]); |
| 1502 EXPECT_EQ("dirty_and_pinned:existing", resource_ids[1]); | 1464 EXPECT_EQ("dirty_and_pinned:existing", resource_ids[1]); |
| 1503 EXPECT_EQ("pinned:existing", resource_ids[2]); | 1465 EXPECT_EQ("pinned:existing", resource_ids[2]); |
| 1504 EXPECT_EQ("pinned:non-existent", resource_ids[3]); | 1466 EXPECT_EQ("pinned:non-existent", resource_ids[3]); |
| 1505 EXPECT_EQ("tmp:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?", resource_ids[4]); | 1467 EXPECT_EQ("tmp:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?", resource_ids[4]); |
| 1506 EXPECT_EQ("tmp:resource_id", resource_ids[5]); | 1468 EXPECT_EQ("tmp:resource_id", resource_ids[5]); |
| 1507 | 1469 |
| 1508 ASSERT_EQ(6U, cache_entries.size()); | 1470 ASSERT_EQ(6U, cache_entries.size()); |
| 1509 } | 1471 } |
| 1510 | 1472 |
| 1511 | 1473 |
| 1512 TEST_F(DriveCacheTest, ClearAll) { | 1474 TEST_F(DriveCacheTest, ClearAll) { |
| 1513 PrepareForInitCacheTest(); | |
| 1514 | |
| 1515 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 1475 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
| 1516 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); | 1476 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); |
| 1517 | 1477 |
| 1518 std::string resource_id("pdf:1a2b"); | 1478 std::string resource_id("pdf:1a2b"); |
| 1519 std::string md5("abcdef0123456789"); | 1479 std::string md5("abcdef0123456789"); |
| 1520 | 1480 |
| 1521 // Store an existing file. | 1481 // Store an existing file. |
| 1522 TestStoreToCache( | 1482 TestStoreToCache( |
| 1523 resource_id, md5, | 1483 resource_id, md5, |
| 1524 google_apis::test_util::GetTestFilePath("gdata/root_feed.json"), | 1484 google_apis::test_util::GetTestFilePath("gdata/root_feed.json"), |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1578 cache->RequestInitialize( | 1538 cache->RequestInitialize( |
| 1579 base::Bind(&test_util::CopyResultFromInitializeCacheCallback, &success)); | 1539 base::Bind(&test_util::CopyResultFromInitializeCacheCallback, &success)); |
| 1580 google_apis::test_util::RunBlockingPoolTask(); | 1540 google_apis::test_util::RunBlockingPoolTask(); |
| 1581 EXPECT_FALSE(success); | 1541 EXPECT_FALSE(success); |
| 1582 | 1542 |
| 1583 cache->Destroy(); | 1543 cache->Destroy(); |
| 1584 google_apis::test_util::RunBlockingPoolTask(); | 1544 google_apis::test_util::RunBlockingPoolTask(); |
| 1585 } | 1545 } |
| 1586 | 1546 |
| 1587 } // namespace drive | 1547 } // namespace drive |
| OLD | NEW |