Chromium Code Reviews| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 using chromeos::DBusThreadManager; | 22 using chromeos::DBusThreadManager; |
| 23 using chromeos::FakeCrosDisksClient; | 23 using chromeos::FakeCrosDisksClient; |
| 24 using chromeos::MountType; | 24 using chromeos::MountType; |
| 25 using chromeos::disks::MountCondition; | 25 using chromeos::disks::MountCondition; |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 const char kDevice1SourcePath[] = "/device/source_path"; | 29 const char kDevice1SourcePath[] = "/device/source_path"; |
| 30 const char kDevice1MountPath[] = "/device/mount_path"; | 30 const char kDevice1MountPath[] = "/device/mount_path"; |
| 31 const char kDevice2SourcePath[] = "/device/source_path2"; | 31 const char kDevice2SourcePath[] = "/device/source_path2"; |
| 32 const char kDevice2MountPath[] = "/device/mount_path2"; | |
| 33 const char kReadOnlyDeviceMountPath[] = "/device/read_only_mount_path"; | 32 const char kReadOnlyDeviceMountPath[] = "/device/read_only_mount_path"; |
| 34 const char kReadOnlyDeviceSourcePath[] = "/device/read_only_source_path"; | 33 const char kReadOnlyDeviceSourcePath[] = "/device/read_only_source_path"; |
| 35 | 34 |
| 36 // Holds information needed to create a DiskMountManager::Disk instance. | 35 // Holds information needed to create a DiskMountManager::Disk instance. |
| 37 struct TestDiskInfo { | 36 struct TestDiskInfo { |
| 38 const char* source_path; | 37 const char* source_path; |
| 39 const char* mount_path; | 38 const char* mount_path; |
| 40 bool write_disabled_by_policy; | 39 bool write_disabled_by_policy; |
| 41 const char* system_path; | 40 const char* system_path; |
| 42 const char* file_path; | 41 const char* file_path; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 1073741824, // size in bytes | 85 1073741824, // size in bytes |
| 87 false, // is parent | 86 false, // is parent |
| 88 false, // is read only | 87 false, // is read only |
| 89 true, // has media | 88 true, // has media |
| 90 false, // is on boot device | 89 false, // is on boot device |
| 91 true, // is on removable device | 90 true, // is on removable device |
| 92 false // is hidden | 91 false // is hidden |
| 93 }, | 92 }, |
| 94 { | 93 { |
| 95 kDevice2SourcePath, | 94 kDevice2SourcePath, |
| 96 kDevice2MountPath, | 95 "", // not mounted initially |
| 97 false, // write_disabled_by_policy | 96 false, // write_disabled_by_policy |
| 98 "/device/prefix/system_path2", | 97 "/device/prefix/system_path2", |
| 99 "/device/file_path2", | 98 "/device/file_path2", |
| 100 "/device/device_label2", | 99 "/device/device_label2", |
| 101 "/device/drive_label2", | 100 "/device/drive_label2", |
| 102 "/device/vendor_id2", | 101 "/device/vendor_id2", |
| 103 "/device/vendor_name2", | 102 "/device/vendor_name2", |
| 104 "/device/product_id2", | 103 "/device/product_id2", |
| 105 "/device/product_name2", | 104 "/device/product_name2", |
| 106 "/device/fs_uuid2", | 105 "/device/fs_uuid2", |
| (...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 888 // Event handlers of observers should be called. | 887 // Event handlers of observers should be called. |
| 889 ASSERT_EQ(1U, observer_->GetEventCount()); | 888 ASSERT_EQ(1U, observer_->GetEventCount()); |
| 890 VerifyMountEvent(observer_->GetMountEvent(0), DiskMountManager::MOUNTING, | 889 VerifyMountEvent(observer_->GetMountEvent(0), DiskMountManager::MOUNTING, |
| 891 chromeos::MOUNT_ERROR_NONE, kReadOnlyDeviceMountPath); | 890 chromeos::MOUNT_ERROR_NONE, kReadOnlyDeviceMountPath); |
| 892 const DiskMountManager::DiskMap& disks = manager->disks(); | 891 const DiskMountManager::DiskMap& disks = manager->disks(); |
| 893 ASSERT_GT(disks.count(kReadOnlyDeviceSourcePath), 0U); | 892 ASSERT_GT(disks.count(kReadOnlyDeviceSourcePath), 0U); |
| 894 // The mounted disk should preserve the read-only flag of the block device. | 893 // The mounted disk should preserve the read-only flag of the block device. |
| 895 EXPECT_TRUE(disks.find(kReadOnlyDeviceSourcePath)->second->is_read_only()); | 894 EXPECT_TRUE(disks.find(kReadOnlyDeviceSourcePath)->second->is_read_only()); |
| 896 } | 895 } |
| 897 | 896 |
| 897 TEST_F(DiskMountManagerTest, RemountRemovableDrives) { | |
| 898 DiskMountManager* manager = DiskMountManager::GetInstance(); | |
| 899 manager->RemountAllRemovableDrives(chromeos::MOUNT_ACCESS_MODE_READ_ONLY); | |
| 900 | |
| 901 // Simulate cros_disks reporting mount completed. | |
| 902 fake_cros_disks_client_->SendMountCompletedEvent( | |
| 903 chromeos::MOUNT_ERROR_NONE, kDevice1SourcePath, | |
| 904 chromeos::MOUNT_TYPE_DEVICE, kDevice1MountPath); | |
| 905 | |
| 906 // Should remount all devices but read-only hardwares. | |
|
hashimoto
2016/10/27 08:31:52
"but read-only hardwares" what this mean?
It seems
yamaguchi
2016/10/27 09:52:41
It means that "all volumes should be remounted, bu
| |
| 907 ASSERT_EQ(1U, observer_->GetEventCount()); | |
| 908 VerifyMountEvent(observer_->GetMountEvent(0), DiskMountManager::MOUNTING, | |
| 909 chromeos::MOUNT_ERROR_NONE, kDevice1MountPath); | |
| 910 // The device is remounted in read-only mode. | |
| 911 EXPECT_TRUE( | |
| 912 manager->FindDiskBySourcePath(kDevice1SourcePath)->is_read_only()); | |
| 913 // Remounted disk should also appear as read-only to observers. | |
| 914 EXPECT_TRUE(observer_->GetMountEvent(0).disk->is_read_only()); | |
| 915 | |
| 916 // Remount in read-write mode again. | |
| 917 manager->RemountAllRemovableDrives(chromeos::MOUNT_ACCESS_MODE_READ_WRITE); | |
| 918 | |
| 919 // Simulate cros_disks reporting mount completed. | |
| 920 fake_cros_disks_client_->SendMountCompletedEvent( | |
| 921 chromeos::MOUNT_ERROR_NONE, kDevice1SourcePath, | |
| 922 chromeos::MOUNT_TYPE_DEVICE, kDevice1MountPath); | |
| 923 // Event handlers of observers should be called. | |
| 924 ASSERT_EQ(2U, observer_->GetEventCount()); | |
| 925 VerifyMountEvent(observer_->GetMountEvent(1), DiskMountManager::MOUNTING, | |
| 926 chromeos::MOUNT_ERROR_NONE, kDevice1MountPath); | |
| 927 // The read-write device should be remounted in read-write mode. | |
| 928 EXPECT_FALSE( | |
| 929 manager->FindDiskBySourcePath(kDevice1SourcePath)->is_read_only()); | |
| 930 // Remounted disk should also appear as writable to observers. | |
| 931 EXPECT_FALSE(observer_->GetMountEvent(1).disk->is_read_only()); | |
| 932 } | |
| 933 | |
| 898 } // namespace | 934 } // namespace |
| OLD | NEW |