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 27 matching lines...) Expand all Loading... |
38 const char* resource_id; | 38 const char* resource_id; |
39 const char* md5; | 39 const char* md5; |
40 bool is_pinned; | 40 bool is_pinned; |
41 bool is_dirty; | 41 bool is_dirty; |
42 } const test_cache_resources[] = { | 42 } const test_cache_resources[] = { |
43 // Cache resource in tmp dir, i.e. not pinned or dirty. | 43 // Cache resource in tmp dir, i.e. not pinned or dirty. |
44 { "gdata/root_feed.json", "tmp:resource_id", "md5_tmp_alphanumeric", | 44 { "gdata/root_feed.json", "tmp:resource_id", "md5_tmp_alphanumeric", |
45 false, false }, | 45 false, false }, |
46 // Cache resource in tmp dir, i.e. not pinned or dirty, with resource_id | 46 // Cache resource in tmp dir, i.e. not pinned or dirty, with resource_id |
47 // containing non-alphanumeric characters. | 47 // containing non-alphanumeric characters. |
48 { "gdata/subdir_feed.json", "tmp:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?", | 48 { "gdata/empty_feed.json", "tmp:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?", |
49 "md5_tmp_non_alphanumeric", false, false }, | 49 "md5_tmp_non_alphanumeric", false, false }, |
50 // Cache resource that is pinned and persistent. | 50 // Cache resource that is pinned and persistent. |
51 { "gdata/directory_entry_atom.json", "pinned:existing", "md5_pinned_existing", | 51 { "gdata/directory_entry.json", "pinned:existing", "md5_pinned_existing", |
52 true, false }, | 52 true, false }, |
53 // Cache resource with a non-existent source file that is pinned. | 53 // Cache resource with a non-existent source file that is pinned. |
54 { "", "pinned:non-existent", "md5_pinned_non_existent", true, false }, | 54 { "", "pinned:non-existent", "md5_pinned_non_existent", true, false }, |
55 // Cache resource that is dirty. | 55 // Cache resource that is dirty. |
56 { "gdata/account_metadata.json", "dirty:existing", "md5_dirty_existing", | 56 { "gdata/account_metadata.json", "dirty:existing", "md5_dirty_existing", |
57 false, true }, | 57 false, true }, |
58 // Cache resource that is pinned and dirty. | 58 // Cache resource that is pinned and dirty. |
59 { "gdata/basic_feed.json", "dirty_and_pinned:existing", | 59 { "gdata/basic_feed.json", "dirty_and_pinned:existing", |
60 "md5_dirty_and_pinned_existing", true, true }, | 60 "md5_dirty_and_pinned_existing", true, true }, |
61 }; | 61 }; |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 DRIVE_FILE_ERROR_FAILED, | 678 DRIVE_FILE_ERROR_FAILED, |
679 test_util::TEST_CACHE_STATE_PRESENT, | 679 test_util::TEST_CACHE_STATE_PRESENT, |
680 DriveCache::CACHE_TYPE_TMP); | 680 DriveCache::CACHE_TYPE_TMP); |
681 | 681 |
682 // Store a different existing file to the same |resource_id| but different | 682 // Store a different existing file to the same |resource_id| but different |
683 // |md5|. | 683 // |md5|. |
684 md5 = "new_md5"; | 684 md5 = "new_md5"; |
685 TestStoreToCache( | 685 TestStoreToCache( |
686 resource_id, md5, | 686 resource_id, md5, |
687 google_apis::test_util::GetTestFilePath( | 687 google_apis::test_util::GetTestFilePath( |
688 "chromeos/gdata/subdir_feed.json"), | 688 "chromeos/gdata/empty_feed.json"), |
689 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, | 689 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, |
690 DriveCache::CACHE_TYPE_TMP); | 690 DriveCache::CACHE_TYPE_TMP); |
691 | 691 |
692 // Verify that there's only one file with name <resource_id>, i.e. previously | 692 // Verify that there's only one file with name <resource_id>, i.e. previously |
693 // cached file with the different md5 should be deleted. | 693 // cached file with the different md5 should be deleted. |
694 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5)); | 694 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5)); |
695 } | 695 } |
696 | 696 |
697 TEST_F(DriveCacheTest, GetFromCacheSimple) { | 697 TEST_F(DriveCacheTest, GetFromCacheSimple) { |
698 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); | 698 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 // but different md5, which should fail. | 1158 // but different md5, which should fail. |
1159 TestMarkDirty(resource_id, md5, DRIVE_FILE_OK, | 1159 TestMarkDirty(resource_id, md5, DRIVE_FILE_OK, |
1160 test_util::TEST_CACHE_STATE_PRESENT | | 1160 test_util::TEST_CACHE_STATE_PRESENT | |
1161 test_util::TEST_CACHE_STATE_DIRTY | | 1161 test_util::TEST_CACHE_STATE_DIRTY | |
1162 test_util::TEST_CACHE_STATE_PERSISTENT, | 1162 test_util::TEST_CACHE_STATE_PERSISTENT, |
1163 DriveCache::CACHE_TYPE_PERSISTENT); | 1163 DriveCache::CACHE_TYPE_PERSISTENT); |
1164 md5 = "new_md5"; | 1164 md5 = "new_md5"; |
1165 TestStoreToCache( | 1165 TestStoreToCache( |
1166 resource_id, md5, | 1166 resource_id, md5, |
1167 google_apis::test_util::GetTestFilePath( | 1167 google_apis::test_util::GetTestFilePath( |
1168 "chromeos/gdata/subdir_feed.json"), | 1168 "chromeos/gdata/empty_feed.json"), |
1169 DRIVE_FILE_ERROR_IN_USE, | 1169 DRIVE_FILE_ERROR_IN_USE, |
1170 test_util::TEST_CACHE_STATE_PRESENT | | 1170 test_util::TEST_CACHE_STATE_PRESENT | |
1171 test_util::TEST_CACHE_STATE_DIRTY | | 1171 test_util::TEST_CACHE_STATE_DIRTY | |
1172 test_util::TEST_CACHE_STATE_PERSISTENT, | 1172 test_util::TEST_CACHE_STATE_PERSISTENT, |
1173 DriveCache::CACHE_TYPE_PERSISTENT); | 1173 DriveCache::CACHE_TYPE_PERSISTENT); |
1174 } | 1174 } |
1175 | 1175 |
1176 TEST_F(DriveCacheTest, RemoveFromDirtyCache) { | 1176 TEST_F(DriveCacheTest, RemoveFromDirtyCache) { |
1177 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); | 1177 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); |
1178 | 1178 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 NULL /* free_disk_space_getter */)); | 1340 NULL /* free_disk_space_getter */)); |
1341 | 1341 |
1342 bool success = true; | 1342 bool success = true; |
1343 cache->RequestInitialize( | 1343 cache->RequestInitialize( |
1344 google_apis::test_util::CreateCopyResultCallback(&success)); | 1344 google_apis::test_util::CreateCopyResultCallback(&success)); |
1345 google_apis::test_util::RunBlockingPoolTask(); | 1345 google_apis::test_util::RunBlockingPoolTask(); |
1346 EXPECT_FALSE(success); | 1346 EXPECT_FALSE(success); |
1347 } | 1347 } |
1348 | 1348 |
1349 } // namespace drive | 1349 } // namespace drive |
OLD | NEW |