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

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

Issue 10690028: gdata: Get rid of GDataFileSystem::GetCacheState() (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
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
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 <errno.h> 5 #include <errno.h>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 io_thread_(content::BrowserThread::IO), 204 io_thread_(content::BrowserThread::IO),
205 sequence_token_( 205 sequence_token_(
206 content::BrowserThread::GetBlockingPool()->GetSequenceToken()), 206 content::BrowserThread::GetBlockingPool()->GetSequenceToken()),
207 cache_(NULL), 207 cache_(NULL),
208 file_system_(NULL), 208 file_system_(NULL),
209 mock_doc_service_(NULL), 209 mock_doc_service_(NULL),
210 num_callback_invocations_(0), 210 num_callback_invocations_(0),
211 expected_error_(base::PLATFORM_FILE_OK), 211 expected_error_(base::PLATFORM_FILE_OK),
212 expected_cache_state_(0), 212 expected_cache_state_(0),
213 expected_sub_dir_type_(GDataCache::CACHE_TYPE_META), 213 expected_sub_dir_type_(GDataCache::CACHE_TYPE_META),
214 expected_success_(true),
214 expect_outgoing_symlink_(false), 215 expect_outgoing_symlink_(false),
215 root_feed_changestamp_(0) { 216 root_feed_changestamp_(0) {
216 } 217 }
217 218
218 virtual void SetUp() OVERRIDE { 219 virtual void SetUp() OVERRIDE {
219 chromeos::CrosLibrary::Initialize(true /* use_stub */); 220 chromeos::CrosLibrary::Initialize(true /* use_stub */);
220 io_thread_.StartIOThread(); 221 io_thread_.StartIOThread();
221 222
222 profile_.reset(new TestingProfile); 223 profile_.reset(new TestingProfile);
223 224
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 725
725 cache_->UnpinOnUIThread( 726 cache_->UnpinOnUIThread(
726 resource_id, md5, 727 resource_id, md5,
727 base::Bind(&GDataFileSystemTest::VerifyCacheFileState, 728 base::Bind(&GDataFileSystemTest::VerifyCacheFileState,
728 base::Unretained(this))); 729 base::Unretained(this)));
729 730
730 RunAllPendingForIO(); // Post Unpin() to blocking pool. 731 RunAllPendingForIO(); // Post Unpin() to blocking pool.
731 RunAllPendingForIO(); // Post FreeDiskSpaceIfNeededFor to blocking pool. 732 RunAllPendingForIO(); // Post FreeDiskSpaceIfNeededFor to blocking pool.
732 } 733 }
733 734
734 void TestGetCacheState(const std::string& resource_id, const std::string& md5, 735 void TestGetCacheState(const std::string& resource_id,
735 base::PlatformFileError expected_error, 736 const std::string& md5,
736 int expected_cache_state, GDataFile* expected_file) { 737 bool expected_success,
737 expected_error_ = expected_error; 738 int expected_cache_state,
739 GDataFile* expected_file) {
740 expected_success_ = expected_success;
738 expected_cache_state_ = expected_cache_state; 741 expected_cache_state_ = expected_cache_state;
739 742
740 file_system_->GetCacheState(resource_id, md5, 743 cache_->GetCacheEntryOnUIThread(resource_id, md5,
741 base::Bind(&GDataFileSystemTest::VerifyGetCacheState, 744 base::Bind(&GDataFileSystemTest::VerifyGetCacheState,
742 base::Unretained(this))); 745 base::Unretained(this)));
743 746
744 RunAllPendingForIO(); 747 RunAllPendingForIO();
745 } 748 }
746 749
747 void VerifyGetCacheState(base::PlatformFileError error, int cache_state) { 750 void VerifyGetCacheState(bool success,
751 const GDataCache::CacheEntry& cache_entry) {
748 ++num_callback_invocations_; 752 ++num_callback_invocations_;
749 753
750 EXPECT_EQ(expected_error_, error); 754 EXPECT_EQ(expected_success_, success);
751 755
752 if (error == base::PLATFORM_FILE_OK) { 756 if (success) {
753 EXPECT_EQ(expected_cache_state_, cache_state); 757 EXPECT_EQ(expected_cache_state_, cache_entry.cache_state);
754 } 758 }
755 } 759 }
756 760
757 void TestMarkDirty( 761 void TestMarkDirty(
758 const std::string& resource_id, 762 const std::string& resource_id,
759 const std::string& md5, 763 const std::string& md5,
760 base::PlatformFileError expected_error, 764 base::PlatformFileError expected_error,
761 int expected_cache_state, 765 int expected_cache_state,
762 GDataCache::CacheSubDirectoryType expected_sub_dir_type) { 766 GDataCache::CacheSubDirectoryType expected_sub_dir_type) {
763 expected_error_ = expected_error; 767 expected_error_ = expected_error;
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 GDataFileSystem* file_system_; 1324 GDataFileSystem* file_system_;
1321 MockDocumentsService* mock_doc_service_; 1325 MockDocumentsService* mock_doc_service_;
1322 MockFreeDiskSpaceGetter* mock_free_disk_space_checker_; 1326 MockFreeDiskSpaceGetter* mock_free_disk_space_checker_;
1323 scoped_ptr<StrictMock<MockGDataSyncClient> > mock_sync_client_; 1327 scoped_ptr<StrictMock<MockGDataSyncClient> > mock_sync_client_;
1324 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; 1328 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_;
1325 1329
1326 int num_callback_invocations_; 1330 int num_callback_invocations_;
1327 base::PlatformFileError expected_error_; 1331 base::PlatformFileError expected_error_;
1328 int expected_cache_state_; 1332 int expected_cache_state_;
1329 GDataCache::CacheSubDirectoryType expected_sub_dir_type_; 1333 GDataCache::CacheSubDirectoryType expected_sub_dir_type_;
1334 bool expected_success_;
1330 bool expect_outgoing_symlink_; 1335 bool expect_outgoing_symlink_;
1331 std::string expected_file_extension_; 1336 std::string expected_file_extension_;
1332 int root_feed_changestamp_; 1337 int root_feed_changestamp_;
1333 static bool cros_initialized_; 1338 static bool cros_initialized_;
1334 }; 1339 };
1335 1340
1336 bool GDataFileSystemTest::cros_initialized_ = false; 1341 bool GDataFileSystemTest::cros_initialized_ = false;
1337 1342
1338 void AsyncInitializationCallback( 1343 void AsyncInitializationCallback(
1339 int* counter, 1344 int* counter,
(...skipping 1623 matching lines...) Expand 10 before | Expand all | Expand 10 after
2963 std::string resource_id = file->resource_id(); 2968 std::string resource_id = file->resource_id();
2964 std::string md5 = file->file_md5(); 2969 std::string md5 = file->file_md5();
2965 2970
2966 // Store a file corresponding to |resource_id| and |md5| to cache. 2971 // Store a file corresponding to |resource_id| and |md5| to cache.
2967 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 2972 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
2968 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, 2973 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT,
2969 GDataCache::CACHE_TYPE_TMP); 2974 GDataCache::CACHE_TYPE_TMP);
2970 2975
2971 // Get its cache state. 2976 // Get its cache state.
2972 num_callback_invocations_ = 0; 2977 num_callback_invocations_ = 0;
2973 TestGetCacheState(resource_id, md5, base::PLATFORM_FILE_OK, 2978 TestGetCacheState(resource_id, md5, true,
2974 GDataCache::CACHE_STATE_PRESENT, file); 2979 GDataCache::CACHE_STATE_PRESENT, file);
2975 EXPECT_EQ(1, num_callback_invocations_); 2980 EXPECT_EQ(1, num_callback_invocations_);
2976 } 2981 }
2977 2982
2978 { // Test cache state of an existing pinned file. 2983 { // Test cache state of an existing pinned file.
2979 // Retrieve resource id and md5 of a file from file system. 2984 // Retrieve resource id and md5 of a file from file system.
2980 FilePath file_path( 2985 FilePath file_path(
2981 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); 2986 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt"));
2982 GDataEntry* entry = FindEntry(file_path); 2987 GDataEntry* entry = FindEntry(file_path);
2983 ASSERT_TRUE(entry != NULL); 2988 ASSERT_TRUE(entry != NULL);
2984 GDataFile* file = entry->AsGDataFile(); 2989 GDataFile* file = entry->AsGDataFile();
2985 ASSERT_TRUE(file != NULL); 2990 ASSERT_TRUE(file != NULL);
2986 std::string resource_id = file->resource_id(); 2991 std::string resource_id = file->resource_id();
2987 std::string md5 = file->file_md5(); 2992 std::string md5 = file->file_md5();
2988 2993
2989 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1); 2994 EXPECT_CALL(*mock_sync_client_, OnCachePinned(resource_id, md5)).Times(1);
2990 2995
2991 // Store a file corresponding to |resource_id| and |md5| to cache, and pin 2996 // Store a file corresponding to |resource_id| and |md5| to cache, and pin
2992 // it. 2997 // it.
2993 int expected_cache_state = GDataCache::CACHE_STATE_PRESENT | 2998 int expected_cache_state = GDataCache::CACHE_STATE_PRESENT |
2994 GDataCache::CACHE_STATE_PINNED; 2999 GDataCache::CACHE_STATE_PINNED;
2995 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 3000 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
2996 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, 3001 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT,
2997 GDataCache::CACHE_TYPE_TMP); 3002 GDataCache::CACHE_TYPE_TMP);
2998 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, expected_cache_state, 3003 TestPin(resource_id, md5, base::PLATFORM_FILE_OK, expected_cache_state,
2999 GDataCache::CACHE_TYPE_PERSISTENT); 3004 GDataCache::CACHE_TYPE_PERSISTENT);
3000 3005
3001 // Get its cache state. 3006 // Get its cache state.
3002 num_callback_invocations_ = 0; 3007 num_callback_invocations_ = 0;
3003 TestGetCacheState(resource_id, md5, base::PLATFORM_FILE_OK, 3008 TestGetCacheState(resource_id, md5, true,
3004 expected_cache_state, file); 3009 expected_cache_state, file);
3005 EXPECT_EQ(1, num_callback_invocations_); 3010 EXPECT_EQ(1, num_callback_invocations_);
3006 } 3011 }
3007 3012
3008 { // Test cache state of a non-existent file. 3013 { // Test cache state of a non-existent file.
3009 num_callback_invocations_ = 0; 3014 num_callback_invocations_ = 0;
3010 TestGetCacheState("pdf:12345", "abcd", base::PLATFORM_FILE_ERROR_NOT_FOUND, 3015 TestGetCacheState("pdf:12345", "abcd", false,
3011 0, NULL); 3016 0, NULL);
3012 EXPECT_EQ(1, num_callback_invocations_); 3017 EXPECT_EQ(1, num_callback_invocations_);
3013 } 3018 }
3014 } 3019 }
3015 3020
3016 TEST_F(GDataFileSystemTest, InitializeCache) { 3021 TEST_F(GDataFileSystemTest, InitializeCache) {
3017 PrepareForInitCacheTest(); 3022 PrepareForInitCacheTest();
3018 TestInitializeCache(); 3023 TestInitializeCache();
3019 } 3024 }
3020 3025
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
3693 3698
3694 // Try to close the same file twice. 3699 // Try to close the same file twice.
3695 file_system_->CloseFile(kFileInRoot, close_file_callback); 3700 file_system_->CloseFile(kFileInRoot, close_file_callback);
3696 message_loop_.Run(); 3701 message_loop_.Run();
3697 3702
3698 // It must fail. 3703 // It must fail.
3699 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); 3704 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_);
3700 } 3705 }
3701 3706
3702 } // namespace gdata 3707 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698