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

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

Issue 10765020: gdata: Simplify semantics of sub_dir_type in CacheEntry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/json/json_file_value_serializer.h" 6 #include "base/json/json_file_value_serializer.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "chrome/browser/chromeos/cros/cros_library.h" 9 #include "chrome/browser/chromeos/cros/cros_library.h"
10 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" 10 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // Cache resource that is pinned, to test a pinned file is in persistent dir 51 // Cache resource that is pinned, to test a pinned file is in persistent dir
52 // with a symlink in pinned dir referencing it. 52 // with a symlink in pinned dir referencing it.
53 { "directory_entry_atom.json", "pinned:existing", "md5_pinned_existing", 53 { "directory_entry_atom.json", "pinned:existing", "md5_pinned_existing",
54 GDataCache::CACHE_STATE_PRESENT | 54 GDataCache::CACHE_STATE_PRESENT |
55 GDataCache::CACHE_STATE_PINNED, 55 GDataCache::CACHE_STATE_PINNED,
56 "md5_pinned_existing", GDataCache::CACHE_TYPE_PERSISTENT }, 56 "md5_pinned_existing", GDataCache::CACHE_TYPE_PERSISTENT },
57 // Cache resource with a non-existent source file that is pinned, to test that 57 // Cache resource with a non-existent source file that is pinned, to test that
58 // a pinned file can reference a non-existent file. 58 // a pinned file can reference a non-existent file.
59 { "", "pinned:non-existent", "md5_pinned_non_existent", 59 { "", "pinned:non-existent", "md5_pinned_non_existent",
60 GDataCache::CACHE_STATE_PINNED, 60 GDataCache::CACHE_STATE_PINNED,
61 "md5_pinned_non_existent", GDataCache::CACHE_TYPE_PINNED }, 61 "md5_pinned_non_existent", GDataCache::CACHE_TYPE_TMP },
62 // Cache resource that is dirty, to test a dirty file is in persistent dir 62 // Cache resource that is dirty, to test a dirty file is in persistent dir
63 // with a symlink in outgoing dir referencing it. 63 // with a symlink in outgoing dir referencing it.
64 { "account_metadata.json", "dirty:existing", "md5_dirty_existing", 64 { "account_metadata.json", "dirty:existing", "md5_dirty_existing",
65 GDataCache::CACHE_STATE_PRESENT | 65 GDataCache::CACHE_STATE_PRESENT |
66 GDataCache::CACHE_STATE_DIRTY, 66 GDataCache::CACHE_STATE_DIRTY,
67 "local", GDataCache::CACHE_TYPE_PERSISTENT }, 67 "local", GDataCache::CACHE_TYPE_PERSISTENT },
68 // Cache resource that is pinned and dirty, to test a dirty pinned file is in 68 // Cache resource that is pinned and dirty, to test a dirty pinned file is in
69 // persistent dir with symlink in pinned and outgoing dirs referencing it. 69 // persistent dir with symlink in pinned and outgoing dirs referencing it.
70 { "basic_feed.json", "dirty_and_pinned:existing", 70 { "basic_feed.json", "dirty_and_pinned:existing",
71 "md5_dirty_and_pinned_existing", 71 "md5_dirty_and_pinned_existing",
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 // - no "<resource_id>" symlink exists in pinned and outgoing dirs. 424 // - no "<resource_id>" symlink exists in pinned and outgoing dirs.
425 std::vector<PathToVerify> paths_to_verify; 425 std::vector<PathToVerify> paths_to_verify;
426 paths_to_verify.push_back( // Index 0: CACHE_TYPE_TMP. 426 paths_to_verify.push_back( // Index 0: CACHE_TYPE_TMP.
427 PathToVerify(cache_->GetCacheFilePath(resource_id, "*", 427 PathToVerify(cache_->GetCacheFilePath(resource_id, "*",
428 GDataCache::CACHE_TYPE_TMP, 428 GDataCache::CACHE_TYPE_TMP,
429 GDataCache::CACHED_FILE_FROM_SERVER), FilePath())); 429 GDataCache::CACHED_FILE_FROM_SERVER), FilePath()));
430 paths_to_verify.push_back( // Index 1: CACHE_TYPE_PERSISTENT. 430 paths_to_verify.push_back( // Index 1: CACHE_TYPE_PERSISTENT.
431 PathToVerify(cache_->GetCacheFilePath(resource_id, "*", 431 PathToVerify(cache_->GetCacheFilePath(resource_id, "*",
432 GDataCache::CACHE_TYPE_PERSISTENT, 432 GDataCache::CACHE_TYPE_PERSISTENT,
433 GDataCache::CACHED_FILE_FROM_SERVER), FilePath())); 433 GDataCache::CACHED_FILE_FROM_SERVER), FilePath()));
434 paths_to_verify.push_back( // Index 2: CACHE_TYPE_PINNED. 434 paths_to_verify.push_back( // Index 2: CACHE_TYPE_TMP, but STATE_PINNED.
435 PathToVerify(cache_->GetCacheFilePath(resource_id, "", 435 PathToVerify(cache_->GetCacheFilePath(resource_id, "",
436 GDataCache::CACHE_TYPE_PINNED, 436 GDataCache::CACHE_TYPE_PINNED,
437 GDataCache::CACHED_FILE_FROM_SERVER), FilePath())); 437 GDataCache::CACHED_FILE_FROM_SERVER), FilePath()));
438 paths_to_verify.push_back( // Index 3: CACHE_TYPE_OUTGOING. 438 paths_to_verify.push_back( // Index 3: CACHE_TYPE_OUTGOING.
439 PathToVerify(cache_->GetCacheFilePath(resource_id, "", 439 PathToVerify(cache_->GetCacheFilePath(resource_id, "",
440 GDataCache::CACHE_TYPE_OUTGOING, 440 GDataCache::CACHE_TYPE_OUTGOING,
441 GDataCache::CACHED_FILE_FROM_SERVER), FilePath())); 441 GDataCache::CACHED_FILE_FROM_SERVER), FilePath()));
442 if (!cache_entry.get()) { 442 if (!cache_entry.get()) {
443 for (size_t i = 0; i < paths_to_verify.size(); ++i) { 443 for (size_t i = 0; i < paths_to_verify.size(); ++i) {
444 file_util::FileEnumerator enumerator( 444 file_util::FileEnumerator enumerator(
(...skipping 19 matching lines...) Expand all
464 GDataCache::CACHED_FILE_LOCALLY_MODIFIED); 464 GDataCache::CACHED_FILE_LOCALLY_MODIFIED);
465 465
466 // Change expected_existing_path of CACHE_TYPE_OUTGOING (index 3). 466 // Change expected_existing_path of CACHE_TYPE_OUTGOING (index 3).
467 paths_to_verify[3].expected_existing_path = 467 paths_to_verify[3].expected_existing_path =
468 GetCacheFilePath(resource_id, 468 GetCacheFilePath(resource_id,
469 std::string(), 469 std::string(),
470 GDataCache::CACHE_TYPE_OUTGOING, 470 GDataCache::CACHE_TYPE_OUTGOING,
471 GDataCache::CACHED_FILE_FROM_SERVER); 471 GDataCache::CACHED_FILE_FROM_SERVER);
472 472
473 if (cache_entry->IsPinned()) { 473 if (cache_entry->IsPinned()) {
474 // Change expected_existing_path of CACHE_TYPE_PINNED (index 2). 474 // Change expected_existing_path of CACHE_TYPE_TMP but STATE_PINNED
475 // (index 2).
475 paths_to_verify[2].expected_existing_path = 476 paths_to_verify[2].expected_existing_path =
476 GetCacheFilePath(resource_id, 477 GetCacheFilePath(resource_id,
477 std::string(), 478 std::string(),
478 GDataCache::CACHE_TYPE_PINNED, 479 GDataCache::CACHE_TYPE_PINNED,
479 GDataCache::CACHED_FILE_FROM_SERVER); 480 GDataCache::CACHED_FILE_FROM_SERVER);
480 } 481 }
481 482
482 for (size_t i = 0; i < paths_to_verify.size(); ++i) { 483 for (size_t i = 0; i < paths_to_verify.size(); ++i) {
483 const struct PathToVerify& verify = paths_to_verify[i]; 484 const struct PathToVerify& verify = paths_to_verify[i];
484 file_util::FileEnumerator enumerator( 485 file_util::FileEnumerator enumerator(
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 EXPECT_EQ(1, num_callback_invocations_); 1098 EXPECT_EQ(1, num_callback_invocations_);
1098 1099
1099 // Pin a non-existent file in cache. 1100 // Pin a non-existent file in cache.
1100 resource_id = "document:1a2b"; 1101 resource_id = "document:1a2b";
1101 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); 1102 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1);
1102 EXPECT_CALL(*mock_sync_client_, OnCacheUnpinned(resource_id, md5)).Times(1); 1103 EXPECT_CALL(*mock_sync_client_, OnCacheUnpinned(resource_id, md5)).Times(1);
1103 1104
1104 num_callback_invocations_ = 0; 1105 num_callback_invocations_ = 0;
1105 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, 1106 TestPin(resource_id, md5, base::PLATFORM_FILE_OK,
1106 GDataCache::CACHE_STATE_PINNED, 1107 GDataCache::CACHE_STATE_PINNED,
1107 GDataCache::CACHE_TYPE_PINNED); 1108 GDataCache::CACHE_TYPE_TMP);
1108 EXPECT_EQ(1, num_callback_invocations_); 1109 EXPECT_EQ(1, num_callback_invocations_);
1109 1110
1110 // Unpin the previously pinned non-existent file in cache. 1111 // Unpin the previously pinned non-existent file in cache.
1111 num_callback_invocations_ = 0; 1112 num_callback_invocations_ = 0;
1112 TestUnpin(resource_id, md5, base::PLATFORM_FILE_OK, 1113 TestUnpin(resource_id, md5, base::PLATFORM_FILE_OK,
1113 GDataCache::CACHE_STATE_NONE, 1114 GDataCache::CACHE_STATE_NONE,
1114 GDataCache::CACHE_TYPE_PINNED); 1115 GDataCache::CACHE_TYPE_TMP);
1115 EXPECT_EQ(1, num_callback_invocations_); 1116 EXPECT_EQ(1, num_callback_invocations_);
1116 1117
1117 // Unpin a file that doesn't exist in cache and is not pinned, i.e. cache 1118 // Unpin a file that doesn't exist in cache and is not pinned, i.e. cache
1118 // has zero knowledge of the file. 1119 // has zero knowledge of the file.
1119 resource_id = "not-in-cache:1a2b"; 1120 resource_id = "not-in-cache:1a2b";
1120 // Because unpinning will fail, OnCacheUnpinned() won't be run. 1121 // Because unpinning will fail, OnCacheUnpinned() won't be run.
1121 EXPECT_CALL(*mock_sync_client_, OnCacheUnpinned(resource_id, md5)).Times(0); 1122 EXPECT_CALL(*mock_sync_client_, OnCacheUnpinned(resource_id, md5)).Times(0);
1122 1123
1123 num_callback_invocations_ = 0; 1124 num_callback_invocations_ = 0;
1124 TestUnpin(resource_id, md5, base::PLATFORM_FILE_ERROR_NOT_FOUND, 1125 TestUnpin(resource_id, md5, base::PLATFORM_FILE_ERROR_NOT_FOUND,
1125 GDataCache::CACHE_STATE_NONE, 1126 GDataCache::CACHE_STATE_NONE,
1126 GDataCache::CACHE_TYPE_PINNED /* non-applicable */); 1127 GDataCache::CACHE_TYPE_TMP /* non-applicable */);
1127 EXPECT_EQ(1, num_callback_invocations_); 1128 EXPECT_EQ(1, num_callback_invocations_);
1128 } 1129 }
1129 1130
1130 TEST_F(GDataCacheTest, StoreToCachePinned) { 1131 TEST_F(GDataCacheTest, StoreToCachePinned) {
1131 std::string resource_id("pdf:1a2b"); 1132 std::string resource_id("pdf:1a2b");
1132 std::string md5("abcdef0123456789"); 1133 std::string md5("abcdef0123456789");
1133 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); 1134 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1);
1134 1135
1135 // Pin a non-existent file. 1136 // Pin a non-existent file.
1136 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, 1137 TestPin(resource_id, md5, base::PLATFORM_FILE_OK,
1137 GDataCache::CACHE_STATE_PINNED, 1138 GDataCache::CACHE_STATE_PINNED,
1138 GDataCache::CACHE_TYPE_PINNED); 1139 GDataCache::CACHE_TYPE_TMP);
1139 1140
1140 // Store an existing file to a previously pinned file. 1141 // Store an existing file to a previously pinned file.
1141 num_callback_invocations_ = 0; 1142 num_callback_invocations_ = 0;
1142 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1143 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1143 base::PLATFORM_FILE_OK, 1144 base::PLATFORM_FILE_OK,
1144 GDataCache::CACHE_STATE_PRESENT | 1145 GDataCache::CACHE_STATE_PRESENT |
1145 GDataCache::CACHE_STATE_PINNED, 1146 GDataCache::CACHE_STATE_PINNED,
1146 GDataCache::CACHE_TYPE_PERSISTENT); 1147 GDataCache::CACHE_TYPE_PERSISTENT);
1147 EXPECT_EQ(1, num_callback_invocations_); 1148 EXPECT_EQ(1, num_callback_invocations_);
1148 1149
1149 // Store a non-existent file to a previously pinned and stored file. 1150 // Store a non-existent file to a previously pinned and stored file.
1150 num_callback_invocations_ = 0; 1151 num_callback_invocations_ = 0;
1151 TestStoreToCache(resource_id, md5, FilePath("./non_existent.json"), 1152 TestStoreToCache(resource_id, md5, FilePath("./non_existent.json"),
1152 base::PLATFORM_FILE_ERROR_NOT_FOUND, 1153 base::PLATFORM_FILE_ERROR_NOT_FOUND,
1153 GDataCache::CACHE_STATE_PRESENT | 1154 GDataCache::CACHE_STATE_PRESENT |
1154 GDataCache::CACHE_STATE_PINNED, 1155 GDataCache::CACHE_STATE_PINNED,
1155 GDataCache::CACHE_TYPE_PERSISTENT); 1156 GDataCache::CACHE_TYPE_PERSISTENT);
1156 EXPECT_EQ(1, num_callback_invocations_); 1157 EXPECT_EQ(1, num_callback_invocations_);
1157 } 1158 }
1158 1159
1159 TEST_F(GDataCacheTest, GetFromCachePinned) { 1160 TEST_F(GDataCacheTest, GetFromCachePinned) {
1160 std::string resource_id("pdf:1a2b"); 1161 std::string resource_id("pdf:1a2b");
1161 std::string md5("abcdef0123456789"); 1162 std::string md5("abcdef0123456789");
1162 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); 1163 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1);
1163 1164
1164 // Pin a non-existent file. 1165 // Pin a non-existent file.
1165 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, 1166 TestPin(resource_id, md5, base::PLATFORM_FILE_OK,
1166 GDataCache::CACHE_STATE_PINNED, 1167 GDataCache::CACHE_STATE_PINNED,
1167 GDataCache::CACHE_TYPE_PINNED); 1168 GDataCache::CACHE_TYPE_TMP);
1168 1169
1169 // Get the non-existent pinned file from cache. 1170 // Get the non-existent pinned file from cache.
1170 num_callback_invocations_ = 0; 1171 num_callback_invocations_ = 0;
1171 TestGetFileFromCacheByResourceIdAndMd5( 1172 TestGetFileFromCacheByResourceIdAndMd5(
1172 resource_id, md5, base::PLATFORM_FILE_ERROR_NOT_FOUND, md5); 1173 resource_id, md5, base::PLATFORM_FILE_ERROR_NOT_FOUND, md5);
1173 EXPECT_EQ(1, num_callback_invocations_); 1174 EXPECT_EQ(1, num_callback_invocations_);
1174 1175
1175 // Store an existing file to the previously pinned non-existent file. 1176 // Store an existing file to the previously pinned non-existent file.
1176 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1177 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1177 base::PLATFORM_FILE_OK, 1178 base::PLATFORM_FILE_OK,
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 EXPECT_EQ(1, num_callback_invocations_); 1603 EXPECT_EQ(1, num_callback_invocations_);
1603 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); 1604 EXPECT_TRUE(CacheEntryExists(resource_id, md5));
1604 1605
1605 // Try to remove the file. 1606 // Try to remove the file.
1606 num_callback_invocations_ = 0; 1607 num_callback_invocations_ = 0;
1607 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK); 1608 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK);
1608 EXPECT_EQ(1, num_callback_invocations_); 1609 EXPECT_EQ(1, num_callback_invocations_);
1609 } 1610 }
1610 1611
1611 } // namespace gdata 1612 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698