| 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 11 matching lines...) Expand all Loading... |
| 22 #include "components/user_manager/user_manager.h" | 22 #include "components/user_manager/user_manager.h" |
| 23 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
| 24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 25 #include "content/public/test/test_utils.h" | 25 #include "content/public/test/test_utils.h" |
| 26 #include "extensions/browser/notification_types.h" | 26 #include "extensions/browser/notification_types.h" |
| 27 #include "extensions/test/result_catcher.h" | 27 #include "extensions/test/result_catcher.h" |
| 28 #include "google_apis/drive/drive_api_parser.h" | 28 #include "google_apis/drive/drive_api_parser.h" |
| 29 #include "google_apis/drive/test_util.h" | 29 #include "google_apis/drive/test_util.h" |
| 30 #include "google_apis/drive/time_util.h" | 30 #include "google_apis/drive/time_util.h" |
| 31 #include "storage/browser/fileapi/external_mount_points.h" | 31 #include "storage/browser/fileapi/external_mount_points.h" |
| 32 #include "ui/shell_dialogs/select_file_dialog_factory.h" |
| 32 | 33 |
| 33 // Tests for access to external file systems (as defined in | 34 // Tests for access to external file systems (as defined in |
| 34 // storage/common/fileapi/file_system_types.h) from extensions with | 35 // storage/common/fileapi/file_system_types.h) from extensions with |
| 35 // fileManagerPrivate and fileBrowserHandler extension permissions. | 36 // fileManagerPrivate and fileBrowserHandler extension permissions. |
| 36 // The tests cover following external file system types: | 37 // The tests cover following external file system types: |
| 37 // - local (kFileSystemTypeLocalNative): a local file system on which files are | 38 // - local (kFileSystemTypeLocalNative): a local file system on which files are |
| 38 // accessed using native local path. | 39 // accessed using native local path. |
| 39 // - restricted (kFileSystemTypeRestrictedLocalNative): a *read-only* local file | 40 // - restricted (kFileSystemTypeRestrictedLocalNative): a *read-only* local file |
| 40 // system which can only be accessed by extensions that have full access to | 41 // system which can only be accessed by extensions that have full access to |
| 41 // external file systems (i.e. extensions with fileManagerPrivate permission). | 42 // external file systems (i.e. extensions with fileManagerPrivate permission). |
| (...skipping 25 matching lines...) Expand all Loading... |
| 67 const char kRestrictedMountPointName[] = "restricted"; | 68 const char kRestrictedMountPointName[] = "restricted"; |
| 68 | 69 |
| 69 // Default file content for the test files. | 70 // Default file content for the test files. |
| 70 const char kTestFileContent[] = "This is some test content."; | 71 const char kTestFileContent[] = "This is some test content."; |
| 71 | 72 |
| 72 // User account email and directory hash for secondary account for multi-profile | 73 // User account email and directory hash for secondary account for multi-profile |
| 73 // sensitive test cases. | 74 // sensitive test cases. |
| 74 const char kSecondProfileAccount[] = "profile2@test.com"; | 75 const char kSecondProfileAccount[] = "profile2@test.com"; |
| 75 const char kSecondProfileHash[] = "fileBrowserApiTestProfile2"; | 76 const char kSecondProfileHash[] = "fileBrowserApiTestProfile2"; |
| 76 | 77 |
| 78 class FakeSelectFileDialog : public ui::SelectFileDialog { |
| 79 public: |
| 80 FakeSelectFileDialog(ui::SelectFileDialog::Listener* listener, |
| 81 ui::SelectFilePolicy* policy) |
| 82 : ui::SelectFileDialog(listener, policy) {} |
| 83 |
| 84 virtual void SelectFileImpl( |
| 85 Type type, |
| 86 const base::string16& title, |
| 87 const base::FilePath& default_path, |
| 88 const FileTypeInfo* file_types, |
| 89 int file_type_index, |
| 90 const base::FilePath::StringType& default_extension, |
| 91 gfx::NativeWindow owning_window, |
| 92 void* params) override { |
| 93 listener_->FileSelected( |
| 94 base::FilePath("/special/drive-user/root/test_dir"), 0, NULL); |
| 95 } |
| 96 |
| 97 virtual bool IsRunning(gfx::NativeWindow owning_window) const override { |
| 98 return false; |
| 99 } |
| 100 |
| 101 virtual void ListenerDestroyed() override {} |
| 102 |
| 103 virtual bool HasMultipleFileTypeChoicesImpl() override { return false; } |
| 104 |
| 105 private: |
| 106 virtual ~FakeSelectFileDialog() {} |
| 107 }; |
| 108 |
| 109 class FakeSelectFileDialogFactory : public ui::SelectFileDialogFactory { |
| 110 private: |
| 111 virtual ui::SelectFileDialog* Create(ui::SelectFileDialog::Listener* listener, |
| 112 ui::SelectFilePolicy* policy) override { |
| 113 return new FakeSelectFileDialog(listener, policy); |
| 114 } |
| 115 }; |
| 116 |
| 77 // Sets up the initial file system state for native local and restricted native | 117 // Sets up the initial file system state for native local and restricted native |
| 78 // local file systems. The hierarchy is the same as for the drive file system. | 118 // local file systems. The hierarchy is the same as for the drive file system. |
| 79 // The directory is created at unique_temp_dir/|mount_point_name| path. | 119 // The directory is created at unique_temp_dir/|mount_point_name| path. |
| 80 bool InitializeLocalFileSystem(std::string mount_point_name, | 120 bool InitializeLocalFileSystem(std::string mount_point_name, |
| 81 base::ScopedTempDir* tmp_dir, | 121 base::ScopedTempDir* tmp_dir, |
| 82 base::FilePath* mount_point_dir) { | 122 base::FilePath* mount_point_dir) { |
| 83 if (!tmp_dir->CreateUniqueTempDir()) | 123 if (!tmp_dir->CreateUniqueTempDir()) |
| 84 return false; | 124 return false; |
| 85 | 125 |
| 86 *mount_point_dir = tmp_dir->path().AppendASCII(mount_point_name); | 126 *mount_point_dir = tmp_dir->path().AppendASCII(mount_point_name); |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 service_factory_for_test_.reset( | 513 service_factory_for_test_.reset( |
| 474 new DriveIntegrationServiceFactory::ScopedFactoryForTest( | 514 new DriveIntegrationServiceFactory::ScopedFactoryForTest( |
| 475 &create_drive_integration_service_)); | 515 &create_drive_integration_service_)); |
| 476 } | 516 } |
| 477 | 517 |
| 478 // FileSystemExtensionApiTestBase override. | 518 // FileSystemExtensionApiTestBase override. |
| 479 virtual void AddTestMountPoint() override { | 519 virtual void AddTestMountPoint() override { |
| 480 test_util::WaitUntilDriveMountPointIsAdded(browser()->profile()); | 520 test_util::WaitUntilDriveMountPointIsAdded(browser()->profile()); |
| 481 } | 521 } |
| 482 | 522 |
| 523 // FileSystemExtensionApiTestBase override. |
| 524 virtual void TearDown() override { |
| 525 FileSystemExtensionApiTestBase::TearDown(); |
| 526 ui::SelectFileDialog::SetFactory(NULL); |
| 527 } |
| 528 |
| 483 protected: | 529 protected: |
| 484 // DriveIntegrationService factory function for this test. | 530 // DriveIntegrationService factory function for this test. |
| 485 drive::DriveIntegrationService* CreateDriveIntegrationService( | 531 drive::DriveIntegrationService* CreateDriveIntegrationService( |
| 486 Profile* profile) { | 532 Profile* profile) { |
| 487 fake_drive_service_ = new drive::FakeDriveService; | 533 fake_drive_service_ = new drive::FakeDriveService; |
| 488 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json"); | 534 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json"); |
| 489 | 535 |
| 490 std::map<std::string, std::string> resource_ids; | 536 std::map<std::string, std::string> resource_ids; |
| 491 EXPECT_TRUE(InitializeDriveService(fake_drive_service_, &resource_ids)); | 537 EXPECT_TRUE(InitializeDriveService(fake_drive_service_, &resource_ids)); |
| 492 | 538 |
| 493 return new drive::DriveIntegrationService( | 539 return new drive::DriveIntegrationService( |
| 494 profile, NULL, | 540 profile, NULL, fake_drive_service_, "", test_cache_root_.path(), NULL); |
| 495 fake_drive_service_, "drive", test_cache_root_.path(), NULL); | |
| 496 } | 541 } |
| 497 | 542 |
| 498 base::ScopedTempDir test_cache_root_; | 543 base::ScopedTempDir test_cache_root_; |
| 499 drive::FakeDriveService* fake_drive_service_; | 544 drive::FakeDriveService* fake_drive_service_; |
| 500 DriveIntegrationServiceFactory::FactoryCallback | 545 DriveIntegrationServiceFactory::FactoryCallback |
| 501 create_drive_integration_service_; | 546 create_drive_integration_service_; |
| 502 scoped_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest> | 547 scoped_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest> |
| 503 service_factory_for_test_; | 548 service_factory_for_test_; |
| 504 }; | 549 }; |
| 505 | 550 |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 } | 811 } |
| 767 | 812 |
| 768 IN_PROC_BROWSER_TEST_F(DriveFileSystemExtensionApiTest, AppFileHandler) { | 813 IN_PROC_BROWSER_TEST_F(DriveFileSystemExtensionApiTest, AppFileHandler) { |
| 769 EXPECT_TRUE(RunFileSystemExtensionApiTest( | 814 EXPECT_TRUE(RunFileSystemExtensionApiTest( |
| 770 "file_browser/handler_test_runner", | 815 "file_browser/handler_test_runner", |
| 771 FILE_PATH_LITERAL("manifest.json"), | 816 FILE_PATH_LITERAL("manifest.json"), |
| 772 "file_browser/app_file_handler", | 817 "file_browser/app_file_handler", |
| 773 FLAGS_USE_FILE_HANDLER)) << message_; | 818 FLAGS_USE_FILE_HANDLER)) << message_; |
| 774 } | 819 } |
| 775 | 820 |
| 821 IN_PROC_BROWSER_TEST_F(DriveFileSystemExtensionApiTest, RetainEntry) { |
| 822 ui::SelectFileDialog::SetFactory(new FakeSelectFileDialogFactory()); |
| 823 EXPECT_TRUE(RunFileSystemExtensionApiTest("file_browser/retain_entry", |
| 824 FILE_PATH_LITERAL("manifest.json"), |
| 825 "", |
| 826 FLAGS_NONE)) |
| 827 << message_; |
| 828 } |
| 829 |
| 776 IN_PROC_BROWSER_TEST_F(MultiProfileDriveFileSystemExtensionApiTest, | 830 IN_PROC_BROWSER_TEST_F(MultiProfileDriveFileSystemExtensionApiTest, |
| 777 CrossProfileCopy) { | 831 CrossProfileCopy) { |
| 778 ASSERT_TRUE(AddTestHostedDocuments()); | 832 ASSERT_TRUE(AddTestHostedDocuments()); |
| 779 EXPECT_TRUE(RunFileSystemExtensionApiTest( | 833 EXPECT_TRUE(RunFileSystemExtensionApiTest( |
| 780 "file_browser/multi_profile_copy", | 834 "file_browser/multi_profile_copy", |
| 781 FILE_PATH_LITERAL("manifest.json"), | 835 FILE_PATH_LITERAL("manifest.json"), |
| 782 "", | 836 "", |
| 783 FLAGS_NONE)) << message_; | 837 FLAGS_NONE)) << message_; |
| 784 } | 838 } |
| 785 | 839 |
| 786 // | 840 // |
| 787 // LocalAndDriveFileSystemExtensionApiTests. | 841 // LocalAndDriveFileSystemExtensionApiTests. |
| 788 // | 842 // |
| 789 IN_PROC_BROWSER_TEST_F(LocalAndDriveFileSystemExtensionApiTest, | 843 IN_PROC_BROWSER_TEST_F(LocalAndDriveFileSystemExtensionApiTest, |
| 790 AppFileHandlerMulti) { | 844 AppFileHandlerMulti) { |
| 791 EXPECT_TRUE( | 845 EXPECT_TRUE( |
| 792 RunFileSystemExtensionApiTest("file_browser/app_file_handler_multi", | 846 RunFileSystemExtensionApiTest("file_browser/app_file_handler_multi", |
| 793 FILE_PATH_LITERAL("manifest.json"), | 847 FILE_PATH_LITERAL("manifest.json"), |
| 794 "", | 848 "", |
| 795 FLAGS_NONE)) | 849 FLAGS_NONE)) |
| 796 << message_; | 850 << message_; |
| 797 } | 851 } |
| 798 } // namespace | 852 } // namespace |
| 799 } // namespace file_manager | 853 } // namespace file_manager |
| OLD | NEW |