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/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "chromeos/dbus/dbus_thread_manager.h" | 10 #include "chromeos/dbus/dbus_thread_manager.h" |
| 11 #include "chromeos/dbus/fake_cros_disks_client.h" | 11 #include "chromeos/dbus/fake_cros_disks_client.h" |
| 12 #include "chromeos/disks/disk_mount_manager.h" | 12 #include "chromeos/disks/disk_mount_manager.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 using chromeos::disks::DiskMountManager; | 16 using chromeos::disks::DiskMountManager; |
| 17 using chromeos::CrosDisksClient; | 17 using chromeos::CrosDisksClient; |
| 18 using chromeos::DBusThreadManager; | 18 using chromeos::DBusThreadManager; |
| 19 using chromeos::FakeCrosDisksClient; | 19 using chromeos::FakeCrosDisksClient; |
| 20 using testing::_; | 20 using testing::_; |
| 21 using testing::Field; | 21 using testing::Field; |
| 22 using testing::InSequence; | 22 using testing::InSequence; |
| 23 using testing::InvokeWithoutArgs; | |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 const char kReadOnlyMountpath[] = "/device/read_only_mount_path"; | 27 const char kReadOnlyMountpath[] = "/device/read_only_mount_path"; |
| 27 const char kReadOnlyDeviceSource[] = "/device/read_only_source_path"; | 28 const char kReadOnlyDeviceSource[] = "/device/read_only_source_path"; |
| 28 | 29 |
| 29 // Holds information needed to create a DiskMountManager::Disk instance. | 30 // Holds information needed to create a DiskMountManager::Disk instance. |
| 30 struct TestDiskInfo { | 31 struct TestDiskInfo { |
| 31 const char* source_path; | 32 const char* source_path; |
| 32 const char* mount_path; | 33 const char* mount_path; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 "/device/device_label", | 69 "/device/device_label", |
| 69 "/device/drive_label", | 70 "/device/drive_label", |
| 70 "/device/vendor_id", | 71 "/device/vendor_id", |
| 71 "/device/vendor_name", | 72 "/device/vendor_name", |
| 72 "/device/product_id", | 73 "/device/product_id", |
| 73 "/device/product_name", | 74 "/device/product_name", |
| 74 "/device/fs_uuid", | 75 "/device/fs_uuid", |
| 75 "/device/prefix", | 76 "/device/prefix", |
| 76 chromeos::DEVICE_TYPE_USB, | 77 chromeos::DEVICE_TYPE_USB, |
| 77 1073741824, // size in bytes | 78 1073741824, // size in bytes |
| 78 false, // is parent | 79 false, // is parent |
| 79 false, // is read only | 80 false, // is read only |
| 80 true, // has media | 81 true, // has media |
| 81 false, // is on boot device | 82 false, // is on boot device |
| 82 true, // is on removable device | 83 true, // is on removable device |
| 83 false // is hidden | 84 false // is hidden |
| 85 }, | |
| 86 { | |
| 87 "/device/source_path2", | |
| 88 "/device/mount_path2", | |
| 89 "/device/prefix/system_path2", | |
| 90 "/device/file_path2", | |
| 91 "/device/device_label2", | |
| 92 "/device/drive_label2", | |
| 93 "/device/vendor_id2", | |
| 94 "/device/vendor_name2", | |
| 95 "/device/product_id2", | |
| 96 "/device/product_name2", | |
| 97 "/device/fs_uuid2", | |
| 98 "/device/prefix2", | |
| 99 chromeos::DEVICE_TYPE_SD, | |
| 100 1073741824, // size in bytes | |
| 101 false, // is parent | |
| 102 false, // is read only | |
| 103 true, // has media | |
| 104 false, // is on boot device | |
| 105 true, // is on removable device | |
| 106 false // is hidden | |
| 84 }, | 107 }, |
| 85 { | 108 { |
| 86 kReadOnlyDeviceSource, | 109 kReadOnlyDeviceSource, |
| 87 kReadOnlyMountpath, | 110 kReadOnlyMountpath, |
| 88 "/device/prefix/system_path_2", | 111 "/device/prefix/system_path_3", |
| 89 "/device/file_path_2", | 112 "/device/file_path_3", |
| 90 "/device/device_label_2", | 113 "/device/device_label_3", |
| 91 "/device/drive_label_2", | 114 "/device/drive_label_3", |
| 92 "/device/vendor_id_2", | 115 "/device/vendor_id_3", |
| 93 "/device/vendor_name_2", | 116 "/device/vendor_name_3", |
| 94 "/device/product_id_2", | 117 "/device/product_id_3", |
| 95 "/device/product_name_2", | 118 "/device/product_name_3", |
| 96 "/device/fs_uuid_2", | 119 "/device/fs_uuid_3", |
| 97 "/device/prefix", | 120 "/device/prefix", |
| 98 chromeos::DEVICE_TYPE_USB, | 121 chromeos::DEVICE_TYPE_USB, |
| 99 1073741824, // size in bytes | 122 1073741824, // size in bytes |
| 100 false, // is parent | 123 false, // is parent |
| 101 true, // is read only | 124 true, // is read only |
| 102 true, // has media | 125 true, // has media |
| 103 false, // is on boot device | 126 false, // is on boot device |
| 104 true, // is on removable device | 127 true, // is on removable device |
| 105 false // is hidden | 128 false // is hidden |
| 106 }, | 129 }, |
| 107 }; | 130 }; |
| 108 | 131 |
| 109 // List of mount points held in DiskMountManager at the begining of the test. | 132 // List of mount points held in DiskMountManager at the begining of the test. |
| 110 const TestMountPointInfo kTestMountPoints[] = { | 133 const TestMountPointInfo kTestMountPoints[] = { |
| 111 { | 134 { |
| 112 "/archive/source_path", | 135 "/archive/source_path", |
| 113 "/archive/mount_path", | 136 "/archive/mount_path", |
| 114 chromeos::MOUNT_TYPE_ARCHIVE, | 137 chromeos::MOUNT_TYPE_ARCHIVE, |
| 115 chromeos::disks::MOUNT_CONDITION_NONE | 138 chromeos::disks::MOUNT_CONDITION_NONE |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 140 MOCK_METHOD3(OnMountEvent, | 163 MOCK_METHOD3(OnMountEvent, |
| 141 void(DiskMountManager::MountEvent event, | 164 void(DiskMountManager::MountEvent event, |
| 142 chromeos::MountError error_code, | 165 chromeos::MountError error_code, |
| 143 const DiskMountManager::MountPointInfo& mount_point)); | 166 const DiskMountManager::MountPointInfo& mount_point)); |
| 144 MOCK_METHOD3(OnFormatEvent, | 167 MOCK_METHOD3(OnFormatEvent, |
| 145 void(DiskMountManager::FormatEvent event, | 168 void(DiskMountManager::FormatEvent event, |
| 146 chromeos::FormatError error_code, | 169 chromeos::FormatError error_code, |
| 147 const std::string& device_path)); | 170 const std::string& device_path)); |
| 148 }; | 171 }; |
| 149 | 172 |
| 173 // Expect |is_read_only| value of a disk object keyed by |source_path|. | |
| 174 void ExpectDiskReadOnly(const DiskMountManager* manager, | |
| 175 const std::string& source_path, | |
| 176 bool expected) { | |
| 177 EXPECT_EQ(expected, | |
| 178 manager->disks().find(source_path)->second->is_read_only()); | |
| 179 } | |
| 180 | |
| 150 class DiskMountManagerTest : public testing::Test { | 181 class DiskMountManagerTest : public testing::Test { |
| 151 public: | 182 public: |
| 152 DiskMountManagerTest() {} | 183 DiskMountManagerTest() {} |
| 153 ~DiskMountManagerTest() override {} | 184 ~DiskMountManagerTest() override {} |
| 154 | 185 |
| 155 // Sets up test dbus tread manager and disks mount manager. | 186 // Sets up test dbus tread manager and disks mount manager. |
| 156 // Initializes disk mount manager disks and mount points. | 187 // Initializes disk mount manager disks and mount points. |
| 157 // Adds a test observer to the disk mount manager. | 188 // Adds a test observer to the disk mount manager. |
| 158 void SetUp() override { | 189 void SetUp() override { |
| 159 fake_cros_disks_client_ = new FakeCrosDisksClient; | 190 fake_cros_disks_client_ = new FakeCrosDisksClient; |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 EXPECT_EQ(2, fake_cros_disks_client_->format_call_count()); | 644 EXPECT_EQ(2, fake_cros_disks_client_->format_call_count()); |
| 614 EXPECT_EQ("/device/source_path", | 645 EXPECT_EQ("/device/source_path", |
| 615 fake_cros_disks_client_->last_format_device_path()); | 646 fake_cros_disks_client_->last_format_device_path()); |
| 616 EXPECT_EQ("vfat", fake_cros_disks_client_->last_format_filesystem()); | 647 EXPECT_EQ("vfat", fake_cros_disks_client_->last_format_filesystem()); |
| 617 | 648 |
| 618 // Simulate cros_disks reporting success. | 649 // Simulate cros_disks reporting success. |
| 619 fake_cros_disks_client_->SendFormatCompletedEvent( | 650 fake_cros_disks_client_->SendFormatCompletedEvent( |
| 620 chromeos::FORMAT_ERROR_NONE, "/device/source_path"); | 651 chromeos::FORMAT_ERROR_NONE, "/device/source_path"); |
| 621 } | 652 } |
| 622 | 653 |
| 654 TEST_F(DiskMountManagerTest, MountPath_RecordAccessMode) { | |
| 655 DiskMountManager* manager = DiskMountManager::GetInstance(); | |
| 656 const std::string kSourcePath1 = "/device/source_path"; | |
| 657 const std::string kSourcePath2 = "/device/source_path2"; | |
| 658 const std::string kSourceFormat = std::string(); | |
| 659 const std::string kMountLabel = std::string(); // N/A for MOUNT_TYPE_DEVICE | |
| 660 // For MountCompleted. Must be non-empty strings. | |
| 661 const std::string kMountPath1 = "/media/foo"; | |
| 662 const std::string kMountPath2 = "/media/bar"; | |
| 663 | |
| 664 EXPECT_CALL( | |
| 665 observer_, | |
| 666 OnMountEvent( | |
| 667 DiskMountManager::MOUNTING, chromeos::MOUNT_ERROR_NONE, | |
| 668 Field(&DiskMountManager::MountPointInfo::mount_path, kMountPath1))); | |
| 669 // Observers should see updated disks_ object reflecting mount option. | |
| 670 EXPECT_CALL( | |
| 671 observer_, | |
| 672 OnMountEvent( | |
| 673 DiskMountManager::MOUNTING, chromeos::MOUNT_ERROR_NONE, | |
| 674 Field(&DiskMountManager::MountPointInfo::mount_path, kMountPath2))) | |
| 675 .WillOnce(InvokeWithoutArgs( | |
| 676 [&]() { ExpectDiskReadOnly(manager, kSourcePath2, true); })); | |
|
satorux1
2016/08/24 22:05:50
hmm, this is hard to read... Please add some comme
| |
| 677 | |
| 678 manager->MountPath(kSourcePath1, kSourceFormat, std::string(), | |
| 679 chromeos::MOUNT_TYPE_DEVICE, | |
| 680 chromeos::MOUNT_ACCESS_MODE_READ_WRITE); | |
| 681 manager->MountPath(kSourcePath2, kSourceFormat, std::string(), | |
| 682 chromeos::MOUNT_TYPE_DEVICE, | |
| 683 chromeos::MOUNT_ACCESS_MODE_READ_ONLY); | |
| 684 // Simulate cros_disks reporting mount completed. | |
| 685 fake_cros_disks_client_->SendMountCompletedEvent( | |
| 686 chromeos::MOUNT_ERROR_NONE, kSourcePath1, chromeos::MOUNT_TYPE_DEVICE, | |
| 687 kMountPath1); | |
| 688 fake_cros_disks_client_->SendMountCompletedEvent( | |
| 689 chromeos::MOUNT_ERROR_NONE, kSourcePath2, chromeos::MOUNT_TYPE_DEVICE, | |
| 690 kMountPath2); | |
| 691 | |
| 692 const DiskMountManager::DiskMap& disks = manager->disks(); | |
| 693 ASSERT_GT(disks.count(kSourcePath1), 0U); | |
| 694 EXPECT_FALSE(disks.find(kSourcePath1)->second->is_read_only()); | |
| 695 ASSERT_GT(disks.count(kSourcePath2), 0U); | |
| 696 EXPECT_TRUE(disks.find(kSourcePath2)->second->is_read_only()); | |
| 697 } | |
| 698 | |
| 623 } // namespace | 699 } // namespace |
| OLD | NEW |