Ben Chan | 1e5a0cb | 2012-03-22 00:41:52 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Chan | d30e743 | 2011-11-28 13:43:17 -0800 | [diff] [blame] | 5 | // Unit tests for cros_disks::MountManager. See mount-manager.h for details |
| 6 | // on MountManager. |
| 7 | |
Ben Chan | 5ccd9fe | 2013-11-13 18:28:27 -0800 | [diff] [blame] | 8 | #include "cros-disks/mount_manager.h" |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 9 | |
| 10 | #include <sys/mount.h> |
| 11 | #include <sys/unistd.h> |
| 12 | |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 13 | #include <algorithm> |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
Sergei Datsenko | a910bba | 2019-06-18 13:31:59 +1000 | [diff] [blame] | 17 | #include <brillo/process_reaper.h> |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 18 | #include <gmock/gmock.h> |
| 19 | #include <gtest/gtest.h> |
| 20 | |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 21 | #include "cros-disks/metrics.h" |
Ben Chan | 8fb742b | 2014-04-28 23:46:57 -0700 | [diff] [blame] | 22 | #include "cros-disks/mount_entry.h" |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 23 | #include "cros-disks/mount_options.h" |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 24 | #include "cros-disks/mount_point.h" |
| 25 | #include "cros-disks/mounter.h" |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 26 | #include "cros-disks/platform.h" |
| 27 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 28 | using testing::_; |
Ben Chan | 09c90d0 | 2012-04-25 22:09:09 -0700 | [diff] [blame] | 29 | using testing::ElementsAre; |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 30 | using testing::Invoke; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 31 | using testing::Return; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 32 | |
Anand K Mistry | 40cff45 | 2019-07-30 10:24:48 +1000 | [diff] [blame] | 33 | namespace cros_disks { |
Ben Chan | 460439f | 2011-09-13 09:16:28 -0700 | [diff] [blame] | 34 | namespace { |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 35 | |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 36 | const char kMountRootDirectory[] = "/media/removable"; |
| 37 | const char kTestSourcePath[] = "source"; |
| 38 | const char kTestMountPath[] = "/media/removable/test"; |
| 39 | const char kInvalidMountPath[] = "/media/removable/../test/doc"; |
Tatsuhisa Yamaguchi | b670bd1 | 2016-09-28 23:06:44 +0900 | [diff] [blame] | 40 | const char kMountOptionRemount[] = "remount"; |
| 41 | const char kMountOptionReadOnly[] = "ro"; |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 42 | const char kMountOptionReadWrite[] = "rw"; |
Ben Chan | 460439f | 2011-09-13 09:16:28 -0700 | [diff] [blame] | 43 | |
| 44 | } // namespace |
| 45 | |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 46 | // A mock platform class for testing the mount manager base class. |
| 47 | class MockPlatform : public Platform { |
| 48 | public: |
Ben Chan | 40ecb9b | 2017-03-08 11:26:07 -0800 | [diff] [blame] | 49 | MockPlatform() = default; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 50 | |
Ben Chan | 21150af | 2019-09-11 17:04:07 -0700 | [diff] [blame] | 51 | MOCK_METHOD(bool, CreateDirectory, (const std::string&), (const, override)); |
| 52 | MOCK_METHOD(bool, |
| 53 | CreateOrReuseEmptyDirectory, |
| 54 | (const std::string&), |
| 55 | (const, override)); |
| 56 | MOCK_METHOD(bool, |
| 57 | CreateOrReuseEmptyDirectoryWithFallback, |
| 58 | (std::string*, unsigned, const std::set<std::string>&), |
| 59 | (const, override)); |
| 60 | MOCK_METHOD(bool, |
| 61 | RemoveEmptyDirectory, |
| 62 | (const std::string&), |
| 63 | (const, override)); |
| 64 | MOCK_METHOD(bool, |
| 65 | SetOwnership, |
| 66 | (const std::string&, uid_t, gid_t), |
| 67 | (const, override)); |
| 68 | MOCK_METHOD(bool, |
| 69 | SetPermissions, |
| 70 | (const std::string&, mode_t), |
| 71 | (const, override)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | // A mock mount manager class for testing the mount manager base class. |
| 75 | class MountManagerUnderTest : public MountManager { |
| 76 | public: |
Sergei Datsenko | a910bba | 2019-06-18 13:31:59 +1000 | [diff] [blame] | 77 | MountManagerUnderTest(Platform* platform, |
| 78 | Metrics* metrics, |
| 79 | brillo::ProcessReaper* process_reaper) |
| 80 | : MountManager(kMountRootDirectory, platform, metrics, process_reaper) {} |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 81 | |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 82 | ~MountManagerUnderTest() override { UnmountAll(); } |
| 83 | |
Ben Chan | 21150af | 2019-09-11 17:04:07 -0700 | [diff] [blame] | 84 | MOCK_METHOD(bool, CanMount, (const std::string&), (const, override)); |
| 85 | MOCK_METHOD(MountSourceType, GetMountSourceType, (), (const, override)); |
| 86 | MOCK_METHOD(MountErrorType, |
| 87 | DoMount, |
| 88 | (const std::string&, |
| 89 | const std::string&, |
| 90 | const std::vector<std::string>&, |
| 91 | const std::string&, |
| 92 | MountOptions*), |
| 93 | (override)); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 94 | MOCK_METHOD(MountErrorType, DoUnmount, (const std::string&), (override)); |
Ben Chan | 21150af | 2019-09-11 17:04:07 -0700 | [diff] [blame] | 95 | MOCK_METHOD(bool, |
| 96 | ShouldReserveMountPathOnError, |
| 97 | (MountErrorType), |
| 98 | (const, override)); |
| 99 | MOCK_METHOD(std::string, |
| 100 | SuggestMountPath, |
| 101 | (const std::string&), |
| 102 | (const, override)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | class MountManagerTest : public ::testing::Test { |
| 106 | public: |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 107 | MountManagerTest() : manager_(&platform_, &metrics_, &process_reaper_) { |
| 108 | ON_CALL(manager_, GetMountSourceType()) |
| 109 | .WillByDefault(Return(MOUNT_SOURCE_REMOVABLE_DEVICE)); |
| 110 | } |
| 111 | |
| 112 | std::unique_ptr<MountPoint> MakeMountPoint(const std::string& mount_path) { |
Anand K Mistry | f1bd086 | 2019-12-20 11:54:55 +1100 | [diff] [blame] | 113 | return MountPoint::CreateLeaking(base::FilePath(mount_path)); |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 114 | } |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 115 | |
| 116 | protected: |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 117 | Metrics metrics_; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 118 | MockPlatform platform_; |
Sergei Datsenko | a910bba | 2019-06-18 13:31:59 +1000 | [diff] [blame] | 119 | brillo::ProcessReaper process_reaper_; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 120 | MountManagerUnderTest manager_; |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 121 | std::string filesystem_type_; |
| 122 | std::string mount_path_; |
| 123 | std::string source_path_; |
| 124 | std::vector<std::string> options_; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
Tatsuhisa Yamaguchi | 578b3bf | 2016-09-30 16:57:18 +0900 | [diff] [blame] | 127 | // Mock action to emulate DoMount with fallback to read-only mode. |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 128 | MountErrorType DoMountSuccessReadOnly(const std::string& source_path, |
| 129 | const std::string& filesystem_type, |
| 130 | const std::vector<std::string>& options, |
| 131 | const std::string& mount_path, |
| 132 | MountOptions* applied_options) { |
Tatsuhisa Yamaguchi | 578b3bf | 2016-09-30 16:57:18 +0900 | [diff] [blame] | 133 | applied_options->Initialize(options, false, "", ""); |
| 134 | applied_options->SetReadOnlyOption(); |
| 135 | return MOUNT_ERROR_NONE; |
| 136 | } |
| 137 | |
| 138 | // Mock action to emulate DoMount successfully finished. |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 139 | MountErrorType DoMountSuccess(const std::string& source_path, |
| 140 | const std::string& filesystem_type, |
| 141 | const std::vector<std::string>& options, |
| 142 | const std::string& mount_path, |
| 143 | MountOptions* applied_options) { |
Tatsuhisa Yamaguchi | 578b3bf | 2016-09-30 16:57:18 +0900 | [diff] [blame] | 144 | applied_options->Initialize(options, false, "", ""); |
| 145 | return MOUNT_ERROR_NONE; |
| 146 | } |
| 147 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 148 | // Verifies that MountManager::Initialize() returns false when it fails to |
| 149 | // create the mount root directory. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 150 | TEST_F(MountManagerTest, InitializeFailedInCreateDirectory) { |
| 151 | EXPECT_CALL(platform_, CreateDirectory(kMountRootDirectory)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 152 | .WillOnce(Return(false)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 153 | EXPECT_CALL(platform_, SetOwnership(kMountRootDirectory, getuid(), getgid())) |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 154 | .Times(0); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 155 | EXPECT_CALL(platform_, SetPermissions(kMountRootDirectory, _)).Times(0); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 156 | |
| 157 | EXPECT_FALSE(manager_.Initialize()); |
| 158 | } |
| 159 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 160 | // Verifies that MountManager::Initialize() returns false when it fails to |
| 161 | // set the ownership of the created mount root directory. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 162 | TEST_F(MountManagerTest, InitializeFailedInSetOwnership) { |
| 163 | EXPECT_CALL(platform_, CreateDirectory(kMountRootDirectory)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 164 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 165 | EXPECT_CALL(platform_, SetOwnership(kMountRootDirectory, getuid(), getgid())) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 166 | .WillOnce(Return(false)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 167 | EXPECT_CALL(platform_, SetPermissions(kMountRootDirectory, _)).Times(0); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 168 | |
| 169 | EXPECT_FALSE(manager_.Initialize()); |
| 170 | } |
| 171 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 172 | // Verifies that MountManager::Initialize() returns false when it fails to |
| 173 | // set the permissions of the created mount root directory. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 174 | TEST_F(MountManagerTest, InitializeFailedInSetPermissions) { |
| 175 | EXPECT_CALL(platform_, CreateDirectory(kMountRootDirectory)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 176 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 177 | EXPECT_CALL(platform_, SetOwnership(kMountRootDirectory, getuid(), getgid())) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 178 | .WillOnce(Return(true)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 179 | EXPECT_CALL(platform_, SetPermissions(kMountRootDirectory, _)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 180 | .WillOnce(Return(false)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 181 | |
| 182 | EXPECT_FALSE(manager_.Initialize()); |
| 183 | } |
| 184 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 185 | // Verifies that MountManager::Initialize() returns true when it creates |
| 186 | // the mount root directory with the specified ownership and permissions. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 187 | TEST_F(MountManagerTest, InitializeSucceeded) { |
| 188 | EXPECT_CALL(platform_, CreateDirectory(kMountRootDirectory)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 189 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 190 | EXPECT_CALL(platform_, SetOwnership(kMountRootDirectory, getuid(), getgid())) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 191 | .WillOnce(Return(true)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 192 | EXPECT_CALL(platform_, SetPermissions(kMountRootDirectory, _)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 193 | .WillOnce(Return(true)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 194 | |
| 195 | EXPECT_TRUE(manager_.Initialize()); |
| 196 | } |
| 197 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 198 | // Verifies that MountManager::Mount() returns an error when it is invoked |
| 199 | // to mount an empty source path. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 200 | TEST_F(MountManagerTest, MountFailedWithEmptySourcePath) { |
| 201 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(_)).Times(0); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 202 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 203 | .Times(0); |
| 204 | EXPECT_CALL(platform_, RemoveEmptyDirectory(_)).Times(0); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 205 | EXPECT_CALL(manager_, DoMount(_, _, _, _, _)).Times(0); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 206 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 207 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 208 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 209 | EXPECT_EQ( |
| 210 | MOUNT_ERROR_INVALID_ARGUMENT, |
| 211 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 214 | // Verifies that MountManager::Mount() returns an error when it is invoked |
Ben Chan | 44e7ea6 | 2014-08-29 18:13:37 -0700 | [diff] [blame] | 215 | // with a nullptr mount path. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 216 | TEST_F(MountManagerTest, MountFailedWithNullMountPath) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 217 | source_path_ = kTestSourcePath; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 218 | |
| 219 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(_)).Times(0); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 220 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 221 | .Times(0); |
| 222 | EXPECT_CALL(platform_, RemoveEmptyDirectory(_)).Times(0); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 223 | EXPECT_CALL(manager_, DoMount(_, _, _, _, _)).Times(0); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 224 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 225 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 226 | |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 227 | EXPECT_EQ(MOUNT_ERROR_INVALID_ARGUMENT, |
Ben Chan | 44e7ea6 | 2014-08-29 18:13:37 -0700 | [diff] [blame] | 228 | manager_.Mount(source_path_, filesystem_type_, options_, nullptr)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 231 | // Verifies that MountManager::Mount() returns an error when it is invoked |
| 232 | // with an invalid mount path. |
| 233 | TEST_F(MountManagerTest, MountFailedWithInvalidMountPath) { |
| 234 | source_path_ = kTestSourcePath; |
| 235 | mount_path_ = kInvalidMountPath; |
| 236 | |
| 237 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(_)).Times(0); |
| 238 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
| 239 | .Times(0); |
| 240 | EXPECT_CALL(platform_, RemoveEmptyDirectory(_)).Times(0); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 241 | EXPECT_CALL(manager_, DoMount(_, _, _, _, _)).Times(0); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 242 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 243 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 244 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 245 | EXPECT_EQ( |
| 246 | MOUNT_ERROR_INVALID_PATH, |
| 247 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | // Verifies that MountManager::Mount() returns an error when it is invoked |
| 251 | // without a given mount path and the suggested mount path is invalid. |
| 252 | TEST_F(MountManagerTest, MountFailedWithInvalidSuggestedMountPath) { |
| 253 | source_path_ = kTestSourcePath; |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 254 | std::string suggested_mount_path = kInvalidMountPath; |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 255 | |
| 256 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(_)).Times(0); |
| 257 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
| 258 | .Times(0); |
| 259 | EXPECT_CALL(platform_, RemoveEmptyDirectory(_)).Times(0); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 260 | EXPECT_CALL(manager_, DoMount(_, _, _, _, _)).Times(0); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 261 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 262 | EXPECT_CALL(manager_, SuggestMountPath(_)) |
| 263 | .WillRepeatedly(Return(suggested_mount_path)); |
| 264 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 265 | EXPECT_EQ( |
| 266 | MOUNT_ERROR_INVALID_PATH, |
| 267 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 268 | |
| 269 | options_.push_back("mountlabel=custom_label"); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 270 | EXPECT_EQ( |
| 271 | MOUNT_ERROR_INVALID_PATH, |
| 272 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | // Verifies that MountManager::Mount() returns an error when it is invoked |
| 276 | // with an mount label that yields an invalid mount path. |
| 277 | TEST_F(MountManagerTest, MountFailedWithInvalidMountLabel) { |
| 278 | source_path_ = kTestSourcePath; |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 279 | std::string suggested_mount_path = kTestSourcePath; |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 280 | options_.push_back("mountlabel=../custom_label"); |
| 281 | |
| 282 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(_)).Times(0); |
| 283 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
| 284 | .Times(0); |
| 285 | EXPECT_CALL(platform_, RemoveEmptyDirectory(_)).Times(0); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 286 | EXPECT_CALL(manager_, DoMount(_, _, _, _, _)).Times(0); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 287 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 288 | EXPECT_CALL(manager_, SuggestMountPath(_)) |
| 289 | .WillOnce(Return(suggested_mount_path)); |
| 290 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 291 | EXPECT_EQ( |
| 292 | MOUNT_ERROR_INVALID_PATH, |
| 293 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 296 | // Verifies that MountManager::Mount() returns an error when it fails to |
| 297 | // create the specified mount directory. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 298 | TEST_F(MountManagerTest, MountFailedInCreateOrReuseEmptyDirectory) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 299 | source_path_ = kTestSourcePath; |
| 300 | mount_path_ = kTestMountPath; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 301 | |
| 302 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(mount_path_)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 303 | .WillOnce(Return(false)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 304 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 305 | .Times(0); |
| 306 | EXPECT_CALL(platform_, RemoveEmptyDirectory(_)).Times(0); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 307 | EXPECT_CALL(manager_, DoMount(_, _, _, _, _)).Times(0); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 308 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 309 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 310 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 311 | EXPECT_EQ( |
| 312 | MOUNT_ERROR_DIRECTORY_CREATION_FAILED, |
| 313 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 314 | EXPECT_EQ(kTestMountPath, mount_path_); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 315 | EXPECT_FALSE(manager_.IsMountPathInCache(mount_path_)); |
| 316 | } |
| 317 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 318 | // Verifies that MountManager::Mount() returns an error when it fails to |
| 319 | // create a specified but already reserved mount directory. |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 320 | TEST_F(MountManagerTest, MountFailedInCreateDirectoryDueToReservedMountPath) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 321 | source_path_ = kTestSourcePath; |
| 322 | mount_path_ = kTestMountPath; |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 323 | |
| 324 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(mount_path_)).Times(0); |
| 325 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
| 326 | .Times(0); |
| 327 | EXPECT_CALL(platform_, RemoveEmptyDirectory(_)).Times(0); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 328 | EXPECT_CALL(manager_, DoMount(_, _, _, _, _)).Times(0); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 329 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 330 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 331 | |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 332 | manager_.ReserveMountPath(mount_path_, MOUNT_ERROR_UNKNOWN_FILESYSTEM); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 333 | EXPECT_TRUE(manager_.IsMountPathReserved(mount_path_)); |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 334 | EXPECT_EQ(MOUNT_ERROR_UNKNOWN_FILESYSTEM, |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 335 | manager_.GetMountErrorOfReservedMountPath(mount_path_)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 336 | EXPECT_EQ( |
| 337 | MOUNT_ERROR_DIRECTORY_CREATION_FAILED, |
| 338 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 339 | EXPECT_EQ(kTestMountPath, mount_path_); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 340 | EXPECT_FALSE(manager_.IsMountPathInCache(mount_path_)); |
| 341 | EXPECT_TRUE(manager_.IsMountPathReserved(mount_path_)); |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 342 | EXPECT_EQ(MOUNT_ERROR_UNKNOWN_FILESYSTEM, |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 343 | manager_.GetMountErrorOfReservedMountPath(mount_path_)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 346 | // Verifies that MountManager::Mount() returns an error when it fails to |
| 347 | // create a mount directory after a number of trials. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 348 | TEST_F(MountManagerTest, MountFailedInCreateOrReuseEmptyDirectoryWithFallback) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 349 | source_path_ = kTestSourcePath; |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 350 | std::string suggested_mount_path = kTestMountPath; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 351 | |
| 352 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(_)).Times(0); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 353 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 354 | .WillOnce(Return(false)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 355 | EXPECT_CALL(platform_, RemoveEmptyDirectory(_)).Times(0); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 356 | EXPECT_CALL(manager_, DoMount(_, _, _, _, _)).Times(0); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 357 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 358 | EXPECT_CALL(manager_, SuggestMountPath(source_path_)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 359 | .WillOnce(Return(suggested_mount_path)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 360 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 361 | EXPECT_EQ( |
| 362 | MOUNT_ERROR_DIRECTORY_CREATION_FAILED, |
| 363 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 364 | EXPECT_EQ("", mount_path_); |
| 365 | EXPECT_FALSE(manager_.IsMountPathInCache(suggested_mount_path)); |
| 366 | } |
| 367 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 368 | // Verifies that MountManager::Mount() returns an error when it fails to |
| 369 | // set the ownership of the created mount directory. |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 370 | TEST_F(MountManagerTest, MountFailedInSetOwnership) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 371 | source_path_ = kTestSourcePath; |
| 372 | mount_path_ = kTestMountPath; |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 373 | |
| 374 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(mount_path_)) |
| 375 | .WillOnce(Return(true)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 376 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 377 | .Times(0); |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 378 | EXPECT_CALL(platform_, SetOwnership(mount_path_, _, _)) |
| 379 | .WillOnce(Return(false)); |
| 380 | EXPECT_CALL(platform_, SetPermissions(_, _)).Times(0); |
| 381 | EXPECT_CALL(platform_, RemoveEmptyDirectory(mount_path_)) |
| 382 | .WillOnce(Return(true)); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 383 | EXPECT_CALL(manager_, DoMount(_, _, _, _, _)).Times(0); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 384 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 385 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 386 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 387 | EXPECT_EQ( |
| 388 | MOUNT_ERROR_DIRECTORY_CREATION_FAILED, |
| 389 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 390 | EXPECT_EQ(kTestMountPath, mount_path_); |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 391 | EXPECT_FALSE(manager_.IsMountPathInCache(mount_path_)); |
| 392 | } |
| 393 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 394 | // Verifies that MountManager::Mount() returns an error when it fails to |
| 395 | // set the permissions of the created mount directory. |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 396 | TEST_F(MountManagerTest, MountFailedInSetPermissions) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 397 | source_path_ = kTestSourcePath; |
| 398 | mount_path_ = kTestMountPath; |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 399 | |
| 400 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(mount_path_)) |
| 401 | .WillOnce(Return(true)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 402 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 403 | .Times(0); |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 404 | EXPECT_CALL(platform_, SetOwnership(mount_path_, _, _)) |
| 405 | .WillOnce(Return(true)); |
| 406 | EXPECT_CALL(platform_, SetPermissions(mount_path_, _)) |
| 407 | .WillOnce(Return(false)); |
| 408 | EXPECT_CALL(platform_, RemoveEmptyDirectory(mount_path_)) |
| 409 | .WillOnce(Return(true)); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 410 | EXPECT_CALL(manager_, DoMount(_, _, _, _, _)).Times(0); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 411 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 412 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 413 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 414 | EXPECT_EQ( |
| 415 | MOUNT_ERROR_DIRECTORY_CREATION_FAILED, |
| 416 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 417 | EXPECT_EQ(kTestMountPath, mount_path_); |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 418 | EXPECT_FALSE(manager_.IsMountPathInCache(mount_path_)); |
| 419 | } |
| 420 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 421 | // Verifies that MountManager::Mount() returns no error when it successfully |
Tatsuhisa Yamaguchi | 578b3bf | 2016-09-30 16:57:18 +0900 | [diff] [blame] | 422 | // mounts a source path to a specified mount path in read-write mode. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 423 | TEST_F(MountManagerTest, MountSucceededWithGivenMountPath) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 424 | source_path_ = kTestSourcePath; |
| 425 | mount_path_ = kTestMountPath; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 426 | |
Tatsuhisa Yamaguchi | 578b3bf | 2016-09-30 16:57:18 +0900 | [diff] [blame] | 427 | options_.push_back(MountOptions::kOptionReadWrite); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 428 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(mount_path_)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 429 | .WillOnce(Return(true)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 430 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 431 | .Times(0); |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 432 | EXPECT_CALL(platform_, SetOwnership(mount_path_, _, _)) |
| 433 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 434 | EXPECT_CALL(platform_, SetPermissions(mount_path_, _)).WillOnce(Return(true)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 435 | EXPECT_CALL(platform_, RemoveEmptyDirectory(mount_path_)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 436 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 437 | EXPECT_CALL(manager_, |
| 438 | DoMount(source_path_, filesystem_type_, options_, mount_path_, _)) |
Tatsuhisa Yamaguchi | 578b3bf | 2016-09-30 16:57:18 +0900 | [diff] [blame] | 439 | .WillOnce(Invoke(DoMountSuccess)); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 440 | EXPECT_CALL(manager_, DoUnmount(mount_path_)) |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 441 | .WillOnce(Return(MOUNT_ERROR_NONE)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 442 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 443 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 444 | EXPECT_EQ(MOUNT_ERROR_NONE, manager_.Mount(source_path_, filesystem_type_, |
| 445 | options_, &mount_path_)); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 446 | EXPECT_EQ(kTestMountPath, mount_path_); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 447 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 448 | |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 449 | base::Optional<MountEntry> mount_entry; |
| 450 | mount_entry = manager_.GetMountEntryForTest(source_path_); |
| 451 | EXPECT_TRUE(mount_entry); |
| 452 | EXPECT_FALSE(mount_entry->is_read_only); |
George Burgess IV | 3d44fa8 | 2016-09-07 23:47:21 -0700 | [diff] [blame] | 453 | |
| 454 | EXPECT_TRUE(manager_.UnmountAll()); |
| 455 | EXPECT_FALSE(manager_.IsMountPathReserved(mount_path_)); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 456 | } |
| 457 | |
Tatsuhisa Yamaguchi | 578b3bf | 2016-09-30 16:57:18 +0900 | [diff] [blame] | 458 | // Verifies that MountManager::Mount() stores correct mount status in cache when |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 459 | // read-only option is specified. |
| 460 | TEST_F(MountManagerTest, MountCachesStatusWithReadOnlyOption) { |
| 461 | source_path_ = kTestSourcePath; |
| 462 | mount_path_ = kTestMountPath; |
| 463 | |
| 464 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(mount_path_)) |
| 465 | .WillOnce(Return(true)); |
| 466 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
| 467 | .Times(0); |
| 468 | EXPECT_CALL(platform_, SetOwnership(mount_path_, _, _)) |
| 469 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 470 | EXPECT_CALL(platform_, SetPermissions(mount_path_, _)).WillOnce(Return(true)); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 471 | // Add read-only mount option. |
Tatsuhisa Yamaguchi | 578b3bf | 2016-09-30 16:57:18 +0900 | [diff] [blame] | 472 | options_.push_back(MountOptions::kOptionReadOnly); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 473 | EXPECT_CALL(manager_, |
| 474 | DoMount(source_path_, filesystem_type_, options_, mount_path_, _)) |
Tatsuhisa Yamaguchi | 578b3bf | 2016-09-30 16:57:18 +0900 | [diff] [blame] | 475 | .WillOnce(Invoke(DoMountSuccess)); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 476 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 477 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 478 | EXPECT_EQ(MOUNT_ERROR_NONE, manager_.Mount(source_path_, filesystem_type_, |
| 479 | options_, &mount_path_)); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 480 | EXPECT_EQ(kTestMountPath, mount_path_); |
| 481 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 482 | |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 483 | base::Optional<MountEntry> mount_entry; |
| 484 | mount_entry = manager_.GetMountEntryForTest(source_path_); |
| 485 | EXPECT_TRUE(mount_entry); |
| 486 | EXPECT_TRUE(mount_entry->is_read_only); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 487 | } |
| 488 | |
Tatsuhisa Yamaguchi | 578b3bf | 2016-09-30 16:57:18 +0900 | [diff] [blame] | 489 | // Verifies that MountManager::Mount() stores correct mount status in cache when |
| 490 | // the mounter requested to mount in read-write mode but fell back to read-only |
| 491 | // mode. |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 492 | TEST_F(MountManagerTest, MountSuccededWithReadOnlyFallback) { |
| 493 | source_path_ = kTestSourcePath; |
| 494 | mount_path_ = kTestMountPath; |
| 495 | |
| 496 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(mount_path_)) |
| 497 | .WillOnce(Return(true)); |
| 498 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
| 499 | .Times(0); |
| 500 | EXPECT_CALL(platform_, SetOwnership(mount_path_, _, _)) |
| 501 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 502 | EXPECT_CALL(platform_, SetPermissions(mount_path_, _)).WillOnce(Return(true)); |
Tatsuhisa Yamaguchi | 578b3bf | 2016-09-30 16:57:18 +0900 | [diff] [blame] | 503 | options_.push_back(MountOptions::kOptionReadWrite); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 504 | // Emulate Mounter added read-only option as a fallback. |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 505 | EXPECT_CALL(manager_, |
| 506 | DoMount(source_path_, filesystem_type_, options_, mount_path_, _)) |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 507 | .WillOnce(Invoke(DoMountSuccessReadOnly)); |
| 508 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 509 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 510 | EXPECT_EQ(MOUNT_ERROR_NONE, manager_.Mount(source_path_, filesystem_type_, |
| 511 | options_, &mount_path_)); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 512 | EXPECT_EQ(kTestMountPath, mount_path_); |
| 513 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 514 | |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 515 | base::Optional<MountEntry> mount_entry; |
| 516 | mount_entry = manager_.GetMountEntryForTest(source_path_); |
| 517 | EXPECT_TRUE(mount_entry); |
| 518 | EXPECT_TRUE(mount_entry->is_read_only); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 521 | // Verifies that MountManager::Mount() returns no error when it successfully |
| 522 | // mounts a source path with no mount path specified. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 523 | TEST_F(MountManagerTest, MountSucceededWithEmptyMountPath) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 524 | source_path_ = kTestSourcePath; |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 525 | std::string suggested_mount_path = kTestMountPath; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 526 | |
| 527 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(_)).Times(0); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 528 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 529 | .WillOnce(Return(true)); |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 530 | EXPECT_CALL(platform_, SetOwnership(suggested_mount_path, _, _)) |
| 531 | .WillOnce(Return(true)); |
| 532 | EXPECT_CALL(platform_, SetPermissions(suggested_mount_path, _)) |
| 533 | .WillOnce(Return(true)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 534 | EXPECT_CALL(platform_, RemoveEmptyDirectory(suggested_mount_path)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 535 | .WillOnce(Return(true)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 536 | EXPECT_CALL(manager_, DoMount(source_path_, filesystem_type_, options_, |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 537 | suggested_mount_path, _)) |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 538 | .WillOnce(Return(MOUNT_ERROR_NONE)); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 539 | EXPECT_CALL(manager_, DoUnmount(suggested_mount_path)) |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 540 | .WillOnce(Return(MOUNT_ERROR_NONE)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 541 | EXPECT_CALL(manager_, SuggestMountPath(source_path_)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 542 | .WillOnce(Return(suggested_mount_path)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 543 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 544 | EXPECT_EQ(MOUNT_ERROR_NONE, manager_.Mount(source_path_, filesystem_type_, |
| 545 | options_, &mount_path_)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 546 | EXPECT_EQ(suggested_mount_path, mount_path_); |
| 547 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 548 | EXPECT_TRUE(manager_.UnmountAll()); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 549 | EXPECT_FALSE(manager_.IsMountPathReserved(mount_path_)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 550 | } |
| 551 | |
Ben Chan | 09c90d0 | 2012-04-25 22:09:09 -0700 | [diff] [blame] | 552 | // Verifies that MountManager::Mount() returns no error when it successfully |
| 553 | // mounts a source path with a given mount label in options. |
| 554 | TEST_F(MountManagerTest, MountSucceededWithGivenMountLabel) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 555 | source_path_ = kTestSourcePath; |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 556 | std::string suggested_mount_path = kTestMountPath; |
| 557 | std::string final_mount_path = |
| 558 | std::string(kMountRootDirectory) + "/custom_label"; |
Ben Chan | 09c90d0 | 2012-04-25 22:09:09 -0700 | [diff] [blame] | 559 | options_.push_back("mountlabel=custom_label"); |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 560 | std::vector<std::string> updated_options; |
Ben Chan | 09c90d0 | 2012-04-25 22:09:09 -0700 | [diff] [blame] | 561 | |
| 562 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(_)).Times(0); |
| 563 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
| 564 | .WillOnce(Return(true)); |
| 565 | EXPECT_CALL(platform_, SetOwnership(final_mount_path, _, _)) |
| 566 | .WillOnce(Return(true)); |
| 567 | EXPECT_CALL(platform_, SetPermissions(final_mount_path, _)) |
| 568 | .WillOnce(Return(true)); |
| 569 | EXPECT_CALL(platform_, RemoveEmptyDirectory(final_mount_path)) |
| 570 | .WillOnce(Return(true)); |
| 571 | EXPECT_CALL(manager_, DoMount(source_path_, filesystem_type_, updated_options, |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 572 | final_mount_path, _)) |
Ben Chan | 09c90d0 | 2012-04-25 22:09:09 -0700 | [diff] [blame] | 573 | .WillOnce(Return(MOUNT_ERROR_NONE)); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 574 | EXPECT_CALL(manager_, DoUnmount(final_mount_path)) |
Ben Chan | 09c90d0 | 2012-04-25 22:09:09 -0700 | [diff] [blame] | 575 | .WillOnce(Return(MOUNT_ERROR_NONE)); |
| 576 | EXPECT_CALL(manager_, SuggestMountPath(source_path_)) |
| 577 | .WillOnce(Return(suggested_mount_path)); |
| 578 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 579 | EXPECT_EQ(MOUNT_ERROR_NONE, manager_.Mount(source_path_, filesystem_type_, |
| 580 | options_, &mount_path_)); |
Ben Chan | 09c90d0 | 2012-04-25 22:09:09 -0700 | [diff] [blame] | 581 | EXPECT_EQ(final_mount_path, mount_path_); |
| 582 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 583 | EXPECT_TRUE(manager_.UnmountAll()); |
| 584 | EXPECT_FALSE(manager_.IsMountPathReserved(mount_path_)); |
| 585 | } |
| 586 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 587 | // Verifies that MountManager::Mount() handles the mounting of an already |
| 588 | // mounted source path properly. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 589 | TEST_F(MountManagerTest, MountWithAlreadyMountedSourcePath) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 590 | source_path_ = kTestSourcePath; |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 591 | std::string suggested_mount_path = kTestMountPath; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 592 | |
| 593 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(_)).Times(0); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 594 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 595 | .WillOnce(Return(true)); |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 596 | EXPECT_CALL(platform_, SetOwnership(suggested_mount_path, _, _)) |
| 597 | .WillOnce(Return(true)); |
| 598 | EXPECT_CALL(platform_, SetPermissions(suggested_mount_path, _)) |
| 599 | .WillOnce(Return(true)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 600 | EXPECT_CALL(platform_, RemoveEmptyDirectory(suggested_mount_path)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 601 | .WillOnce(Return(true)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 602 | EXPECT_CALL(manager_, DoMount(source_path_, filesystem_type_, options_, |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 603 | suggested_mount_path, _)) |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 604 | .WillOnce(Return(MOUNT_ERROR_NONE)); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 605 | EXPECT_CALL(manager_, DoUnmount(suggested_mount_path)) |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 606 | .WillOnce(Return(MOUNT_ERROR_NONE)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 607 | EXPECT_CALL(manager_, SuggestMountPath(source_path_)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 608 | .WillOnce(Return(suggested_mount_path)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 609 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 610 | EXPECT_EQ(MOUNT_ERROR_NONE, manager_.Mount(source_path_, filesystem_type_, |
| 611 | options_, &mount_path_)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 612 | EXPECT_EQ(suggested_mount_path, mount_path_); |
| 613 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 614 | |
| 615 | // Mount an already-mounted source path without specifying a mount path |
| 616 | mount_path_.clear(); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 617 | EXPECT_EQ(MOUNT_ERROR_NONE, manager_.Mount(source_path_, filesystem_type_, |
| 618 | options_, &mount_path_)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 619 | EXPECT_EQ(suggested_mount_path, mount_path_); |
| 620 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 621 | |
| 622 | // Mount an already-mounted source path to the same mount path |
| 623 | mount_path_ = suggested_mount_path; |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 624 | EXPECT_EQ(MOUNT_ERROR_NONE, manager_.Mount(source_path_, filesystem_type_, |
| 625 | options_, &mount_path_)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 626 | EXPECT_EQ(suggested_mount_path, mount_path_); |
| 627 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 628 | |
| 629 | // Mount an already-mounted source path to a different mount path |
| 630 | mount_path_ = "another-path"; |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 631 | EXPECT_EQ( |
| 632 | MOUNT_ERROR_PATH_ALREADY_MOUNTED, |
| 633 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 634 | EXPECT_FALSE(manager_.IsMountPathInCache(mount_path_)); |
| 635 | EXPECT_TRUE(manager_.IsMountPathInCache(suggested_mount_path)); |
| 636 | |
| 637 | EXPECT_TRUE(manager_.UnmountAll()); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 638 | EXPECT_FALSE(manager_.IsMountPathReserved(suggested_mount_path)); |
| 639 | } |
| 640 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 641 | // Verifies that MountManager::Mount() successfully reserves a path for a given |
| 642 | // type of error. A specific mount path is given in this case. |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 643 | TEST_F(MountManagerTest, MountSucceededWithGivenMountPathInReservedCase) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 644 | source_path_ = kTestSourcePath; |
| 645 | mount_path_ = kTestMountPath; |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 646 | |
| 647 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(mount_path_)) |
| 648 | .WillOnce(Return(true)); |
| 649 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
| 650 | .Times(0); |
| 651 | EXPECT_CALL(platform_, SetOwnership(mount_path_, _, _)) |
| 652 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 653 | EXPECT_CALL(platform_, SetPermissions(mount_path_, _)).WillOnce(Return(true)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 654 | EXPECT_CALL(platform_, RemoveEmptyDirectory(mount_path_)) |
| 655 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 656 | EXPECT_CALL(manager_, |
| 657 | DoMount(source_path_, filesystem_type_, options_, mount_path_, _)) |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 658 | .WillOnce(Return(MOUNT_ERROR_UNKNOWN_FILESYSTEM)); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 659 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 660 | EXPECT_CALL(manager_, |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 661 | ShouldReserveMountPathOnError(MOUNT_ERROR_UNKNOWN_FILESYSTEM)) |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 662 | .WillOnce(Return(true)); |
| 663 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 664 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 665 | EXPECT_EQ( |
| 666 | MOUNT_ERROR_UNKNOWN_FILESYSTEM, |
| 667 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 668 | EXPECT_EQ(kTestMountPath, mount_path_); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 669 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 670 | EXPECT_TRUE(manager_.IsMountPathReserved(mount_path_)); |
| 671 | EXPECT_TRUE(manager_.UnmountAll()); |
| 672 | EXPECT_FALSE(manager_.IsMountPathReserved(mount_path_)); |
| 673 | EXPECT_FALSE(manager_.IsMountPathReserved(mount_path_)); |
| 674 | } |
| 675 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 676 | // Verifies that MountManager::Mount() successfully reserves a path for a given |
| 677 | // type of error. No specific mount path is given in this case. |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 678 | TEST_F(MountManagerTest, MountSucceededWithEmptyMountPathInReservedCase) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 679 | source_path_ = kTestSourcePath; |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 680 | std::string suggested_mount_path = kTestMountPath; |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 681 | |
| 682 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(_)).Times(0); |
| 683 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
| 684 | .WillOnce(Return(true)); |
| 685 | EXPECT_CALL(platform_, SetOwnership(suggested_mount_path, _, _)) |
| 686 | .WillOnce(Return(true)); |
| 687 | EXPECT_CALL(platform_, SetPermissions(suggested_mount_path, _)) |
| 688 | .WillOnce(Return(true)); |
| 689 | EXPECT_CALL(platform_, RemoveEmptyDirectory(suggested_mount_path)) |
| 690 | .WillOnce(Return(true)); |
| 691 | EXPECT_CALL(manager_, DoMount(source_path_, filesystem_type_, options_, |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 692 | suggested_mount_path, _)) |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 693 | .WillOnce(Return(MOUNT_ERROR_UNKNOWN_FILESYSTEM)); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 694 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 695 | EXPECT_CALL(manager_, |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 696 | ShouldReserveMountPathOnError(MOUNT_ERROR_UNKNOWN_FILESYSTEM)) |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 697 | .WillOnce(Return(true)); |
| 698 | EXPECT_CALL(manager_, SuggestMountPath(source_path_)) |
| 699 | .WillOnce(Return(suggested_mount_path)); |
| 700 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 701 | EXPECT_EQ( |
| 702 | MOUNT_ERROR_UNKNOWN_FILESYSTEM, |
| 703 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 704 | EXPECT_EQ(suggested_mount_path, mount_path_); |
| 705 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 706 | EXPECT_TRUE(manager_.IsMountPathReserved(mount_path_)); |
| 707 | EXPECT_TRUE(manager_.UnmountAll()); |
| 708 | EXPECT_FALSE(manager_.IsMountPathInCache(mount_path_)); |
| 709 | EXPECT_FALSE(manager_.IsMountPathReserved(mount_path_)); |
| 710 | } |
| 711 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 712 | // Verifies that MountManager::Mount() successfully reserves a path for a given |
| 713 | // type of error and returns the same error when it tries to mount the same path |
| 714 | // again. |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 715 | TEST_F(MountManagerTest, MountSucceededWithAlreadyReservedMountPath) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 716 | source_path_ = kTestSourcePath; |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 717 | std::string suggested_mount_path = kTestMountPath; |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 718 | |
| 719 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(_)).Times(0); |
| 720 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
| 721 | .WillOnce(Return(true)); |
| 722 | EXPECT_CALL(platform_, SetOwnership(suggested_mount_path, _, _)) |
| 723 | .WillOnce(Return(true)); |
| 724 | EXPECT_CALL(platform_, SetPermissions(suggested_mount_path, _)) |
| 725 | .WillOnce(Return(true)); |
| 726 | EXPECT_CALL(platform_, RemoveEmptyDirectory(suggested_mount_path)) |
| 727 | .WillOnce(Return(true)); |
| 728 | EXPECT_CALL(manager_, DoMount(source_path_, filesystem_type_, options_, |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 729 | suggested_mount_path, _)) |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 730 | .WillOnce(Return(MOUNT_ERROR_UNKNOWN_FILESYSTEM)); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 731 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 732 | EXPECT_CALL(manager_, |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 733 | ShouldReserveMountPathOnError(MOUNT_ERROR_UNKNOWN_FILESYSTEM)) |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 734 | .WillOnce(Return(true)); |
| 735 | EXPECT_CALL(manager_, SuggestMountPath(source_path_)) |
| 736 | .WillOnce(Return(suggested_mount_path)); |
| 737 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 738 | EXPECT_EQ( |
| 739 | MOUNT_ERROR_UNKNOWN_FILESYSTEM, |
| 740 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 741 | EXPECT_EQ(suggested_mount_path, mount_path_); |
| 742 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 743 | EXPECT_TRUE(manager_.IsMountPathReserved(mount_path_)); |
| 744 | |
| 745 | mount_path_ = ""; |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 746 | EXPECT_EQ( |
| 747 | MOUNT_ERROR_UNKNOWN_FILESYSTEM, |
| 748 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 749 | EXPECT_EQ(suggested_mount_path, mount_path_); |
| 750 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 751 | EXPECT_TRUE(manager_.IsMountPathReserved(mount_path_)); |
| 752 | |
| 753 | EXPECT_TRUE(manager_.UnmountAll()); |
| 754 | EXPECT_FALSE(manager_.IsMountPathInCache(mount_path_)); |
| 755 | EXPECT_FALSE(manager_.IsMountPathReserved(mount_path_)); |
| 756 | } |
| 757 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 758 | // Verifies that MountManager::Mount() successfully reserves a path for a given |
| 759 | // type of error and returns the same error when it tries to mount the same path |
| 760 | // again. |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 761 | TEST_F(MountManagerTest, MountFailedWithGivenMountPathInReservedCase) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 762 | source_path_ = kTestSourcePath; |
| 763 | mount_path_ = kTestMountPath; |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 764 | |
| 765 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(mount_path_)) |
| 766 | .WillOnce(Return(true)); |
| 767 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
| 768 | .Times(0); |
| 769 | EXPECT_CALL(platform_, SetOwnership(mount_path_, _, _)) |
| 770 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 771 | EXPECT_CALL(platform_, SetPermissions(mount_path_, _)).WillOnce(Return(true)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 772 | EXPECT_CALL(platform_, RemoveEmptyDirectory(mount_path_)) |
| 773 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 774 | EXPECT_CALL(manager_, |
| 775 | DoMount(source_path_, filesystem_type_, options_, mount_path_, _)) |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 776 | .WillOnce(Return(MOUNT_ERROR_UNKNOWN_FILESYSTEM)); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 777 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 778 | EXPECT_CALL(manager_, |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 779 | ShouldReserveMountPathOnError(MOUNT_ERROR_UNKNOWN_FILESYSTEM)) |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 780 | .WillOnce(Return(false)); |
| 781 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 782 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 783 | EXPECT_EQ( |
| 784 | MOUNT_ERROR_UNKNOWN_FILESYSTEM, |
| 785 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 786 | EXPECT_EQ(kTestMountPath, mount_path_); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 787 | EXPECT_FALSE(manager_.IsMountPathInCache(mount_path_)); |
| 788 | EXPECT_FALSE(manager_.IsMountPathReserved(mount_path_)); |
| 789 | } |
| 790 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 791 | // Verifies that MountManager::Mount() fails to mount or reserve a path for |
| 792 | // a type of error that is not enabled for reservation. |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 793 | TEST_F(MountManagerTest, MountFailedWithEmptyMountPathInReservedCase) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 794 | source_path_ = kTestSourcePath; |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 795 | std::string suggested_mount_path = kTestMountPath; |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 796 | |
| 797 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(_)).Times(0); |
| 798 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
| 799 | .WillOnce(Return(true)); |
| 800 | EXPECT_CALL(platform_, SetOwnership(suggested_mount_path, _, _)) |
| 801 | .WillOnce(Return(true)); |
| 802 | EXPECT_CALL(platform_, SetPermissions(suggested_mount_path, _)) |
| 803 | .WillOnce(Return(true)); |
| 804 | EXPECT_CALL(platform_, RemoveEmptyDirectory(suggested_mount_path)) |
| 805 | .WillOnce(Return(true)); |
| 806 | EXPECT_CALL(manager_, DoMount(source_path_, filesystem_type_, options_, |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 807 | suggested_mount_path, _)) |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 808 | .WillOnce(Return(MOUNT_ERROR_UNKNOWN_FILESYSTEM)); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 809 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 810 | EXPECT_CALL(manager_, |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 811 | ShouldReserveMountPathOnError(MOUNT_ERROR_UNKNOWN_FILESYSTEM)) |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 812 | .WillOnce(Return(false)); |
| 813 | EXPECT_CALL(manager_, SuggestMountPath(source_path_)) |
| 814 | .WillOnce(Return(suggested_mount_path)); |
| 815 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 816 | EXPECT_EQ( |
| 817 | MOUNT_ERROR_UNKNOWN_FILESYSTEM, |
| 818 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 819 | EXPECT_EQ("", mount_path_); |
| 820 | EXPECT_FALSE(manager_.IsMountPathInCache(mount_path_)); |
| 821 | EXPECT_FALSE(manager_.IsMountPathReserved(mount_path_)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 824 | // Verifies that MountManager::Unmount() returns an error when it is invoked |
| 825 | // to unmount an empty path. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 826 | TEST_F(MountManagerTest, UnmountFailedWithEmptyPath) { |
| 827 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(_)).Times(0); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 828 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 829 | .Times(0); |
| 830 | EXPECT_CALL(platform_, RemoveEmptyDirectory(_)).Times(0); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 831 | EXPECT_CALL(manager_, DoMount(_, _, _, _, _)).Times(0); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 832 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 833 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 834 | |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 835 | EXPECT_EQ(MOUNT_ERROR_INVALID_ARGUMENT, manager_.Unmount(mount_path_)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 838 | // Verifies that MountManager::Unmount() returns an error when it fails to |
| 839 | // unmount a path that is not mounted. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 840 | TEST_F(MountManagerTest, UnmountFailedWithPathNotMounted) { |
| 841 | mount_path_ = "nonexistent-path"; |
| 842 | |
| 843 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(_)).Times(0); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 844 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 845 | .Times(0); |
| 846 | EXPECT_CALL(platform_, RemoveEmptyDirectory(_)).Times(0); |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 847 | EXPECT_CALL(manager_, DoMount(_, _, _, _, _)).Times(0); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 848 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 849 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 850 | |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 851 | EXPECT_EQ(MOUNT_ERROR_PATH_NOT_MOUNTED, manager_.Unmount(mount_path_)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 852 | } |
| 853 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 854 | // Verifies that MountManager::Unmount() returns no error when it successfully |
| 855 | // unmounts a source path. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 856 | TEST_F(MountManagerTest, UnmountSucceededWithGivenSourcePath) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 857 | source_path_ = kTestSourcePath; |
| 858 | mount_path_ = kTestMountPath; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 859 | |
| 860 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(mount_path_)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 861 | .WillOnce(Return(true)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 862 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 863 | .Times(0); |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 864 | EXPECT_CALL(platform_, SetOwnership(mount_path_, _, _)) |
| 865 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 866 | EXPECT_CALL(platform_, SetPermissions(mount_path_, _)).WillOnce(Return(true)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 867 | EXPECT_CALL(platform_, RemoveEmptyDirectory(mount_path_)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 868 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 869 | EXPECT_CALL(manager_, |
| 870 | DoMount(source_path_, filesystem_type_, options_, mount_path_, _)) |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 871 | .WillOnce(Return(MOUNT_ERROR_NONE)); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 872 | EXPECT_CALL(manager_, DoUnmount(mount_path_)) |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 873 | .WillOnce(Return(MOUNT_ERROR_NONE)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 874 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 875 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 876 | EXPECT_EQ(MOUNT_ERROR_NONE, manager_.Mount(source_path_, filesystem_type_, |
| 877 | options_, &mount_path_)); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 878 | EXPECT_EQ(kTestMountPath, mount_path_); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 879 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 880 | |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 881 | EXPECT_EQ(MOUNT_ERROR_NONE, manager_.Unmount(source_path_)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 882 | EXPECT_FALSE(manager_.IsMountPathInCache(mount_path_)); |
| 883 | } |
| 884 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 885 | // Verifies that MountManager::Unmount() returns no error when it successfully |
| 886 | // unmounts a mount path. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 887 | TEST_F(MountManagerTest, UnmountSucceededWithGivenMountPath) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 888 | source_path_ = kTestSourcePath; |
| 889 | mount_path_ = kTestMountPath; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 890 | |
| 891 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(mount_path_)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 892 | .WillOnce(Return(true)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 893 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 894 | .Times(0); |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 895 | EXPECT_CALL(platform_, SetOwnership(mount_path_, _, _)) |
| 896 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 897 | EXPECT_CALL(platform_, SetPermissions(mount_path_, _)).WillOnce(Return(true)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 898 | EXPECT_CALL(platform_, RemoveEmptyDirectory(mount_path_)) |
Ben Chan | 1d5a8e7 | 2011-08-01 15:21:39 -0700 | [diff] [blame] | 899 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 900 | EXPECT_CALL(manager_, |
| 901 | DoMount(source_path_, filesystem_type_, options_, mount_path_, _)) |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 902 | .WillOnce(Return(MOUNT_ERROR_NONE)); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 903 | EXPECT_CALL(manager_, DoUnmount(mount_path_)) |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 904 | .WillOnce(Return(MOUNT_ERROR_NONE)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 905 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 906 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 907 | EXPECT_EQ(MOUNT_ERROR_NONE, manager_.Mount(source_path_, filesystem_type_, |
| 908 | options_, &mount_path_)); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 909 | EXPECT_EQ(kTestMountPath, mount_path_); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 910 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 911 | |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 912 | EXPECT_EQ(MOUNT_ERROR_NONE, manager_.Unmount(mount_path_)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 913 | EXPECT_FALSE(manager_.IsMountPathInCache(mount_path_)); |
| 914 | } |
| 915 | |
Sergei Datsenko | 2879b5c | 2019-09-26 13:47:40 +1000 | [diff] [blame] | 916 | // Verifies that MountManager::Unmount() removes mount path from cache if |
| 917 | // it appears to be not mounted. |
| 918 | TEST_F(MountManagerTest, UnmountRemovesFromCacheIfNotMounted) { |
| 919 | source_path_ = kTestSourcePath; |
| 920 | mount_path_ = kTestMountPath; |
| 921 | |
| 922 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(mount_path_)) |
| 923 | .WillOnce(Return(true)); |
| 924 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
| 925 | .Times(0); |
| 926 | EXPECT_CALL(platform_, SetOwnership(mount_path_, _, _)) |
| 927 | .WillOnce(Return(true)); |
| 928 | EXPECT_CALL(platform_, SetPermissions(mount_path_, _)).WillOnce(Return(true)); |
| 929 | EXPECT_CALL(platform_, RemoveEmptyDirectory(mount_path_)) |
| 930 | .WillOnce(Return(true)); |
| 931 | EXPECT_CALL(manager_, |
| 932 | DoMount(source_path_, filesystem_type_, options_, mount_path_, _)) |
| 933 | .WillOnce(Return(MOUNT_ERROR_NONE)); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 934 | EXPECT_CALL(manager_, DoUnmount(mount_path_)) |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 935 | .Times(2) |
| 936 | .WillRepeatedly(Return(MOUNT_ERROR_PATH_NOT_MOUNTED)); |
Sergei Datsenko | 2879b5c | 2019-09-26 13:47:40 +1000 | [diff] [blame] | 937 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 938 | |
| 939 | EXPECT_EQ(MOUNT_ERROR_NONE, manager_.Mount(source_path_, filesystem_type_, |
| 940 | options_, &mount_path_)); |
| 941 | EXPECT_EQ(kTestMountPath, mount_path_); |
| 942 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 943 | |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 944 | EXPECT_EQ(MOUNT_ERROR_PATH_NOT_MOUNTED, manager_.Unmount(mount_path_)); |
Sergei Datsenko | 2879b5c | 2019-09-26 13:47:40 +1000 | [diff] [blame] | 945 | EXPECT_FALSE(manager_.IsMountPathInCache(mount_path_)); |
| 946 | } |
| 947 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 948 | // Verifies that MountManager::Unmount() returns no error when it is invoked |
| 949 | // to unmount the source path of a reserved mount path. |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 950 | TEST_F(MountManagerTest, UnmountSucceededWithGivenSourcePathInReservedCase) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 951 | source_path_ = kTestSourcePath; |
| 952 | mount_path_ = kTestMountPath; |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 953 | |
| 954 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(mount_path_)) |
| 955 | .WillOnce(Return(true)); |
| 956 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
| 957 | .Times(0); |
| 958 | EXPECT_CALL(platform_, SetOwnership(mount_path_, _, _)) |
| 959 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 960 | EXPECT_CALL(platform_, SetPermissions(mount_path_, _)).WillOnce(Return(true)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 961 | EXPECT_CALL(platform_, RemoveEmptyDirectory(mount_path_)) |
| 962 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 963 | EXPECT_CALL(manager_, |
| 964 | DoMount(source_path_, filesystem_type_, options_, mount_path_, _)) |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 965 | .WillOnce(Return(MOUNT_ERROR_UNKNOWN_FILESYSTEM)); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 966 | EXPECT_CALL(manager_, DoUnmount(mount_path_)).Times(0); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 967 | EXPECT_CALL(manager_, |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 968 | ShouldReserveMountPathOnError(MOUNT_ERROR_UNKNOWN_FILESYSTEM)) |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 969 | .WillOnce(Return(true)); |
| 970 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 971 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 972 | EXPECT_EQ( |
| 973 | MOUNT_ERROR_UNKNOWN_FILESYSTEM, |
| 974 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 975 | EXPECT_EQ(kTestMountPath, mount_path_); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 976 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 977 | EXPECT_TRUE(manager_.IsMountPathReserved(mount_path_)); |
| 978 | |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 979 | EXPECT_EQ(MOUNT_ERROR_NONE, manager_.Unmount(source_path_)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 980 | EXPECT_FALSE(manager_.IsMountPathInCache(mount_path_)); |
| 981 | EXPECT_FALSE(manager_.IsMountPathReserved(mount_path_)); |
| 982 | } |
| 983 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 984 | // Verifies that MountManager::Unmount() returns no error when it is invoked |
| 985 | // to unmount a reserved mount path. |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 986 | TEST_F(MountManagerTest, UnmountSucceededWithGivenMountPathInReservedCase) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 987 | source_path_ = kTestSourcePath; |
| 988 | mount_path_ = kTestMountPath; |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 989 | |
| 990 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectory(mount_path_)) |
| 991 | .WillOnce(Return(true)); |
| 992 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
| 993 | .Times(0); |
| 994 | EXPECT_CALL(platform_, SetOwnership(mount_path_, _, _)) |
| 995 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 996 | EXPECT_CALL(platform_, SetPermissions(mount_path_, _)).WillOnce(Return(true)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 997 | EXPECT_CALL(platform_, RemoveEmptyDirectory(mount_path_)) |
| 998 | .WillOnce(Return(true)); |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 999 | EXPECT_CALL(manager_, |
| 1000 | DoMount(source_path_, filesystem_type_, options_, mount_path_, _)) |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 1001 | .WillOnce(Return(MOUNT_ERROR_UNKNOWN_FILESYSTEM)); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 1002 | EXPECT_CALL(manager_, DoUnmount(mount_path_)).Times(0); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 1003 | EXPECT_CALL(manager_, |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 1004 | ShouldReserveMountPathOnError(MOUNT_ERROR_UNKNOWN_FILESYSTEM)) |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 1005 | .WillOnce(Return(true)); |
| 1006 | EXPECT_CALL(manager_, SuggestMountPath(_)).Times(0); |
| 1007 | |
Ben Chan | de0e3f6 | 2017-09-26 06:28:39 -0700 | [diff] [blame] | 1008 | EXPECT_EQ( |
| 1009 | MOUNT_ERROR_UNKNOWN_FILESYSTEM, |
| 1010 | manager_.Mount(source_path_, filesystem_type_, options_, &mount_path_)); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 1011 | EXPECT_EQ(kTestMountPath, mount_path_); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 1012 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 1013 | EXPECT_TRUE(manager_.IsMountPathReserved(mount_path_)); |
| 1014 | |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 1015 | EXPECT_EQ(MOUNT_ERROR_NONE, manager_.Unmount(mount_path_)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 1016 | EXPECT_FALSE(manager_.IsMountPathInCache(mount_path_)); |
| 1017 | EXPECT_FALSE(manager_.IsMountPathReserved(mount_path_)); |
| 1018 | } |
| 1019 | |
Tatsuhisa Yamaguchi | b670bd1 | 2016-09-28 23:06:44 +0900 | [diff] [blame] | 1020 | // Verifies that MountManager::AddOrUpdateMountStateCache() works as expected. |
| 1021 | TEST_F(MountManagerTest, AddOrUpdateMountStateCache) { |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 1022 | std::string result; |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 1023 | source_path_ = kTestSourcePath; |
| 1024 | mount_path_ = kTestMountPath; |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 1025 | std::string mount_path_2 = "target2"; |
Tatsuhisa Yamaguchi | 5a6a303 | 2016-08-19 20:03:54 +0900 | [diff] [blame] | 1026 | bool is_read_only = true; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 1027 | |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 1028 | manager_.AddOrUpdateMountStateCache(source_path_, MakeMountPoint(mount_path_), |
| 1029 | is_read_only); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 1030 | EXPECT_TRUE(manager_.GetMountPathFromCache(source_path_, &result)); |
| 1031 | EXPECT_EQ(mount_path_, result); |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 1032 | base::Optional<MountEntry> mount_entry; |
| 1033 | mount_entry = manager_.GetMountEntryForTest(source_path_); |
| 1034 | EXPECT_TRUE(mount_entry); |
| 1035 | EXPECT_EQ(kTestMountPath, mount_entry->mount_path); |
| 1036 | EXPECT_EQ(is_read_only, mount_entry->is_read_only); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 1037 | |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 1038 | manager_.AddOrUpdateMountStateCache(source_path_, |
| 1039 | MakeMountPoint(mount_path_2), false); |
| 1040 | mount_entry = manager_.GetMountEntryForTest(source_path_); |
| 1041 | EXPECT_TRUE(mount_entry); |
| 1042 | EXPECT_EQ(mount_path_2, mount_entry->mount_path); |
| 1043 | EXPECT_FALSE(mount_entry->is_read_only); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 1044 | |
Tatsuhisa Yamaguchi | b670bd1 | 2016-09-28 23:06:44 +0900 | [diff] [blame] | 1045 | EXPECT_FALSE(manager_.RemoveMountPathFromCache(mount_path_)); |
| 1046 | EXPECT_TRUE(manager_.RemoveMountPathFromCache(mount_path_2)); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 1049 | // Verifies that MountManager::IsMountPathInCache() works as expected. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 1050 | TEST_F(MountManagerTest, IsMountPathInCache) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 1051 | source_path_ = kTestSourcePath; |
| 1052 | mount_path_ = kTestMountPath; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 1053 | |
| 1054 | EXPECT_FALSE(manager_.IsMountPathInCache(mount_path_)); |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 1055 | manager_.AddOrUpdateMountStateCache(source_path_, MakeMountPoint(mount_path_), |
| 1056 | false); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 1057 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 1058 | EXPECT_TRUE(manager_.RemoveMountPathFromCache(mount_path_)); |
| 1059 | EXPECT_FALSE(manager_.IsMountPathInCache(mount_path_)); |
| 1060 | } |
| 1061 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 1062 | // Verifies that MountManager::RemoveMountPathFromCache() works as expected. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 1063 | TEST_F(MountManagerTest, RemoveMountPathFromCache) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 1064 | source_path_ = kTestSourcePath; |
| 1065 | mount_path_ = kTestMountPath; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 1066 | |
| 1067 | EXPECT_FALSE(manager_.RemoveMountPathFromCache(mount_path_)); |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 1068 | manager_.AddOrUpdateMountStateCache(source_path_, MakeMountPoint(mount_path_), |
| 1069 | false); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 1070 | EXPECT_TRUE(manager_.RemoveMountPathFromCache(mount_path_)); |
| 1071 | EXPECT_FALSE(manager_.RemoveMountPathFromCache(mount_path_)); |
| 1072 | } |
| 1073 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 1074 | // Verifies that MountManager::GetReservedMountPaths() works as expected. |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 1075 | TEST_F(MountManagerTest, GetReservedMountPaths) { |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 1076 | std::set<std::string> reserved_paths; |
| 1077 | std::set<std::string> expected_paths; |
| 1078 | std::string path1 = "path1"; |
| 1079 | std::string path2 = "path2"; |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 1080 | |
| 1081 | reserved_paths = manager_.GetReservedMountPaths(); |
Ben Chan | d30e743 | 2011-11-28 13:43:17 -0800 | [diff] [blame] | 1082 | EXPECT_TRUE(expected_paths == reserved_paths); |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 1083 | |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 1084 | manager_.ReserveMountPath(path1, MOUNT_ERROR_UNKNOWN_FILESYSTEM); |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 1085 | reserved_paths = manager_.GetReservedMountPaths(); |
| 1086 | expected_paths.insert(path1); |
Ben Chan | d30e743 | 2011-11-28 13:43:17 -0800 | [diff] [blame] | 1087 | EXPECT_TRUE(expected_paths == reserved_paths); |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 1088 | |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 1089 | manager_.ReserveMountPath(path2, MOUNT_ERROR_UNKNOWN_FILESYSTEM); |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 1090 | reserved_paths = manager_.GetReservedMountPaths(); |
| 1091 | expected_paths.insert(path2); |
Ben Chan | d30e743 | 2011-11-28 13:43:17 -0800 | [diff] [blame] | 1092 | EXPECT_TRUE(expected_paths == reserved_paths); |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 1093 | |
| 1094 | manager_.UnreserveMountPath(path1); |
| 1095 | reserved_paths = manager_.GetReservedMountPaths(); |
| 1096 | expected_paths.erase(path1); |
Ben Chan | d30e743 | 2011-11-28 13:43:17 -0800 | [diff] [blame] | 1097 | EXPECT_TRUE(expected_paths == reserved_paths); |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 1098 | |
| 1099 | manager_.UnreserveMountPath(path2); |
| 1100 | reserved_paths = manager_.GetReservedMountPaths(); |
| 1101 | expected_paths.erase(path2); |
Ben Chan | d30e743 | 2011-11-28 13:43:17 -0800 | [diff] [blame] | 1102 | EXPECT_TRUE(expected_paths == reserved_paths); |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 1105 | // Verifies that MountManager::ReserveMountPath() and |
| 1106 | // MountManager::UnreserveMountPath() work as expected. |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 1107 | TEST_F(MountManagerTest, ReserveAndUnreserveMountPath) { |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 1108 | mount_path_ = kTestMountPath; |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 1109 | |
| 1110 | EXPECT_FALSE(manager_.IsMountPathReserved(mount_path_)); |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 1111 | EXPECT_EQ(MOUNT_ERROR_NONE, |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 1112 | manager_.GetMountErrorOfReservedMountPath(mount_path_)); |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 1113 | manager_.ReserveMountPath(mount_path_, MOUNT_ERROR_UNKNOWN_FILESYSTEM); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 1114 | EXPECT_TRUE(manager_.IsMountPathReserved(mount_path_)); |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 1115 | EXPECT_EQ(MOUNT_ERROR_UNKNOWN_FILESYSTEM, |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 1116 | manager_.GetMountErrorOfReservedMountPath(mount_path_)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 1117 | manager_.UnreserveMountPath(mount_path_); |
| 1118 | EXPECT_FALSE(manager_.IsMountPathReserved(mount_path_)); |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 1119 | EXPECT_EQ(MOUNT_ERROR_NONE, |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 1120 | manager_.GetMountErrorOfReservedMountPath(mount_path_)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 1121 | |
| 1122 | // Removing a nonexistent mount path should be ok |
| 1123 | manager_.UnreserveMountPath(mount_path_); |
| 1124 | EXPECT_FALSE(manager_.IsMountPathReserved(mount_path_)); |
| 1125 | |
| 1126 | // Adding an existent mount path should be ok |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 1127 | manager_.ReserveMountPath(mount_path_, MOUNT_ERROR_UNSUPPORTED_FILESYSTEM); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 1128 | EXPECT_TRUE(manager_.IsMountPathReserved(mount_path_)); |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 1129 | EXPECT_EQ(MOUNT_ERROR_UNSUPPORTED_FILESYSTEM, |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 1130 | manager_.GetMountErrorOfReservedMountPath(mount_path_)); |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 1131 | manager_.ReserveMountPath(mount_path_, MOUNT_ERROR_UNKNOWN_FILESYSTEM); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 1132 | EXPECT_TRUE(manager_.IsMountPathReserved(mount_path_)); |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 1133 | EXPECT_EQ(MOUNT_ERROR_UNSUPPORTED_FILESYSTEM, |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 1134 | manager_.GetMountErrorOfReservedMountPath(mount_path_)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 1135 | manager_.UnreserveMountPath(mount_path_); |
| 1136 | EXPECT_FALSE(manager_.IsMountPathReserved(mount_path_)); |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 1137 | EXPECT_EQ(MOUNT_ERROR_NONE, |
Ben Chan | 632c9f8 | 2011-10-11 12:22:16 -0700 | [diff] [blame] | 1138 | manager_.GetMountErrorOfReservedMountPath(mount_path_)); |
Ben Chan | f869288 | 2011-08-21 10:15:30 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
Ben Chan | 8fb742b | 2014-04-28 23:46:57 -0700 | [diff] [blame] | 1141 | // Verifies that MountManager::GetMountEntries() returns the expected list of |
| 1142 | // mount entries under different scenarios. |
| 1143 | TEST_F(MountManagerTest, GetMountEntries) { |
Ben Chan | 7dfb810 | 2017-10-17 15:47:37 -0700 | [diff] [blame] | 1144 | // No mount entry is returned. |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 1145 | std::vector<MountEntry> mount_entries = manager_.GetMountEntries(); |
Ben Chan | 8fb742b | 2014-04-28 23:46:57 -0700 | [diff] [blame] | 1146 | EXPECT_TRUE(mount_entries.empty()); |
| 1147 | |
| 1148 | // A normal mount entry is returned. |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 1149 | manager_.AddOrUpdateMountStateCache(kTestSourcePath, |
| 1150 | MakeMountPoint(kTestMountPath), false); |
Ben Chan | 7dfb810 | 2017-10-17 15:47:37 -0700 | [diff] [blame] | 1151 | mount_entries = manager_.GetMountEntries(); |
Ben Chan | 8fb742b | 2014-04-28 23:46:57 -0700 | [diff] [blame] | 1152 | ASSERT_EQ(1, mount_entries.size()); |
Ben Chan | 0214e30 | 2017-10-17 15:39:16 -0700 | [diff] [blame] | 1153 | EXPECT_EQ(MOUNT_ERROR_NONE, mount_entries[0].error_type); |
| 1154 | EXPECT_EQ(kTestSourcePath, mount_entries[0].source_path); |
| 1155 | EXPECT_EQ(MOUNT_SOURCE_REMOVABLE_DEVICE, mount_entries[0].source_type); |
| 1156 | EXPECT_EQ(kTestMountPath, mount_entries[0].mount_path); |
Ben Chan | 8fb742b | 2014-04-28 23:46:57 -0700 | [diff] [blame] | 1157 | |
| 1158 | // A reserved mount entry is returned. |
| 1159 | manager_.ReserveMountPath(kTestMountPath, MOUNT_ERROR_UNKNOWN_FILESYSTEM); |
Ben Chan | 7dfb810 | 2017-10-17 15:47:37 -0700 | [diff] [blame] | 1160 | mount_entries = manager_.GetMountEntries(); |
Ben Chan | 8fb742b | 2014-04-28 23:46:57 -0700 | [diff] [blame] | 1161 | ASSERT_EQ(1, mount_entries.size()); |
Ben Chan | 0214e30 | 2017-10-17 15:39:16 -0700 | [diff] [blame] | 1162 | EXPECT_EQ(MOUNT_ERROR_UNKNOWN_FILESYSTEM, mount_entries[0].error_type); |
| 1163 | EXPECT_EQ(kTestSourcePath, mount_entries[0].source_path); |
| 1164 | EXPECT_EQ(MOUNT_SOURCE_REMOVABLE_DEVICE, mount_entries[0].source_type); |
| 1165 | EXPECT_EQ(kTestMountPath, mount_entries[0].mount_path); |
Ben Chan | 8fb742b | 2014-04-28 23:46:57 -0700 | [diff] [blame] | 1166 | } |
| 1167 | |
Ben Chan | 09c90d0 | 2012-04-25 22:09:09 -0700 | [diff] [blame] | 1168 | // Verifies that MountManager::ExtractMountLabelFromOptions() extracts a mount |
| 1169 | // label from the given options and returns true. |
| 1170 | TEST_F(MountManagerTest, ExtractMountLabelFromOptions) { |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 1171 | std::vector<std::string> options = {"ro", "mountlabel=My USB Drive", |
| 1172 | "noexec"}; |
| 1173 | std::string mount_label; |
Ben Chan | 09c90d0 | 2012-04-25 22:09:09 -0700 | [diff] [blame] | 1174 | |
| 1175 | EXPECT_TRUE(manager_.ExtractMountLabelFromOptions(&options, &mount_label)); |
| 1176 | EXPECT_THAT(options, ElementsAre("ro", "noexec")); |
| 1177 | EXPECT_EQ("My USB Drive", mount_label); |
| 1178 | } |
| 1179 | |
| 1180 | // Verifies that MountManager::ExtractMountLabelFromOptions() returns false |
| 1181 | // when no mount label is found in the given options. |
| 1182 | TEST_F(MountManagerTest, ExtractMountLabelFromOptionsWithNoMountLabel) { |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 1183 | std::vector<std::string> options; |
| 1184 | std::string mount_label; |
Ben Chan | 09c90d0 | 2012-04-25 22:09:09 -0700 | [diff] [blame] | 1185 | |
| 1186 | EXPECT_FALSE(manager_.ExtractMountLabelFromOptions(&options, &mount_label)); |
| 1187 | EXPECT_THAT(options, ElementsAre()); |
| 1188 | EXPECT_EQ("", mount_label); |
| 1189 | |
| 1190 | options.push_back("ro"); |
| 1191 | EXPECT_FALSE(manager_.ExtractMountLabelFromOptions(&options, &mount_label)); |
| 1192 | EXPECT_THAT(options, ElementsAre("ro")); |
| 1193 | EXPECT_EQ("", mount_label); |
| 1194 | |
| 1195 | options.push_back("mountlabel"); |
| 1196 | EXPECT_FALSE(manager_.ExtractMountLabelFromOptions(&options, &mount_label)); |
| 1197 | EXPECT_THAT(options, ElementsAre("ro", "mountlabel")); |
| 1198 | EXPECT_EQ("", mount_label); |
| 1199 | } |
| 1200 | |
| 1201 | // Verifies that MountManager::ExtractMountLabelFromOptions() extracts the last |
| 1202 | // mount label from the given options with two mount labels. |
| 1203 | TEST_F(MountManagerTest, ExtractMountLabelFromOptionsWithTwoMountLabels) { |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 1204 | std::vector<std::string> options = {"ro", "mountlabel=My USB Drive", "noexec", |
| 1205 | "mountlabel=Another Label"}; |
| 1206 | std::string mount_label; |
Ben Chan | 09c90d0 | 2012-04-25 22:09:09 -0700 | [diff] [blame] | 1207 | |
| 1208 | EXPECT_TRUE(manager_.ExtractMountLabelFromOptions(&options, &mount_label)); |
| 1209 | EXPECT_THAT(options, ElementsAre("ro", "noexec")); |
| 1210 | EXPECT_EQ("Another Label", mount_label); |
| 1211 | } |
| 1212 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 1213 | // Verifies that MountManager::IsPathImmediateChildOfParent() correctly |
| 1214 | // determines if a path is an immediate child of another path. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 1215 | TEST_F(MountManagerTest, IsPathImmediateChildOfParent) { |
Anand K Mistry | 09f2db1 | 2019-11-07 17:06:56 +1100 | [diff] [blame] | 1216 | EXPECT_TRUE(manager_.IsPathImmediateChildOfParent( |
| 1217 | base::FilePath("/media/archive/test.zip"), |
| 1218 | base::FilePath("/media/archive"))); |
| 1219 | EXPECT_TRUE(manager_.IsPathImmediateChildOfParent( |
| 1220 | base::FilePath("/media/archive/test.zip/"), |
| 1221 | base::FilePath("/media/archive"))); |
| 1222 | EXPECT_TRUE(manager_.IsPathImmediateChildOfParent( |
| 1223 | base::FilePath("/media/archive/test.zip"), |
| 1224 | base::FilePath("/media/archive/"))); |
| 1225 | EXPECT_TRUE(manager_.IsPathImmediateChildOfParent( |
| 1226 | base::FilePath("/media/archive/test.zip/"), |
| 1227 | base::FilePath("/media/archive/"))); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 1228 | EXPECT_FALSE(manager_.IsPathImmediateChildOfParent( |
Anand K Mistry | 09f2db1 | 2019-11-07 17:06:56 +1100 | [diff] [blame] | 1229 | base::FilePath("/media/archive/test.zip/doc.zip"), |
| 1230 | base::FilePath("/media/archive/"))); |
| 1231 | EXPECT_FALSE(manager_.IsPathImmediateChildOfParent( |
| 1232 | base::FilePath("/media/archive/test.zip"), |
| 1233 | base::FilePath("/media/removable"))); |
| 1234 | EXPECT_FALSE(manager_.IsPathImmediateChildOfParent( |
| 1235 | base::FilePath("/tmp/archive/test.zip"), |
| 1236 | base::FilePath("/media/removable"))); |
| 1237 | EXPECT_FALSE(manager_.IsPathImmediateChildOfParent( |
| 1238 | base::FilePath("/media"), base::FilePath("/media/removable"))); |
| 1239 | EXPECT_FALSE(manager_.IsPathImmediateChildOfParent( |
| 1240 | base::FilePath("/media/removable"), base::FilePath("/media/removable"))); |
| 1241 | EXPECT_FALSE(manager_.IsPathImmediateChildOfParent( |
| 1242 | base::FilePath("/media/removable/"), base::FilePath("/media/removable"))); |
| 1243 | EXPECT_FALSE(manager_.IsPathImmediateChildOfParent( |
| 1244 | base::FilePath("/media/removable/."), |
| 1245 | base::FilePath("/media/removable"))); |
| 1246 | EXPECT_FALSE(manager_.IsPathImmediateChildOfParent( |
| 1247 | base::FilePath("/media/removable/.."), |
| 1248 | base::FilePath("/media/removable"))); |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 1251 | // Verifies that MountManager::IsValidMountPath() correctly determines if a |
| 1252 | // mount path is an immediate child of the mount root. |
| 1253 | TEST_F(MountManagerTest, IsValidMountPath) { |
Anand K Mistry | 09f2db1 | 2019-11-07 17:06:56 +1100 | [diff] [blame] | 1254 | EXPECT_TRUE( |
| 1255 | manager_.IsValidMountPath(base::FilePath("/media/removable/test"))); |
| 1256 | EXPECT_TRUE( |
| 1257 | manager_.IsValidMountPath(base::FilePath("/media/removable/test/"))); |
| 1258 | EXPECT_TRUE( |
| 1259 | manager_.IsValidMountPath(base::FilePath("/media/removable/test/"))); |
| 1260 | EXPECT_TRUE( |
| 1261 | manager_.IsValidMountPath(base::FilePath("/media/removable//test"))); |
| 1262 | EXPECT_FALSE( |
| 1263 | manager_.IsValidMountPath(base::FilePath("/media/archive/test"))); |
| 1264 | EXPECT_FALSE(manager_.IsValidMountPath(base::FilePath("/media/removable"))); |
| 1265 | EXPECT_FALSE(manager_.IsValidMountPath(base::FilePath("/media/removable/"))); |
| 1266 | EXPECT_FALSE(manager_.IsValidMountPath(base::FilePath("/media/removable/."))); |
| 1267 | EXPECT_FALSE( |
| 1268 | manager_.IsValidMountPath(base::FilePath("/media/removable/.."))); |
| 1269 | EXPECT_FALSE( |
| 1270 | manager_.IsValidMountPath(base::FilePath("/media/removable/test/doc"))); |
| 1271 | EXPECT_FALSE( |
| 1272 | manager_.IsValidMountPath(base::FilePath("/media/removable/../test"))); |
| 1273 | EXPECT_FALSE( |
| 1274 | manager_.IsValidMountPath(base::FilePath("/media/removable/../test/"))); |
| 1275 | EXPECT_FALSE( |
| 1276 | manager_.IsValidMountPath(base::FilePath("/media/removable/test/.."))); |
| 1277 | EXPECT_FALSE( |
| 1278 | manager_.IsValidMountPath(base::FilePath("/media/removable/test/../"))); |
Ben Chan | adc5d00 | 2014-03-12 15:02:26 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
Tatsuhisa Yamaguchi | b670bd1 | 2016-09-28 23:06:44 +0900 | [diff] [blame] | 1281 | // Verifies that MountManager::Mount() returns an error when the source is |
| 1282 | // not mounted yet but attempted to remount it. |
| 1283 | TEST_F(MountManagerTest, RemountFailedNotMounted) { |
| 1284 | options_.push_back(kMountOptionRemount); |
| 1285 | |
| 1286 | EXPECT_CALL(manager_, DoMount(_, _, _, _, _)).Times(0); |
Anand K Mistry | 5a6d5fa | 2019-11-05 17:21:48 +1100 | [diff] [blame] | 1287 | EXPECT_CALL(manager_, DoUnmount(_)).Times(0); |
Tatsuhisa Yamaguchi | b670bd1 | 2016-09-28 23:06:44 +0900 | [diff] [blame] | 1288 | |
| 1289 | // source_path = kTestSourcePath has not been mounted yet. |
| 1290 | EXPECT_EQ(MOUNT_ERROR_PATH_NOT_MOUNTED, |
| 1291 | manager_.Mount(kTestSourcePath, filesystem_type_, options_, |
| 1292 | &mount_path_)); |
| 1293 | } |
| 1294 | |
| 1295 | // Verifies that MountManager::Mount() returns no error when it successfully |
| 1296 | // remounts a source path on a specified mount path. |
| 1297 | TEST_F(MountManagerTest, RemountSucceededWithGivenSourcePath) { |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 1298 | // Since the mount point will be remounted, only expect unmount to be called |
| 1299 | // once. |
| 1300 | EXPECT_CALL(manager_, DoUnmount(kTestMountPath)) |
| 1301 | .WillOnce(Return(MOUNT_ERROR_NONE)); |
Tatsuhisa Yamaguchi | b670bd1 | 2016-09-28 23:06:44 +0900 | [diff] [blame] | 1302 | |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 1303 | // Mount a device in read-write mode. |
| 1304 | EXPECT_CALL(manager_, SuggestMountPath(_)).WillOnce(Return(kTestMountPath)); |
| 1305 | EXPECT_CALL(platform_, CreateOrReuseEmptyDirectoryWithFallback(_, _, _)) |
| 1306 | .WillOnce(Return(true)); |
| 1307 | EXPECT_CALL(platform_, SetOwnership(kTestMountPath, _, _)) |
| 1308 | .WillOnce(Return(true)); |
| 1309 | EXPECT_CALL(platform_, SetPermissions(kTestMountPath, _)) |
| 1310 | .WillOnce(Return(true)); |
| 1311 | EXPECT_CALL(manager_, |
| 1312 | DoMount(kTestSourcePath, filesystem_type_, |
| 1313 | std::vector<std::string>({kMountOptionReadWrite}), |
| 1314 | kTestMountPath, _)) |
| 1315 | .WillOnce(Invoke(DoMountSuccess)); |
| 1316 | mount_path_ = ""; |
| 1317 | EXPECT_EQ(MOUNT_ERROR_NONE, |
| 1318 | manager_.Mount(kTestSourcePath, filesystem_type_, |
| 1319 | {kMountOptionReadWrite}, &mount_path_)); |
| 1320 | EXPECT_EQ(kTestMountPath, mount_path_); |
| 1321 | base::Optional<MountEntry> mount_entry; |
| 1322 | mount_entry = manager_.GetMountEntryForTest(kTestSourcePath); |
| 1323 | ASSERT_TRUE(mount_entry); |
| 1324 | EXPECT_FALSE(mount_entry->is_read_only); |
| 1325 | EXPECT_EQ(kTestMountPath, mount_entry->mount_path); |
| 1326 | |
| 1327 | // Remount with read-only mount option. |
Tatsuhisa Yamaguchi | b670bd1 | 2016-09-28 23:06:44 +0900 | [diff] [blame] | 1328 | options_.push_back(kMountOptionRemount); |
| 1329 | options_.push_back(kMountOptionReadOnly); |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 1330 | std::vector<std::string> expected_options = options_; |
Tatsuhisa Yamaguchi | b670bd1 | 2016-09-28 23:06:44 +0900 | [diff] [blame] | 1331 | EXPECT_CALL(manager_, DoMount(kTestSourcePath, filesystem_type_, |
| 1332 | expected_options, kTestMountPath, _)) |
| 1333 | .WillOnce(Invoke(DoMountSuccess)); |
Tatsuhisa Yamaguchi | b670bd1 | 2016-09-28 23:06:44 +0900 | [diff] [blame] | 1334 | mount_path_ = ""; |
| 1335 | EXPECT_EQ(MOUNT_ERROR_NONE, manager_.Mount(kTestSourcePath, filesystem_type_, |
| 1336 | options_, &mount_path_)); |
| 1337 | EXPECT_EQ(kTestMountPath, mount_path_); |
| 1338 | EXPECT_TRUE(manager_.IsMountPathInCache(mount_path_)); |
| 1339 | |
Anand K Mistry | e9a60fb | 2019-11-07 16:41:03 +1100 | [diff] [blame] | 1340 | mount_entry = manager_.GetMountEntryForTest(kTestSourcePath); |
| 1341 | EXPECT_TRUE(mount_entry); |
| 1342 | EXPECT_TRUE(mount_entry->is_read_only); |
Tatsuhisa Yamaguchi | b670bd1 | 2016-09-28 23:06:44 +0900 | [diff] [blame] | 1343 | |
| 1344 | // Should be unmounted correctly even after remount. |
Tatsuhisa Yamaguchi | b670bd1 | 2016-09-28 23:06:44 +0900 | [diff] [blame] | 1345 | EXPECT_TRUE(manager_.UnmountAll()); |
| 1346 | EXPECT_FALSE(manager_.IsMountPathInCache(kTestMountPath)); |
| 1347 | EXPECT_FALSE(manager_.IsMountPathReserved(kTestMountPath)); |
| 1348 | } |
| 1349 | |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 1350 | } // namespace cros_disks |