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

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

Issue 11106007: drive: Rename 'gdata' namespace to 'drive' in chrome/browser/chromeos/drive (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 2 months 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
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/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"
11 #include "base/json/json_file_value_serializer.h" 11 #include "base/json/json_file_value_serializer.h"
12 #include "base/message_loop_proxy.h" 12 #include "base/message_loop_proxy.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/platform_file.h" 14 #include "base/platform_file.h"
15 #include "chrome/browser/chromeos/drive/drive_test_util.h" 15 #include "chrome/browser/chromeos/drive/drive_test_util.h"
16 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
17 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
18 18
19 using ::testing::_; 19 using ::testing::_;
20 using ::testing::Invoke; 20 using ::testing::Invoke;
21 using ::testing::Return; 21 using ::testing::Return;
22 22
23 namespace gdata { 23 namespace drive {
24 24
25 MockDriveService::MockDriveService() { 25 MockDriveService::MockDriveService() {
26 ON_CALL(*this, GetProgressStatusList()) 26 ON_CALL(*this, GetProgressStatusList())
27 .WillByDefault(Return(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 test_util::LoadJSONFile("gdata/account_metadata.json"); 56 gdata::test_util::LoadJSONFile("gdata/account_metadata.json");
57 feed_data_ = 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 test_util::LoadJSONFile("gdata/new_folder_entry.json"); 59 gdata::test_util::LoadJSONFile("gdata/new_folder_entry.json");
60 } 60 }
61 61
62 MockDriveService::~MockDriveService() {} 62 MockDriveService::~MockDriveService() {}
63 63
64 void MockDriveService::set_search_result( 64 void MockDriveService::set_search_result(
65 const std::string& search_result_feed) { 65 const std::string& search_result_feed) {
66 search_result_ = test_util::LoadJSONFile(search_result_feed); 66 search_result_ = gdata::test_util::LoadJSONFile(search_result_feed);
67 } 67 }
68 68
69 void MockDriveService::AuthenticateStub( 69 void MockDriveService::AuthenticateStub(
70 const AuthStatusCallback& callback) { 70 const gdata::AuthStatusCallback& callback) {
71 base::MessageLoopProxy::current()->PostTask( 71 base::MessageLoopProxy::current()->PostTask(
72 FROM_HERE, 72 FROM_HERE,
73 base::Bind(callback, HTTP_SUCCESS, "my_auth_token")); 73 base::Bind(callback, gdata::HTTP_SUCCESS, "my_auth_token"));
74 } 74 }
75 75
76 void MockDriveService::GetDocumentsStub( 76 void MockDriveService::GetDocumentsStub(
77 const GURL& feed_url, 77 const GURL& feed_url,
78 int64 start_changestamp, 78 int64 start_changestamp,
79 const std::string& search_string, 79 const std::string& search_string,
80 const std::string& directory_resource_id, 80 const std::string& directory_resource_id,
81 const GetDataCallback& callback) { 81 const gdata::GetDataCallback& callback) {
82 if (search_string.empty()) { 82 if (search_string.empty()) {
83 base::MessageLoopProxy::current()->PostTask( 83 base::MessageLoopProxy::current()->PostTask(
84 FROM_HERE, 84 FROM_HERE,
85 base::Bind(callback, HTTP_SUCCESS, base::Passed(&feed_data_))); 85 base::Bind(callback, gdata::HTTP_SUCCESS,
86 base::Passed(&feed_data_)));
86 } else { 87 } else {
87 base::MessageLoopProxy::current()->PostTask( 88 base::MessageLoopProxy::current()->PostTask(
88 FROM_HERE, 89 FROM_HERE,
89 base::Bind(callback, HTTP_SUCCESS, base::Passed(&search_result_))); 90 base::Bind(callback, gdata::HTTP_SUCCESS,
91 base::Passed(&search_result_)));
90 } 92 }
91 } 93 }
92 94
93 void MockDriveService::GetAccountMetadataStub( 95 void MockDriveService::GetAccountMetadataStub(
94 const GetDataCallback& callback) { 96 const gdata::GetDataCallback& callback) {
95 base::MessageLoopProxy::current()->PostTask( 97 base::MessageLoopProxy::current()->PostTask(
96 FROM_HERE, 98 FROM_HERE,
97 base::Bind(callback, HTTP_SUCCESS, base::Passed(&account_metadata_))); 99 base::Bind(callback, gdata::HTTP_SUCCESS,
100 base::Passed(&account_metadata_)));
98 } 101 }
99 102
100 void MockDriveService::DeleteDocumentStub( 103 void MockDriveService::DeleteDocumentStub(
101 const GURL& document_url, 104 const GURL& document_url,
102 const EntryActionCallback& callback) { 105 const gdata::EntryActionCallback& callback) {
103 base::MessageLoopProxy::current()->PostTask( 106 base::MessageLoopProxy::current()->PostTask(
104 FROM_HERE, 107 FROM_HERE,
105 base::Bind(callback, HTTP_SUCCESS, document_url)); 108 base::Bind(callback, gdata::HTTP_SUCCESS, document_url));
106 } 109 }
107 110
108 void MockDriveService::DownloadDocumentStub( 111 void MockDriveService::DownloadDocumentStub(
109 const FilePath& virtual_path, 112 const FilePath& virtual_path,
110 const FilePath& local_tmp_path, 113 const FilePath& local_tmp_path,
111 const GURL& content_url, 114 const GURL& content_url,
112 DocumentExportFormat format, 115 DocumentExportFormat format,
113 const DownloadActionCallback& callback) { 116 const gdata::DownloadActionCallback& callback) {
114 base::MessageLoopProxy::current()->PostTask( 117 base::MessageLoopProxy::current()->PostTask(
115 FROM_HERE, 118 FROM_HERE,
116 base::Bind(callback, HTTP_SUCCESS, content_url, local_tmp_path)); 119 base::Bind(callback, gdata::HTTP_SUCCESS, content_url, local_tmp_path));
117 } 120 }
118 121
119 void MockDriveService::CopyDocumentStub( 122 void MockDriveService::CopyDocumentStub(
120 const std::string& resource_id, 123 const std::string& resource_id,
121 const FilePath::StringType& new_name, 124 const FilePath::StringType& new_name,
122 const GetDataCallback& callback) { 125 const gdata::GetDataCallback& callback) {
123 base::MessageLoopProxy::current()->PostTask( 126 base::MessageLoopProxy::current()->PostTask(
124 FROM_HERE, 127 FROM_HERE,
125 base::Bind(callback, HTTP_SUCCESS, base::Passed(&document_data_))); 128 base::Bind(callback, gdata::HTTP_SUCCESS, base::Passed(&document_data_)));
126 } 129 }
127 130
128 void MockDriveService::RenameResourceStub( 131 void MockDriveService::RenameResourceStub(
129 const GURL& resource_url, 132 const GURL& resource_url,
130 const FilePath::StringType& new_name, 133 const FilePath::StringType& new_name,
131 const EntryActionCallback& callback) { 134 const gdata::EntryActionCallback& callback) {
132 base::MessageLoopProxy::current()->PostTask( 135 base::MessageLoopProxy::current()->PostTask(
133 FROM_HERE, 136 FROM_HERE,
134 base::Bind(callback, HTTP_SUCCESS, resource_url)); 137 base::Bind(callback, gdata::HTTP_SUCCESS, resource_url));
135 } 138 }
136 139
137 void MockDriveService::AddResourceToDirectoryStub( 140 void MockDriveService::AddResourceToDirectoryStub(
138 const GURL& parent_content_url, 141 const GURL& parent_content_url,
139 const GURL& resource_url, 142 const GURL& resource_url,
140 const EntryActionCallback& callback) { 143 const gdata::EntryActionCallback& callback) {
141 base::MessageLoopProxy::current()->PostTask( 144 base::MessageLoopProxy::current()->PostTask(
142 FROM_HERE, 145 FROM_HERE,
143 base::Bind(callback, HTTP_SUCCESS, resource_url)); 146 base::Bind(callback, gdata::HTTP_SUCCESS, resource_url));
144 } 147 }
145 148
146 void MockDriveService::RemoveResourceFromDirectoryStub( 149 void MockDriveService::RemoveResourceFromDirectoryStub(
147 const GURL& parent_content_url, 150 const GURL& parent_content_url,
148 const GURL& resource_url, 151 const GURL& resource_url,
149 const std::string& resource_id, 152 const std::string& resource_id,
150 const EntryActionCallback& callback) { 153 const gdata::EntryActionCallback& callback) {
151 base::MessageLoopProxy::current()->PostTask( 154 base::MessageLoopProxy::current()->PostTask(
152 FROM_HERE, 155 FROM_HERE,
153 base::Bind(callback, HTTP_SUCCESS, resource_url)); 156 base::Bind(callback, gdata::HTTP_SUCCESS, resource_url));
154 } 157 }
155 158
156 void MockDriveService::CreateDirectoryStub( 159 void MockDriveService::CreateDirectoryStub(
157 const GURL& parent_content_url, 160 const GURL& parent_content_url,
158 const FilePath::StringType& directory_name, 161 const FilePath::StringType& directory_name,
159 const GetDataCallback& callback) { 162 const gdata::GetDataCallback& callback) {
160 base::MessageLoopProxy::current()->PostTask( 163 base::MessageLoopProxy::current()->PostTask(
161 FROM_HERE, 164 FROM_HERE,
162 base::Bind(callback, HTTP_SUCCESS, base::Passed(&directory_data_))); 165 base::Bind(callback, gdata::HTTP_SUCCESS,
166 base::Passed(&directory_data_)));
163 } 167 }
164 168
165 void MockDriveService::DownloadFileStub( 169 void MockDriveService::DownloadFileStub(
166 const FilePath& virtual_path, 170 const FilePath& virtual_path,
167 const FilePath& local_tmp_path, 171 const FilePath& local_tmp_path,
168 const GURL& content_url, 172 const GURL& content_url,
169 const DownloadActionCallback& download_action_callback, 173 const gdata::DownloadActionCallback& download_action_callback,
170 const GetContentCallback& get_content_callback) { 174 const gdata::GetContentCallback& get_content_callback) {
171 GDataErrorCode error = HTTP_SUCCESS; 175 gdata::GDataErrorCode error = gdata::HTTP_SUCCESS;
172 if (file_data_.get()) { 176 if (file_data_.get()) {
173 int file_data_size = static_cast<int>(file_data_->size()); 177 int file_data_size = static_cast<int>(file_data_->size());
174 ASSERT_EQ(file_data_size, 178 ASSERT_EQ(file_data_size,
175 file_util::WriteFile(local_tmp_path, file_data_->data(), 179 file_util::WriteFile(local_tmp_path, file_data_->data(),
176 file_data_size)); 180 file_data_size));
177 } 181 }
178 base::MessageLoopProxy::current()->PostTask( 182 base::MessageLoopProxy::current()->PostTask(
179 FROM_HERE, 183 FROM_HERE,
180 base::Bind(download_action_callback, error, content_url, local_tmp_path)); 184 base::Bind(download_action_callback, error, content_url, local_tmp_path));
181 } 185 }
182 186
183 } // namespace gdata 187 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/mock_drive_service.h ('k') | chrome/browser/chromeos/drive/mock_drive_uploader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698