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

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

Issue 98513003: drive: Support offline move/rename (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/move_operation.h"
19 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" 20 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h"
20 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h" 21 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h"
22 #include "chrome/browser/chromeos/drive/file_system_util.h"
21 #include "chrome/browser/chromeos/drive/job_scheduler.h" 23 #include "chrome/browser/chromeos/drive/job_scheduler.h"
22 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" 24 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h"
23 #include "chrome/browser/chromeos/drive/resource_metadata.h" 25 #include "chrome/browser/chromeos/drive/resource_metadata.h"
24 #include "chrome/browser/chromeos/drive/test_util.h" 26 #include "chrome/browser/chromeos/drive/test_util.h"
25 #include "chrome/browser/drive/fake_drive_service.h" 27 #include "chrome/browser/drive/fake_drive_service.h"
26 #include "chrome/browser/google_apis/test_util.h" 28 #include "chrome/browser/google_apis/test_util.h"
27 #include "content/public/test/test_browser_thread_bundle.h" 29 #include "content/public/test/test_browser_thread_bundle.h"
28 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
29 31
30 namespace drive { 32 namespace drive {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(temp_file, 157 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(temp_file,
156 kLocalContent)); 158 kLocalContent));
157 159
158 // Add file entries to the service. 160 // Add file entries to the service.
159 ASSERT_NO_FATAL_FAILURE(AddFileEntry("foo")); 161 ASSERT_NO_FATAL_FAILURE(AddFileEntry("foo"));
160 ASSERT_NO_FATAL_FAILURE(AddFileEntry("bar")); 162 ASSERT_NO_FATAL_FAILURE(AddFileEntry("bar"));
161 ASSERT_NO_FATAL_FAILURE(AddFileEntry("baz")); 163 ASSERT_NO_FATAL_FAILURE(AddFileEntry("baz"));
162 ASSERT_NO_FATAL_FAILURE(AddFileEntry("fetched")); 164 ASSERT_NO_FATAL_FAILURE(AddFileEntry("fetched"));
163 ASSERT_NO_FATAL_FAILURE(AddFileEntry("dirty")); 165 ASSERT_NO_FATAL_FAILURE(AddFileEntry("dirty"));
164 ASSERT_NO_FATAL_FAILURE(AddFileEntry("removed")); 166 ASSERT_NO_FATAL_FAILURE(AddFileEntry("removed"));
167 ASSERT_NO_FATAL_FAILURE(AddFileEntry("moved"));
165 168
166 // Load data from the service to the metadata. 169 // Load data from the service to the metadata.
167 FileError error = FILE_ERROR_FAILED; 170 FileError error = FILE_ERROR_FAILED;
168 internal::ChangeListLoader change_list_loader( 171 internal::ChangeListLoader change_list_loader(
169 base::MessageLoopProxy::current().get(), 172 base::MessageLoopProxy::current().get(),
170 metadata_.get(), 173 metadata_.get(),
171 scheduler_.get(), 174 scheduler_.get(),
172 drive_service_.get()); 175 drive_service_.get());
173 change_list_loader.LoadIfNeeded( 176 change_list_loader.LoadIfNeeded(
174 DirectoryFetchInfo(), 177 DirectoryFetchInfo(),
(...skipping 24 matching lines...) Expand all
199 // Prepare a removed file. 202 // Prepare a removed file.
200 file_system::RemoveOperation remove_operation( 203 file_system::RemoveOperation remove_operation(
201 base::MessageLoopProxy::current().get(), &observer_, metadata_.get(), 204 base::MessageLoopProxy::current().get(), &observer_, metadata_.get(),
202 cache_.get()); 205 cache_.get());
203 remove_operation.Remove( 206 remove_operation.Remove(
204 metadata_->GetFilePath(GetLocalId("removed")), 207 metadata_->GetFilePath(GetLocalId("removed")),
205 false, // is_recursive 208 false, // is_recursive
206 google_apis::test_util::CreateCopyResultCallback(&error)); 209 google_apis::test_util::CreateCopyResultCallback(&error));
207 base::RunLoop().RunUntilIdle(); 210 base::RunLoop().RunUntilIdle();
208 EXPECT_EQ(FILE_ERROR_OK, error); 211 EXPECT_EQ(FILE_ERROR_OK, error);
212
213 // Prepare a moved file.
214 file_system::MoveOperation move_operation(
215 base::MessageLoopProxy::current().get(), &observer_, metadata_.get());
216 move_operation.Move(
217 metadata_->GetFilePath(GetLocalId("moved")),
218 util::GetDriveMyDriveRootPath().AppendASCII("moved_new_title"),
219 false, // preserve_last_modified
220 google_apis::test_util::CreateCopyResultCallback(&error));
221 base::RunLoop().RunUntilIdle();
222 EXPECT_EQ(FILE_ERROR_OK, error);
209 } 223 }
210 224
211 protected: 225 protected:
212 std::string GetLocalId(const std::string& title) { 226 std::string GetLocalId(const std::string& title) {
213 EXPECT_EQ(1U, resource_ids_.count(title)); 227 EXPECT_EQ(1U, resource_ids_.count(title));
214 std::string local_id; 228 std::string local_id;
215 EXPECT_EQ(FILE_ERROR_OK, 229 EXPECT_EQ(FILE_ERROR_OK,
216 metadata_->GetIdByResourceId(resource_ids_[title], &local_id)); 230 metadata_->GetIdByResourceId(resource_ids_[title], &local_id));
217 return local_id; 231 return local_id;
218 } 232 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 271 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
258 scoped_ptr<google_apis::ResourceEntry> resource_entry; 272 scoped_ptr<google_apis::ResourceEntry> resource_entry;
259 drive_service_->GetResourceEntry( 273 drive_service_->GetResourceEntry(
260 resource_ids_["removed"], 274 resource_ids_["removed"],
261 google_apis::test_util::CreateCopyResultCallback(&status, 275 google_apis::test_util::CreateCopyResultCallback(&status,
262 &resource_entry)); 276 &resource_entry));
263 base::RunLoop().RunUntilIdle(); 277 base::RunLoop().RunUntilIdle();
264 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 278 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
265 ASSERT_TRUE(resource_entry); 279 ASSERT_TRUE(resource_entry);
266 EXPECT_TRUE(resource_entry->deleted()); 280 EXPECT_TRUE(resource_entry->deleted());
281
282 // Moved entry was moved.
283 status = google_apis::GDATA_OTHER_ERROR;
284 drive_service_->GetResourceEntry(
285 resource_ids_["moved"],
286 google_apis::test_util::CreateCopyResultCallback(&status,
287 &resource_entry));
288 base::RunLoop().RunUntilIdle();
289 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
290 ASSERT_TRUE(resource_entry);
291 EXPECT_EQ("moved_new_title", resource_entry->title());
267 } 292 }
268 293
269 TEST_F(SyncClientTest, AddFetchTask) { 294 TEST_F(SyncClientTest, AddFetchTask) {
270 sync_client_->AddFetchTask(GetLocalId("foo")); 295 sync_client_->AddFetchTask(GetLocalId("foo"));
271 base::RunLoop().RunUntilIdle(); 296 base::RunLoop().RunUntilIdle();
272 297
273 FileCacheEntry cache_entry; 298 FileCacheEntry cache_entry;
274 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry)); 299 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry));
275 EXPECT_TRUE(cache_entry.is_present()); 300 EXPECT_TRUE(cache_entry.is_present());
276 } 301 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 388
364 // Fetched and uploaded. 389 // Fetched and uploaded.
365 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry)); 390 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("foo"), &cache_entry));
366 EXPECT_TRUE(cache_entry.is_present()); 391 EXPECT_TRUE(cache_entry.is_present());
367 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("dirty"), &cache_entry)); 392 EXPECT_TRUE(cache_->GetCacheEntry(GetLocalId("dirty"), &cache_entry));
368 EXPECT_FALSE(cache_entry.is_dirty()); 393 EXPECT_FALSE(cache_entry.is_dirty());
369 } 394 }
370 395
371 } // namespace internal 396 } // namespace internal
372 } // namespace drive 397 } // 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