| 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/mock_drive_service.h" | 5 #include "chrome/browser/chromeos/drive/mock_drive_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 MockDriveService::MockDriveService() { | 25 MockDriveService::MockDriveService() { |
| 26 ON_CALL(*this, GetProgressStatusList()) | 26 ON_CALL(*this, GetProgressStatusList()) |
| 27 .WillByDefault(Return(gdata::OperationProgressStatusList())); | 27 .WillByDefault(Return(gdata::OperationProgressStatusList())); |
| 28 ON_CALL(*this, Authenticate(_)) | 28 ON_CALL(*this, Authenticate(_)) |
| 29 .WillByDefault(Invoke(this, &MockDriveService::AuthenticateStub)); | 29 .WillByDefault(Invoke(this, &MockDriveService::AuthenticateStub)); |
| 30 ON_CALL(*this, GetDocuments(_, _, _, _, _)) | 30 ON_CALL(*this, GetDocuments(_, _, _, _, _)) |
| 31 .WillByDefault(Invoke(this, &MockDriveService::GetDocumentsStub)); | 31 .WillByDefault(Invoke(this, &MockDriveService::GetDocumentsStub)); |
| 32 ON_CALL(*this, GetAccountMetadata(_)) | 32 ON_CALL(*this, GetAccountMetadata(_)) |
| 33 .WillByDefault(Invoke(this, | 33 .WillByDefault(Invoke(this, |
| 34 &MockDriveService::GetAccountMetadataStub)); | 34 &MockDriveService::GetAccountMetadataStub)); |
| 35 ON_CALL(*this, DeleteDocument(_, _)) | 35 ON_CALL(*this, DeleteDocument(_, _, _)) |
| 36 .WillByDefault(Invoke(this, &MockDriveService::DeleteDocumentStub)); | 36 .WillByDefault(Invoke(this, &MockDriveService::DeleteDocumentStub)); |
| 37 ON_CALL(*this, DownloadDocument(_, _, _, _, _)) | 37 ON_CALL(*this, DownloadDocument(_, _, _, _, _, _)) |
| 38 .WillByDefault(Invoke(this, &MockDriveService::DownloadDocumentStub)); | 38 .WillByDefault(Invoke(this, &MockDriveService::DownloadDocumentStub)); |
| 39 ON_CALL(*this, CopyDocument(_, _, _)) | 39 ON_CALL(*this, CopyDocument(_, _, _)) |
| 40 .WillByDefault(Invoke(this, &MockDriveService::CopyDocumentStub)); | 40 .WillByDefault(Invoke(this, &MockDriveService::CopyDocumentStub)); |
| 41 ON_CALL(*this, RenameResource(_, _, _)) | 41 ON_CALL(*this, RenameResource(_, _, _)) |
| 42 .WillByDefault(Invoke(this, &MockDriveService::RenameResourceStub)); | 42 .WillByDefault(Invoke(this, &MockDriveService::RenameResourceStub)); |
| 43 ON_CALL(*this, AddResourceToDirectory(_, _, _)) | 43 ON_CALL(*this, AddResourceToDirectory(_, _, _)) |
| 44 .WillByDefault( | 44 .WillByDefault( |
| 45 Invoke(this, &MockDriveService::AddResourceToDirectoryStub)); | 45 Invoke(this, &MockDriveService::AddResourceToDirectoryStub)); |
| 46 ON_CALL(*this, RemoveResourceFromDirectory(_, _, _, _)) | 46 ON_CALL(*this, RemoveResourceFromDirectory(_, _, _, _)) |
| 47 .WillByDefault( | 47 .WillByDefault( |
| 48 Invoke(this, &MockDriveService::RemoveResourceFromDirectoryStub)); | 48 Invoke(this, &MockDriveService::RemoveResourceFromDirectoryStub)); |
| 49 ON_CALL(*this, CreateDirectory(_, _, _)) | 49 ON_CALL(*this, CreateDirectory(_, _, _)) |
| 50 .WillByDefault(Invoke(this, &MockDriveService::CreateDirectoryStub)); | 50 .WillByDefault(Invoke(this, &MockDriveService::CreateDirectoryStub)); |
| 51 ON_CALL(*this, DownloadFile(_, _, _, _, _)) | 51 ON_CALL(*this, DownloadFile(_, _, _, _, _, _)) |
| 52 .WillByDefault(Invoke(this, &MockDriveService::DownloadFileStub)); | 52 .WillByDefault(Invoke(this, &MockDriveService::DownloadFileStub)); |
| 53 | 53 |
| 54 // Fill in the default values for mock feeds. | 54 // Fill in the default values for mock feeds. |
| 55 account_metadata_ = | 55 account_metadata_ = |
| 56 gdata::test_util::LoadJSONFile("gdata/account_metadata.json"); | 56 gdata::test_util::LoadJSONFile("gdata/account_metadata.json"); |
| 57 feed_data_ = gdata::test_util::LoadJSONFile("gdata/basic_feed.json"); | 57 feed_data_ = gdata::test_util::LoadJSONFile("gdata/basic_feed.json"); |
| 58 directory_data_ = | 58 directory_data_ = |
| 59 gdata::test_util::LoadJSONFile("gdata/new_folder_entry.json"); | 59 gdata::test_util::LoadJSONFile("gdata/new_folder_entry.json"); |
| 60 } | 60 } |
| 61 | 61 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 void MockDriveService::GetAccountMetadataStub( | 95 void MockDriveService::GetAccountMetadataStub( |
| 96 const gdata::GetDataCallback& callback) { | 96 const gdata::GetDataCallback& callback) { |
| 97 base::MessageLoopProxy::current()->PostTask( | 97 base::MessageLoopProxy::current()->PostTask( |
| 98 FROM_HERE, | 98 FROM_HERE, |
| 99 base::Bind(callback, gdata::HTTP_SUCCESS, | 99 base::Bind(callback, gdata::HTTP_SUCCESS, |
| 100 base::Passed(&account_metadata_))); | 100 base::Passed(&account_metadata_))); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void MockDriveService::DeleteDocumentStub( | 103 void MockDriveService::DeleteDocumentStub( |
| 104 const GURL& document_url, | 104 const GURL& document_url, |
| 105 const std::string& etag, |
| 105 const gdata::EntryActionCallback& callback) { | 106 const gdata::EntryActionCallback& callback) { |
| 106 base::MessageLoopProxy::current()->PostTask( | 107 base::MessageLoopProxy::current()->PostTask( |
| 107 FROM_HERE, | 108 FROM_HERE, |
| 108 base::Bind(callback, gdata::HTTP_SUCCESS, document_url)); | 109 base::Bind(callback, gdata::HTTP_SUCCESS, document_url)); |
| 109 } | 110 } |
| 110 | 111 |
| 111 void MockDriveService::DownloadDocumentStub( | 112 void MockDriveService::DownloadDocumentStub( |
| 112 const FilePath& virtual_path, | 113 const FilePath& virtual_path, |
| 113 const FilePath& local_tmp_path, | 114 const FilePath& local_tmp_path, |
| 114 const GURL& content_url, | 115 const GURL& content_url, |
| 115 DocumentExportFormat format, | 116 DocumentExportFormat format, |
| 117 const std::string& etag, |
| 116 const gdata::DownloadActionCallback& callback) { | 118 const gdata::DownloadActionCallback& callback) { |
| 117 base::MessageLoopProxy::current()->PostTask( | 119 base::MessageLoopProxy::current()->PostTask( |
| 118 FROM_HERE, | 120 FROM_HERE, |
| 119 base::Bind(callback, gdata::HTTP_SUCCESS, content_url, local_tmp_path)); | 121 base::Bind(callback, gdata::HTTP_SUCCESS, content_url, local_tmp_path)); |
| 120 } | 122 } |
| 121 | 123 |
| 122 void MockDriveService::CopyDocumentStub( | 124 void MockDriveService::CopyDocumentStub( |
| 123 const std::string& resource_id, | 125 const std::string& resource_id, |
| 124 const FilePath::StringType& new_name, | 126 const FilePath::StringType& new_name, |
| 125 const gdata::GetDataCallback& callback) { | 127 const gdata::GetDataCallback& callback) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 base::MessageLoopProxy::current()->PostTask( | 165 base::MessageLoopProxy::current()->PostTask( |
| 164 FROM_HERE, | 166 FROM_HERE, |
| 165 base::Bind(callback, gdata::HTTP_SUCCESS, | 167 base::Bind(callback, gdata::HTTP_SUCCESS, |
| 166 base::Passed(&directory_data_))); | 168 base::Passed(&directory_data_))); |
| 167 } | 169 } |
| 168 | 170 |
| 169 void MockDriveService::DownloadFileStub( | 171 void MockDriveService::DownloadFileStub( |
| 170 const FilePath& virtual_path, | 172 const FilePath& virtual_path, |
| 171 const FilePath& local_tmp_path, | 173 const FilePath& local_tmp_path, |
| 172 const GURL& content_url, | 174 const GURL& content_url, |
| 175 const std::string& etag, |
| 173 const gdata::DownloadActionCallback& download_action_callback, | 176 const gdata::DownloadActionCallback& download_action_callback, |
| 174 const gdata::GetContentCallback& get_content_callback) { | 177 const gdata::GetContentCallback& get_content_callback) { |
| 175 gdata::GDataErrorCode error = gdata::HTTP_SUCCESS; | 178 gdata::GDataErrorCode error = gdata::HTTP_SUCCESS; |
| 176 if (file_data_.get()) { | 179 if (file_data_.get()) { |
| 177 int file_data_size = static_cast<int>(file_data_->size()); | 180 int file_data_size = static_cast<int>(file_data_->size()); |
| 178 ASSERT_EQ(file_data_size, | 181 ASSERT_EQ(file_data_size, |
| 179 file_util::WriteFile(local_tmp_path, file_data_->data(), | 182 file_util::WriteFile(local_tmp_path, file_data_->data(), |
| 180 file_data_size)); | 183 file_data_size)); |
| 181 } | 184 } |
| 182 base::MessageLoopProxy::current()->PostTask( | 185 base::MessageLoopProxy::current()->PostTask( |
| 183 FROM_HERE, | 186 FROM_HERE, |
| 184 base::Bind(download_action_callback, error, content_url, local_tmp_path)); | 187 base::Bind(download_action_callback, error, content_url, local_tmp_path)); |
| 185 } | 188 } |
| 186 | 189 |
| 187 } // namespace drive | 190 } // namespace drive |
| OLD | NEW |