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/file_cache.h" | 5 #include "chrome/browser/chromeos/drive/file_cache.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 125 |
126 FileError error = FILE_ERROR_OK; | 126 FileError error = FILE_ERROR_OK; |
127 cache_->StoreOnUIThread( | 127 cache_->StoreOnUIThread( |
128 resource_id, md5, source_path, | 128 resource_id, md5, source_path, |
129 FileCache::FILE_OPERATION_COPY, | 129 FileCache::FILE_OPERATION_COPY, |
130 google_apis::test_util::CreateCopyResultCallback(&error)); | 130 google_apis::test_util::CreateCopyResultCallback(&error)); |
131 google_apis::test_util::RunBlockingPoolTask(); | 131 google_apis::test_util::RunBlockingPoolTask(); |
132 VerifyCacheFileState(error, resource_id, md5); | 132 VerifyCacheFileState(error, resource_id, md5); |
133 } | 133 } |
134 | 134 |
135 void TestStoreLocallyModifiedToCache( | |
136 const std::string& resource_id, | |
137 const std::string& md5, | |
138 const base::FilePath& source_path, | |
139 FileError expected_error, | |
140 int expected_cache_state, | |
141 FileCache::CacheSubDirectoryType expected_sub_dir_type) { | |
142 expected_error_ = expected_error; | |
143 expected_cache_state_ = expected_cache_state; | |
144 expected_sub_dir_type_ = expected_sub_dir_type; | |
145 | |
146 FileError error = FILE_ERROR_OK; | |
147 cache_->StoreLocallyModifiedOnUIThread( | |
148 resource_id, md5, source_path, | |
149 FileCache::FILE_OPERATION_COPY, | |
150 google_apis::test_util::CreateCopyResultCallback(&error)); | |
151 google_apis::test_util::RunBlockingPoolTask(); | |
152 VerifyCacheFileState(error, resource_id, md5); | |
153 } | |
154 | |
155 void TestRemoveFromCache(const std::string& resource_id, | 135 void TestRemoveFromCache(const std::string& resource_id, |
156 FileError expected_error) { | 136 FileError expected_error) { |
157 expected_error_ = expected_error; | 137 expected_error_ = expected_error; |
158 | 138 |
159 FileError error = FILE_ERROR_OK; | 139 FileError error = FILE_ERROR_OK; |
160 cache_->RemoveOnUIThread( | 140 cache_->RemoveOnUIThread( |
161 resource_id, | 141 resource_id, |
162 google_apis::test_util::CreateCopyResultCallback(&error)); | 142 google_apis::test_util::CreateCopyResultCallback(&error)); |
163 google_apis::test_util::RunBlockingPoolTask(); | 143 google_apis::test_util::RunBlockingPoolTask(); |
164 VerifyRemoveFromCache(error, resource_id, ""); | 144 VerifyRemoveFromCache(error, resource_id, ""); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 259 |
280 EXPECT_EQ(FILE_ERROR_OK, error); | 260 EXPECT_EQ(FILE_ERROR_OK, error); |
281 base::FilePath base_name = cache_file_path.BaseName(); | 261 base::FilePath base_name = cache_file_path.BaseName(); |
282 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + | 262 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + |
283 base::FilePath::kExtensionSeparator + | 263 base::FilePath::kExtensionSeparator + |
284 "local", | 264 "local", |
285 base_name.value()); | 265 base_name.value()); |
286 } | 266 } |
287 } | 267 } |
288 | 268 |
289 void TestCommitDirty( | |
290 const std::string& resource_id, | |
291 const std::string& md5, | |
292 FileError expected_error, | |
293 int expected_cache_state, | |
294 FileCache::CacheSubDirectoryType expected_sub_dir_type) { | |
295 expected_error_ = expected_error; | |
296 expected_cache_state_ = expected_cache_state; | |
297 expected_sub_dir_type_ = expected_sub_dir_type; | |
298 | |
299 FileError error = FILE_ERROR_OK; | |
300 cache_->CommitDirtyOnUIThread( | |
301 resource_id, md5, | |
302 google_apis::test_util::CreateCopyResultCallback(&error)); | |
303 google_apis::test_util::RunBlockingPoolTask(); | |
304 VerifyCacheFileState(error, resource_id, md5); | |
305 } | |
306 | |
307 void TestClearDirty( | 269 void TestClearDirty( |
308 const std::string& resource_id, | 270 const std::string& resource_id, |
309 const std::string& md5, | 271 const std::string& md5, |
310 FileError expected_error, | 272 FileError expected_error, |
311 int expected_cache_state, | 273 int expected_cache_state, |
312 FileCache::CacheSubDirectoryType expected_sub_dir_type) { | 274 FileCache::CacheSubDirectoryType expected_sub_dir_type) { |
313 expected_error_ = expected_error; | 275 expected_error_ = expected_error; |
314 expected_cache_state_ = expected_cache_state; | 276 expected_cache_state_ = expected_cache_state; |
315 expected_sub_dir_type_ = expected_sub_dir_type; | 277 expected_sub_dir_type_ = expected_sub_dir_type; |
316 | 278 |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 md5 = "new_md5"; | 521 md5 = "new_md5"; |
560 TestStoreToCache(resource_id, md5, dummy_file_path_, | 522 TestStoreToCache(resource_id, md5, dummy_file_path_, |
561 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 523 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, |
562 FileCache::CACHE_TYPE_TMP); | 524 FileCache::CACHE_TYPE_TMP); |
563 | 525 |
564 // Verify that there's only one file with name <resource_id>, i.e. previously | 526 // Verify that there's only one file with name <resource_id>, i.e. previously |
565 // cached file with the different md5 should be deleted. | 527 // cached file with the different md5 should be deleted. |
566 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5)); | 528 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5)); |
567 } | 529 } |
568 | 530 |
569 TEST_F(FileCacheTestOnUIThread, LocallyModifiedSimple) { | |
570 std::string resource_id("pdf:1a2b"); | |
571 std::string md5("abcdef0123456789"); | |
572 | |
573 const int kDirtyCacheState = | |
574 test_util::TEST_CACHE_STATE_PRESENT | | |
575 test_util::TEST_CACHE_STATE_DIRTY | | |
576 test_util::TEST_CACHE_STATE_PERSISTENT; | |
577 | |
578 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1); | |
579 TestStoreLocallyModifiedToCache( | |
580 resource_id, md5, | |
581 dummy_file_path_, | |
582 FILE_ERROR_OK, kDirtyCacheState, FileCache::CACHE_TYPE_PERSISTENT); | |
583 } | |
584 | 531 |
585 TEST_F(FileCacheTestOnUIThread, GetFromCacheSimple) { | 532 TEST_F(FileCacheTestOnUIThread, GetFromCacheSimple) { |
586 std::string resource_id("pdf:1a2b"); | 533 std::string resource_id("pdf:1a2b"); |
587 std::string md5("abcdef0123456789"); | 534 std::string md5("abcdef0123456789"); |
588 // First store a file to cache. | 535 // First store a file to cache. |
589 TestStoreToCache(resource_id, md5, dummy_file_path_, | 536 TestStoreToCache(resource_id, md5, dummy_file_path_, |
590 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 537 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, |
591 FileCache::CACHE_TYPE_TMP); | 538 FileCache::CACHE_TYPE_TMP); |
592 | 539 |
593 // Then try to get the existing file from cache. | 540 // Then try to get the existing file from cache. |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 test_util::TEST_CACHE_STATE_PINNED | | 720 test_util::TEST_CACHE_STATE_PINNED | |
774 test_util::TEST_CACHE_STATE_PERSISTENT, | 721 test_util::TEST_CACHE_STATE_PERSISTENT, |
775 FileCache::CACHE_TYPE_PERSISTENT); | 722 FileCache::CACHE_TYPE_PERSISTENT); |
776 | 723 |
777 TestRemoveFromCache(resource_id, FILE_ERROR_OK); | 724 TestRemoveFromCache(resource_id, FILE_ERROR_OK); |
778 } | 725 } |
779 | 726 |
780 TEST_F(FileCacheTestOnUIThread, DirtyCacheSimple) { | 727 TEST_F(FileCacheTestOnUIThread, DirtyCacheSimple) { |
781 std::string resource_id("pdf:1a2b"); | 728 std::string resource_id("pdf:1a2b"); |
782 std::string md5("abcdef0123456789"); | 729 std::string md5("abcdef0123456789"); |
783 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1); | |
784 | 730 |
785 // First store a file to cache. | 731 // First store a file to cache. |
786 TestStoreToCache(resource_id, md5, dummy_file_path_, | 732 TestStoreToCache(resource_id, md5, dummy_file_path_, |
787 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 733 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, |
788 FileCache::CACHE_TYPE_TMP); | 734 FileCache::CACHE_TYPE_TMP); |
789 | 735 |
790 // Mark the file dirty. | 736 // Mark the file dirty. |
791 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, | 737 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, |
792 test_util::TEST_CACHE_STATE_PRESENT | | 738 test_util::TEST_CACHE_STATE_PRESENT | |
793 test_util::TEST_CACHE_STATE_DIRTY | | 739 test_util::TEST_CACHE_STATE_DIRTY | |
794 test_util::TEST_CACHE_STATE_PERSISTENT, | 740 test_util::TEST_CACHE_STATE_PERSISTENT, |
795 FileCache::CACHE_TYPE_PERSISTENT); | 741 FileCache::CACHE_TYPE_PERSISTENT); |
796 | 742 |
797 // Commit the file dirty. | |
798 TestCommitDirty(resource_id, md5, FILE_ERROR_OK, | |
799 test_util::TEST_CACHE_STATE_PRESENT | | |
800 test_util::TEST_CACHE_STATE_DIRTY | | |
801 test_util::TEST_CACHE_STATE_PERSISTENT, | |
802 FileCache::CACHE_TYPE_PERSISTENT); | |
803 | |
804 // Clear dirty state of the file. | 743 // Clear dirty state of the file. |
805 TestClearDirty(resource_id, md5, FILE_ERROR_OK, | 744 TestClearDirty(resource_id, md5, FILE_ERROR_OK, |
806 test_util::TEST_CACHE_STATE_PRESENT, | 745 test_util::TEST_CACHE_STATE_PRESENT, |
807 FileCache::CACHE_TYPE_TMP); | 746 FileCache::CACHE_TYPE_TMP); |
808 } | 747 } |
809 | 748 |
810 TEST_F(FileCacheTestOnUIThread, DirtyCachePinned) { | 749 TEST_F(FileCacheTestOnUIThread, DirtyCachePinned) { |
811 std::string resource_id("pdf:1a2b"); | 750 std::string resource_id("pdf:1a2b"); |
812 std::string md5("abcdef0123456789"); | 751 std::string md5("abcdef0123456789"); |
813 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); | 752 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); |
814 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1); | |
815 | 753 |
816 // First store a file to cache and pin it. | 754 // First store a file to cache and pin it. |
817 TestStoreToCache(resource_id, md5, dummy_file_path_, | 755 TestStoreToCache(resource_id, md5, dummy_file_path_, |
818 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 756 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, |
819 FileCache::CACHE_TYPE_TMP); | 757 FileCache::CACHE_TYPE_TMP); |
820 TestPin(resource_id, md5, FILE_ERROR_OK, | 758 TestPin(resource_id, md5, FILE_ERROR_OK, |
821 test_util::TEST_CACHE_STATE_PRESENT | | 759 test_util::TEST_CACHE_STATE_PRESENT | |
822 test_util::TEST_CACHE_STATE_PINNED | | 760 test_util::TEST_CACHE_STATE_PINNED | |
823 test_util::TEST_CACHE_STATE_PERSISTENT, | 761 test_util::TEST_CACHE_STATE_PERSISTENT, |
824 FileCache::CACHE_TYPE_PERSISTENT); | 762 FileCache::CACHE_TYPE_PERSISTENT); |
825 | 763 |
826 // Mark the file dirty. | 764 // Mark the file dirty. |
827 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, | 765 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, |
828 test_util::TEST_CACHE_STATE_PRESENT | | 766 test_util::TEST_CACHE_STATE_PRESENT | |
829 test_util::TEST_CACHE_STATE_DIRTY | | 767 test_util::TEST_CACHE_STATE_DIRTY | |
830 test_util::TEST_CACHE_STATE_PINNED | | 768 test_util::TEST_CACHE_STATE_PINNED | |
831 test_util::TEST_CACHE_STATE_PERSISTENT, | 769 test_util::TEST_CACHE_STATE_PERSISTENT, |
832 FileCache::CACHE_TYPE_PERSISTENT); | 770 FileCache::CACHE_TYPE_PERSISTENT); |
833 | 771 |
834 // Commit the file dirty. | |
835 TestCommitDirty(resource_id, md5, FILE_ERROR_OK, | |
836 test_util::TEST_CACHE_STATE_PRESENT | | |
837 test_util::TEST_CACHE_STATE_DIRTY | | |
838 test_util::TEST_CACHE_STATE_PINNED | | |
839 test_util::TEST_CACHE_STATE_PERSISTENT, | |
840 FileCache::CACHE_TYPE_PERSISTENT); | |
841 | |
842 // Clear dirty state of the file. | 772 // Clear dirty state of the file. |
843 TestClearDirty(resource_id, md5, FILE_ERROR_OK, | 773 TestClearDirty(resource_id, md5, FILE_ERROR_OK, |
844 test_util::TEST_CACHE_STATE_PRESENT | | 774 test_util::TEST_CACHE_STATE_PRESENT | |
845 test_util::TEST_CACHE_STATE_PINNED | | 775 test_util::TEST_CACHE_STATE_PINNED | |
846 test_util::TEST_CACHE_STATE_PERSISTENT, | 776 test_util::TEST_CACHE_STATE_PERSISTENT, |
847 FileCache::CACHE_TYPE_PERSISTENT); | 777 FileCache::CACHE_TYPE_PERSISTENT); |
848 } | 778 } |
849 | 779 |
850 TEST_F(FileCacheTestOnUIThread, PinAndUnpinDirtyCache) { | 780 TEST_F(FileCacheTestOnUIThread, PinAndUnpinDirtyCache) { |
851 std::string resource_id("pdf:1a2b"); | 781 std::string resource_id("pdf:1a2b"); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 test_util::TEST_CACHE_STATE_PERSISTENT, | 822 test_util::TEST_CACHE_STATE_PERSISTENT, |
893 FileCache::CACHE_TYPE_PERSISTENT); | 823 FileCache::CACHE_TYPE_PERSISTENT); |
894 | 824 |
895 // Verify dirty file still exist at the same pathname. | 825 // Verify dirty file still exist at the same pathname. |
896 EXPECT_TRUE(file_util::PathExists(dirty_path)); | 826 EXPECT_TRUE(file_util::PathExists(dirty_path)); |
897 } | 827 } |
898 | 828 |
899 TEST_F(FileCacheTestOnUIThread, DirtyCacheRepetitive) { | 829 TEST_F(FileCacheTestOnUIThread, DirtyCacheRepetitive) { |
900 std::string resource_id("pdf:1a2b"); | 830 std::string resource_id("pdf:1a2b"); |
901 std::string md5("abcdef0123456789"); | 831 std::string md5("abcdef0123456789"); |
902 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(3); | |
903 | 832 |
904 // First store a file to cache. | 833 // First store a file to cache. |
905 TestStoreToCache(resource_id, md5, dummy_file_path_, | 834 TestStoreToCache(resource_id, md5, dummy_file_path_, |
906 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 835 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, |
907 FileCache::CACHE_TYPE_TMP); | 836 FileCache::CACHE_TYPE_TMP); |
908 | 837 |
909 // Mark the file dirty. | 838 // Mark the file dirty. |
910 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, | 839 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, |
911 test_util::TEST_CACHE_STATE_PRESENT | | 840 test_util::TEST_CACHE_STATE_PRESENT | |
912 test_util::TEST_CACHE_STATE_DIRTY | | 841 test_util::TEST_CACHE_STATE_DIRTY | |
913 test_util::TEST_CACHE_STATE_PERSISTENT, | 842 test_util::TEST_CACHE_STATE_PERSISTENT, |
914 FileCache::CACHE_TYPE_PERSISTENT); | 843 FileCache::CACHE_TYPE_PERSISTENT); |
915 | 844 |
916 // Again, mark the file dirty. Nothing should change. | 845 // Again, mark the file dirty. Nothing should change. |
917 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, | 846 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, |
918 test_util::TEST_CACHE_STATE_PRESENT | | 847 test_util::TEST_CACHE_STATE_PRESENT | |
919 test_util::TEST_CACHE_STATE_DIRTY | | 848 test_util::TEST_CACHE_STATE_DIRTY | |
920 test_util::TEST_CACHE_STATE_PERSISTENT, | 849 test_util::TEST_CACHE_STATE_PERSISTENT, |
921 FileCache::CACHE_TYPE_PERSISTENT); | 850 FileCache::CACHE_TYPE_PERSISTENT); |
922 | 851 |
923 // Commit the file dirty. | |
924 TestCommitDirty(resource_id, md5, FILE_ERROR_OK, | |
925 test_util::TEST_CACHE_STATE_PRESENT | | |
926 test_util::TEST_CACHE_STATE_DIRTY | | |
927 test_util::TEST_CACHE_STATE_PERSISTENT, | |
928 FileCache::CACHE_TYPE_PERSISTENT); | |
929 | |
930 // Again, commit the file dirty. Nothing should change. | |
931 TestCommitDirty(resource_id, md5, FILE_ERROR_OK, | |
932 test_util::TEST_CACHE_STATE_PRESENT | | |
933 test_util::TEST_CACHE_STATE_DIRTY | | |
934 test_util::TEST_CACHE_STATE_PERSISTENT, | |
935 FileCache::CACHE_TYPE_PERSISTENT); | |
936 | |
937 // Mark the file dirty again after it's being committed. | |
938 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, | |
939 test_util::TEST_CACHE_STATE_PRESENT | | |
940 test_util::TEST_CACHE_STATE_DIRTY | | |
941 test_util::TEST_CACHE_STATE_PERSISTENT, | |
942 FileCache::CACHE_TYPE_PERSISTENT); | |
943 | |
944 // Commit the file dirty. | |
945 TestCommitDirty(resource_id, md5, FILE_ERROR_OK, | |
946 test_util::TEST_CACHE_STATE_PRESENT | | |
947 test_util::TEST_CACHE_STATE_DIRTY | | |
948 test_util::TEST_CACHE_STATE_PERSISTENT, | |
949 FileCache::CACHE_TYPE_PERSISTENT); | |
950 | |
951 // Clear dirty state of the file. | 852 // Clear dirty state of the file. |
952 TestClearDirty(resource_id, md5, FILE_ERROR_OK, | 853 TestClearDirty(resource_id, md5, FILE_ERROR_OK, |
953 test_util::TEST_CACHE_STATE_PRESENT, | 854 test_util::TEST_CACHE_STATE_PRESENT, |
954 FileCache::CACHE_TYPE_TMP); | 855 FileCache::CACHE_TYPE_TMP); |
955 | 856 |
956 // Again, clear dirty state of the file, which is no longer dirty. | 857 // Again, clear dirty state of the file, which is no longer dirty. |
957 TestClearDirty(resource_id, md5, FILE_ERROR_INVALID_OPERATION, | 858 TestClearDirty(resource_id, md5, FILE_ERROR_INVALID_OPERATION, |
958 test_util::TEST_CACHE_STATE_PRESENT, | 859 test_util::TEST_CACHE_STATE_PRESENT, |
959 FileCache::CACHE_TYPE_TMP); | 860 FileCache::CACHE_TYPE_TMP); |
960 } | 861 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 test_util::TEST_CACHE_STATE_PRESENT | | 897 test_util::TEST_CACHE_STATE_PRESENT | |
997 test_util::TEST_CACHE_STATE_DIRTY | | 898 test_util::TEST_CACHE_STATE_DIRTY | |
998 test_util::TEST_CACHE_STATE_PERSISTENT, | 899 test_util::TEST_CACHE_STATE_PERSISTENT, |
999 FileCache::CACHE_TYPE_PERSISTENT); | 900 FileCache::CACHE_TYPE_PERSISTENT); |
1000 } | 901 } |
1001 | 902 |
1002 TEST_F(FileCacheTestOnUIThread, RemoveFromDirtyCache) { | 903 TEST_F(FileCacheTestOnUIThread, RemoveFromDirtyCache) { |
1003 std::string resource_id("pdf:1a2b"); | 904 std::string resource_id("pdf:1a2b"); |
1004 std::string md5("abcdef0123456789"); | 905 std::string md5("abcdef0123456789"); |
1005 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); | 906 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); |
1006 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1); | |
1007 | 907 |
1008 // Store a file to cache, pin it, mark it dirty and commit it. | 908 // Store a file to cache, pin it, mark it dirty and commit it. |
1009 TestStoreToCache(resource_id, md5, dummy_file_path_, | 909 TestStoreToCache(resource_id, md5, dummy_file_path_, |
1010 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 910 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, |
1011 FileCache::CACHE_TYPE_TMP); | 911 FileCache::CACHE_TYPE_TMP); |
1012 TestPin(resource_id, md5, FILE_ERROR_OK, | 912 TestPin(resource_id, md5, FILE_ERROR_OK, |
1013 test_util::TEST_CACHE_STATE_PRESENT | | 913 test_util::TEST_CACHE_STATE_PRESENT | |
1014 test_util::TEST_CACHE_STATE_PINNED | | 914 test_util::TEST_CACHE_STATE_PINNED | |
1015 test_util::TEST_CACHE_STATE_PERSISTENT, | 915 test_util::TEST_CACHE_STATE_PERSISTENT, |
1016 FileCache::CACHE_TYPE_PERSISTENT); | 916 FileCache::CACHE_TYPE_PERSISTENT); |
1017 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, | 917 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, |
1018 test_util::TEST_CACHE_STATE_PRESENT | | 918 test_util::TEST_CACHE_STATE_PRESENT | |
1019 test_util::TEST_CACHE_STATE_PINNED | | 919 test_util::TEST_CACHE_STATE_PINNED | |
1020 test_util::TEST_CACHE_STATE_DIRTY | | 920 test_util::TEST_CACHE_STATE_DIRTY | |
1021 test_util::TEST_CACHE_STATE_PERSISTENT, | 921 test_util::TEST_CACHE_STATE_PERSISTENT, |
1022 FileCache::CACHE_TYPE_PERSISTENT); | 922 FileCache::CACHE_TYPE_PERSISTENT); |
1023 TestCommitDirty(resource_id, md5, FILE_ERROR_OK, | |
1024 test_util::TEST_CACHE_STATE_PRESENT | | |
1025 test_util::TEST_CACHE_STATE_PINNED | | |
1026 test_util::TEST_CACHE_STATE_DIRTY | | |
1027 test_util::TEST_CACHE_STATE_PERSISTENT, | |
1028 FileCache::CACHE_TYPE_PERSISTENT); | |
1029 | 923 |
1030 // Try to remove the file. Since file is dirty, it should not be removed. | 924 // Try to remove the file. Since file is dirty, it should not be removed. |
1031 TestRemoveFromCache(resource_id, FILE_ERROR_OK); | 925 TestRemoveFromCache(resource_id, FILE_ERROR_OK); |
1032 } | 926 } |
1033 | 927 |
1034 TEST_F(FileCacheTestOnUIThread, MountUnmount) { | 928 TEST_F(FileCacheTestOnUIThread, MountUnmount) { |
1035 std::string resource_id("pdf:1a2b"); | 929 std::string resource_id("pdf:1a2b"); |
1036 std::string md5("abcdef0123456789"); | 930 std::string md5("abcdef0123456789"); |
1037 | 931 |
1038 // First store a file to cache in the tmp subdir. | 932 // First store a file to cache in the tmp subdir. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 TEST_F(FileCacheTestOnUIThread, Iterate) { | 965 TEST_F(FileCacheTestOnUIThread, Iterate) { |
1072 const std::vector<test_util::TestCacheResource> cache_resources( | 966 const std::vector<test_util::TestCacheResource> cache_resources( |
1073 test_util::GetDefaultTestCacheResources()); | 967 test_util::GetDefaultTestCacheResources()); |
1074 // Set mock expectations. | 968 // Set mock expectations. |
1075 for (size_t i = 0; i < cache_resources.size(); ++i) { | 969 for (size_t i = 0; i < cache_resources.size(); ++i) { |
1076 if (cache_resources[i].is_pinned) { | 970 if (cache_resources[i].is_pinned) { |
1077 EXPECT_CALL(*mock_cache_observer_, | 971 EXPECT_CALL(*mock_cache_observer_, |
1078 OnCachePinned(cache_resources[i].resource_id, | 972 OnCachePinned(cache_resources[i].resource_id, |
1079 cache_resources[i].md5)).Times(1); | 973 cache_resources[i].md5)).Times(1); |
1080 } | 974 } |
1081 if (cache_resources[i].is_dirty) { | |
1082 EXPECT_CALL(*mock_cache_observer_, | |
1083 OnCacheCommitted(cache_resources[i].resource_id)).Times(1); | |
1084 } | |
1085 } | 975 } |
1086 ASSERT_TRUE(test_util::PrepareTestCacheResources( | 976 ASSERT_TRUE(test_util::PrepareTestCacheResources( |
1087 cache_.get(), | 977 cache_.get(), |
1088 cache_resources)); | 978 cache_resources)); |
1089 | 979 |
1090 std::vector<std::string> resource_ids; | 980 std::vector<std::string> resource_ids; |
1091 std::vector<FileCacheEntry> cache_entries; | 981 std::vector<FileCacheEntry> cache_entries; |
1092 bool completed = false; | 982 bool completed = false; |
1093 cache_->IterateOnUIThread( | 983 cache_->IterateOnUIThread( |
1094 base::Bind(&OnIterate, &resource_ids, &cache_entries), | 984 base::Bind(&OnIterate, &resource_ids, &cache_entries), |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 EXPECT_TRUE(cache_->GetCacheEntry(resource_id_pinned, md5_pinned, &entry)); | 1200 EXPECT_TRUE(cache_->GetCacheEntry(resource_id_pinned, md5_pinned, &entry)); |
1311 EXPECT_TRUE(file_util::PathExists(pinned_path)); | 1201 EXPECT_TRUE(file_util::PathExists(pinned_path)); |
1312 | 1202 |
1313 // Returns false when disk space cannot be freed. | 1203 // Returns false when disk space cannot be freed. |
1314 fake_free_disk_space_getter_->set_default_value(0); | 1204 fake_free_disk_space_getter_->set_default_value(0); |
1315 EXPECT_FALSE(cache_->FreeDiskSpaceIfNeededFor(kNeededBytes)); | 1205 EXPECT_FALSE(cache_->FreeDiskSpaceIfNeededFor(kNeededBytes)); |
1316 } | 1206 } |
1317 | 1207 |
1318 } // namespace internal | 1208 } // namespace internal |
1319 } // namespace drive | 1209 } // namespace drive |
OLD | NEW |