| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <stdio.h> | |
| 6 | |
| 7 #include "base/stl_util.h" | |
| 8 #include "chrome/browser/chromeos/disks/mock_disk_mount_manager.h" | |
| 9 #include "chrome/browser/extensions/extension_apitest.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/browser/ui/browser.h" | |
| 12 #include "webkit/fileapi/file_system_context.h" | |
| 13 #include "webkit/fileapi/file_system_mount_point_provider.h" | |
| 14 #include "webkit/fileapi/file_system_path_manager.h" | |
| 15 | |
| 16 using ::testing::_; | |
| 17 using ::testing::ReturnRef; | |
| 18 using ::testing::StrEq; | |
| 19 | |
| 20 class FileBrowserExtensionApiTest : public ExtensionApiTest { | |
| 21 public: | |
| 22 FileBrowserExtensionApiTest() | |
| 23 : disk_mount_manager_mock_(NULL), | |
| 24 test_mount_point_("/tmp") { | |
| 25 CreateVolumeMap(); | |
| 26 } | |
| 27 | |
| 28 virtual ~FileBrowserExtensionApiTest() { | |
| 29 DCHECK(!disk_mount_manager_mock_); | |
| 30 STLDeleteValues(&volumes_); | |
| 31 } | |
| 32 | |
| 33 // ExtensionApiTest override | |
| 34 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | |
| 35 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | |
| 36 | |
| 37 disk_mount_manager_mock_ = new chromeos::disks::MockDiskMountManager; | |
| 38 chromeos::disks::DiskMountManager::InitializeForTesting( | |
| 39 disk_mount_manager_mock_); | |
| 40 disk_mount_manager_mock_->SetupDefaultReplies(); | |
| 41 } | |
| 42 | |
| 43 // ExtensionApiTest override | |
| 44 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { | |
| 45 chromeos::disks::DiskMountManager::Shutdown(); | |
| 46 disk_mount_manager_mock_ = NULL; | |
| 47 | |
| 48 ExtensionApiTest::TearDownInProcessBrowserTestFixture(); | |
| 49 } | |
| 50 | |
| 51 void AddTmpMountPoint() { | |
| 52 fileapi::FileSystemPathManager* path_manager = | |
| 53 browser()->profile()->GetFileSystemContext()->path_manager(); | |
| 54 fileapi::ExternalFileSystemMountPointProvider* provider = | |
| 55 path_manager->external_provider(); | |
| 56 provider->AddMountPoint(test_mount_point_); | |
| 57 } | |
| 58 | |
| 59 private: | |
| 60 void CreateVolumeMap() { | |
| 61 // These have to be sync'd with values in filebrowser_mount extension. | |
| 62 volumes_.insert( | |
| 63 std::pair<std::string, chromeos::disks::DiskMountManager::Disk*>( | |
| 64 "device_path1", | |
| 65 new chromeos::disks::DiskMountManager::Disk( | |
| 66 "device_path1", | |
| 67 "/media/removable/mount_path1", | |
| 68 "system_path1", | |
| 69 "file_path1", | |
| 70 "device_label1", | |
| 71 "drive_label1", | |
| 72 "system_path_prefix1", | |
| 73 chromeos::FLASH, | |
| 74 1073741824, | |
| 75 false, | |
| 76 false, | |
| 77 false, | |
| 78 false, | |
| 79 false))); | |
| 80 volumes_.insert( | |
| 81 std::pair<std::string, chromeos::disks::DiskMountManager::Disk*>( | |
| 82 "device_path2", | |
| 83 new chromeos::disks::DiskMountManager::Disk( | |
| 84 "device_path2", | |
| 85 "/media/removable/mount_path2", | |
| 86 "system_path2", | |
| 87 "file_path2", | |
| 88 "device_label2", | |
| 89 "drive_label2", | |
| 90 "system_path_prefix2", | |
| 91 chromeos::HDD, | |
| 92 47723, | |
| 93 true, | |
| 94 true, | |
| 95 true, | |
| 96 true, | |
| 97 false))); | |
| 98 volumes_.insert( | |
| 99 std::pair<std::string, chromeos::disks::DiskMountManager::Disk*>( | |
| 100 "device_path3", | |
| 101 new chromeos::disks::DiskMountManager::Disk( | |
| 102 "device_path3", | |
| 103 "/media/removable/mount_path3", | |
| 104 "system_path3", | |
| 105 "file_path3", | |
| 106 "device_label3", | |
| 107 "drive_label3", | |
| 108 "system_path_prefix3", | |
| 109 chromeos::OPTICAL, | |
| 110 0, | |
| 111 true, | |
| 112 false, | |
| 113 false, | |
| 114 true, | |
| 115 false))); | |
| 116 } | |
| 117 | |
| 118 protected: | |
| 119 chromeos::disks::MockDiskMountManager* disk_mount_manager_mock_; | |
| 120 chromeos::disks::DiskMountManager::DiskMap volumes_; | |
| 121 | |
| 122 private: | |
| 123 FilePath test_mount_point_; | |
| 124 }; | |
| 125 | |
| 126 IN_PROC_BROWSER_TEST_F(FileBrowserExtensionApiTest, FileBrowserMount) { | |
| 127 // We will call fileBrowserPrivate.unmountVolume once. To test that method, we | |
| 128 // check that UnmountPath is really called with the same value. | |
| 129 AddTmpMountPoint(); | |
| 130 EXPECT_CALL(*disk_mount_manager_mock_, UnmountPath(_)) | |
| 131 .Times(0); | |
| 132 EXPECT_CALL(*disk_mount_manager_mock_, | |
| 133 UnmountPath(StrEq("/tmp/test_file.zip"))).Times(1); | |
| 134 | |
| 135 EXPECT_CALL(*disk_mount_manager_mock_, disks()) | |
| 136 .WillRepeatedly(ReturnRef(volumes_)); | |
| 137 | |
| 138 ASSERT_TRUE(RunComponentExtensionTest("filebrowser_mount")) << message_; | |
| 139 } | |
| OLD | NEW |