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

Side by Side Diff: chrome/browser/chromeos/extensions/external_filesystem_apitest.cc

Issue 10828385: Rename DocumentsServiceInterface to DriveServiceInterface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unnecessary includes. Created 8 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/extensions/file_browser_event_router.cc » ('j') | 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/file_path.h" 6 #include "base/file_path.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/scoped_temp_dir.h" 12 #include "base/scoped_temp_dir.h"
13 #include "base/threading/worker_pool.h" 13 #include "base/threading/worker_pool.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" 15 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h"
16 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 16 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
17 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" 17 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h"
18 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" 18 #include "chrome/browser/chromeos/gdata/gdata_system_service.h"
19 #include "chrome/browser/chromeos/gdata/gdata_util.h" 19 #include "chrome/browser/chromeos/gdata/gdata_util.h"
20 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" 20 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h"
21 #include "chrome/browser/chromeos/gdata/mock_documents_service.h" 21 #include "chrome/browser/chromeos/gdata/mock_drive_service.h"
22 #include "chrome/browser/extensions/extension_apitest.h" 22 #include "chrome/browser/extensions/extension_apitest.h"
23 #include "chrome/browser/extensions/extension_test_message_listener.h" 23 #include "chrome/browser/extensions/extension_test_message_listener.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
26 #include "chrome/common/chrome_notification_types.h" 26 #include "chrome/common/chrome_notification_types.h"
27 #include "chrome/common/chrome_paths.h" 27 #include "chrome/common/chrome_paths.h"
28 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
29 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
31 #include "content/public/test/test_utils.h" 31 #include "content/public/test/test_utils.h"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // Set up cache root and documents service to be used when creating gdata 197 // Set up cache root and documents service to be used when creating gdata
198 // system service. This has to be done early on (before the browser is 198 // system service. This has to be done early on (before the browser is
199 // created) because the system service instance is initialized very early 199 // created) because the system service instance is initialized very early
200 // by FileBrowserEventRouter. 200 // by FileBrowserEventRouter.
201 FilePath tmp_dir_path; 201 FilePath tmp_dir_path;
202 PathService::Get(base::DIR_TEMP, &tmp_dir_path); 202 PathService::Get(base::DIR_TEMP, &tmp_dir_path);
203 ASSERT_TRUE(test_cache_root_.CreateUniqueTempDirUnderPath(tmp_dir_path)); 203 ASSERT_TRUE(test_cache_root_.CreateUniqueTempDirUnderPath(tmp_dir_path));
204 gdata::GDataSystemServiceFactory::set_cache_root_for_test( 204 gdata::GDataSystemServiceFactory::set_cache_root_for_test(
205 test_cache_root_.path().value()); 205 test_cache_root_.path().value());
206 206
207 mock_documents_service_ = new gdata::MockDocumentsService(); 207 mock_drive_service_ = new gdata::MockDriveService();
208 208
209 operation_registry_.reset(new gdata::GDataOperationRegistry()); 209 operation_registry_.reset(new gdata::GDataOperationRegistry());
210 // FileBrowserEventRouter will add and remove itself from operation registry 210 // FileBrowserEventRouter will add and remove itself from operation registry
211 // observer list. 211 // observer list.
212 EXPECT_CALL(*mock_documents_service_, operation_registry()). 212 EXPECT_CALL(*mock_drive_service_, operation_registry()).
213 WillRepeatedly(Return(operation_registry_.get())); 213 WillRepeatedly(Return(operation_registry_.get()));
214 214
215 // |mock_documents_service_| will eventually get owned by a system service. 215 // |mock_drive_service_| will eventually get owned by a system service.
216 gdata::GDataSystemServiceFactory::set_documents_service_for_test( 216 gdata::GDataSystemServiceFactory::set_drive_service_for_test(
217 mock_documents_service_); 217 mock_drive_service_);
218 218
219 ExtensionApiTest::SetUp(); 219 ExtensionApiTest::SetUp();
220 } 220 }
221 221
222 virtual void TearDown() OVERRIDE { 222 virtual void TearDown() OVERRIDE {
223 // Let's make sure we don't leak documents service. 223 // Let's make sure we don't leak documents service.
224 gdata::GDataSystemServiceFactory::set_documents_service_for_test(NULL); 224 gdata::GDataSystemServiceFactory::set_drive_service_for_test(NULL);
225 gdata::GDataSystemServiceFactory::set_cache_root_for_test(std::string()); 225 gdata::GDataSystemServiceFactory::set_cache_root_for_test(std::string());
226 ExtensionApiTest::TearDown(); 226 ExtensionApiTest::TearDown();
227 } 227 }
228 228
229 protected: 229 protected:
230 ScopedTempDir test_cache_root_; 230 ScopedTempDir test_cache_root_;
231 gdata::MockDocumentsService* mock_documents_service_; 231 gdata::MockDriveService* mock_drive_service_;
232 scoped_ptr<gdata::GDataOperationRegistry> operation_registry_; 232 scoped_ptr<gdata::GDataOperationRegistry> operation_registry_;
233 }; 233 };
234 234
235 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, LocalFileSystem) { 235 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, LocalFileSystem) {
236 AddTmpMountPoint(); 236 AddTmpMountPoint();
237 ASSERT_TRUE(RunComponentExtensionTest("local_filesystem")) << message_; 237 ASSERT_TRUE(RunComponentExtensionTest("local_filesystem")) << message_;
238 } 238 }
239 239
240 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, FileBrowserTest) { 240 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, FileBrowserTest) {
241 AddTmpMountPoint(); 241 AddTmpMountPoint();
(...skipping 29 matching lines...) Expand all
271 FileBrowserTestWriteComponent) { 271 FileBrowserTestWriteComponent) {
272 AddTmpMountPoint(); 272 AddTmpMountPoint();
273 ASSERT_TRUE(RunComponentExtensionTest("filesystem_handler_write")) 273 ASSERT_TRUE(RunComponentExtensionTest("filesystem_handler_write"))
274 << message_; 274 << message_;
275 ASSERT_TRUE(RunExtensionSubtest( 275 ASSERT_TRUE(RunExtensionSubtest(
276 "filebrowser_component", "write.html", kComponentFlags)) << message_; 276 "filebrowser_component", "write.html", kComponentFlags)) << message_;
277 } 277 }
278 278
279 IN_PROC_BROWSER_TEST_F(RemoteFileSystemExtensionApiTest, 279 IN_PROC_BROWSER_TEST_F(RemoteFileSystemExtensionApiTest,
280 RemoteMountPoint) { 280 RemoteMountPoint) {
281 EXPECT_CALL(*mock_documents_service_, GetAccountMetadata(_)).Times(1); 281 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1);
282 282
283 // First, file browser will try to create new directory. 283 // First, file browser will try to create new directory.
284 scoped_ptr<base::Value> dir_value(LoadJSONFile(kTestDirectory)); 284 scoped_ptr<base::Value> dir_value(LoadJSONFile(kTestDirectory));
285 EXPECT_CALL(*mock_documents_service_, 285 EXPECT_CALL(*mock_drive_service_,
286 CreateDirectory(_, _, _)) 286 CreateDirectory(_, _, _))
287 .WillOnce(MockCreateDirectoryCallback(gdata::HTTP_SUCCESS, &dir_value)); 287 .WillOnce(MockCreateDirectoryCallback(gdata::HTTP_SUCCESS, &dir_value));
288 288
289 // Then the test will try to read an existing file file. 289 // Then the test will try to read an existing file file.
290 // Remote filesystem should first request root feed from gdata server. 290 // Remote filesystem should first request root feed from gdata server.
291 scoped_ptr<base::Value> documents_value(LoadJSONFile(kTestRootFeed)); 291 scoped_ptr<base::Value> documents_value(LoadJSONFile(kTestRootFeed));
292 EXPECT_CALL(*mock_documents_service_, 292 EXPECT_CALL(*mock_drive_service_,
293 GetDocuments(_, _, _, _, _)) 293 GetDocuments(_, _, _, _, _))
294 .WillOnce(MockGetDocumentsCallback(gdata::HTTP_SUCCESS, 294 .WillOnce(MockGetDocumentsCallback(gdata::HTTP_SUCCESS,
295 &documents_value)); 295 &documents_value));
296 296
297 // When file browser tries to read the file, remote filesystem should detect 297 // When file browser tries to read the file, remote filesystem should detect
298 // that the cached file is not present on the disk and download it. Mocked 298 // that the cached file is not present on the disk and download it. Mocked
299 // download file will create file with the cached name and predetermined 299 // download file will create file with the cached name and predetermined
300 // content. This is the file file browser will read content from. 300 // content. This is the file file browser will read content from.
301 // Later in the test, file handler will try to open the same file on gdata 301 // Later in the test, file handler will try to open the same file on gdata
302 // mount point. This time, DownloadFile should not be called because local 302 // mount point. This time, DownloadFile should not be called because local
303 // copy is already present in the cache. 303 // copy is already present in the cache.
304 scoped_ptr<base::Value> document_to_download_value( 304 scoped_ptr<base::Value> document_to_download_value(
305 LoadJSONFile(kTestDocumentToDownloadEntry)); 305 LoadJSONFile(kTestDocumentToDownloadEntry));
306 EXPECT_CALL(*mock_documents_service_, 306 EXPECT_CALL(*mock_drive_service_,
307 GetDocumentEntry("file:1_file_resource_id", _)) 307 GetDocumentEntry("file:1_file_resource_id", _))
308 .WillOnce(MockGetDocumentEntryCallback(gdata::HTTP_SUCCESS, 308 .WillOnce(MockGetDocumentEntryCallback(gdata::HTTP_SUCCESS,
309 &document_to_download_value)); 309 &document_to_download_value));
310 310
311 // We expect to download url defined in document entry returned by 311 // We expect to download url defined in document entry returned by
312 // GetDocumentEntry mock implementation. 312 // GetDocumentEntry mock implementation.
313 EXPECT_CALL(*mock_documents_service_, 313 EXPECT_CALL(*mock_drive_service_,
314 DownloadFile(_, _, GURL("https://file_content_url_changed"), 314 DownloadFile(_, _, GURL("https://file_content_url_changed"),
315 _, _)) 315 _, _))
316 .WillOnce(MockDownloadFileCallback(gdata::HTTP_SUCCESS)); 316 .WillOnce(MockDownloadFileCallback(gdata::HTTP_SUCCESS));
317 317
318 // On exit, all operations in progress should be cancelled. 318 // On exit, all operations in progress should be cancelled.
319 EXPECT_CALL(*mock_documents_service_, CancelAll()); 319 EXPECT_CALL(*mock_drive_service_, CancelAll());
320 320
321 // All is set... RUN THE TEST. 321 // All is set... RUN THE TEST.
322 EXPECT_TRUE(RunExtensionTest("filesystem_handler")) << message_; 322 EXPECT_TRUE(RunExtensionTest("filesystem_handler")) << message_;
323 EXPECT_TRUE(RunExtensionSubtest("filebrowser_component", "remote.html", 323 EXPECT_TRUE(RunExtensionSubtest("filebrowser_component", "remote.html",
324 kComponentFlags)) << message_; 324 kComponentFlags)) << message_;
325 } 325 }
326 326
327 IN_PROC_BROWSER_TEST_F(RemoteFileSystemExtensionApiTest, ContentSearch) { 327 IN_PROC_BROWSER_TEST_F(RemoteFileSystemExtensionApiTest, ContentSearch) {
328 EXPECT_CALL(*mock_documents_service_, GetAccountMetadata(_)).Times(1); 328 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1);
329 329
330 // First, test will get drive root directory, to init file system. 330 // First, test will get drive root directory, to init file system.
331 scoped_ptr<base::Value> documents_value(LoadJSONFile(kTestRootFeed)); 331 scoped_ptr<base::Value> documents_value(LoadJSONFile(kTestRootFeed));
332 EXPECT_CALL(*mock_documents_service_, 332 EXPECT_CALL(*mock_drive_service_,
333 GetDocuments(_, _, "", _, _)) 333 GetDocuments(_, _, "", _, _))
334 .WillOnce(MockGetDocumentsCallback(gdata::HTTP_SUCCESS, 334 .WillOnce(MockGetDocumentsCallback(gdata::HTTP_SUCCESS,
335 &documents_value)); 335 &documents_value));
336 336
337 // We return the whole test file system in serch results. 337 // We return the whole test file system in serch results.
338 scoped_ptr<base::Value> search_value(LoadJSONFile(kTestRootFeed)); 338 scoped_ptr<base::Value> search_value(LoadJSONFile(kTestRootFeed));
339 EXPECT_CALL(*mock_documents_service_, 339 EXPECT_CALL(*mock_drive_service_,
340 GetDocuments(_, _, "foo", _, _)) 340 GetDocuments(_, _, "foo", _, _))
341 .WillOnce(MockGetDocumentsCallback(gdata::HTTP_SUCCESS, 341 .WillOnce(MockGetDocumentsCallback(gdata::HTTP_SUCCESS,
342 &search_value)); 342 &search_value));
343 343
344 // Test will try to create a snapshot of the returned file. 344 // Test will try to create a snapshot of the returned file.
345 scoped_ptr<base::Value> document_to_download_value( 345 scoped_ptr<base::Value> document_to_download_value(
346 LoadJSONFile(kTestDocumentToDownloadEntry)); 346 LoadJSONFile(kTestDocumentToDownloadEntry));
347 EXPECT_CALL(*mock_documents_service_, 347 EXPECT_CALL(*mock_drive_service_,
348 GetDocumentEntry("file:1_file_resource_id", _)) 348 GetDocumentEntry("file:1_file_resource_id", _))
349 .WillOnce(MockGetDocumentEntryCallback(gdata::HTTP_SUCCESS, 349 .WillOnce(MockGetDocumentEntryCallback(gdata::HTTP_SUCCESS,
350 &document_to_download_value)); 350 &document_to_download_value));
351 351
352 // We expect to download url defined in document entry returned by 352 // We expect to download url defined in document entry returned by
353 // GetDocumentEntry mock implementation. 353 // GetDocumentEntry mock implementation.
354 EXPECT_CALL(*mock_documents_service_, 354 EXPECT_CALL(*mock_drive_service_,
355 DownloadFile(_, _, GURL("https://file_content_url_changed"), 355 DownloadFile(_, _, GURL("https://file_content_url_changed"),
356 _, _)) 356 _, _))
357 .WillOnce(MockDownloadFileCallback(gdata::HTTP_SUCCESS)); 357 .WillOnce(MockDownloadFileCallback(gdata::HTTP_SUCCESS));
358 358
359 // On exit, all operations in progress should be cancelled. 359 // On exit, all operations in progress should be cancelled.
360 EXPECT_CALL(*mock_documents_service_, CancelAll()); 360 EXPECT_CALL(*mock_drive_service_, CancelAll());
361 361
362 // All is set... RUN THE TEST. 362 // All is set... RUN THE TEST.
363 EXPECT_TRUE(RunExtensionSubtest("filebrowser_component", "remote_search.html", 363 EXPECT_TRUE(RunExtensionSubtest("filebrowser_component", "remote_search.html",
364 kComponentFlags)) << message_; 364 kComponentFlags)) << message_;
365 } 365 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/extensions/file_browser_event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698