| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/stl_util.h" | |
| 6 #include "chrome/browser/chromeos/file_manager/drive_test_util.h" | |
| 7 #include "chrome/browser/extensions/extension_apitest.h" | |
| 8 #include "chromeos/dbus/cros_disks_client.h" | |
| 9 #include "chromeos/disks/mock_disk_mount_manager.h" | |
| 10 | |
| 11 using ::testing::_; | |
| 12 using ::testing::ReturnRef; | |
| 13 | |
| 14 using chromeos::disks::DiskMountManager; | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 struct TestDiskInfo { | |
| 19 const char* system_path; | |
| 20 const char* file_path; | |
| 21 const char* device_label; | |
| 22 const char* drive_label; | |
| 23 const char* vendor_id; | |
| 24 const char* vendor_name; | |
| 25 const char* product_id; | |
| 26 const char* product_name; | |
| 27 const char* fs_uuid; | |
| 28 const char* system_path_prefix; | |
| 29 chromeos::DeviceType device_type; | |
| 30 uint64 size_in_bytes; | |
| 31 bool is_parent; | |
| 32 bool is_read_only; | |
| 33 bool has_media; | |
| 34 bool on_boot_device; | |
| 35 bool on_removable_device; | |
| 36 bool is_hidden; | |
| 37 }; | |
| 38 | |
| 39 struct TestMountPoint { | |
| 40 std::string source_path; | |
| 41 std::string mount_path; | |
| 42 chromeos::MountType mount_type; | |
| 43 chromeos::disks::MountCondition mount_condition; | |
| 44 | |
| 45 // -1 if there is no disk info. | |
| 46 int disk_info_index; | |
| 47 }; | |
| 48 | |
| 49 TestDiskInfo kTestDisks[] = { | |
| 50 { | |
| 51 "system_path1", | |
| 52 "file_path1", | |
| 53 "device_label1", | |
| 54 "drive_label1", | |
| 55 "0123", | |
| 56 "vendor1", | |
| 57 "abcd", | |
| 58 "product1", | |
| 59 "FFFF-FFFF", | |
| 60 "system_path_prefix1", | |
| 61 chromeos::DEVICE_TYPE_USB, | |
| 62 1073741824, | |
| 63 false, | |
| 64 false, | |
| 65 false, | |
| 66 false, | |
| 67 false | |
| 68 }, | |
| 69 { | |
| 70 "system_path2", | |
| 71 "file_path2", | |
| 72 "device_label2", | |
| 73 "drive_label2", | |
| 74 "4567", | |
| 75 "vendor2", | |
| 76 "cdef", | |
| 77 "product2", | |
| 78 "0FFF-FFFF", | |
| 79 "system_path_prefix2", | |
| 80 chromeos::DEVICE_TYPE_MOBILE, | |
| 81 47723, | |
| 82 true, | |
| 83 true, | |
| 84 true, | |
| 85 true, | |
| 86 false | |
| 87 }, | |
| 88 { | |
| 89 "system_path3", | |
| 90 "file_path3", | |
| 91 "device_label3", | |
| 92 "drive_label3", | |
| 93 "89ab", | |
| 94 "vendor3", | |
| 95 "ef01", | |
| 96 "product3", | |
| 97 "00FF-FFFF", | |
| 98 "system_path_prefix3", | |
| 99 chromeos::DEVICE_TYPE_OPTICAL_DISC, | |
| 100 0, | |
| 101 true, | |
| 102 false, | |
| 103 false, | |
| 104 true, | |
| 105 false | |
| 106 } | |
| 107 }; | |
| 108 | |
| 109 } // namespace | |
| 110 | |
| 111 class FileBrowserPrivateApiTest : public ExtensionApiTest { | |
| 112 public: | |
| 113 FileBrowserPrivateApiTest() | |
| 114 : disk_mount_manager_mock_(NULL) { | |
| 115 InitMountPoints(); | |
| 116 } | |
| 117 | |
| 118 virtual ~FileBrowserPrivateApiTest() { | |
| 119 DCHECK(!disk_mount_manager_mock_); | |
| 120 STLDeleteValues(&volumes_); | |
| 121 } | |
| 122 | |
| 123 // ExtensionApiTest override | |
| 124 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | |
| 125 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | |
| 126 | |
| 127 disk_mount_manager_mock_ = new chromeos::disks::MockDiskMountManager; | |
| 128 chromeos::disks::DiskMountManager::InitializeForTesting( | |
| 129 disk_mount_manager_mock_); | |
| 130 disk_mount_manager_mock_->SetupDefaultReplies(); | |
| 131 | |
| 132 // OVERRIDE mock functions. | |
| 133 ON_CALL(*disk_mount_manager_mock_, FindDiskBySourcePath(_)).WillByDefault( | |
| 134 Invoke(this, &FileBrowserPrivateApiTest::FindVolumeBySourcePath)); | |
| 135 EXPECT_CALL(*disk_mount_manager_mock_, disks()) | |
| 136 .WillRepeatedly(ReturnRef(volumes_)); | |
| 137 EXPECT_CALL(*disk_mount_manager_mock_, mount_points()) | |
| 138 .WillRepeatedly(ReturnRef(mount_points_)); | |
| 139 } | |
| 140 | |
| 141 // ExtensionApiTest override | |
| 142 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { | |
| 143 chromeos::disks::DiskMountManager::Shutdown(); | |
| 144 disk_mount_manager_mock_ = NULL; | |
| 145 | |
| 146 ExtensionApiTest::TearDownInProcessBrowserTestFixture(); | |
| 147 } | |
| 148 | |
| 149 private: | |
| 150 void InitMountPoints() { | |
| 151 const TestMountPoint kTestMountPoints[] = { | |
| 152 { | |
| 153 "device_path1", | |
| 154 chromeos::CrosDisksClient::GetRemovableDiskMountPoint().AppendASCII( | |
| 155 "mount_path1").AsUTF8Unsafe(), | |
| 156 chromeos::MOUNT_TYPE_DEVICE, | |
| 157 chromeos::disks::MOUNT_CONDITION_NONE, | |
| 158 0 | |
| 159 }, | |
| 160 { | |
| 161 "device_path2", | |
| 162 chromeos::CrosDisksClient::GetRemovableDiskMountPoint().AppendASCII( | |
| 163 "mount_path2").AsUTF8Unsafe(), | |
| 164 chromeos::MOUNT_TYPE_DEVICE, | |
| 165 chromeos::disks::MOUNT_CONDITION_NONE, | |
| 166 1 | |
| 167 }, | |
| 168 { | |
| 169 "device_path3", | |
| 170 chromeos::CrosDisksClient::GetRemovableDiskMountPoint().AppendASCII( | |
| 171 "mount_path3").AsUTF8Unsafe(), | |
| 172 chromeos::MOUNT_TYPE_DEVICE, | |
| 173 chromeos::disks::MOUNT_CONDITION_NONE, | |
| 174 2 | |
| 175 }, | |
| 176 { | |
| 177 // Set source path inside another mounted volume. | |
| 178 chromeos::CrosDisksClient::GetRemovableDiskMountPoint().AppendASCII( | |
| 179 "mount_path3/archive.zip").AsUTF8Unsafe(), | |
| 180 chromeos::CrosDisksClient::GetArchiveMountPoint().AppendASCII( | |
| 181 "archive_mount_path").AsUTF8Unsafe(), | |
| 182 chromeos::MOUNT_TYPE_ARCHIVE, | |
| 183 chromeos::disks::MOUNT_CONDITION_NONE, | |
| 184 -1 | |
| 185 } | |
| 186 }; | |
| 187 | |
| 188 for (size_t i = 0; i < arraysize(kTestMountPoints); i++) { | |
| 189 mount_points_.insert(DiskMountManager::MountPointMap::value_type( | |
| 190 kTestMountPoints[i].mount_path, | |
| 191 DiskMountManager::MountPointInfo(kTestMountPoints[i].source_path, | |
| 192 kTestMountPoints[i].mount_path, | |
| 193 kTestMountPoints[i].mount_type, | |
| 194 kTestMountPoints[i].mount_condition) | |
| 195 )); | |
| 196 int disk_info_index = kTestMountPoints[i].disk_info_index; | |
| 197 if (kTestMountPoints[i].disk_info_index >= 0) { | |
| 198 EXPECT_GT(arraysize(kTestDisks), static_cast<size_t>(disk_info_index)); | |
| 199 if (static_cast<size_t>(disk_info_index) >= arraysize(kTestDisks)) | |
| 200 return; | |
| 201 | |
| 202 volumes_.insert(DiskMountManager::DiskMap::value_type( | |
| 203 kTestMountPoints[i].source_path, | |
| 204 new DiskMountManager::Disk( | |
| 205 kTestMountPoints[i].source_path, | |
| 206 kTestMountPoints[i].mount_path, | |
| 207 kTestDisks[disk_info_index].system_path, | |
| 208 kTestDisks[disk_info_index].file_path, | |
| 209 kTestDisks[disk_info_index].device_label, | |
| 210 kTestDisks[disk_info_index].drive_label, | |
| 211 kTestDisks[disk_info_index].vendor_id, | |
| 212 kTestDisks[disk_info_index].vendor_name, | |
| 213 kTestDisks[disk_info_index].product_id, | |
| 214 kTestDisks[disk_info_index].product_name, | |
| 215 kTestDisks[disk_info_index].fs_uuid, | |
| 216 kTestDisks[disk_info_index].system_path_prefix, | |
| 217 kTestDisks[disk_info_index].device_type, | |
| 218 kTestDisks[disk_info_index].size_in_bytes, | |
| 219 kTestDisks[disk_info_index].is_parent, | |
| 220 kTestDisks[disk_info_index].is_read_only, | |
| 221 kTestDisks[disk_info_index].has_media, | |
| 222 kTestDisks[disk_info_index].on_boot_device, | |
| 223 kTestDisks[disk_info_index].on_removable_device, | |
| 224 kTestDisks[disk_info_index].is_hidden | |
| 225 ) | |
| 226 )); | |
| 227 } | |
| 228 } | |
| 229 } | |
| 230 | |
| 231 const DiskMountManager::Disk* FindVolumeBySourcePath( | |
| 232 const std::string& source_path) { | |
| 233 DiskMountManager::DiskMap::const_iterator volume_it = | |
| 234 volumes_.find(source_path); | |
| 235 return (volume_it == volumes_.end()) ? NULL : volume_it->second; | |
| 236 } | |
| 237 | |
| 238 protected: | |
| 239 chromeos::disks::MockDiskMountManager* disk_mount_manager_mock_; | |
| 240 DiskMountManager::DiskMap volumes_; | |
| 241 DiskMountManager::MountPointMap mount_points_; | |
| 242 }; | |
| 243 | |
| 244 IN_PROC_BROWSER_TEST_F(FileBrowserPrivateApiTest, Mount) { | |
| 245 file_manager::test_util::WaitUntilDriveMountPointIsAdded( | |
| 246 browser()->profile()); | |
| 247 | |
| 248 // We will call fileBrowserPrivate.unmountVolume once. To test that method, we | |
| 249 // check that UnmountPath is really called with the same value. | |
| 250 EXPECT_CALL(*disk_mount_manager_mock_, UnmountPath(_, _, _)) | |
| 251 .Times(0); | |
| 252 EXPECT_CALL(*disk_mount_manager_mock_, | |
| 253 UnmountPath( | |
| 254 chromeos::CrosDisksClient::GetArchiveMountPoint().AppendASCII( | |
| 255 "archive_mount_path").AsUTF8Unsafe(), | |
| 256 chromeos::UNMOUNT_OPTIONS_NONE, _)).Times(1); | |
| 257 | |
| 258 ASSERT_TRUE(RunComponentExtensionTest("file_browser/mount_test")) | |
| 259 << message_; | |
| 260 } | |
| OLD | NEW |