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 "chrome/browser/chromeos/drive/sync_client.h" | 5 #include "chrome/browser/chromeos/drive/sync_client.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.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" |
(...skipping 24 matching lines...) Expand all Loading... |
35 namespace internal { | 35 namespace internal { |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 // The content of files initially stored in the cache. | 39 // The content of files initially stored in the cache. |
40 const char kLocalContent[] = "Hello!"; | 40 const char kLocalContent[] = "Hello!"; |
41 | 41 |
42 // The content of files stored in the service. | 42 // The content of files stored in the service. |
43 const char kRemoteContent[] = "World!"; | 43 const char kRemoteContent[] = "World!"; |
44 | 44 |
45 // SyncClientTestDriveService will return GDATA_CANCELLED when a request is | 45 // SyncClientTestDriveService will return DRIVE_CANCELLED when a request is |
46 // made with the specified resource ID. | 46 // made with the specified resource ID. |
47 class SyncClientTestDriveService : public ::drive::FakeDriveService { | 47 class SyncClientTestDriveService : public ::drive::FakeDriveService { |
48 public: | 48 public: |
49 SyncClientTestDriveService() : download_file_count_(0) {} | 49 SyncClientTestDriveService() : download_file_count_(0) {} |
50 | 50 |
51 // FakeDriveService override: | 51 // FakeDriveService override: |
52 google_apis::CancelCallback DownloadFile( | 52 google_apis::CancelCallback DownloadFile( |
53 const base::FilePath& local_cache_path, | 53 const base::FilePath& local_cache_path, |
54 const std::string& resource_id, | 54 const std::string& resource_id, |
55 const google_apis::DownloadActionCallback& download_action_callback, | 55 const google_apis::DownloadActionCallback& download_action_callback, |
56 const google_apis::GetContentCallback& get_content_callback, | 56 const google_apis::GetContentCallback& get_content_callback, |
57 const google_apis::ProgressCallback& progress_callback) override { | 57 const google_apis::ProgressCallback& progress_callback) override { |
58 ++download_file_count_; | 58 ++download_file_count_; |
59 if (resource_id == resource_id_to_be_cancelled_) { | 59 if (resource_id == resource_id_to_be_cancelled_) { |
60 base::MessageLoopProxy::current()->PostTask( | 60 base::MessageLoopProxy::current()->PostTask( |
61 FROM_HERE, | 61 FROM_HERE, |
62 base::Bind(download_action_callback, | 62 base::Bind(download_action_callback, |
63 google_apis::GDATA_CANCELLED, | 63 google_apis::DRIVE_CANCELLED, |
64 base::FilePath())); | 64 base::FilePath())); |
65 return google_apis::CancelCallback(); | 65 return google_apis::CancelCallback(); |
66 } | 66 } |
67 if (resource_id == resource_id_to_be_paused_) { | 67 if (resource_id == resource_id_to_be_paused_) { |
68 paused_action_ = base::Bind(download_action_callback, | 68 paused_action_ = base::Bind(download_action_callback, |
69 google_apis::GDATA_OTHER_ERROR, | 69 google_apis::DRIVE_OTHER_ERROR, |
70 base::FilePath()); | 70 base::FilePath()); |
71 return google_apis::CancelCallback(); | 71 return google_apis::CancelCallback(); |
72 } | 72 } |
73 return FakeDriveService::DownloadFile(local_cache_path, | 73 return FakeDriveService::DownloadFile(local_cache_path, |
74 resource_id, | 74 resource_id, |
75 download_action_callback, | 75 download_action_callback, |
76 get_content_callback, | 76 get_content_callback, |
77 progress_callback); | 77 progress_callback); |
78 } | 78 } |
79 | 79 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 cache_.get(), | 151 cache_.get(), |
152 loader_controller_.get(), | 152 loader_controller_.get(), |
153 temp_dir_.path())); | 153 temp_dir_.path())); |
154 | 154 |
155 // Disable delaying so that DoSyncLoop() starts immediately. | 155 // Disable delaying so that DoSyncLoop() starts immediately. |
156 sync_client_->set_delay_for_testing(base::TimeDelta::FromSeconds(0)); | 156 sync_client_->set_delay_for_testing(base::TimeDelta::FromSeconds(0)); |
157 } | 157 } |
158 | 158 |
159 // Adds a file to the service root and |resource_ids_|. | 159 // Adds a file to the service root and |resource_ids_|. |
160 void AddFileEntry(const std::string& title) { | 160 void AddFileEntry(const std::string& title) { |
161 google_apis::GDataErrorCode error = google_apis::GDATA_FILE_ERROR; | 161 google_apis::DriveApiErrorCode error = google_apis::DRIVE_FILE_ERROR; |
162 scoped_ptr<google_apis::FileResource> entry; | 162 scoped_ptr<google_apis::FileResource> entry; |
163 drive_service_->AddNewFile( | 163 drive_service_->AddNewFile( |
164 "text/plain", | 164 "text/plain", |
165 kRemoteContent, | 165 kRemoteContent, |
166 drive_service_->GetRootResourceId(), | 166 drive_service_->GetRootResourceId(), |
167 title, | 167 title, |
168 false, // shared_with_me | 168 false, // shared_with_me |
169 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 169 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
170 base::RunLoop().RunUntilIdle(); | 170 base::RunLoop().RunUntilIdle(); |
171 ASSERT_EQ(google_apis::HTTP_CREATED, error); | 171 ASSERT_EQ(google_apis::HTTP_CREATED, error); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 EXPECT_EQ(FILE_ERROR_OK, | 284 EXPECT_EQ(FILE_ERROR_OK, |
285 metadata_->GetResourceEntryById(GetLocalId("baz"), &entry)); | 285 metadata_->GetResourceEntryById(GetLocalId("baz"), &entry)); |
286 EXPECT_TRUE(entry.file_specific_info().cache_state().is_present()); | 286 EXPECT_TRUE(entry.file_specific_info().cache_state().is_present()); |
287 | 287 |
288 // Dirty file gets uploaded. | 288 // Dirty file gets uploaded. |
289 EXPECT_EQ(FILE_ERROR_OK, | 289 EXPECT_EQ(FILE_ERROR_OK, |
290 metadata_->GetResourceEntryById(GetLocalId("dirty"), &entry)); | 290 metadata_->GetResourceEntryById(GetLocalId("dirty"), &entry)); |
291 EXPECT_FALSE(entry.file_specific_info().cache_state().is_dirty()); | 291 EXPECT_FALSE(entry.file_specific_info().cache_state().is_dirty()); |
292 | 292 |
293 // Removed entry is not found. | 293 // Removed entry is not found. |
294 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; | 294 google_apis::DriveApiErrorCode status = google_apis::DRIVE_OTHER_ERROR; |
295 scoped_ptr<google_apis::FileResource> server_entry; | 295 scoped_ptr<google_apis::FileResource> server_entry; |
296 drive_service_->GetFileResource( | 296 drive_service_->GetFileResource( |
297 resource_ids_["removed"], | 297 resource_ids_["removed"], |
298 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); | 298 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); |
299 base::RunLoop().RunUntilIdle(); | 299 base::RunLoop().RunUntilIdle(); |
300 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); | 300 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); |
301 ASSERT_TRUE(server_entry); | 301 ASSERT_TRUE(server_entry); |
302 EXPECT_TRUE(server_entry->labels().is_trashed()); | 302 EXPECT_TRUE(server_entry->labels().is_trashed()); |
303 | 303 |
304 // Moved entry was moved. | 304 // Moved entry was moved. |
305 status = google_apis::GDATA_OTHER_ERROR; | 305 status = google_apis::DRIVE_OTHER_ERROR; |
306 drive_service_->GetFileResource( | 306 drive_service_->GetFileResource( |
307 resource_ids_["moved"], | 307 resource_ids_["moved"], |
308 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); | 308 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); |
309 base::RunLoop().RunUntilIdle(); | 309 base::RunLoop().RunUntilIdle(); |
310 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); | 310 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); |
311 ASSERT_TRUE(server_entry); | 311 ASSERT_TRUE(server_entry); |
312 EXPECT_EQ("moved_new_title", server_entry->title()); | 312 EXPECT_EQ("moved_new_title", server_entry->title()); |
313 } | 313 } |
314 | 314 |
315 TEST_F(SyncClientTest, AddFetchTask) { | 315 TEST_F(SyncClientTest, AddFetchTask) { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 local_id, google_apis::test_util::CreateCopyResultCallback(&error))); | 511 local_id, google_apis::test_util::CreateCopyResultCallback(&error))); |
512 | 512 |
513 base::RunLoop().RunUntilIdle(); | 513 base::RunLoop().RunUntilIdle(); |
514 | 514 |
515 // The callback is called. | 515 // The callback is called. |
516 EXPECT_EQ(FILE_ERROR_OK, error); | 516 EXPECT_EQ(FILE_ERROR_OK, error); |
517 } | 517 } |
518 | 518 |
519 } // namespace internal | 519 } // namespace internal |
520 } // namespace drive | 520 } // namespace drive |
OLD | NEW |