Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: chromeos/disks/disk_mount_manager_unittest.cc

Issue 2247263002: Prevent formatting a device being mounted in read-only mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix indent to preserve existing style. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/disks/disk_mount_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23
24 namespace { 24 namespace {
25 25
26 const char kReadOnlyMountpath[] = "/device/read_only_mount_path";
27 const char kReadOnlyDeviceSource[] = "/device/read_only_source_path";
28
26 // Holds information needed to create a DiskMountManager::Disk instance. 29 // Holds information needed to create a DiskMountManager::Disk instance.
27 struct TestDiskInfo { 30 struct TestDiskInfo {
28 const char* source_path; 31 const char* source_path;
29 const char* mount_path; 32 const char* mount_path;
30 const char* system_path; 33 const char* system_path;
31 const char* file_path; 34 const char* file_path;
32 const char* device_label; 35 const char* device_label;
33 const char* drive_label; 36 const char* drive_label;
34 const char* vendor_id; 37 const char* vendor_id;
35 const char* vendor_name; 38 const char* vendor_name;
(...skipping 14 matching lines...) Expand all
50 // Holds information to create a DiskMOuntManager::MountPointInfo instance. 53 // Holds information to create a DiskMOuntManager::MountPointInfo instance.
51 struct TestMountPointInfo { 54 struct TestMountPointInfo {
52 const char* source_path; 55 const char* source_path;
53 const char* mount_path; 56 const char* mount_path;
54 chromeos::MountType mount_type; 57 chromeos::MountType mount_type;
55 chromeos::disks::MountCondition mount_condition; 58 chromeos::disks::MountCondition mount_condition;
56 }; 59 };
57 60
58 // List of disks held in DiskMountManager at the begining of the test. 61 // List of disks held in DiskMountManager at the begining of the test.
59 const TestDiskInfo kTestDisks[] = { 62 const TestDiskInfo kTestDisks[] = {
60 { 63 {
satorux1 2016/08/16 20:24:04 Is this indentation change necessary? Maybe done b
yamaguchi 2016/08/17 04:06:17 It was done by clang-format. Reverted some changes
61 "/device/source_path", 64 "/device/source_path",
62 "/device/mount_path", 65 "/device/mount_path",
63 "/device/prefix/system_path", 66 "/device/prefix/system_path",
64 "/device/file_path", 67 "/device/file_path",
65 "/device/device_label", 68 "/device/device_label",
66 "/device/drive_label", 69 "/device/drive_label",
67 "/device/vendor_id", 70 "/device/vendor_id",
68 "/device/vendor_name", 71 "/device/vendor_name",
69 "/device/product_id", 72 "/device/product_id",
70 "/device/product_name", 73 "/device/product_name",
71 "/device/fs_uuid", 74 "/device/fs_uuid",
72 "/device/prefix", 75 "/device/prefix",
73 chromeos::DEVICE_TYPE_USB, 76 chromeos::DEVICE_TYPE_USB,
74 1073741824, // size in bytes 77 1073741824, // size in bytes
75 false, // is parent 78 false, // is parent
76 false, // is read only 79 false, // is read only
77 true, // has media 80 true, // has media
78 false, // is on boot device 81 false, // is on boot device
79 true, // is on removable device 82 true, // is on removable device
80 false // is hidden 83 false // is hidden
81 }, 84 },
85 {
86 kReadOnlyDeviceSource,
87 kReadOnlyMountpath,
88 "/device/prefix/system_path_2",
89 "/device/file_path_2",
90 "/device/device_label_2",
91 "/device/drive_label_2",
92 "/device/vendor_id_2",
93 "/device/vendor_name_2",
94 "/device/product_id_2",
95 "/device/product_name_2",
96 "/device/fs_uuid_2",
97 "/device/prefix",
98 chromeos::DEVICE_TYPE_USB,
99 1073741824, // size in bytes
100 false, // is parent
101 true, // is read only
102 true, // has media
103 false, // is on boot device
104 true, // is on removable device
105 false // is hidden
106 },
82 }; 107 };
83 108
84 // List of mount points held in DiskMountManager at the begining of the test. 109 // List of mount points held in DiskMountManager at the begining of the test.
85 const TestMountPointInfo kTestMountPoints[] = { 110 const TestMountPointInfo kTestMountPoints[] = {
86 { 111 {
87 "/archive/source_path", 112 "/archive/source_path",
88 "/archive/mount_path", 113 "/archive/mount_path",
89 chromeos::MOUNT_TYPE_ARCHIVE, 114 chromeos::MOUNT_TYPE_ARCHIVE,
90 chromeos::disks::MOUNT_CONDITION_NONE 115 chromeos::disks::MOUNT_CONDITION_NONE
91 }, 116 },
92 { 117 {
93 "/device/source_path", 118 "/device/source_path",
94 "/device/mount_path", 119 "/device/mount_path",
95 chromeos::MOUNT_TYPE_DEVICE, 120 chromeos::MOUNT_TYPE_DEVICE,
96 chromeos::disks::MOUNT_CONDITION_NONE 121 chromeos::disks::MOUNT_CONDITION_NONE
97 }, 122 },
123 {
124 kReadOnlyDeviceSource,
125 kReadOnlyMountpath,
126 chromeos::MOUNT_TYPE_DEVICE,
127 chromeos::disks::MOUNT_CONDITION_NONE
128 },
98 }; 129 };
99 130
100 // Mocks DiskMountManager observer. 131 // Mocks DiskMountManager observer.
101 class MockDiskMountManagerObserver : public DiskMountManager::Observer { 132 class MockDiskMountManagerObserver : public DiskMountManager::Observer {
102 public: 133 public:
103 virtual ~MockDiskMountManagerObserver() {} 134 virtual ~MockDiskMountManagerObserver() {}
104 135
105 MOCK_METHOD2(OnDiskEvent, void(DiskMountManager::DiskEvent event, 136 MOCK_METHOD2(OnDiskEvent, void(DiskMountManager::DiskEvent event,
106 const DiskMountManager::Disk* disk)); 137 const DiskMountManager::Disk* disk));
107 MOCK_METHOD2(OnDeviceEvent, void(DiskMountManager::DeviceEvent event, 138 MOCK_METHOD2(OnDeviceEvent, void(DiskMountManager::DeviceEvent event,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // Tests that the observer gets notified on attempt to format non existent mount 240 // Tests that the observer gets notified on attempt to format non existent mount
210 // point. 241 // point.
211 TEST_F(DiskMountManagerTest, Format_NotMounted) { 242 TEST_F(DiskMountManagerTest, Format_NotMounted) {
212 EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_COMPLETED, 243 EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_COMPLETED,
213 chromeos::FORMAT_ERROR_UNKNOWN, 244 chromeos::FORMAT_ERROR_UNKNOWN,
214 "/mount/non_existent")) 245 "/mount/non_existent"))
215 .Times(1); 246 .Times(1);
216 DiskMountManager::GetInstance()->FormatMountedDevice("/mount/non_existent"); 247 DiskMountManager::GetInstance()->FormatMountedDevice("/mount/non_existent");
217 } 248 }
218 249
250 // Tests that the observer gets notified on attempt to format read-only mount
251 // point.
252 TEST_F(DiskMountManagerTest, Format_ReadOnly) {
253 EXPECT_CALL(observer_,
254 OnFormatEvent(DiskMountManager::FORMAT_COMPLETED,
255 chromeos::FORMAT_ERROR_DEVICE_NOT_ALLOWED,
256 kReadOnlyMountpath))
257 .Times(1);
258 DiskMountManager::GetInstance()->FormatMountedDevice(kReadOnlyMountpath);
259 }
260
219 // Tests that it is not possible to format archive mount point. 261 // Tests that it is not possible to format archive mount point.
220 TEST_F(DiskMountManagerTest, Format_Archive) { 262 TEST_F(DiskMountManagerTest, Format_Archive) {
221 EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_COMPLETED, 263 EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_COMPLETED,
222 chromeos::FORMAT_ERROR_UNKNOWN, 264 chromeos::FORMAT_ERROR_UNKNOWN,
223 "/archive/source_path")) 265 "/archive/source_path"))
224 .Times(1); 266 .Times(1);
225 267
226 DiskMountManager::GetInstance()->FormatMountedDevice("/archive/mount_path"); 268 DiskMountManager::GetInstance()->FormatMountedDevice("/archive/mount_path");
227 } 269 }
228 270
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 EXPECT_EQ("/device/source_path", 614 EXPECT_EQ("/device/source_path",
573 fake_cros_disks_client_->last_format_device_path()); 615 fake_cros_disks_client_->last_format_device_path());
574 EXPECT_EQ("vfat", fake_cros_disks_client_->last_format_filesystem()); 616 EXPECT_EQ("vfat", fake_cros_disks_client_->last_format_filesystem());
575 617
576 // Simulate cros_disks reporting success. 618 // Simulate cros_disks reporting success.
577 fake_cros_disks_client_->SendFormatCompletedEvent( 619 fake_cros_disks_client_->SendFormatCompletedEvent(
578 chromeos::FORMAT_ERROR_NONE, "/device/source_path"); 620 chromeos::FORMAT_ERROR_NONE, "/device/source_path");
579 } 621 }
580 622
581 } // namespace 623 } // namespace
OLDNEW
« no previous file with comments | « chromeos/disks/disk_mount_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698