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

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

Issue 10836354: Rename GData* to Drive* in gdata.proto (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for comments. Created 8 years, 4 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/threading/sequenced_worker_pool.h" 11 #include "base/threading/sequenced_worker_pool.h"
12 #include "chrome/browser/chromeos/gdata/gdata.pb.h" 12 #include "chrome/browser/chromeos/gdata/drive.pb.h"
13 #include "chrome/browser/chromeos/gdata/gdata_cache.h" 13 #include "chrome/browser/chromeos/gdata/gdata_cache.h"
14 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 14 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
15 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" 15 #include "chrome/browser/chromeos/gdata/gdata_test_util.h"
16 #include "chrome/browser/chromeos/gdata/gdata_util.h" 16 #include "chrome/browser/chromeos/gdata/gdata_util.h"
17 #include "chrome/browser/chromeos/gdata/mock_gdata_cache_observer.h" 17 #include "chrome/browser/chromeos/gdata/mock_gdata_cache_observer.h"
18 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
19 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
20 #include "content/public/test/test_browser_thread.h" 20 #include "content/public/test/test_browser_thread.h"
21 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 test_util::ToCacheEntry(resource.cache_state).is_present() ? 250 test_util::ToCacheEntry(resource.cache_state).is_present() ?
251 GDATA_FILE_OK : 251 GDATA_FILE_OK :
252 GDATA_FILE_ERROR_NOT_FOUND, 252 GDATA_FILE_ERROR_NOT_FOUND,
253 resource.expected_file_extension); 253 resource.expected_file_extension);
254 EXPECT_EQ(1, num_callback_invocations_); 254 EXPECT_EQ(1, num_callback_invocations_);
255 255
256 // Verify cache state. 256 // Verify cache state.
257 std::string md5; 257 std::string md5;
258 if (test_util::ToCacheEntry(resource.cache_state).is_present()) 258 if (test_util::ToCacheEntry(resource.cache_state).is_present())
259 md5 = resource.md5; 259 md5 = resource.md5;
260 GDataCacheEntry cache_entry; 260 DriveCacheEntry cache_entry;
261 ASSERT_TRUE(GetCacheEntryFromOriginThread( 261 ASSERT_TRUE(GetCacheEntryFromOriginThread(
262 resource.resource_id, md5, &cache_entry)); 262 resource.resource_id, md5, &cache_entry));
263 EXPECT_TRUE(test_util::CacheStatesEqual( 263 EXPECT_TRUE(test_util::CacheStatesEqual(
264 test_util::ToCacheEntry(resource.cache_state), 264 test_util::ToCacheEntry(resource.cache_state),
265 cache_entry)); 265 cache_entry));
266 EXPECT_EQ(resource.expected_sub_dir_type, 266 EXPECT_EQ(resource.expected_sub_dir_type,
267 GDataCache::GetSubDirectoryType(cache_entry)); 267 GDataCache::GetSubDirectoryType(cache_entry));
268 } 268 }
269 } 269 }
270 270
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 } 339 }
340 340
341 void VerifyRemoveFromCache(GDataFileError error, 341 void VerifyRemoveFromCache(GDataFileError error,
342 const std::string& resource_id, 342 const std::string& resource_id,
343 const std::string& md5) { 343 const std::string& md5) {
344 ++num_callback_invocations_; 344 ++num_callback_invocations_;
345 345
346 EXPECT_EQ(expected_error_, error); 346 EXPECT_EQ(expected_error_, error);
347 347
348 // Verify cache map. 348 // Verify cache map.
349 GDataCacheEntry cache_entry; 349 DriveCacheEntry cache_entry;
350 const bool cache_entry_found = 350 const bool cache_entry_found =
351 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); 351 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry);
352 if (cache_entry_found) 352 if (cache_entry_found)
353 EXPECT_TRUE(cache_entry.is_dirty()); 353 EXPECT_TRUE(cache_entry.is_dirty());
354 354
355 // If entry doesn't exist, verify that: 355 // If entry doesn't exist, verify that:
356 // - no files with "<resource_id>.* exists in persistent and tmp dirs 356 // - no files with "<resource_id>.* exists in persistent and tmp dirs
357 // - no "<resource_id>" symlink exists in pinned and outgoing dirs. 357 // - no "<resource_id>" symlink exists in pinned and outgoing dirs.
358 std::vector<PathToVerify> paths_to_verify; 358 std::vector<PathToVerify> paths_to_verify;
359 paths_to_verify.push_back( // Index 0: CACHE_TYPE_TMP. 359 paths_to_verify.push_back( // Index 0: CACHE_TYPE_TMP.
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 } 580 }
581 581
582 void VerifyCacheFileState(GDataFileError error, 582 void VerifyCacheFileState(GDataFileError error,
583 const std::string& resource_id, 583 const std::string& resource_id,
584 const std::string& md5) { 584 const std::string& md5) {
585 ++num_callback_invocations_; 585 ++num_callback_invocations_;
586 586
587 EXPECT_EQ(expected_error_, error); 587 EXPECT_EQ(expected_error_, error);
588 588
589 // Verify cache map. 589 // Verify cache map.
590 GDataCacheEntry cache_entry; 590 DriveCacheEntry cache_entry;
591 const bool cache_entry_found = 591 const bool cache_entry_found =
592 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); 592 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry);
593 if (test_util::ToCacheEntry(expected_cache_state_).is_present() || 593 if (test_util::ToCacheEntry(expected_cache_state_).is_present() ||
594 test_util::ToCacheEntry(expected_cache_state_).is_pinned()) { 594 test_util::ToCacheEntry(expected_cache_state_).is_pinned()) {
595 ASSERT_TRUE(cache_entry_found); 595 ASSERT_TRUE(cache_entry_found);
596 EXPECT_TRUE(test_util::CacheStatesEqual( 596 EXPECT_TRUE(test_util::CacheStatesEqual(
597 test_util::ToCacheEntry(expected_cache_state_), 597 test_util::ToCacheEntry(expected_cache_state_),
598 cache_entry)); 598 cache_entry));
599 EXPECT_EQ(expected_sub_dir_type_, 599 EXPECT_EQ(expected_sub_dir_type_,
600 GDataCache::GetSubDirectoryType(cache_entry)); 600 GDataCache::GetSubDirectoryType(cache_entry));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 const std::string& md5, 664 const std::string& md5,
665 GDataCache::CacheSubDirectoryType sub_dir_type, 665 GDataCache::CacheSubDirectoryType sub_dir_type,
666 GDataCache::CachedFileOrigin file_origin) { 666 GDataCache::CachedFileOrigin file_origin) {
667 return cache_->GetCacheFilePath(resource_id, md5, sub_dir_type, 667 return cache_->GetCacheFilePath(resource_id, md5, sub_dir_type,
668 file_origin); 668 file_origin);
669 } 669 }
670 670
671 // Helper function to call GetCacheEntry from origin thread. 671 // Helper function to call GetCacheEntry from origin thread.
672 bool GetCacheEntryFromOriginThread(const std::string& resource_id, 672 bool GetCacheEntryFromOriginThread(const std::string& resource_id,
673 const std::string& md5, 673 const std::string& md5,
674 GDataCacheEntry* cache_entry) { 674 DriveCacheEntry* cache_entry) {
675 bool result = false; 675 bool result = false;
676 blocking_task_runner_->PostTask( 676 blocking_task_runner_->PostTask(
677 FROM_HERE, 677 FROM_HERE,
678 base::Bind(&GDataCacheTest::GetCacheEntryFromOriginThreadInternal, 678 base::Bind(&GDataCacheTest::GetCacheEntryFromOriginThreadInternal,
679 base::Unretained(this), 679 base::Unretained(this),
680 resource_id, 680 resource_id,
681 md5, 681 md5,
682 cache_entry, 682 cache_entry,
683 &result)); 683 &result));
684 test_util::RunBlockingPoolTask(); 684 test_util::RunBlockingPoolTask();
685 return result; 685 return result;
686 } 686 }
687 687
688 // Used to implement GetCacheEntry. 688 // Used to implement GetCacheEntry.
689 void GetCacheEntryFromOriginThreadInternal( 689 void GetCacheEntryFromOriginThreadInternal(
690 const std::string& resource_id, 690 const std::string& resource_id,
691 const std::string& md5, 691 const std::string& md5,
692 GDataCacheEntry* cache_entry, 692 DriveCacheEntry* cache_entry,
693 bool* result) { 693 bool* result) {
694 *result = cache_->GetCacheEntry(resource_id, md5, cache_entry); 694 *result = cache_->GetCacheEntry(resource_id, md5, cache_entry);
695 } 695 }
696 696
697 // Returns true if the cache entry exists for the given resource ID and MD5. 697 // Returns true if the cache entry exists for the given resource ID and MD5.
698 bool CacheEntryExists(const std::string& resource_id, 698 bool CacheEntryExists(const std::string& resource_id,
699 const std::string& md5) { 699 const std::string& md5) {
700 GDataCacheEntry cache_entry; 700 DriveCacheEntry cache_entry;
701 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); 701 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry);
702 } 702 }
703 703
704 void TestGetCacheFilePath(const std::string& resource_id, 704 void TestGetCacheFilePath(const std::string& resource_id,
705 const std::string& md5, 705 const std::string& md5,
706 const std::string& expected_filename) { 706 const std::string& expected_filename) {
707 FilePath actual_path = cache_->GetCacheFilePath( 707 FilePath actual_path = cache_->GetCacheFilePath(
708 resource_id, 708 resource_id,
709 md5, 709 md5,
710 GDataCache::CACHE_TYPE_TMP, 710 GDataCache::CACHE_TYPE_TMP,
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 test_util::TEST_CACHE_STATE_NONE, 1558 test_util::TEST_CACHE_STATE_NONE,
1559 GDataCache::CACHE_TYPE_TMP); 1559 GDataCache::CACHE_TYPE_TMP);
1560 EXPECT_EQ(1, num_callback_invocations_); 1560 EXPECT_EQ(1, num_callback_invocations_);
1561 1561
1562 // Verify that there's no files added. 1562 // Verify that there's no files added.
1563 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5)); 1563 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5));
1564 } 1564 }
1565 1565
1566 1566
1567 } // namespace gdata 1567 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698