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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 public: | 316 public: |
317 enum Flags { | 317 enum Flags { |
318 FLAGS_NONE = 0, | 318 FLAGS_NONE = 0, |
319 FLAGS_USE_FILE_HANDLER = 1 << 1, | 319 FLAGS_USE_FILE_HANDLER = 1 << 1, |
320 FLAGS_LAZY_FILE_HANDLER = 1 << 2 | 320 FLAGS_LAZY_FILE_HANDLER = 1 << 2 |
321 }; | 321 }; |
322 | 322 |
323 FileSystemExtensionApiTestBase() {} | 323 FileSystemExtensionApiTestBase() {} |
324 virtual ~FileSystemExtensionApiTestBase() {} | 324 virtual ~FileSystemExtensionApiTestBase() {} |
325 | 325 |
326 virtual void SetUp() OVERRIDE { | 326 virtual void SetUp() override { |
327 InitTestFileSystem(); | 327 InitTestFileSystem(); |
328 ExtensionApiTest::SetUp(); | 328 ExtensionApiTest::SetUp(); |
329 } | 329 } |
330 | 330 |
331 virtual void SetUpOnMainThread() OVERRIDE { | 331 virtual void SetUpOnMainThread() override { |
332 AddTestMountPoint(); | 332 AddTestMountPoint(); |
333 ExtensionApiTest::SetUpOnMainThread(); | 333 ExtensionApiTest::SetUpOnMainThread(); |
334 } | 334 } |
335 | 335 |
336 // Runs a file system extension API test. | 336 // Runs a file system extension API test. |
337 // It loads test component extension at |filebrowser_path| with manifest | 337 // It loads test component extension at |filebrowser_path| with manifest |
338 // at |filebrowser_manifest|. The |filebrowser_manifest| should be a path | 338 // at |filebrowser_manifest|. The |filebrowser_manifest| should be a path |
339 // relative to |filebrowser_path|. The method waits until the test extension | 339 // relative to |filebrowser_path|. The method waits until the test extension |
340 // sends test succeed or fail message. It returns true if the test succeeds. | 340 // sends test succeed or fail message. It returns true if the test succeeds. |
341 // If |FLAGS_USE_FILE_HANDLER| flag is set, the file handler extension at path | 341 // If |FLAGS_USE_FILE_HANDLER| flag is set, the file handler extension at path |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 // Registers mount point used in the test. | 392 // Registers mount point used in the test. |
393 virtual void AddTestMountPoint() = 0; | 393 virtual void AddTestMountPoint() = 0; |
394 }; | 394 }; |
395 | 395 |
396 // Tests for a native local file system. | 396 // Tests for a native local file system. |
397 class LocalFileSystemExtensionApiTest : public FileSystemExtensionApiTestBase { | 397 class LocalFileSystemExtensionApiTest : public FileSystemExtensionApiTestBase { |
398 public: | 398 public: |
399 LocalFileSystemExtensionApiTest() {} | 399 LocalFileSystemExtensionApiTest() {} |
400 virtual ~LocalFileSystemExtensionApiTest() {} | 400 virtual ~LocalFileSystemExtensionApiTest() {} |
401 | 401 |
402 // FileSystemExtensionApiTestBase OVERRIDE. | 402 // FileSystemExtensionApiTestBase override. |
403 virtual void InitTestFileSystem() OVERRIDE { | 403 virtual void InitTestFileSystem() override { |
404 ASSERT_TRUE(InitializeLocalFileSystem( | 404 ASSERT_TRUE(InitializeLocalFileSystem( |
405 kLocalMountPointName, &tmp_dir_, &mount_point_dir_)) | 405 kLocalMountPointName, &tmp_dir_, &mount_point_dir_)) |
406 << "Failed to initialize file system."; | 406 << "Failed to initialize file system."; |
407 } | 407 } |
408 | 408 |
409 // FileSystemExtensionApiTestBase OVERRIDE. | 409 // FileSystemExtensionApiTestBase override. |
410 virtual void AddTestMountPoint() OVERRIDE { | 410 virtual void AddTestMountPoint() override { |
411 EXPECT_TRUE(content::BrowserContext::GetMountPoints(browser()->profile()) | 411 EXPECT_TRUE(content::BrowserContext::GetMountPoints(browser()->profile()) |
412 ->RegisterFileSystem(kLocalMountPointName, | 412 ->RegisterFileSystem(kLocalMountPointName, |
413 storage::kFileSystemTypeNativeLocal, | 413 storage::kFileSystemTypeNativeLocal, |
414 storage::FileSystemMountOption(), | 414 storage::FileSystemMountOption(), |
415 mount_point_dir_)); | 415 mount_point_dir_)); |
416 VolumeManager::Get(browser()->profile())->AddVolumeInfoForTesting( | 416 VolumeManager::Get(browser()->profile())->AddVolumeInfoForTesting( |
417 mount_point_dir_, VOLUME_TYPE_TESTING, chromeos::DEVICE_TYPE_UNKNOWN); | 417 mount_point_dir_, VOLUME_TYPE_TESTING, chromeos::DEVICE_TYPE_UNKNOWN); |
418 } | 418 } |
419 | 419 |
420 private: | 420 private: |
421 base::ScopedTempDir tmp_dir_; | 421 base::ScopedTempDir tmp_dir_; |
422 base::FilePath mount_point_dir_; | 422 base::FilePath mount_point_dir_; |
423 }; | 423 }; |
424 | 424 |
425 // Tests for restricted native local file systems. | 425 // Tests for restricted native local file systems. |
426 class RestrictedFileSystemExtensionApiTest | 426 class RestrictedFileSystemExtensionApiTest |
427 : public FileSystemExtensionApiTestBase { | 427 : public FileSystemExtensionApiTestBase { |
428 public: | 428 public: |
429 RestrictedFileSystemExtensionApiTest() {} | 429 RestrictedFileSystemExtensionApiTest() {} |
430 virtual ~RestrictedFileSystemExtensionApiTest() {} | 430 virtual ~RestrictedFileSystemExtensionApiTest() {} |
431 | 431 |
432 // FileSystemExtensionApiTestBase OVERRIDE. | 432 // FileSystemExtensionApiTestBase override. |
433 virtual void InitTestFileSystem() OVERRIDE { | 433 virtual void InitTestFileSystem() override { |
434 ASSERT_TRUE(InitializeLocalFileSystem( | 434 ASSERT_TRUE(InitializeLocalFileSystem( |
435 kRestrictedMountPointName, &tmp_dir_, &mount_point_dir_)) | 435 kRestrictedMountPointName, &tmp_dir_, &mount_point_dir_)) |
436 << "Failed to initialize file system."; | 436 << "Failed to initialize file system."; |
437 } | 437 } |
438 | 438 |
439 // FileSystemExtensionApiTestBase OVERRIDE. | 439 // FileSystemExtensionApiTestBase override. |
440 virtual void AddTestMountPoint() OVERRIDE { | 440 virtual void AddTestMountPoint() override { |
441 EXPECT_TRUE( | 441 EXPECT_TRUE( |
442 content::BrowserContext::GetMountPoints(browser()->profile()) | 442 content::BrowserContext::GetMountPoints(browser()->profile()) |
443 ->RegisterFileSystem(kRestrictedMountPointName, | 443 ->RegisterFileSystem(kRestrictedMountPointName, |
444 storage::kFileSystemTypeRestrictedNativeLocal, | 444 storage::kFileSystemTypeRestrictedNativeLocal, |
445 storage::FileSystemMountOption(), | 445 storage::FileSystemMountOption(), |
446 mount_point_dir_)); | 446 mount_point_dir_)); |
447 VolumeManager::Get(browser()->profile())->AddVolumeInfoForTesting( | 447 VolumeManager::Get(browser()->profile())->AddVolumeInfoForTesting( |
448 mount_point_dir_, VOLUME_TYPE_TESTING, chromeos::DEVICE_TYPE_UNKNOWN); | 448 mount_point_dir_, VOLUME_TYPE_TESTING, chromeos::DEVICE_TYPE_UNKNOWN); |
449 } | 449 } |
450 | 450 |
451 private: | 451 private: |
452 base::ScopedTempDir tmp_dir_; | 452 base::ScopedTempDir tmp_dir_; |
453 base::FilePath mount_point_dir_; | 453 base::FilePath mount_point_dir_; |
454 }; | 454 }; |
455 | 455 |
456 // Tests for a drive file system. | 456 // Tests for a drive file system. |
457 class DriveFileSystemExtensionApiTest : public FileSystemExtensionApiTestBase { | 457 class DriveFileSystemExtensionApiTest : public FileSystemExtensionApiTestBase { |
458 public: | 458 public: |
459 DriveFileSystemExtensionApiTest() : fake_drive_service_(NULL) {} | 459 DriveFileSystemExtensionApiTest() : fake_drive_service_(NULL) {} |
460 virtual ~DriveFileSystemExtensionApiTest() {} | 460 virtual ~DriveFileSystemExtensionApiTest() {} |
461 | 461 |
462 // FileSystemExtensionApiTestBase OVERRIDE. | 462 // FileSystemExtensionApiTestBase override. |
463 virtual void InitTestFileSystem() OVERRIDE { | 463 virtual void InitTestFileSystem() override { |
464 // Set up cache root to be used by DriveIntegrationService. This has to be | 464 // Set up cache root to be used by DriveIntegrationService. This has to be |
465 // done before the browser is created because the service instance is | 465 // done before the browser is created because the service instance is |
466 // initialized by EventRouter. | 466 // initialized by EventRouter. |
467 ASSERT_TRUE(test_cache_root_.CreateUniqueTempDir()); | 467 ASSERT_TRUE(test_cache_root_.CreateUniqueTempDir()); |
468 | 468 |
469 // This callback will get called during Profile creation. | 469 // This callback will get called during Profile creation. |
470 create_drive_integration_service_ = base::Bind( | 470 create_drive_integration_service_ = base::Bind( |
471 &DriveFileSystemExtensionApiTest::CreateDriveIntegrationService, | 471 &DriveFileSystemExtensionApiTest::CreateDriveIntegrationService, |
472 base::Unretained(this)); | 472 base::Unretained(this)); |
473 service_factory_for_test_.reset( | 473 service_factory_for_test_.reset( |
474 new DriveIntegrationServiceFactory::ScopedFactoryForTest( | 474 new DriveIntegrationServiceFactory::ScopedFactoryForTest( |
475 &create_drive_integration_service_)); | 475 &create_drive_integration_service_)); |
476 } | 476 } |
477 | 477 |
478 // FileSystemExtensionApiTestBase OVERRIDE. | 478 // FileSystemExtensionApiTestBase override. |
479 virtual void AddTestMountPoint() OVERRIDE { | 479 virtual void AddTestMountPoint() override { |
480 test_util::WaitUntilDriveMountPointIsAdded(browser()->profile()); | 480 test_util::WaitUntilDriveMountPointIsAdded(browser()->profile()); |
481 } | 481 } |
482 | 482 |
483 protected: | 483 protected: |
484 // DriveIntegrationService factory function for this test. | 484 // DriveIntegrationService factory function for this test. |
485 drive::DriveIntegrationService* CreateDriveIntegrationService( | 485 drive::DriveIntegrationService* CreateDriveIntegrationService( |
486 Profile* profile) { | 486 Profile* profile) { |
487 fake_drive_service_ = new drive::FakeDriveService; | 487 fake_drive_service_ = new drive::FakeDriveService; |
488 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json"); | 488 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json"); |
489 | 489 |
(...skipping 12 matching lines...) Expand all Loading... |
502 scoped_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest> | 502 scoped_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest> |
503 service_factory_for_test_; | 503 service_factory_for_test_; |
504 }; | 504 }; |
505 | 505 |
506 // Tests for Drive file systems in multi-profile setting. | 506 // Tests for Drive file systems in multi-profile setting. |
507 class MultiProfileDriveFileSystemExtensionApiTest : | 507 class MultiProfileDriveFileSystemExtensionApiTest : |
508 public FileSystemExtensionApiTestBase { | 508 public FileSystemExtensionApiTestBase { |
509 public: | 509 public: |
510 MultiProfileDriveFileSystemExtensionApiTest() : second_profile(NULL) {} | 510 MultiProfileDriveFileSystemExtensionApiTest() : second_profile(NULL) {} |
511 | 511 |
512 virtual void SetUpOnMainThread() OVERRIDE { | 512 virtual void SetUpOnMainThread() override { |
513 base::FilePath user_data_directory; | 513 base::FilePath user_data_directory; |
514 PathService::Get(chrome::DIR_USER_DATA, &user_data_directory); | 514 PathService::Get(chrome::DIR_USER_DATA, &user_data_directory); |
515 user_manager::UserManager::Get()->UserLoggedIn( | 515 user_manager::UserManager::Get()->UserLoggedIn( |
516 kSecondProfileAccount, kSecondProfileHash, false); | 516 kSecondProfileAccount, kSecondProfileHash, false); |
517 // Set up the secondary profile. | 517 // Set up the secondary profile. |
518 base::FilePath profile_dir = | 518 base::FilePath profile_dir = |
519 user_data_directory.Append( | 519 user_data_directory.Append( |
520 chromeos::ProfileHelper::GetUserProfileDir( | 520 chromeos::ProfileHelper::GetUserProfileDir( |
521 kSecondProfileHash).BaseName()); | 521 kSecondProfileHash).BaseName()); |
522 second_profile = | 522 second_profile = |
523 g_browser_process->profile_manager()->GetProfile(profile_dir); | 523 g_browser_process->profile_manager()->GetProfile(profile_dir); |
524 | 524 |
525 FileSystemExtensionApiTestBase::SetUpOnMainThread(); | 525 FileSystemExtensionApiTestBase::SetUpOnMainThread(); |
526 } | 526 } |
527 | 527 |
528 virtual void InitTestFileSystem() OVERRIDE { | 528 virtual void InitTestFileSystem() override { |
529 // This callback will get called during Profile creation. | 529 // This callback will get called during Profile creation. |
530 create_drive_integration_service_ = base::Bind( | 530 create_drive_integration_service_ = base::Bind( |
531 &MultiProfileDriveFileSystemExtensionApiTest:: | 531 &MultiProfileDriveFileSystemExtensionApiTest:: |
532 CreateDriveIntegrationService, | 532 CreateDriveIntegrationService, |
533 base::Unretained(this)); | 533 base::Unretained(this)); |
534 service_factory_for_test_.reset( | 534 service_factory_for_test_.reset( |
535 new DriveIntegrationServiceFactory::ScopedFactoryForTest( | 535 new DriveIntegrationServiceFactory::ScopedFactoryForTest( |
536 &create_drive_integration_service_)); | 536 &create_drive_integration_service_)); |
537 } | 537 } |
538 | 538 |
539 virtual void AddTestMountPoint() OVERRIDE { | 539 virtual void AddTestMountPoint() override { |
540 test_util::WaitUntilDriveMountPointIsAdded(browser()->profile()); | 540 test_util::WaitUntilDriveMountPointIsAdded(browser()->profile()); |
541 test_util::WaitUntilDriveMountPointIsAdded(second_profile); | 541 test_util::WaitUntilDriveMountPointIsAdded(second_profile); |
542 } | 542 } |
543 | 543 |
544 protected: | 544 protected: |
545 // DriveIntegrationService factory function for this test. | 545 // DriveIntegrationService factory function for this test. |
546 drive::DriveIntegrationService* CreateDriveIntegrationService( | 546 drive::DriveIntegrationService* CreateDriveIntegrationService( |
547 Profile* profile) { | 547 Profile* profile) { |
548 base::FilePath cache_dir; | 548 base::FilePath cache_dir; |
549 base::CreateNewTempDirectory(base::FilePath::StringType(), &cache_dir); | 549 base::CreateNewTempDirectory(base::FilePath::StringType(), &cache_dir); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 Profile* second_profile; | 597 Profile* second_profile; |
598 std::map<std::string, std::string> resource_ids_; | 598 std::map<std::string, std::string> resource_ids_; |
599 }; | 599 }; |
600 | 600 |
601 class LocalAndDriveFileSystemExtensionApiTest | 601 class LocalAndDriveFileSystemExtensionApiTest |
602 : public FileSystemExtensionApiTestBase { | 602 : public FileSystemExtensionApiTestBase { |
603 public: | 603 public: |
604 LocalAndDriveFileSystemExtensionApiTest() {} | 604 LocalAndDriveFileSystemExtensionApiTest() {} |
605 virtual ~LocalAndDriveFileSystemExtensionApiTest() {} | 605 virtual ~LocalAndDriveFileSystemExtensionApiTest() {} |
606 | 606 |
607 // FileSystemExtensionApiTestBase OVERRIDE. | 607 // FileSystemExtensionApiTestBase override. |
608 virtual void InitTestFileSystem() OVERRIDE { | 608 virtual void InitTestFileSystem() override { |
609 ASSERT_TRUE(InitializeLocalFileSystem( | 609 ASSERT_TRUE(InitializeLocalFileSystem( |
610 kLocalMountPointName, &local_tmp_dir_, &local_mount_point_dir_)) | 610 kLocalMountPointName, &local_tmp_dir_, &local_mount_point_dir_)) |
611 << "Failed to initialize file system."; | 611 << "Failed to initialize file system."; |
612 | 612 |
613 // Set up cache root to be used by DriveIntegrationService. This has to be | 613 // Set up cache root to be used by DriveIntegrationService. This has to be |
614 // done before the browser is created because the service instance is | 614 // done before the browser is created because the service instance is |
615 // initialized by EventRouter. | 615 // initialized by EventRouter. |
616 ASSERT_TRUE(test_cache_root_.CreateUniqueTempDir()); | 616 ASSERT_TRUE(test_cache_root_.CreateUniqueTempDir()); |
617 | 617 |
618 // This callback will get called during Profile creation. | 618 // This callback will get called during Profile creation. |
619 create_drive_integration_service_ = base::Bind( | 619 create_drive_integration_service_ = base::Bind( |
620 &LocalAndDriveFileSystemExtensionApiTest::CreateDriveIntegrationService, | 620 &LocalAndDriveFileSystemExtensionApiTest::CreateDriveIntegrationService, |
621 base::Unretained(this)); | 621 base::Unretained(this)); |
622 service_factory_for_test_.reset( | 622 service_factory_for_test_.reset( |
623 new DriveIntegrationServiceFactory::ScopedFactoryForTest( | 623 new DriveIntegrationServiceFactory::ScopedFactoryForTest( |
624 &create_drive_integration_service_)); | 624 &create_drive_integration_service_)); |
625 } | 625 } |
626 | 626 |
627 // FileSystemExtensionApiTestBase OVERRIDE. | 627 // FileSystemExtensionApiTestBase override. |
628 virtual void AddTestMountPoint() OVERRIDE { | 628 virtual void AddTestMountPoint() override { |
629 EXPECT_TRUE(content::BrowserContext::GetMountPoints(browser()->profile()) | 629 EXPECT_TRUE(content::BrowserContext::GetMountPoints(browser()->profile()) |
630 ->RegisterFileSystem(kLocalMountPointName, | 630 ->RegisterFileSystem(kLocalMountPointName, |
631 storage::kFileSystemTypeNativeLocal, | 631 storage::kFileSystemTypeNativeLocal, |
632 storage::FileSystemMountOption(), | 632 storage::FileSystemMountOption(), |
633 local_mount_point_dir_)); | 633 local_mount_point_dir_)); |
634 VolumeManager::Get(browser()->profile()) | 634 VolumeManager::Get(browser()->profile()) |
635 ->AddVolumeInfoForTesting(local_mount_point_dir_, | 635 ->AddVolumeInfoForTesting(local_mount_point_dir_, |
636 VOLUME_TYPE_TESTING, | 636 VOLUME_TYPE_TESTING, |
637 chromeos::DEVICE_TYPE_UNKNOWN); | 637 chromeos::DEVICE_TYPE_UNKNOWN); |
638 test_util::WaitUntilDriveMountPointIsAdded(browser()->profile()); | 638 test_util::WaitUntilDriveMountPointIsAdded(browser()->profile()); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 AppFileHandlerMulti) { | 799 AppFileHandlerMulti) { |
800 EXPECT_TRUE( | 800 EXPECT_TRUE( |
801 RunFileSystemExtensionApiTest("file_browser/app_file_handler_multi", | 801 RunFileSystemExtensionApiTest("file_browser/app_file_handler_multi", |
802 FILE_PATH_LITERAL("manifest.json"), | 802 FILE_PATH_LITERAL("manifest.json"), |
803 "", | 803 "", |
804 FLAGS_NONE)) | 804 FLAGS_NONE)) |
805 << message_; | 805 << message_; |
806 } | 806 } |
807 } // namespace | 807 } // namespace |
808 } // namespace file_manager | 808 } // namespace file_manager |
OLD | NEW |