| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // Browser test for basic Chrome OS file manager functionality: | 5 // Browser test for basic Chrome OS file manager functionality: |
| 6 // - The file list is updated when a file is added externally to the Downloads | 6 // - The file list is updated when a file is added externally to the Downloads |
| 7 // folder. | 7 // folder. |
| 8 // - Selecting a file and copy-pasting it with the keyboard copies the file. | 8 // - Selecting a file and copy-pasting it with the keyboard copies the file. |
| 9 // - Selecting a file and pressing delete deletes it. | 9 // - Selecting a file and pressing delete deletes it. |
| 10 | 10 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 &AddEntriesMessage::entries); | 202 &AddEntriesMessage::entries); |
| 203 } | 203 } |
| 204 | 204 |
| 205 // Test volume. | 205 // Test volume. |
| 206 class TestVolume { | 206 class TestVolume { |
| 207 protected: | 207 protected: |
| 208 explicit TestVolume(const std::string& name) : name_(name) {} | 208 explicit TestVolume(const std::string& name) : name_(name) {} |
| 209 virtual ~TestVolume() {} | 209 virtual ~TestVolume() {} |
| 210 | 210 |
| 211 bool CreateRootDirectory(const Profile* profile) { | 211 bool CreateRootDirectory(const Profile* profile) { |
| 212 return root_.Set(profile->GetPath().Append(name_)); | 212 const base::FilePath path = profile->GetPath().Append(name_); |
| 213 return root_.path() == path || root_.Set(path); |
| 213 } | 214 } |
| 214 | 215 |
| 215 const std::string& name() { return name_; } | 216 const std::string& name() { return name_; } |
| 216 const base::FilePath root_path() { return root_.path(); } | 217 const base::FilePath root_path() { return root_.path(); } |
| 217 | 218 |
| 218 private: | 219 private: |
| 219 std::string name_; | 220 std::string name_; |
| 220 base::ScopedTempDir root_; | 221 base::ScopedTempDir root_; |
| 221 }; | 222 }; |
| 222 | 223 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 DownloadsTestVolume() : LocalTestVolume("Downloads") {} | 285 DownloadsTestVolume() : LocalTestVolume("Downloads") {} |
| 285 virtual ~DownloadsTestVolume() {} | 286 virtual ~DownloadsTestVolume() {} |
| 286 | 287 |
| 287 virtual bool Mount(Profile* profile) OVERRIDE { | 288 virtual bool Mount(Profile* profile) OVERRIDE { |
| 288 return CreateRootDirectory(profile) && | 289 return CreateRootDirectory(profile) && |
| 289 VolumeManager::Get(profile) | 290 VolumeManager::Get(profile) |
| 290 ->RegisterDownloadsDirectoryForTesting(root_path()); | 291 ->RegisterDownloadsDirectoryForTesting(root_path()); |
| 291 } | 292 } |
| 292 }; | 293 }; |
| 293 | 294 |
| 294 class FakeUsbTestVolume : public LocalTestVolume { | 295 // Test volume for mimicing a specified type of volumes by a local folder. |
| 296 class FakeTestVolume : public LocalTestVolume { |
| 295 public: | 297 public: |
| 296 FakeUsbTestVolume() : LocalTestVolume("fake-usb") {} | 298 FakeTestVolume(const std::string& name, |
| 297 virtual ~FakeUsbTestVolume() {} | 299 VolumeType volume_type, |
| 300 chromeos::DeviceType device_type) |
| 301 : LocalTestVolume(name), |
| 302 volume_type_(volume_type), |
| 303 device_type_(device_type) {} |
| 304 virtual ~FakeTestVolume() {} |
| 305 |
| 306 // Simple test entries used for testing, e.g., read-only volumes. |
| 307 bool PrepareTestEntries(Profile* profile) { |
| 308 if (!CreateRootDirectory(profile)) |
| 309 return false; |
| 310 // Must be in sync with BASIC_FAKE_ENTRY_SET in the JS test code. |
| 311 CreateEntry( |
| 312 TestEntryInfo(FILE, "text.txt", "hello.txt", "text/plain", NONE, |
| 313 base::Time::Now())); |
| 314 CreateEntry( |
| 315 TestEntryInfo(DIRECTORY, std::string(), "A", std::string(), NONE, |
| 316 base::Time::Now())); |
| 317 return true; |
| 318 } |
| 298 | 319 |
| 299 virtual bool Mount(Profile* profile) OVERRIDE { | 320 virtual bool Mount(Profile* profile) OVERRIDE { |
| 300 if (!CreateRootDirectory(profile)) | 321 if (!CreateRootDirectory(profile)) |
| 301 return false; | 322 return false; |
| 302 fileapi::ExternalMountPoints* const mount_points = | 323 fileapi::ExternalMountPoints* const mount_points = |
| 303 fileapi::ExternalMountPoints::GetSystemInstance(); | 324 fileapi::ExternalMountPoints::GetSystemInstance(); |
| 304 | 325 |
| 305 // First revoke the existing mount point (if any). | 326 // First revoke the existing mount point (if any). |
| 306 mount_points->RevokeFileSystem(name()); | 327 mount_points->RevokeFileSystem(name()); |
| 307 const bool result = | 328 const bool result = |
| 308 mount_points->RegisterFileSystem(name(), | 329 mount_points->RegisterFileSystem(name(), |
| 309 fileapi::kFileSystemTypeNativeLocal, | 330 fileapi::kFileSystemTypeNativeLocal, |
| 310 fileapi::FileSystemMountOption(), | 331 fileapi::FileSystemMountOption(), |
| 311 root_path()); | 332 root_path()); |
| 312 if (!result) | 333 if (!result) |
| 313 return false; | 334 return false; |
| 314 | 335 |
| 315 VolumeManager::Get(profile) | 336 VolumeManager::Get(profile)->AddVolumeInfoForTesting( |
| 316 ->AddVolumeInfoForTesting(root_path(), | 337 root_path(), volume_type_, device_type_); |
| 317 VOLUME_TYPE_REMOVABLE_DISK_PARTITION, | |
| 318 chromeos::DEVICE_TYPE_USB); | |
| 319 return true; | 338 return true; |
| 320 } | 339 } |
| 340 |
| 341 private: |
| 342 const VolumeType volume_type_; |
| 343 const chromeos::DeviceType device_type_; |
| 321 }; | 344 }; |
| 322 | 345 |
| 323 // The drive volume class for test. | 346 // The drive volume class for test. |
| 324 // This class provides the operations for a test volume that simulates Google | 347 // This class provides the operations for a test volume that simulates Google |
| 325 // drive. | 348 // drive. |
| 326 class DriveTestVolume : public TestVolume { | 349 class DriveTestVolume : public TestVolume { |
| 327 public: | 350 public: |
| 328 DriveTestVolume() : TestVolume("drive"), integration_service_(NULL) {} | 351 DriveTestVolume() : TestVolume("drive"), integration_service_(NULL) {} |
| 329 virtual ~DriveTestVolume() {} | 352 virtual ~DriveTestVolume() {} |
| 330 | 353 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 return "file_manager_test_manifest.json"; | 555 return "file_manager_test_manifest.json"; |
| 533 } | 556 } |
| 534 virtual GuestMode GetGuestModeParam() const = 0; | 557 virtual GuestMode GetGuestModeParam() const = 0; |
| 535 virtual const char* GetTestCaseNameParam() const = 0; | 558 virtual const char* GetTestCaseNameParam() const = 0; |
| 536 virtual std::string OnMessage(const std::string& name, | 559 virtual std::string OnMessage(const std::string& name, |
| 537 const base::Value* value); | 560 const base::Value* value); |
| 538 | 561 |
| 539 scoped_ptr<LocalTestVolume> local_volume_; | 562 scoped_ptr<LocalTestVolume> local_volume_; |
| 540 linked_ptr<DriveTestVolume> drive_volume_; | 563 linked_ptr<DriveTestVolume> drive_volume_; |
| 541 std::map<Profile*, linked_ptr<DriveTestVolume> > drive_volumes_; | 564 std::map<Profile*, linked_ptr<DriveTestVolume> > drive_volumes_; |
| 542 scoped_ptr<LocalTestVolume> usb_volume_; | 565 scoped_ptr<FakeTestVolume> usb_volume_; |
| 566 scoped_ptr<FakeTestVolume> mtp_volume_; |
| 543 | 567 |
| 544 private: | 568 private: |
| 545 drive::DriveIntegrationService* CreateDriveIntegrationService( | 569 drive::DriveIntegrationService* CreateDriveIntegrationService( |
| 546 Profile* profile); | 570 Profile* profile); |
| 547 DriveIntegrationServiceFactory::FactoryCallback | 571 DriveIntegrationServiceFactory::FactoryCallback |
| 548 create_drive_integration_service_; | 572 create_drive_integration_service_; |
| 549 scoped_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest> | 573 scoped_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest> |
| 550 service_factory_for_test_; | 574 service_factory_for_test_; |
| 551 }; | 575 }; |
| 552 | 576 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 if (usb_volume_) | 708 if (usb_volume_) |
| 685 usb_volume_->CreateEntry(*message.entries[i]); | 709 usb_volume_->CreateEntry(*message.entries[i]); |
| 686 break; | 710 break; |
| 687 default: | 711 default: |
| 688 NOTREACHED(); | 712 NOTREACHED(); |
| 689 break; | 713 break; |
| 690 } | 714 } |
| 691 } | 715 } |
| 692 return "onEntryAdded"; | 716 return "onEntryAdded"; |
| 693 } else if (name == "mountFakeUsb") { | 717 } else if (name == "mountFakeUsb") { |
| 694 usb_volume_.reset(new FakeUsbTestVolume()); | 718 usb_volume_.reset(new FakeTestVolume("fake-usb", |
| 719 VOLUME_TYPE_REMOVABLE_DISK_PARTITION, |
| 720 chromeos::DEVICE_TYPE_USB)); |
| 695 usb_volume_->Mount(profile()); | 721 usb_volume_->Mount(profile()); |
| 696 return "true"; | 722 return "true"; |
| 723 } else if (name == "mountFakeMtp") { |
| 724 mtp_volume_.reset(new FakeTestVolume("fake-mtp", |
| 725 VOLUME_TYPE_MTP, |
| 726 chromeos::DEVICE_TYPE_UNKNOWN)); |
| 727 if (!mtp_volume_->PrepareTestEntries(profile())) |
| 728 return "false"; |
| 729 mtp_volume_->Mount(profile()); |
| 730 return "true"; |
| 697 } | 731 } |
| 698 return "unknownMessage"; | 732 return "unknownMessage"; |
| 699 } | 733 } |
| 700 | 734 |
| 701 drive::DriveIntegrationService* | 735 drive::DriveIntegrationService* |
| 702 FileManagerBrowserTestBase::CreateDriveIntegrationService(Profile* profile) { | 736 FileManagerBrowserTestBase::CreateDriveIntegrationService(Profile* profile) { |
| 703 drive_volumes_[profile].reset(new DriveTestVolume()); | 737 drive_volumes_[profile].reset(new DriveTestVolume()); |
| 704 return drive_volumes_[profile]->CreateDriveIntegrationService(profile); | 738 return drive_volumes_[profile]->CreateDriveIntegrationService(profile); |
| 705 } | 739 } |
| 706 | 740 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 722 | 756 |
| 723 IN_PROC_BROWSER_TEST_P(FileManagerBrowserTest, Test) { | 757 IN_PROC_BROWSER_TEST_P(FileManagerBrowserTest, Test) { |
| 724 StartTest(); | 758 StartTest(); |
| 725 } | 759 } |
| 726 | 760 |
| 727 INSTANTIATE_TEST_CASE_P( | 761 INSTANTIATE_TEST_CASE_P( |
| 728 FileDisplay, | 762 FileDisplay, |
| 729 FileManagerBrowserTest, | 763 FileManagerBrowserTest, |
| 730 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "fileDisplayDownloads"), | 764 ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "fileDisplayDownloads"), |
| 731 TestParameter(IN_GUEST_MODE, "fileDisplayDownloads"), | 765 TestParameter(IN_GUEST_MODE, "fileDisplayDownloads"), |
| 732 TestParameter(NOT_IN_GUEST_MODE, "fileDisplayDrive"))); | 766 TestParameter(NOT_IN_GUEST_MODE, "fileDisplayDrive"), |
| 767 TestParameter(NOT_IN_GUEST_MODE, "fileDisplayMtp"))); |
| 733 | 768 |
| 734 INSTANTIATE_TEST_CASE_P( | 769 INSTANTIATE_TEST_CASE_P( |
| 735 OpenZipFiles, | 770 OpenZipFiles, |
| 736 FileManagerBrowserTest, | 771 FileManagerBrowserTest, |
| 737 ::testing::Values(TestParameter(IN_GUEST_MODE, "zipOpenDownloads"), | 772 ::testing::Values(TestParameter(IN_GUEST_MODE, "zipOpenDownloads"), |
| 738 TestParameter(NOT_IN_GUEST_MODE, "zipOpenDownloads"), | 773 TestParameter(NOT_IN_GUEST_MODE, "zipOpenDownloads"), |
| 739 TestParameter(NOT_IN_GUEST_MODE, "zipOpenDrive"))); | 774 TestParameter(NOT_IN_GUEST_MODE, "zipOpenDrive"))); |
| 740 | 775 |
| 741 INSTANTIATE_TEST_CASE_P( | 776 INSTANTIATE_TEST_CASE_P( |
| 742 OpenVideoFiles, | 777 OpenVideoFiles, |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1140 } | 1175 } |
| 1141 | 1176 |
| 1142 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, OpenSingleImageOnDrive) { | 1177 IN_PROC_BROWSER_TEST_F(GalleryBrowserTest, OpenSingleImageOnDrive) { |
| 1143 AddScript("gallery/open_image_files.js"); | 1178 AddScript("gallery/open_image_files.js"); |
| 1144 set_test_case_name("openSingleImageOnDrive"); | 1179 set_test_case_name("openSingleImageOnDrive"); |
| 1145 StartTest(); | 1180 StartTest(); |
| 1146 } | 1181 } |
| 1147 | 1182 |
| 1148 } // namespace | 1183 } // namespace |
| 1149 } // namespace file_manager | 1184 } // namespace file_manager |
| OLD | NEW |