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

Side by Side Diff: chrome/browser/chromeos/drive/sync_client_unittest.cc

Issue 68543002: drive: Support offline delete (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Stop modifying local state after server side update Created 7 years 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
« no previous file with comments | « chrome/browser/chromeos/drive/sync_client.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/sync_client.h" 5 #include "chrome/browser/chromeos/drive/sync_client.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/prefs/testing_pref_service.h" 11 #include "base/prefs/testing_pref_service.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/test/test_timeouts.h" 13 #include "base/test/test_timeouts.h"
14 #include "chrome/browser/chromeos/drive/change_list_loader.h" 14 #include "chrome/browser/chromeos/drive/change_list_loader.h"
15 #include "chrome/browser/chromeos/drive/change_list_processor.h" 15 #include "chrome/browser/chromeos/drive/change_list_processor.h"
16 #include "chrome/browser/chromeos/drive/drive.pb.h" 16 #include "chrome/browser/chromeos/drive/drive.pb.h"
17 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" 17 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h"
18 #include "chrome/browser/chromeos/drive/file_cache.h" 18 #include "chrome/browser/chromeos/drive/file_cache.h"
19 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" 19 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h"
20 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h"
20 #include "chrome/browser/chromeos/drive/job_scheduler.h" 21 #include "chrome/browser/chromeos/drive/job_scheduler.h"
21 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" 22 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h"
22 #include "chrome/browser/chromeos/drive/resource_metadata.h" 23 #include "chrome/browser/chromeos/drive/resource_metadata.h"
23 #include "chrome/browser/chromeos/drive/test_util.h" 24 #include "chrome/browser/chromeos/drive/test_util.h"
24 #include "chrome/browser/drive/fake_drive_service.h" 25 #include "chrome/browser/drive/fake_drive_service.h"
25 #include "chrome/browser/google_apis/test_util.h" 26 #include "chrome/browser/google_apis/test_util.h"
26 #include "content/public/test/test_browser_thread_bundle.h" 27 #include "content/public/test/test_browser_thread_bundle.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 29
29 namespace drive { 30 namespace drive {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 &temp_file)); 154 &temp_file));
154 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(temp_file, 155 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(temp_file,
155 kLocalContent)); 156 kLocalContent));
156 157
157 // Add file entries to the service. 158 // Add file entries to the service.
158 ASSERT_NO_FATAL_FAILURE(AddFileEntry("foo")); 159 ASSERT_NO_FATAL_FAILURE(AddFileEntry("foo"));
159 ASSERT_NO_FATAL_FAILURE(AddFileEntry("bar")); 160 ASSERT_NO_FATAL_FAILURE(AddFileEntry("bar"));
160 ASSERT_NO_FATAL_FAILURE(AddFileEntry("baz")); 161 ASSERT_NO_FATAL_FAILURE(AddFileEntry("baz"));
161 ASSERT_NO_FATAL_FAILURE(AddFileEntry("fetched")); 162 ASSERT_NO_FATAL_FAILURE(AddFileEntry("fetched"));
162 ASSERT_NO_FATAL_FAILURE(AddFileEntry("dirty")); 163 ASSERT_NO_FATAL_FAILURE(AddFileEntry("dirty"));
164 ASSERT_NO_FATAL_FAILURE(AddFileEntry("removed"));
163 165
164 // Load data from the service to the metadata. 166 // Load data from the service to the metadata.
165 FileError error = FILE_ERROR_FAILED; 167 FileError error = FILE_ERROR_FAILED;
166 internal::ChangeListLoader change_list_loader( 168 internal::ChangeListLoader change_list_loader(
167 base::MessageLoopProxy::current().get(), 169 base::MessageLoopProxy::current().get(),
168 metadata_.get(), 170 metadata_.get(),
169 scheduler_.get(), 171 scheduler_.get(),
170 drive_service_.get()); 172 drive_service_.get());
171 change_list_loader.LoadIfNeeded( 173 change_list_loader.LoadIfNeeded(
172 DirectoryFetchInfo(), 174 DirectoryFetchInfo(),
(...skipping 14 matching lines...) Expand all
187 EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(GetLocalId("fetched"))); 189 EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(GetLocalId("fetched")));
188 190
189 // Prepare a pinned-and-fetched-and-dirty file. 191 // Prepare a pinned-and-fetched-and-dirty file.
190 const std::string md5_dirty = ""; // Don't care. 192 const std::string md5_dirty = ""; // Don't care.
191 EXPECT_EQ(FILE_ERROR_OK, 193 EXPECT_EQ(FILE_ERROR_OK,
192 cache_->Store(GetLocalId("dirty"), md5_dirty, 194 cache_->Store(GetLocalId("dirty"), md5_dirty,
193 temp_file, FileCache::FILE_OPERATION_COPY)); 195 temp_file, FileCache::FILE_OPERATION_COPY));
194 EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(GetLocalId("dirty"))); 196 EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(GetLocalId("dirty")));
195 EXPECT_EQ(FILE_ERROR_OK, cache_->MarkDirty(GetLocalId("dirty"))); 197 EXPECT_EQ(FILE_ERROR_OK, cache_->MarkDirty(GetLocalId("dirty")));
196 198
199 // Prepare a removed file.
200 file_system::RemoveOperation remove_operation(
201 base::MessageLoopProxy::current().get(), &observer_, metadata_.get(),
202 cache_.get());
203 remove_operation.Remove(
204 metadata_->GetFilePath(GetLocalId("removed")),
205 false, // is_recursive
206 google_apis::test_util::CreateCopyResultCallback(&error));
207 base::RunLoop().RunUntilIdle();
208 EXPECT_EQ(FILE_ERROR_OK, error);
197 } 209 }
198 210
199 protected: 211 protected:
200 std::string GetLocalId(const std::string& title) { 212 std::string GetLocalId(const std::string& title) {
201 EXPECT_EQ(1U, resource_ids_.count(title)); 213 EXPECT_EQ(1U, resource_ids_.count(title));
202 std::string local_id; 214 std::string local_id;
203 EXPECT_EQ(FILE_ERROR_OK, 215 EXPECT_EQ(FILE_ERROR_OK,
204 metadata_->GetIdByResourceId(resource_ids_[title], &local_id)); 216 metadata_->GetIdByResourceId(resource_ids_[title], &local_id));
205 return local_id; 217 return local_id;
206 } 218 }
(...skipping 26 matching lines...) Expand all
233 245
234 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("bar"), &cache_entry)); 246 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("bar"), &cache_entry));
235 EXPECT_TRUE(cache_entry.is_present()); 247 EXPECT_TRUE(cache_entry.is_present());
236 248
237 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("baz"), &cache_entry)); 249 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("baz"), &cache_entry));
238 EXPECT_TRUE(cache_entry.is_present()); 250 EXPECT_TRUE(cache_entry.is_present());
239 251
240 // Dirty file gets uploaded. 252 // Dirty file gets uploaded.
241 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("dirty"), &cache_entry)); 253 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("dirty"), &cache_entry));
242 EXPECT_FALSE(cache_entry.is_dirty()); 254 EXPECT_FALSE(cache_entry.is_dirty());
255
256 // Removed entry is not found.
257 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
258 scoped_ptr<google_apis::ResourceEntry> resource_entry;
259 drive_service_->GetResourceEntry(
260 resource_ids_["removed"],
261 google_apis::test_util::CreateCopyResultCallback(&status,
262 &resource_entry));
263 base::RunLoop().RunUntilIdle();
264 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
265 ASSERT_TRUE(resource_entry);
266 EXPECT_TRUE(resource_entry->deleted());
243 } 267 }
244 268
245 TEST_F(SyncClientTest, AddFetchTask) { 269 TEST_F(SyncClientTest, AddFetchTask) {
246 sync_client_->AddFetchTask(GetLocalId("foo")); 270 sync_client_->AddFetchTask(GetLocalId("foo"));
247 base::RunLoop().RunUntilIdle(); 271 base::RunLoop().RunUntilIdle();
248 272
249 FileCacheEntry cache_entry; 273 FileCacheEntry cache_entry;
250 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry)); 274 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry));
251 EXPECT_TRUE(cache_entry.is_present()); 275 EXPECT_TRUE(cache_entry.is_present());
252 } 276 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 363
340 // Fetched and uploaded. 364 // Fetched and uploaded.
341 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry)); 365 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry));
342 EXPECT_TRUE(cache_entry.is_present()); 366 EXPECT_TRUE(cache_entry.is_present());
343 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("dirty"), &cache_entry)); 367 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("dirty"), &cache_entry));
344 EXPECT_FALSE(cache_entry.is_dirty()); 368 EXPECT_FALSE(cache_entry.is_dirty());
345 } 369 }
346 370
347 } // namespace internal 371 } // namespace internal
348 } // namespace drive 372 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/sync_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698