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 <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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 public: | 159 public: |
160 virtual ~MockFreeDiskSpaceGetter() {} | 160 virtual ~MockFreeDiskSpaceGetter() {} |
161 MOCK_CONST_METHOD0(AmountOfFreeDiskSpace, int64()); | 161 MOCK_CONST_METHOD0(AmountOfFreeDiskSpace, int64()); |
162 }; | 162 }; |
163 | 163 |
164 class GDataFileSystemTest : public testing::Test { | 164 class GDataFileSystemTest : public testing::Test { |
165 protected: | 165 protected: |
166 GDataFileSystemTest() | 166 GDataFileSystemTest() |
167 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 167 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
168 io_thread_(content::BrowserThread::IO), | 168 io_thread_(content::BrowserThread::IO), |
| 169 sequence_token_( |
| 170 content::BrowserThread::GetBlockingPool()->GetSequenceToken()), |
169 file_system_(NULL), | 171 file_system_(NULL), |
170 mock_doc_service_(NULL), | 172 mock_doc_service_(NULL), |
171 num_callback_invocations_(0), | 173 num_callback_invocations_(0), |
172 expected_error_(base::PLATFORM_FILE_OK), | 174 expected_error_(base::PLATFORM_FILE_OK), |
173 expected_cache_state_(0), | 175 expected_cache_state_(0), |
174 expected_sub_dir_type_(GDataCache::CACHE_TYPE_META), | 176 expected_sub_dir_type_(GDataCache::CACHE_TYPE_META), |
175 expect_outgoing_symlink_(false), | 177 expect_outgoing_symlink_(false), |
176 root_feed_changestamp_(0) { | 178 root_feed_changestamp_(0) { |
177 } | 179 } |
178 | 180 |
179 virtual void SetUp() OVERRIDE { | 181 virtual void SetUp() OVERRIDE { |
180 chromeos::CrosLibrary::Initialize(true /* use_stub */); | 182 chromeos::CrosLibrary::Initialize(true /* use_stub */); |
181 io_thread_.StartIOThread(); | 183 io_thread_.StartIOThread(); |
182 | 184 |
183 profile_.reset(new TestingProfile); | 185 profile_.reset(new TestingProfile); |
184 | 186 |
185 callback_helper_ = new CallbackHelper; | 187 callback_helper_ = new CallbackHelper; |
186 | 188 |
187 // Allocate and keep a pointer to the mock, and inject it into the | 189 // Allocate and keep a pointer to the mock, and inject it into the |
188 // GDataFileSystem object, which will own the mock object. | 190 // GDataFileSystem object, which will own the mock object. |
189 mock_doc_service_ = new MockDocumentsService; | 191 mock_doc_service_ = new MockDocumentsService; |
190 | 192 |
191 EXPECT_CALL(*mock_doc_service_, Initialize(profile_.get())).Times(1); | 193 EXPECT_CALL(*mock_doc_service_, Initialize(profile_.get())).Times(1); |
192 | 194 |
193 // Likewise, this will be owned by GDataFileSystem. | 195 // Likewise, this will be owned by GDataFileSystem. |
194 mock_free_disk_space_checker_ = new MockFreeDiskSpaceGetter; | 196 mock_free_disk_space_checker_ = new MockFreeDiskSpaceGetter; |
195 SetFreeDiskSpaceGetterForTesting(mock_free_disk_space_checker_); | 197 SetFreeDiskSpaceGetterForTesting(mock_free_disk_space_checker_); |
196 | 198 |
| 199 cache_.reset(GDataCache::CreateGDataCache( |
| 200 GDataCache::GetCacheRootPath(profile_.get()), |
| 201 content::BrowserThread::GetBlockingPool(), |
| 202 sequence_token_).release()); |
| 203 |
197 ASSERT_FALSE(file_system_); | 204 ASSERT_FALSE(file_system_); |
198 file_system_ = new GDataFileSystem(profile_.get(), | 205 file_system_ = new GDataFileSystem(profile_.get(), |
199 mock_doc_service_); | 206 cache_.get(), |
| 207 mock_doc_service_, |
| 208 sequence_token_); |
200 | 209 |
201 mock_sync_client_.reset(new StrictMock<MockGDataSyncClient>); | 210 mock_sync_client_.reset(new StrictMock<MockGDataSyncClient>); |
202 file_system_->AddObserver(mock_sync_client_.get()); | 211 file_system_->AddObserver(mock_sync_client_.get()); |
203 | 212 |
204 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>); | 213 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>); |
205 file_system_->AddObserver(mock_directory_observer_.get()); | 214 file_system_->AddObserver(mock_directory_observer_.get()); |
206 | 215 |
207 file_system_->Initialize(); | 216 file_system_->Initialize(); |
208 // Initialize() initiates the cache initialization on the blocking thread | 217 // Initialize() initiates the cache initialization on the blocking thread |
209 // pool. Block until it's done to ensure that the cache initialization is | 218 // pool. Block until it's done to ensure that the cache initialization is |
210 // done for every test. Otherwise, completion timing is nondeterministic. | 219 // done for every test. Otherwise, completion timing is nondeterministic. |
211 EXPECT_CALL(*mock_sync_client_, OnCacheInitialized()).Times(1); | 220 EXPECT_CALL(*mock_sync_client_, OnCacheInitialized()).Times(1); |
212 RunAllPendingForIO(); | 221 RunAllPendingForIO(); |
213 } | 222 } |
214 | 223 |
215 virtual void TearDown() OVERRIDE { | 224 virtual void TearDown() OVERRIDE { |
216 ASSERT_TRUE(file_system_); | 225 ASSERT_TRUE(file_system_); |
217 EXPECT_CALL(*mock_doc_service_, CancelAll()).Times(1); | 226 EXPECT_CALL(*mock_doc_service_, CancelAll()).Times(1); |
218 delete file_system_; | 227 delete file_system_; |
219 file_system_ = NULL; | 228 file_system_ = NULL; |
220 delete mock_doc_service_; | 229 delete mock_doc_service_; |
221 mock_doc_service_ = NULL; | 230 mock_doc_service_ = NULL; |
222 SetFreeDiskSpaceGetterForTesting(NULL); | 231 SetFreeDiskSpaceGetterForTesting(NULL); |
| 232 content::BrowserThread::GetBlockingPool() |
| 233 ->GetSequencedTaskRunner(sequence_token_)->PostTask( |
| 234 FROM_HERE, |
| 235 base::Bind(&base::DeletePointer<GDataCache>, cache_.release())); |
223 | 236 |
224 // Run the remaining tasks on both the main thread and the IO thread, so | 237 // Run the remaining tasks on both the main thread and the IO thread, so |
225 // that all PostTaskAndReply round trip finish (that is, both the 1st and | 238 // that all PostTaskAndReply round trip finish (that is, both the 1st and |
226 // the 2nd callbacks of PostTaskAndReply are run). Otherwise, there will be | 239 // the 2nd callbacks of PostTaskAndReply are run). Otherwise, there will be |
227 // a leak from PostTaskAndReply() as it deletes an internal object when the | 240 // a leak from PostTaskAndReply() as it deletes an internal object when the |
228 // reply task is run. Note that actual reply tasks on the file system will | 241 // reply task is run. Note that actual reply tasks on the file system will |
229 // be canceled, as these are bound to weak pointers, which are invalidated | 242 // be canceled, as these are bound to weak pointers, which are invalidated |
230 // in ShutdownOnUIThread(). | 243 // in ShutdownOnUIThread(). |
231 // | 244 // |
232 // Note that looping only on the main thread here is not enough. The test | 245 // Note that looping only on the main thread here is not enough. The test |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 largest_changestamp, | 313 largest_changestamp, |
301 root_feed_changestamp_++) == base::PLATFORM_FILE_OK; | 314 root_feed_changestamp_++) == base::PLATFORM_FILE_OK; |
302 } | 315 } |
303 | 316 |
304 bool RemoveEntry(const FilePath& file_path) { | 317 bool RemoveEntry(const FilePath& file_path) { |
305 return file_system_->RemoveEntryFromFileSystem(file_path) == | 318 return file_system_->RemoveEntryFromFileSystem(file_path) == |
306 base::PLATFORM_FILE_OK; | 319 base::PLATFORM_FILE_OK; |
307 } | 320 } |
308 | 321 |
309 FilePath GetCachePathForFile(GDataFile* file) { | 322 FilePath GetCachePathForFile(GDataFile* file) { |
310 return file_system_->GetCacheFilePath( | 323 return cache_->GetCacheFilePath(file->resource_id(), |
311 file->resource_id(), | 324 file->file_md5(), |
312 file->file_md5(), | 325 GDataCache::CACHE_TYPE_TMP, |
313 GDataCache::CACHE_TYPE_TMP, | 326 GDataCache::CACHED_FILE_FROM_SERVER); |
314 GDataCache::CACHED_FILE_FROM_SERVER); | |
315 } | 327 } |
316 | 328 |
317 GDataEntry* FindEntry(const FilePath& file_path) { | 329 GDataEntry* FindEntry(const FilePath& file_path) { |
318 GDataEntry* entry = NULL; | 330 GDataEntry* entry = NULL; |
319 file_system_->root_->FindEntryByPath( | 331 file_system_->root_->FindEntryByPath( |
320 file_path, base::Bind(&ReadOnlyFindEntryCallback, &entry)); | 332 file_path, base::Bind(&ReadOnlyFindEntryCallback, &entry)); |
321 return entry; | 333 return entry; |
322 } | 334 } |
323 | 335 |
324 void FindAndTestFilePath(const FilePath& file_path) { | 336 void FindAndTestFilePath(const FilePath& file_path) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 | 415 |
404 if (callback_helper_->last_error_ != base::PLATFORM_FILE_OK) | 416 if (callback_helper_->last_error_ != base::PLATFORM_FILE_OK) |
405 return false; | 417 return false; |
406 | 418 |
407 scoped_ptr<GDataDirectoryProto> directory_proto = | 419 scoped_ptr<GDataDirectoryProto> directory_proto = |
408 callback_helper_->directory_proto_.Pass(); | 420 callback_helper_->directory_proto_.Pass(); |
409 return (directory->resource_id() == | 421 return (directory->resource_id() == |
410 directory_proto->gdata_entry().resource_id()); | 422 directory_proto->gdata_entry().resource_id()); |
411 } | 423 } |
412 | 424 |
413 FilePath GetCacheFilePath( | 425 FilePath GetCacheFilePath(const std::string& resource_id, |
414 const std::string& resource_id, | 426 const std::string& md5, |
415 const std::string& md5, | 427 GDataCache::CacheSubDirectoryType sub_dir_type, |
416 GDataCache::CacheSubDirectoryType sub_dir_type, | 428 GDataCache::CachedFileOrigin file_origin) { |
417 GDataCache::CachedFileOrigin file_origin) { | 429 return cache_->GetCacheFilePath(resource_id, md5, sub_dir_type, |
418 return file_system_->GetCacheFilePath(resource_id, md5, sub_dir_type, | 430 file_origin); |
419 file_origin); | |
420 } | 431 } |
421 | 432 |
422 // Returns true if the cache entry exists for the given resource ID and MD5. | 433 // Returns true if the cache entry exists for the given resource ID and MD5. |
423 bool CacheEntryExists(const std::string& resource_id, | 434 bool CacheEntryExists(const std::string& resource_id, |
424 const std::string& md5) { | 435 const std::string& md5) { |
425 return file_system_->cache_->GetCacheEntry(resource_id, md5).get(); | 436 return file_system_->cache_->GetCacheEntry(resource_id, md5).get(); |
426 } | 437 } |
427 | 438 |
428 // Returns true if the cache file exists for the given resource ID and MD5. | 439 // Returns true if the cache file exists for the given resource ID and MD5. |
429 bool CacheFileExists(const std::string& resource_id, | 440 bool CacheFileExists(const std::string& resource_id, |
430 const std::string& md5) { | 441 const std::string& md5) { |
431 const FilePath file_path = file_system_->GetCacheFilePath( | 442 const FilePath file_path = cache_->GetCacheFilePath( |
432 resource_id, | 443 resource_id, |
433 md5, | 444 md5, |
434 GDataCache::CACHE_TYPE_TMP, | 445 GDataCache::CACHE_TYPE_TMP, |
435 GDataCache::CACHED_FILE_FROM_SERVER); | 446 GDataCache::CACHED_FILE_FROM_SERVER); |
436 return file_util::PathExists(file_path); | 447 return file_util::PathExists(file_path); |
437 } | 448 } |
438 | 449 |
439 void TestGetCacheFilePath(const std::string& resource_id, | 450 void TestGetCacheFilePath(const std::string& resource_id, |
440 const std::string& md5, | 451 const std::string& md5, |
441 const std::string& expected_filename) { | 452 const std::string& expected_filename) { |
442 FilePath actual_path = file_system_->GetCacheFilePath( | 453 FilePath actual_path = cache_->GetCacheFilePath( |
443 resource_id, | 454 resource_id, |
444 md5, | 455 md5, |
445 GDataCache::CACHE_TYPE_TMP, | 456 GDataCache::CACHE_TYPE_TMP, |
446 GDataCache::CACHED_FILE_FROM_SERVER); | 457 GDataCache::CACHED_FILE_FROM_SERVER); |
447 FilePath expected_path = | 458 FilePath expected_path = |
448 file_system_->cache_->cache_paths()[GDataCache::CACHE_TYPE_TMP]; | 459 file_system_->cache_->cache_paths()[GDataCache::CACHE_TYPE_TMP]; |
449 expected_path = expected_path.Append(expected_filename); | 460 expected_path = expected_path.Append(expected_filename); |
450 EXPECT_EQ(expected_path, actual_path); | 461 EXPECT_EQ(expected_path, actual_path); |
451 | 462 |
452 FilePath base_name = actual_path.BaseName(); | 463 FilePath base_name = actual_path.BaseName(); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 scoped_ptr<GDataCache::CacheEntry> cache_entry = | 549 scoped_ptr<GDataCache::CacheEntry> cache_entry = |
539 file_system_->cache_->GetCacheEntry(resource_id, md5); | 550 file_system_->cache_->GetCacheEntry(resource_id, md5); |
540 if (cache_entry.get()) | 551 if (cache_entry.get()) |
541 EXPECT_TRUE(cache_entry->IsDirty()); | 552 EXPECT_TRUE(cache_entry->IsDirty()); |
542 | 553 |
543 // If entry doesn't exist, verify that: | 554 // If entry doesn't exist, verify that: |
544 // - no files with "<resource_id>.* exists in persistent and tmp dirs | 555 // - no files with "<resource_id>.* exists in persistent and tmp dirs |
545 // - no "<resource_id>" symlink exists in pinned and outgoing dirs. | 556 // - no "<resource_id>" symlink exists in pinned and outgoing dirs. |
546 std::vector<PathToVerify> paths_to_verify; | 557 std::vector<PathToVerify> paths_to_verify; |
547 paths_to_verify.push_back( // Index 0: CACHE_TYPE_TMP. | 558 paths_to_verify.push_back( // Index 0: CACHE_TYPE_TMP. |
548 PathToVerify(file_system_->GetCacheFilePath(resource_id, "*", | 559 PathToVerify(cache_->GetCacheFilePath(resource_id, "*", |
549 GDataCache::CACHE_TYPE_TMP, | 560 GDataCache::CACHE_TYPE_TMP, |
550 GDataCache::CACHED_FILE_FROM_SERVER), FilePath())); | 561 GDataCache::CACHED_FILE_FROM_SERVER), FilePath())); |
551 paths_to_verify.push_back( // Index 1: CACHE_TYPE_PERSISTENT. | 562 paths_to_verify.push_back( // Index 1: CACHE_TYPE_PERSISTENT. |
552 PathToVerify(file_system_->GetCacheFilePath(resource_id, "*", | 563 PathToVerify(cache_->GetCacheFilePath(resource_id, "*", |
553 GDataCache::CACHE_TYPE_PERSISTENT, | 564 GDataCache::CACHE_TYPE_PERSISTENT, |
554 GDataCache::CACHED_FILE_FROM_SERVER), FilePath())); | 565 GDataCache::CACHED_FILE_FROM_SERVER), FilePath())); |
555 paths_to_verify.push_back( // Index 2: CACHE_TYPE_PINNED. | 566 paths_to_verify.push_back( // Index 2: CACHE_TYPE_PINNED. |
556 PathToVerify(file_system_->GetCacheFilePath(resource_id, "", | 567 PathToVerify(cache_->GetCacheFilePath(resource_id, "", |
557 GDataCache::CACHE_TYPE_PINNED, | 568 GDataCache::CACHE_TYPE_PINNED, |
558 GDataCache::CACHED_FILE_FROM_SERVER), FilePath())); | 569 GDataCache::CACHED_FILE_FROM_SERVER), FilePath())); |
559 paths_to_verify.push_back( // Index 3: CACHE_TYPE_OUTGOING. | 570 paths_to_verify.push_back( // Index 3: CACHE_TYPE_OUTGOING. |
560 PathToVerify(file_system_->GetCacheFilePath(resource_id, "", | 571 PathToVerify(cache_->GetCacheFilePath(resource_id, "", |
561 GDataCache::CACHE_TYPE_OUTGOING, | 572 GDataCache::CACHE_TYPE_OUTGOING, |
562 GDataCache::CACHED_FILE_FROM_SERVER), FilePath())); | 573 GDataCache::CACHED_FILE_FROM_SERVER), FilePath())); |
563 if (!cache_entry.get()) { | 574 if (!cache_entry.get()) { |
564 for (size_t i = 0; i < paths_to_verify.size(); ++i) { | 575 for (size_t i = 0; i < paths_to_verify.size(); ++i) { |
565 file_util::FileEnumerator enumerator( | 576 file_util::FileEnumerator enumerator( |
566 paths_to_verify[i].path_to_scan.DirName(), false /* not recursive*/, | 577 paths_to_verify[i].path_to_scan.DirName(), false /* not recursive*/, |
567 static_cast<file_util::FileEnumerator::FileType>( | 578 static_cast<file_util::FileEnumerator::FileType>( |
568 file_util::FileEnumerator::FILES | | 579 file_util::FileEnumerator::FILES | |
569 file_util::FileEnumerator::SHOW_SYM_LINKS), | 580 file_util::FileEnumerator::SHOW_SYM_LINKS), |
570 paths_to_verify[i].path_to_scan.BaseName().value()); | 581 paths_to_verify[i].path_to_scan.BaseName().value()); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 VerifyCacheFileState(error, resource_id, md5); | 791 VerifyCacheFileState(error, resource_id, md5); |
781 } | 792 } |
782 | 793 |
783 void VerifySetMountedState(const std::string& resource_id, | 794 void VerifySetMountedState(const std::string& resource_id, |
784 const std::string& md5, | 795 const std::string& md5, |
785 bool to_mount, | 796 bool to_mount, |
786 base::PlatformFileError error, | 797 base::PlatformFileError error, |
787 const FilePath& file_path) { | 798 const FilePath& file_path) { |
788 ++num_callback_invocations_; | 799 ++num_callback_invocations_; |
789 EXPECT_TRUE(file_util::PathExists(file_path)); | 800 EXPECT_TRUE(file_util::PathExists(file_path)); |
790 EXPECT_TRUE(file_path == file_system_->GetCacheFilePath( | 801 EXPECT_TRUE(file_path == cache_->GetCacheFilePath( |
791 resource_id, | 802 resource_id, |
792 md5, | 803 md5, |
793 expected_sub_dir_type_, | 804 expected_sub_dir_type_, |
794 to_mount ? | 805 to_mount ? |
795 GDataCache::CACHED_FILE_MOUNTED : | 806 GDataCache::CACHED_FILE_MOUNTED : |
796 GDataCache::CACHED_FILE_FROM_SERVER)); | 807 GDataCache::CACHED_FILE_FROM_SERVER)); |
797 } | 808 } |
798 | 809 |
799 void TestSetMountedState( | 810 void TestSetMountedState( |
800 const std::string& resource_id, | 811 const std::string& resource_id, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 file_system_->cache_->cache_paths()[GDataCache::CACHE_TYPE_OUTGOING])); | 843 file_system_->cache_->cache_paths()[GDataCache::CACHE_TYPE_OUTGOING])); |
833 | 844 |
834 // Dump some files into cache dirs so that | 845 // Dump some files into cache dirs so that |
835 // GDataFileSystem::InitializeCacheOnBlockingPool would scan through them | 846 // GDataFileSystem::InitializeCacheOnBlockingPool would scan through them |
836 // and populate cache map accordingly. | 847 // and populate cache map accordingly. |
837 | 848 |
838 // Copy files from data dir to cache dir to act as cached files. | 849 // Copy files from data dir to cache dir to act as cached files. |
839 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(initial_cache_resources); ++i) { | 850 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(initial_cache_resources); ++i) { |
840 const struct InitialCacheResource& resource = initial_cache_resources[i]; | 851 const struct InitialCacheResource& resource = initial_cache_resources[i]; |
841 // Determine gdata cache file absolute path according to cache state. | 852 // Determine gdata cache file absolute path according to cache state. |
842 FilePath dest_path = file_system_->GetCacheFilePath( | 853 FilePath dest_path = cache_->GetCacheFilePath( |
843 resource.resource_id, | 854 resource.resource_id, |
844 resource.md5, | 855 resource.md5, |
845 GDataCache::IsCachePinned(resource.cache_state) || | 856 GDataCache::IsCachePinned(resource.cache_state) || |
846 GDataCache::IsCacheDirty(resource.cache_state) ? | 857 GDataCache::IsCacheDirty(resource.cache_state) ? |
847 GDataCache::CACHE_TYPE_PERSISTENT : | 858 GDataCache::CACHE_TYPE_PERSISTENT : |
848 GDataCache::CACHE_TYPE_TMP, | 859 GDataCache::CACHE_TYPE_TMP, |
849 GDataCache::IsCacheDirty(resource.cache_state) ? | 860 GDataCache::IsCacheDirty(resource.cache_state) ? |
850 GDataCache::CACHED_FILE_LOCALLY_MODIFIED : | 861 GDataCache::CACHED_FILE_LOCALLY_MODIFIED : |
851 GDataCache::CACHED_FILE_FROM_SERVER); | 862 GDataCache::CACHED_FILE_FROM_SERVER); |
852 | 863 |
853 // Copy file from data dir to cache subdir, naming it per cache files | 864 // Copy file from data dir to cache subdir, naming it per cache files |
854 // convention. | 865 // convention. |
855 if (GDataCache::IsCachePresent(resource.cache_state)) { | 866 if (GDataCache::IsCachePresent(resource.cache_state)) { |
856 FilePath source_path = GetTestFilePath(resource.source_file); | 867 FilePath source_path = GetTestFilePath(resource.source_file); |
857 ASSERT_TRUE(file_util::CopyFile(source_path, dest_path)); | 868 ASSERT_TRUE(file_util::CopyFile(source_path, dest_path)); |
858 } else { | 869 } else { |
859 dest_path = FilePath(FILE_PATH_LITERAL(kSymLinkToDevNull)); | 870 dest_path = FilePath(FILE_PATH_LITERAL(kSymLinkToDevNull)); |
860 } | 871 } |
861 | 872 |
862 // Create symbolic link in pinned dir, naming it per cache files | 873 // Create symbolic link in pinned dir, naming it per cache files |
863 // convention. | 874 // convention. |
864 if (GDataCache::IsCachePinned(resource.cache_state)) { | 875 if (GDataCache::IsCachePinned(resource.cache_state)) { |
865 FilePath link_path = file_system_->GetCacheFilePath( | 876 FilePath link_path = cache_->GetCacheFilePath( |
866 resource.resource_id, | 877 resource.resource_id, |
867 "", | 878 "", |
868 GDataCache::CACHE_TYPE_PINNED, | 879 GDataCache::CACHE_TYPE_PINNED, |
869 GDataCache::CACHED_FILE_FROM_SERVER); | 880 GDataCache::CACHED_FILE_FROM_SERVER); |
870 ASSERT_TRUE(file_util::CreateSymbolicLink(dest_path, link_path)); | 881 ASSERT_TRUE(file_util::CreateSymbolicLink(dest_path, link_path)); |
871 } | 882 } |
872 | 883 |
873 // Create symbolic link in outgoing dir, naming it per cache files | 884 // Create symbolic link in outgoing dir, naming it per cache files |
874 // convention. | 885 // convention. |
875 if (GDataCache::IsCacheDirty(resource.cache_state)) { | 886 if (GDataCache::IsCacheDirty(resource.cache_state)) { |
876 FilePath link_path = file_system_->GetCacheFilePath( | 887 FilePath link_path = cache_->GetCacheFilePath( |
877 resource.resource_id, | 888 resource.resource_id, |
878 "", | 889 "", |
879 GDataCache::CACHE_TYPE_OUTGOING, | 890 GDataCache::CACHE_TYPE_OUTGOING, |
880 GDataCache::CACHED_FILE_FROM_SERVER); | 891 GDataCache::CACHED_FILE_FROM_SERVER); |
881 ASSERT_TRUE(file_util::CreateSymbolicLink(dest_path, link_path)); | 892 ASSERT_TRUE(file_util::CreateSymbolicLink(dest_path, link_path)); |
882 } | 893 } |
883 } | 894 } |
884 DVLOG(1) << "PrepareForInitCacheTest finished"; | 895 DVLOG(1) << "PrepareForInitCacheTest finished"; |
885 // Temporarily remove the mock sync client while rescanning. Otherwise, | 896 // Temporarily remove the mock sync client while rescanning. Otherwise, |
886 // OnCacheInitialized() is called again here, which breaks the | 897 // OnCacheInitialized() is called again here, which breaks the |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 if (GDataCache::IsCachePresent(expected_cache_state_) || | 941 if (GDataCache::IsCachePresent(expected_cache_state_) || |
931 GDataCache::IsCachePinned(expected_cache_state_)) { | 942 GDataCache::IsCachePinned(expected_cache_state_)) { |
932 ASSERT_TRUE(cache_entry.get()); | 943 ASSERT_TRUE(cache_entry.get()); |
933 EXPECT_EQ(expected_cache_state_, cache_entry->cache_state); | 944 EXPECT_EQ(expected_cache_state_, cache_entry->cache_state); |
934 EXPECT_EQ(expected_sub_dir_type_, cache_entry->sub_dir_type); | 945 EXPECT_EQ(expected_sub_dir_type_, cache_entry->sub_dir_type); |
935 } else { | 946 } else { |
936 EXPECT_FALSE(cache_entry.get()); | 947 EXPECT_FALSE(cache_entry.get()); |
937 } | 948 } |
938 | 949 |
939 // Verify actual cache file. | 950 // Verify actual cache file. |
940 FilePath dest_path = file_system_->GetCacheFilePath( | 951 FilePath dest_path = cache_->GetCacheFilePath( |
941 resource_id, | 952 resource_id, |
942 md5, | 953 md5, |
943 GDataCache::IsCachePinned(expected_cache_state_) || | 954 GDataCache::IsCachePinned(expected_cache_state_) || |
944 GDataCache::IsCacheDirty(expected_cache_state_) ? | 955 GDataCache::IsCacheDirty(expected_cache_state_) ? |
945 GDataCache::CACHE_TYPE_PERSISTENT : | 956 GDataCache::CACHE_TYPE_PERSISTENT : |
946 GDataCache::CACHE_TYPE_TMP, | 957 GDataCache::CACHE_TYPE_TMP, |
947 GDataCache::IsCacheDirty(expected_cache_state_) ? | 958 GDataCache::IsCacheDirty(expected_cache_state_) ? |
948 GDataCache::CACHED_FILE_LOCALLY_MODIFIED : | 959 GDataCache::CACHED_FILE_LOCALLY_MODIFIED : |
949 GDataCache::CACHED_FILE_FROM_SERVER); | 960 GDataCache::CACHED_FILE_FROM_SERVER); |
950 bool exists = file_util::PathExists(dest_path); | 961 bool exists = file_util::PathExists(dest_path); |
951 if (GDataCache::IsCachePresent(expected_cache_state_)) | 962 if (GDataCache::IsCachePresent(expected_cache_state_)) |
952 EXPECT_TRUE(exists); | 963 EXPECT_TRUE(exists); |
953 else | 964 else |
954 EXPECT_FALSE(exists); | 965 EXPECT_FALSE(exists); |
955 | 966 |
956 // Verify symlink in pinned dir. | 967 // Verify symlink in pinned dir. |
957 FilePath symlink_path = file_system_->GetCacheFilePath( | 968 FilePath symlink_path = cache_->GetCacheFilePath( |
958 resource_id, | 969 resource_id, |
959 std::string(), | 970 std::string(), |
960 GDataCache::CACHE_TYPE_PINNED, | 971 GDataCache::CACHE_TYPE_PINNED, |
961 GDataCache::CACHED_FILE_FROM_SERVER); | 972 GDataCache::CACHED_FILE_FROM_SERVER); |
962 // Check that pin symlink exists, without deferencing to target path. | 973 // Check that pin symlink exists, without deferencing to target path. |
963 exists = file_util::IsLink(symlink_path); | 974 exists = file_util::IsLink(symlink_path); |
964 if (GDataCache::IsCachePinned(expected_cache_state_)) { | 975 if (GDataCache::IsCachePinned(expected_cache_state_)) { |
965 EXPECT_TRUE(exists); | 976 EXPECT_TRUE(exists); |
966 FilePath target_path; | 977 FilePath target_path; |
967 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path)); | 978 EXPECT_TRUE(file_util::ReadSymbolicLink(symlink_path, &target_path)); |
968 if (GDataCache::IsCachePresent(expected_cache_state_)) | 979 if (GDataCache::IsCachePresent(expected_cache_state_)) |
969 EXPECT_EQ(dest_path, target_path); | 980 EXPECT_EQ(dest_path, target_path); |
970 else | 981 else |
971 EXPECT_EQ(kSymLinkToDevNull, target_path.value()); | 982 EXPECT_EQ(kSymLinkToDevNull, target_path.value()); |
972 } else { | 983 } else { |
973 EXPECT_FALSE(exists); | 984 EXPECT_FALSE(exists); |
974 } | 985 } |
975 | 986 |
976 // Verify symlink in outgoing dir. | 987 // Verify symlink in outgoing dir. |
977 symlink_path = file_system_->GetCacheFilePath( | 988 symlink_path = cache_->GetCacheFilePath( |
978 resource_id, | 989 resource_id, |
979 std::string(), | 990 std::string(), |
980 GDataCache::CACHE_TYPE_OUTGOING, | 991 GDataCache::CACHE_TYPE_OUTGOING, |
981 GDataCache::CACHED_FILE_FROM_SERVER); | 992 GDataCache::CACHED_FILE_FROM_SERVER); |
982 // Check that outgoing symlink exists, without deferencing to target path. | 993 // Check that outgoing symlink exists, without deferencing to target path. |
983 exists = file_util::IsLink(symlink_path); | 994 exists = file_util::IsLink(symlink_path); |
984 if (expect_outgoing_symlink_ && | 995 if (expect_outgoing_symlink_ && |
985 GDataCache::IsCacheDirty(expected_cache_state_)) { | 996 GDataCache::IsCacheDirty(expected_cache_state_)) { |
986 EXPECT_TRUE(exists); | 997 EXPECT_TRUE(exists); |
987 FilePath target_path; | 998 FilePath target_path; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 scoped_ptr<GDataEntryProto> entry_proto_; | 1230 scoped_ptr<GDataEntryProto> entry_proto_; |
1220 scoped_ptr<GDataFileProto> file_proto_; | 1231 scoped_ptr<GDataFileProto> file_proto_; |
1221 scoped_ptr<GDataDirectoryProto> directory_proto_; | 1232 scoped_ptr<GDataDirectoryProto> directory_proto_; |
1222 }; | 1233 }; |
1223 | 1234 |
1224 MessageLoopForUI message_loop_; | 1235 MessageLoopForUI message_loop_; |
1225 // The order of the test threads is important, do not change the order. | 1236 // The order of the test threads is important, do not change the order. |
1226 // See also content/browser/browser_thread_imple.cc. | 1237 // See also content/browser/browser_thread_imple.cc. |
1227 content::TestBrowserThread ui_thread_; | 1238 content::TestBrowserThread ui_thread_; |
1228 content::TestBrowserThread io_thread_; | 1239 content::TestBrowserThread io_thread_; |
| 1240 const base::SequencedWorkerPool::SequenceToken sequence_token_; |
1229 scoped_ptr<TestingProfile> profile_; | 1241 scoped_ptr<TestingProfile> profile_; |
1230 scoped_refptr<CallbackHelper> callback_helper_; | 1242 scoped_refptr<CallbackHelper> callback_helper_; |
| 1243 scoped_ptr<GDataCache> cache_; |
1231 GDataFileSystem* file_system_; | 1244 GDataFileSystem* file_system_; |
1232 MockDocumentsService* mock_doc_service_; | 1245 MockDocumentsService* mock_doc_service_; |
1233 MockFreeDiskSpaceGetter* mock_free_disk_space_checker_; | 1246 MockFreeDiskSpaceGetter* mock_free_disk_space_checker_; |
1234 scoped_ptr<StrictMock<MockGDataSyncClient> > mock_sync_client_; | 1247 scoped_ptr<StrictMock<MockGDataSyncClient> > mock_sync_client_; |
1235 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; | 1248 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; |
1236 | 1249 |
1237 int num_callback_invocations_; | 1250 int num_callback_invocations_; |
1238 base::PlatformFileError expected_error_; | 1251 base::PlatformFileError expected_error_; |
1239 int expected_cache_state_; | 1252 int expected_cache_state_; |
1240 GDataCache::CacheSubDirectoryType expected_sub_dir_type_; | 1253 GDataCache::CacheSubDirectoryType expected_sub_dir_type_; |
(...skipping 2455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3696 std::string resource_id("pdf:1a2b"); | 3709 std::string resource_id("pdf:1a2b"); |
3697 std::string md5("abcdef0123456789"); | 3710 std::string md5("abcdef0123456789"); |
3698 | 3711 |
3699 // First store a file to cache in the tmp subdir. | 3712 // First store a file to cache in the tmp subdir. |
3700 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), | 3713 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), |
3701 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, | 3714 base::PLATFORM_FILE_OK, GDataCache::CACHE_STATE_PRESENT, |
3702 GDataCache::CACHE_TYPE_TMP); | 3715 GDataCache::CACHE_TYPE_TMP); |
3703 | 3716 |
3704 // Mark the file mounted. | 3717 // Mark the file mounted. |
3705 num_callback_invocations_ = 0; | 3718 num_callback_invocations_ = 0; |
3706 file_path = file_system_->GetCacheFilePath( | 3719 file_path = cache_->GetCacheFilePath(resource_id, md5, |
3707 resource_id, md5, | 3720 GDataCache::CACHE_TYPE_TMP, |
3708 GDataCache::CACHE_TYPE_TMP, | 3721 GDataCache::CACHED_FILE_FROM_SERVER); |
3709 GDataCache::CACHED_FILE_FROM_SERVER); | |
3710 TestSetMountedState(resource_id, md5, file_path, true, | 3722 TestSetMountedState(resource_id, md5, file_path, true, |
3711 base::PLATFORM_FILE_OK, | 3723 base::PLATFORM_FILE_OK, |
3712 GDataCache::CACHE_STATE_PRESENT | | 3724 GDataCache::CACHE_STATE_PRESENT | |
3713 GDataCache::CACHE_STATE_MOUNTED, | 3725 GDataCache::CACHE_STATE_MOUNTED, |
3714 GDataCache::CACHE_TYPE_PERSISTENT); | 3726 GDataCache::CACHE_TYPE_PERSISTENT); |
3715 EXPECT_EQ(1, num_callback_invocations_); | 3727 EXPECT_EQ(1, num_callback_invocations_); |
3716 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); | 3728 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); |
3717 | 3729 |
3718 // Clear mounted state of the file. | 3730 // Clear mounted state of the file. |
3719 num_callback_invocations_ = 0; | 3731 num_callback_invocations_ = 0; |
3720 file_path = file_system_->GetCacheFilePath( | 3732 file_path = cache_->GetCacheFilePath(resource_id, |
3721 resource_id, | 3733 md5, |
3722 md5, | 3734 GDataCache::CACHE_TYPE_PERSISTENT, |
3723 GDataCache::CACHE_TYPE_PERSISTENT, | 3735 GDataCache::CACHED_FILE_MOUNTED); |
3724 GDataCache::CACHED_FILE_MOUNTED); | |
3725 TestSetMountedState(resource_id, md5, file_path, false, | 3736 TestSetMountedState(resource_id, md5, file_path, false, |
3726 base::PLATFORM_FILE_OK, | 3737 base::PLATFORM_FILE_OK, |
3727 GDataCache::CACHE_STATE_PRESENT, | 3738 GDataCache::CACHE_STATE_PRESENT, |
3728 GDataCache::CACHE_TYPE_TMP); | 3739 GDataCache::CACHE_TYPE_TMP); |
3729 EXPECT_EQ(1, num_callback_invocations_); | 3740 EXPECT_EQ(1, num_callback_invocations_); |
3730 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); | 3741 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); |
3731 | 3742 |
3732 // Try to remove the file. | 3743 // Try to remove the file. |
3733 num_callback_invocations_ = 0; | 3744 num_callback_invocations_ = 0; |
3734 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK); | 3745 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3815 // Verify that the file was properly closed. | 3826 // Verify that the file was properly closed. |
3816 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); | 3827 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); |
3817 | 3828 |
3818 // Verify that the cache state was changed as expected. | 3829 // Verify that the cache state was changed as expected. |
3819 VerifyCacheStateAfterCloseFile(callback_helper_->last_error_, | 3830 VerifyCacheStateAfterCloseFile(callback_helper_->last_error_, |
3820 file_resource_id, | 3831 file_resource_id, |
3821 file_md5); | 3832 file_md5); |
3822 } | 3833 } |
3823 | 3834 |
3824 } // namespace gdata | 3835 } // namespace gdata |
OLD | NEW |