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

Side by Side Diff: trunk/src/chrome/browser/chromeos/drive/file_cache_unittest.cc

Issue 14824006: Revert 198820 "Move FileEnumerator to its own file, do some refa..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 7 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 "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"
11 #include "base/files/file_enumerator.h"
12 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
13 #include "base/message_loop.h" 12 #include "base/message_loop.h"
14 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
15 #include "chrome/browser/chromeos/drive/drive.pb.h" 14 #include "chrome/browser/chromeos/drive/drive.pb.h"
16 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" 15 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h"
17 #include "chrome/browser/chromeos/drive/file_system_util.h" 16 #include "chrome/browser/chromeos/drive/file_system_util.h"
18 #include "chrome/browser/chromeos/drive/mock_file_cache_observer.h" 17 #include "chrome/browser/chromeos/drive/mock_file_cache_observer.h"
19 #include "chrome/browser/chromeos/drive/test_util.h" 18 #include "chrome/browser/chromeos/drive/test_util.h"
20 #include "chrome/browser/google_apis/test_util.h" 19 #include "chrome/browser/google_apis/test_util.h"
21 #include "content/public/test/test_browser_thread.h" 20 #include "content/public/test/test_browser_thread.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 paths_to_verify.push_back( // Index 1: CACHE_TYPE_PERSISTENT. 278 paths_to_verify.push_back( // Index 1: CACHE_TYPE_PERSISTENT.
280 PathToVerify(cache_->GetCacheFilePath(resource_id, "*", 279 PathToVerify(cache_->GetCacheFilePath(resource_id, "*",
281 FileCache::CACHE_TYPE_PERSISTENT, 280 FileCache::CACHE_TYPE_PERSISTENT,
282 FileCache::CACHED_FILE_FROM_SERVER), base::FilePath())); 281 FileCache::CACHED_FILE_FROM_SERVER), base::FilePath()));
283 paths_to_verify.push_back( // Index 2: CACHE_TYPE_OUTGOING. 282 paths_to_verify.push_back( // Index 2: CACHE_TYPE_OUTGOING.
284 PathToVerify(cache_->GetCacheFilePath(resource_id, "", 283 PathToVerify(cache_->GetCacheFilePath(resource_id, "",
285 FileCache::CACHE_TYPE_OUTGOING, 284 FileCache::CACHE_TYPE_OUTGOING,
286 FileCache::CACHED_FILE_FROM_SERVER), base::FilePath())); 285 FileCache::CACHED_FILE_FROM_SERVER), base::FilePath()));
287 if (!cache_entry_found) { 286 if (!cache_entry_found) {
288 for (size_t i = 0; i < paths_to_verify.size(); ++i) { 287 for (size_t i = 0; i < paths_to_verify.size(); ++i) {
289 base::FileEnumerator enumerator( 288 file_util::FileEnumerator enumerator(
290 paths_to_verify[i].path_to_scan.DirName(), false /* not recursive*/, 289 paths_to_verify[i].path_to_scan.DirName(), false /* not recursive*/,
291 base::FileEnumerator::FILES | base::FileEnumerator::SHOW_SYM_LINKS, 290 file_util::FileEnumerator::FILES |
291 file_util::FileEnumerator::SHOW_SYM_LINKS,
292 paths_to_verify[i].path_to_scan.BaseName().value()); 292 paths_to_verify[i].path_to_scan.BaseName().value());
293 EXPECT_TRUE(enumerator.Next().empty()); 293 EXPECT_TRUE(enumerator.Next().empty());
294 } 294 }
295 } else { 295 } else {
296 // Entry is dirty, verify that: 296 // Entry is dirty, verify that:
297 // - no files with "<resource_id>.*" exist in tmp dir 297 // - no files with "<resource_id>.*" exist in tmp dir
298 // - only 1 "<resource_id>.local" exists in persistent dir 298 // - only 1 "<resource_id>.local" exists in persistent dir
299 // - only 1 <resource_id> exists in outgoing dir 299 // - only 1 <resource_id> exists in outgoing dir
300 // - if entry is pinned, only 1 <resource_id> exists in pinned dir. 300 // - if entry is pinned, only 1 <resource_id> exists in pinned dir.
301 301
302 // Change expected_existing_path of CACHE_TYPE_PERSISTENT (index 1). 302 // Change expected_existing_path of CACHE_TYPE_PERSISTENT (index 1).
303 paths_to_verify[1].expected_existing_path = 303 paths_to_verify[1].expected_existing_path =
304 GetCacheFilePath(resource_id, 304 GetCacheFilePath(resource_id,
305 std::string(), 305 std::string(),
306 FileCache::CACHE_TYPE_PERSISTENT, 306 FileCache::CACHE_TYPE_PERSISTENT,
307 FileCache::CACHED_FILE_LOCALLY_MODIFIED); 307 FileCache::CACHED_FILE_LOCALLY_MODIFIED);
308 308
309 // Change expected_existing_path of CACHE_TYPE_OUTGOING (index 2). 309 // Change expected_existing_path of CACHE_TYPE_OUTGOING (index 2).
310 paths_to_verify[2].expected_existing_path = 310 paths_to_verify[2].expected_existing_path =
311 GetCacheFilePath(resource_id, 311 GetCacheFilePath(resource_id,
312 std::string(), 312 std::string(),
313 FileCache::CACHE_TYPE_OUTGOING, 313 FileCache::CACHE_TYPE_OUTGOING,
314 FileCache::CACHED_FILE_FROM_SERVER); 314 FileCache::CACHED_FILE_FROM_SERVER);
315 315
316 for (size_t i = 0; i < paths_to_verify.size(); ++i) { 316 for (size_t i = 0; i < paths_to_verify.size(); ++i) {
317 const struct PathToVerify& verify = paths_to_verify[i]; 317 const struct PathToVerify& verify = paths_to_verify[i];
318 base::FileEnumerator enumerator( 318 file_util::FileEnumerator enumerator(
319 verify.path_to_scan.DirName(), false /* not recursive */, 319 verify.path_to_scan.DirName(), false /* not recursive */,
320 base::FileEnumerator::FILES | base::FileEnumerator::SHOW_SYM_LINKS, 320 file_util::FileEnumerator::FILES |
321 file_util::FileEnumerator::SHOW_SYM_LINKS,
321 verify.path_to_scan.BaseName().value()); 322 verify.path_to_scan.BaseName().value());
322 size_t num_files_found = 0; 323 size_t num_files_found = 0;
323 for (base::FilePath current = enumerator.Next(); !current.empty(); 324 for (base::FilePath current = enumerator.Next(); !current.empty();
324 current = enumerator.Next()) { 325 current = enumerator.Next()) {
325 ++num_files_found; 326 ++num_files_found;
326 EXPECT_EQ(verify.expected_existing_path, current); 327 EXPECT_EQ(verify.expected_existing_path, current);
327 } 328 }
328 if (verify.expected_existing_path.empty()) 329 if (verify.expected_existing_path.empty())
329 EXPECT_EQ(0U, num_files_found); 330 EXPECT_EQ(0U, num_files_found);
330 else 331 else
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 // Returns the number of the cache files with name <resource_id>, and Confirm 614 // Returns the number of the cache files with name <resource_id>, and Confirm
614 // that they have the <md5>. This should return 1 or 0. 615 // that they have the <md5>. This should return 1 or 0.
615 size_t CountCacheFiles(const std::string& resource_id, 616 size_t CountCacheFiles(const std::string& resource_id,
616 const std::string& md5) { 617 const std::string& md5) {
617 base::FilePath path = GetCacheFilePath( 618 base::FilePath path = GetCacheFilePath(
618 resource_id, "*", 619 resource_id, "*",
619 (test_util::ToCacheEntry(expected_cache_state_).is_pinned() ? 620 (test_util::ToCacheEntry(expected_cache_state_).is_pinned() ?
620 FileCache::CACHE_TYPE_PERSISTENT : 621 FileCache::CACHE_TYPE_PERSISTENT :
621 FileCache::CACHE_TYPE_TMP), 622 FileCache::CACHE_TYPE_TMP),
622 FileCache::CACHED_FILE_FROM_SERVER); 623 FileCache::CACHED_FILE_FROM_SERVER);
623 base::FileEnumerator enumerator(path.DirName(), false, 624 file_util::FileEnumerator enumerator(path.DirName(), false,
624 base::FileEnumerator::FILES, 625 file_util::FileEnumerator::FILES,
625 path.BaseName().value()); 626 path.BaseName().value());
626 size_t num_files_found = 0; 627 size_t num_files_found = 0;
627 for (base::FilePath current = enumerator.Next(); !current.empty(); 628 for (base::FilePath current = enumerator.Next(); !current.empty();
628 current = enumerator.Next()) { 629 current = enumerator.Next()) {
629 ++num_files_found; 630 ++num_files_found;
630 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + 631 EXPECT_EQ(util::EscapeCacheFileName(resource_id) +
631 base::FilePath::kExtensionSeparator + 632 base::FilePath::kExtensionSeparator +
632 util::EscapeCacheFileName(md5), 633 util::EscapeCacheFileName(md5),
633 current.BaseName().value()); 634 current.BaseName().value());
634 } 635 }
635 return num_files_found; 636 return num_files_found;
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 google_apis::test_util::GetTestFilePath("chromeos/gdata/empty_feed.json"), 1405 google_apis::test_util::GetTestFilePath("chromeos/gdata/empty_feed.json"),
1405 FILE_ERROR_OK, 1406 FILE_ERROR_OK,
1406 test_util::TEST_CACHE_STATE_PRESENT | 1407 test_util::TEST_CACHE_STATE_PRESENT |
1407 test_util::TEST_CACHE_STATE_PINNED | 1408 test_util::TEST_CACHE_STATE_PINNED |
1408 test_util::TEST_CACHE_STATE_PERSISTENT, 1409 test_util::TEST_CACHE_STATE_PERSISTENT,
1409 FileCache::CACHE_TYPE_PERSISTENT); 1410 FileCache::CACHE_TYPE_PERSISTENT);
1410 } 1411 }
1411 1412
1412 } // namespace internal 1413 } // namespace internal
1413 } // namespace drive 1414 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698