[email protected] | 92b84f33 | 2012-03-21 20:45:21 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d876d70b | 2013-04-23 20:06:15 | [diff] [blame] | 5 | #include "chrome/browser/chromeos/drive/sync_client.h" |
[email protected] | 92b84f33 | 2012-03-21 20:45:21 | [diff] [blame] | 6 | |
[email protected] | 92b84f33 | 2012-03-21 20:45:21 | [diff] [blame] | 7 | #include "base/file_util.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 8 | #include "base/files/file_path.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 9 | #include "base/files/scoped_temp_dir.h" |
[email protected] | 92b84f33 | 2012-03-21 20:45:21 | [diff] [blame] | 10 | #include "base/memory/scoped_ptr.h" |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 11 | #include "base/run_loop.h" |
[email protected] | b83e520 | 2012-06-27 07:50:24 | [diff] [blame] | 12 | #include "base/test/test_timeouts.h" |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 13 | #include "chrome/browser/chromeos/drive/change_list_loader.h" |
[email protected] | 15de814 | 2012-10-11 06:00:54 | [diff] [blame] | 14 | #include "chrome/browser/chromeos/drive/drive.pb.h" |
[email protected] | eca3fc9 | 2013-05-01 03:53:40 | [diff] [blame] | 15 | #include "chrome/browser/chromeos/drive/file_cache.h" |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 16 | #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" |
| 17 | #include "chrome/browser/chromeos/drive/job_scheduler.h" |
| 18 | #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" |
| 19 | #include "chrome/browser/chromeos/drive/resource_metadata.h" |
[email protected] | 92931d7 | 2013-04-24 05:16:15 | [diff] [blame] | 20 | #include "chrome/browser/chromeos/drive/test_util.h" |
[email protected] | 0390b81 | 2013-06-19 00:27:50 | [diff] [blame^] | 21 | #include "chrome/browser/drive/fake_drive_service.h" |
[email protected] | 7601e18 | 2013-03-22 09:38:02 | [diff] [blame] | 22 | #include "chrome/browser/google_apis/test_util.h" |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 23 | #include "chrome/test/base/testing_profile.h" |
| 24 | #include "content/public/test/test_browser_thread_bundle.h" |
[email protected] | 92b84f33 | 2012-03-21 20:45:21 | [diff] [blame] | 25 | #include "testing/gtest/include/gtest/gtest.h" |
| 26 | |
[email protected] | d9d04df | 2012-10-12 07:06:35 | [diff] [blame] | 27 | namespace drive { |
[email protected] | 4e87c486 | 2013-05-20 04:06:32 | [diff] [blame] | 28 | namespace internal { |
[email protected] | 92b84f33 | 2012-03-21 20:45:21 | [diff] [blame] | 29 | |
[email protected] | 8019936 | 2012-09-09 23:24:29 | [diff] [blame] | 30 | namespace { |
| 31 | |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 32 | // The content of files iniitally stored in the cache. |
| 33 | const char kLocalContent[] = "Hello!"; |
[email protected] | 61a41c1 | 2013-06-06 06:23:36 | [diff] [blame] | 34 | |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 35 | // The content of files stored in the service. |
| 36 | const char kRemoteContent[] = "World!"; |
| 37 | |
| 38 | // SyncClientTestDriveService will return GDATA_CANCELLED when a request is |
| 39 | // made with the specified resource ID. |
| 40 | class SyncClientTestDriveService : public google_apis::FakeDriveService { |
[email protected] | 67e264a | 2013-06-03 05:39:01 | [diff] [blame] | 41 | public: |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 42 | // FakeDriveService override: |
[email protected] | cef0f06 | 2013-06-14 16:13:07 | [diff] [blame] | 43 | virtual google_apis::CancelCallback GetResourceEntry( |
[email protected] | 67e264a | 2013-06-03 05:39:01 | [diff] [blame] | 44 | const std::string& resource_id, |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 45 | const google_apis::GetResourceEntryCallback& callback) OVERRIDE { |
| 46 | if (resource_id == resource_id_to_be_cancelled_) { |
| 47 | scoped_ptr<google_apis::ResourceEntry> null; |
| 48 | base::MessageLoopProxy::current()->PostTask( |
| 49 | FROM_HERE, |
| 50 | base::Bind(callback, |
| 51 | google_apis::GDATA_CANCELLED, |
| 52 | base::Passed(&null))); |
[email protected] | cef0f06 | 2013-06-14 16:13:07 | [diff] [blame] | 53 | return google_apis::CancelCallback(); |
[email protected] | 61a41c1 | 2013-06-06 06:23:36 | [diff] [blame] | 54 | } |
[email protected] | cef0f06 | 2013-06-14 16:13:07 | [diff] [blame] | 55 | return FakeDriveService::GetResourceEntry(resource_id, callback); |
[email protected] | 67e264a | 2013-06-03 05:39:01 | [diff] [blame] | 56 | } |
[email protected] | aaa70a4 | 2012-06-05 22:22:51 | [diff] [blame] | 57 | |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 58 | void set_resource_id_to_be_cancelled(const std::string& resource_id) { |
| 59 | resource_id_to_be_cancelled_ = resource_id; |
[email protected] | 67e264a | 2013-06-03 05:39:01 | [diff] [blame] | 60 | } |
[email protected] | b83e520 | 2012-06-27 07:50:24 | [diff] [blame] | 61 | |
[email protected] | 67e264a | 2013-06-03 05:39:01 | [diff] [blame] | 62 | private: |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 63 | std::string resource_id_to_be_cancelled_; |
| 64 | }; |
| 65 | |
| 66 | class DummyOperationObserver : public file_system::OperationObserver { |
[email protected] | 6bf58114 | 2013-06-11 17:13:06 | [diff] [blame] | 67 | // OperationObserver override: |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 68 | virtual void OnDirectoryChangedByOperation( |
| 69 | const base::FilePath& path) OVERRIDE {} |
[email protected] | 6bf58114 | 2013-06-11 17:13:06 | [diff] [blame] | 70 | virtual void OnCacheFileUploadNeededByOperation( |
| 71 | const std::string& resource_id) OVERRIDE {} |
[email protected] | 67e264a | 2013-06-03 05:39:01 | [diff] [blame] | 72 | }; |
[email protected] | 85b6219 | 2012-06-29 19:56:38 | [diff] [blame] | 73 | |
[email protected] | 8019936 | 2012-09-09 23:24:29 | [diff] [blame] | 74 | } // namespace |
| 75 | |
[email protected] | d876d70b | 2013-04-23 20:06:15 | [diff] [blame] | 76 | class SyncClientTest : public testing::Test { |
[email protected] | ffd60e43 | 2012-03-24 20:36:00 | [diff] [blame] | 77 | public: |
[email protected] | 92b84f33 | 2012-03-21 20:45:21 | [diff] [blame] | 78 | virtual void SetUp() OVERRIDE { |
[email protected] | 92b84f33 | 2012-03-21 20:45:21 | [diff] [blame] | 79 | ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 80 | |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 81 | profile_.reset(new TestingProfile); |
| 82 | |
| 83 | drive_service_.reset(new SyncClientTestDriveService); |
| 84 | drive_service_->LoadResourceListForWapi("chromeos/gdata/empty_feed.json"); |
| 85 | drive_service_->LoadAccountMetadataForWapi( |
| 86 | "chromeos/gdata/account_metadata.json"); |
| 87 | |
| 88 | scheduler_.reset(new JobScheduler(profile_.get(), drive_service_.get())); |
| 89 | metadata_.reset(new internal::ResourceMetadata( |
| 90 | temp_dir_.path(), base::MessageLoopProxy::current())); |
[email protected] | 34a1bbf3 | 2013-06-17 07:24:02 | [diff] [blame] | 91 | ASSERT_EQ(FILE_ERROR_OK, metadata_->Initialize()); |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 92 | |
| 93 | cache_.reset(new FileCache(temp_dir_.path(), |
| 94 | base::MessageLoopProxy::current(), |
| 95 | NULL /* free_disk_space_getter */)); |
[email protected] | 34a1bbf3 | 2013-06-17 07:24:02 | [diff] [blame] | 96 | ASSERT_TRUE(cache_->Initialize()); |
[email protected] | e63bdc97 | 2012-11-22 12:10:48 | [diff] [blame] | 97 | |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 98 | ASSERT_NO_FATAL_FAILURE(SetUpTestData()); |
| 99 | |
| 100 | sync_client_.reset(new SyncClient(base::MessageLoopProxy::current(), |
| 101 | &observer_, |
| 102 | scheduler_.get(), |
| 103 | metadata_.get(), |
| 104 | cache_.get())); |
[email protected] | e0529fc | 2012-06-12 11:07:58 | [diff] [blame] | 105 | |
[email protected] | b83e520 | 2012-06-27 07:50:24 | [diff] [blame] | 106 | // Disable delaying so that DoSyncLoop() starts immediately. |
| 107 | sync_client_->set_delay_for_testing(base::TimeDelta::FromSeconds(0)); |
[email protected] | 92b84f33 | 2012-03-21 20:45:21 | [diff] [blame] | 108 | } |
| 109 | |
[email protected] | a538177 | 2012-04-05 02:20:04 | [diff] [blame] | 110 | virtual void TearDown() OVERRIDE { |
[email protected] | 2416a2e | 2012-05-07 20:58:49 | [diff] [blame] | 111 | sync_client_.reset(); |
[email protected] | c0a3b8e8 | 2013-03-18 21:07:45 | [diff] [blame] | 112 | cache_.reset(); |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 113 | metadata_.reset(); |
[email protected] | a538177 | 2012-04-05 02:20:04 | [diff] [blame] | 114 | } |
| 115 | |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 116 | // Adds a file to the service root and |resource_ids_|. |
| 117 | void AddFileEntry(const std::string& title) { |
| 118 | google_apis::GDataErrorCode error = google_apis::GDATA_FILE_ERROR; |
| 119 | scoped_ptr<google_apis::ResourceEntry> entry; |
| 120 | drive_service_->AddNewFile( |
| 121 | "text/plain", |
| 122 | kRemoteContent, |
| 123 | drive_service_->GetRootResourceId(), |
| 124 | title, |
| 125 | false, // shared_with_me |
| 126 | google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
| 127 | base::RunLoop().RunUntilIdle(); |
| 128 | ASSERT_EQ(google_apis::HTTP_CREATED, error); |
| 129 | ASSERT_TRUE(entry); |
| 130 | resource_ids_[title] = entry->resource_id(); |
| 131 | } |
| 132 | |
| 133 | // Sets up data for tests. |
| 134 | void SetUpTestData() { |
[email protected] | e63bdc97 | 2012-11-22 12:10:48 | [diff] [blame] | 135 | // Prepare a temp file. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 136 | base::FilePath temp_file; |
[email protected] | e63bdc97 | 2012-11-22 12:10:48 | [diff] [blame] | 137 | EXPECT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), |
| 138 | &temp_file)); |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 139 | ASSERT_TRUE(google_apis::test_util::WriteStringToFile(temp_file, |
| 140 | kLocalContent)); |
[email protected] | b83e520 | 2012-06-27 07:50:24 | [diff] [blame] | 141 | |
[email protected] | e63bdc97 | 2012-11-22 12:10:48 | [diff] [blame] | 142 | // Prepare 3 pinned-but-not-present files. |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 143 | ASSERT_NO_FATAL_FAILURE(AddFileEntry("foo")); |
[email protected] | ebc70e2 | 2013-06-18 04:09:46 | [diff] [blame] | 144 | EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(resource_ids_["foo"])); |
[email protected] | e63bdc97 | 2012-11-22 12:10:48 | [diff] [blame] | 145 | |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 146 | ASSERT_NO_FATAL_FAILURE(AddFileEntry("bar")); |
[email protected] | ebc70e2 | 2013-06-18 04:09:46 | [diff] [blame] | 147 | EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(resource_ids_["bar"])); |
[email protected] | e63bdc97 | 2012-11-22 12:10:48 | [diff] [blame] | 148 | |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 149 | ASSERT_NO_FATAL_FAILURE(AddFileEntry("baz")); |
[email protected] | ebc70e2 | 2013-06-18 04:09:46 | [diff] [blame] | 150 | EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(resource_ids_["baz"])); |
[email protected] | e63bdc97 | 2012-11-22 12:10:48 | [diff] [blame] | 151 | |
| 152 | // Prepare a pinned-and-fetched file. |
[email protected] | e63bdc97 | 2012-11-22 12:10:48 | [diff] [blame] | 153 | const std::string md5_fetched = "md5"; |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 154 | ASSERT_NO_FATAL_FAILURE(AddFileEntry("fetched")); |
| 155 | EXPECT_EQ(FILE_ERROR_OK, |
| 156 | cache_->Store(resource_ids_["fetched"], md5_fetched, |
| 157 | temp_file, FileCache::FILE_OPERATION_COPY)); |
[email protected] | ebc70e2 | 2013-06-18 04:09:46 | [diff] [blame] | 158 | EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(resource_ids_["fetched"])); |
[email protected] | e63bdc97 | 2012-11-22 12:10:48 | [diff] [blame] | 159 | |
| 160 | // Prepare a pinned-and-fetched-and-dirty file. |
[email protected] | e63bdc97 | 2012-11-22 12:10:48 | [diff] [blame] | 161 | const std::string md5_dirty = ""; // Don't care. |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 162 | ASSERT_NO_FATAL_FAILURE(AddFileEntry("dirty")); |
| 163 | EXPECT_EQ(FILE_ERROR_OK, |
| 164 | cache_->Store(resource_ids_["dirty"], md5_dirty, |
| 165 | temp_file, FileCache::FILE_OPERATION_COPY)); |
[email protected] | ebc70e2 | 2013-06-18 04:09:46 | [diff] [blame] | 166 | EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(resource_ids_["dirty"])); |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 167 | EXPECT_EQ(FILE_ERROR_OK, |
| 168 | cache_->MarkDirty(resource_ids_["dirty"], md5_dirty)); |
[email protected] | adf8440 | 2012-03-25 21:56:38 | [diff] [blame] | 169 | |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 170 | // Load data from the service to the metadata. |
| 171 | FileError error = FILE_ERROR_FAILED; |
| 172 | internal::ChangeListLoader change_list_loader( |
| 173 | base::MessageLoopProxy::current(), metadata_.get(), scheduler_.get()); |
| 174 | change_list_loader.LoadIfNeeded( |
| 175 | DirectoryFetchInfo(), |
| 176 | google_apis::test_util::CreateCopyResultCallback(&error)); |
| 177 | base::RunLoop().RunUntilIdle(); |
| 178 | EXPECT_EQ(FILE_ERROR_OK, error); |
[email protected] | b83e520 | 2012-06-27 07:50:24 | [diff] [blame] | 179 | } |
| 180 | |
[email protected] | ffd60e43 | 2012-03-24 20:36:00 | [diff] [blame] | 181 | protected: |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 182 | content::TestBrowserThreadBundle thread_bundle_; |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 183 | base::ScopedTempDir temp_dir_; |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 184 | scoped_ptr<TestingProfile> profile_; |
| 185 | scoped_ptr<SyncClientTestDriveService> drive_service_; |
| 186 | DummyOperationObserver observer_; |
| 187 | scoped_ptr<JobScheduler> scheduler_; |
| 188 | scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> |
| 189 | metadata_; |
[email protected] | 4e87c486 | 2013-05-20 04:06:32 | [diff] [blame] | 190 | scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; |
[email protected] | d876d70b | 2013-04-23 20:06:15 | [diff] [blame] | 191 | scoped_ptr<SyncClient> sync_client_; |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 192 | |
| 193 | std::map<std::string, std::string> resource_ids_; // Name-to-id map. |
[email protected] | 92b84f33 | 2012-03-21 20:45:21 | [diff] [blame] | 194 | }; |
| 195 | |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 196 | TEST_F(SyncClientTest, StartProcessingBacklog) { |
[email protected] | b83e520 | 2012-06-27 07:50:24 | [diff] [blame] | 197 | sync_client_->StartProcessingBacklog(); |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 198 | base::RunLoop().RunUntilIdle(); |
[email protected] | 92b84f33 | 2012-03-21 20:45:21 | [diff] [blame] | 199 | |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 200 | FileCacheEntry cache_entry; |
| 201 | // Pinned files get downloaded. |
| 202 | EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["foo"], std::string(), |
| 203 | &cache_entry)); |
| 204 | EXPECT_TRUE(cache_entry.is_present()); |
[email protected] | b83e520 | 2012-06-27 07:50:24 | [diff] [blame] | 205 | |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 206 | EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["bar"], std::string(), |
| 207 | &cache_entry)); |
| 208 | EXPECT_TRUE(cache_entry.is_present()); |
| 209 | |
| 210 | EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["baz"], std::string(), |
| 211 | &cache_entry)); |
| 212 | EXPECT_TRUE(cache_entry.is_present()); |
| 213 | |
| 214 | // Dirty file gets uploaded. |
| 215 | EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["dirty"], std::string(), |
| 216 | &cache_entry)); |
| 217 | EXPECT_FALSE(cache_entry.is_dirty()); |
[email protected] | a538177 | 2012-04-05 02:20:04 | [diff] [blame] | 218 | } |
| 219 | |
[email protected] | bd2254d | 2013-06-12 16:00:47 | [diff] [blame] | 220 | TEST_F(SyncClientTest, AddFetchTask) { |
| 221 | sync_client_->AddFetchTask(resource_ids_["foo"]); |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 222 | base::RunLoop().RunUntilIdle(); |
[email protected] | 67e264a | 2013-06-03 05:39:01 | [diff] [blame] | 223 | |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 224 | FileCacheEntry cache_entry; |
| 225 | EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["foo"], std::string(), |
| 226 | &cache_entry)); |
| 227 | EXPECT_TRUE(cache_entry.is_present()); |
[email protected] | adf8440 | 2012-03-25 21:56:38 | [diff] [blame] | 228 | } |
| 229 | |
[email protected] | bd2254d | 2013-06-12 16:00:47 | [diff] [blame] | 230 | TEST_F(SyncClientTest, AddFetchTaskAndCancelled) { |
[email protected] | 61a41c1 | 2013-06-06 06:23:36 | [diff] [blame] | 231 | // Trigger fetching of a file which results in cancellation. |
[email protected] | bd2254d | 2013-06-12 16:00:47 | [diff] [blame] | 232 | drive_service_->set_resource_id_to_be_cancelled(resource_ids_["foo"]); |
| 233 | sync_client_->AddFetchTask(resource_ids_["foo"]); |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 234 | base::RunLoop().RunUntilIdle(); |
[email protected] | 61a41c1 | 2013-06-06 06:23:36 | [diff] [blame] | 235 | |
| 236 | // The file should be unpinned if the user wants the download to be cancelled. |
[email protected] | 61a41c1 | 2013-06-06 06:23:36 | [diff] [blame] | 237 | FileCacheEntry cache_entry; |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 238 | EXPECT_FALSE(cache_->GetCacheEntry(resource_ids_["foo"], std::string(), |
| 239 | &cache_entry)); |
[email protected] | 61a41c1 | 2013-06-06 06:23:36 | [diff] [blame] | 240 | } |
| 241 | |
[email protected] | bd2254d | 2013-06-12 16:00:47 | [diff] [blame] | 242 | TEST_F(SyncClientTest, RemoveFetchTask) { |
[email protected] | 6bf58114 | 2013-06-11 17:13:06 | [diff] [blame] | 243 | sync_client_->AddFetchTask(resource_ids_["foo"]); |
| 244 | sync_client_->AddFetchTask(resource_ids_["bar"]); |
| 245 | sync_client_->AddFetchTask(resource_ids_["baz"]); |
[email protected] | adf8440 | 2012-03-25 21:56:38 | [diff] [blame] | 246 | |
[email protected] | bd2254d | 2013-06-12 16:00:47 | [diff] [blame] | 247 | sync_client_->RemoveFetchTask(resource_ids_["foo"]); |
| 248 | sync_client_->RemoveFetchTask(resource_ids_["baz"]); |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 249 | base::RunLoop().RunUntilIdle(); |
[email protected] | e07bbd97 | 2013-01-23 17:38:42 | [diff] [blame] | 250 | |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 251 | // Only "bar" should be fetched. |
| 252 | FileCacheEntry cache_entry; |
| 253 | EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["foo"], std::string(), |
| 254 | &cache_entry)); |
| 255 | EXPECT_FALSE(cache_entry.is_present()); |
| 256 | |
| 257 | EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["bar"], std::string(), |
| 258 | &cache_entry)); |
| 259 | EXPECT_TRUE(cache_entry.is_present()); |
| 260 | |
| 261 | EXPECT_TRUE(cache_->GetCacheEntry(resource_ids_["baz"], std::string(), |
| 262 | &cache_entry)); |
| 263 | EXPECT_FALSE(cache_entry.is_present()); |
| 264 | |
[email protected] | adf8440 | 2012-03-25 21:56:38 | [diff] [blame] | 265 | } |
| 266 | |
[email protected] | d876d70b | 2013-04-23 20:06:15 | [diff] [blame] | 267 | TEST_F(SyncClientTest, ExistingPinnedFiles) { |
[email protected] | 85b6219 | 2012-06-29 19:56:38 | [diff] [blame] | 268 | // Start checking the existing pinned files. This will collect the resource |
| 269 | // IDs of pinned files, with stale local cache files. |
| 270 | sync_client_->StartCheckingExistingPinnedFiles(); |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 271 | base::RunLoop().RunUntilIdle(); |
[email protected] | 67e264a | 2013-06-03 05:39:01 | [diff] [blame] | 272 | |
[email protected] | b568b88 | 2013-06-10 04:38:07 | [diff] [blame] | 273 | // "fetched" and "dirty" are the existing pinned files. |
| 274 | // The non-dirty one should be synced, but the dirty one should not. |
| 275 | base::FilePath cache_file; |
| 276 | std::string content; |
| 277 | EXPECT_EQ(FILE_ERROR_OK, cache_->GetFile(resource_ids_["fetched"], |
| 278 | std::string(), &cache_file)); |
| 279 | EXPECT_TRUE(file_util::ReadFileToString(cache_file, &content)); |
| 280 | EXPECT_EQ(kRemoteContent, content); |
| 281 | content.clear(); |
| 282 | |
| 283 | EXPECT_EQ(FILE_ERROR_OK, cache_->GetFile(resource_ids_["dirty"], |
| 284 | std::string(), &cache_file)); |
| 285 | EXPECT_TRUE(file_util::ReadFileToString(cache_file, &content)); |
| 286 | EXPECT_EQ(kLocalContent, content); |
[email protected] | 189541ba | 2012-10-24 11:18:15 | [diff] [blame] | 287 | } |
| 288 | |
[email protected] | 4e87c486 | 2013-05-20 04:06:32 | [diff] [blame] | 289 | } // namespace internal |
[email protected] | d9d04df | 2012-10-12 07:06:35 | [diff] [blame] | 290 | } // namespace drive |