| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // MediaDeviceNotificationsLinux unit tests. | 5 // DiskMountWatcherLinux unit tests. |
| 6 | 6 |
| 7 #include "chrome/browser/media_gallery/media_device_notifications_linux.h" | 7 #include "chrome/browser/media_gallery/disk_mount_watcher_linux.h" |
| 8 | 8 |
| 9 #include <mntent.h> | 9 #include <mntent.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| 11 | 11 |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 30 using testing::_; | 30 using testing::_; |
| 31 | 31 |
| 32 const char kValidFS[] = "vfat"; | 32 const char kValidFS[] = "vfat"; |
| 33 const char kInvalidFS[] = "invalidfs"; | 33 const char kInvalidFS[] = "invalidfs"; |
| 34 | 34 |
| 35 const char kInvalidPath[] = "invalid path does not exist"; | 35 const char kInvalidPath[] = "invalid path does not exist"; |
| 36 | 36 |
| 37 const char kDevice1[] = "d1"; | 37 const char kDevice1[] = "d1"; |
| 38 const char kDevice2[] = "d2"; | 38 const char kDevice2[] = "d2"; |
| 39 const char kDevice3[] = "d3"; | 39 const char kDevice3[] = "d3"; |
| 40 const char kDevice4[] = "d4"; |
| 41 const char kDevice5[] = "d5"; |
| 40 | 42 |
| 41 const char kDeviceId1[] = "UUID:FFF0-000F"; | 43 const char kInvalidDevice[] = "invalid_device"; |
| 42 const char kDeviceId2[] = "VendorModelSerial:ComName:Model2010:898989898989"; | |
| 43 const char kDeviceId3[] = "VendorModelSerial:::WEM319X792"; | |
| 44 | |
| 45 const char kDeviceLabel1[] = "TEST_USB_MODEL_1"; | |
| 46 const char kDeviceLabel2[] = "TEST_USB_MODEL_2"; | |
| 47 const char kDeviceLabel3[] = "TEST_USB_MODEL_3"; | |
| 48 | 44 |
| 49 const char kMountPointA[] = "mnt_a"; | 45 const char kMountPointA[] = "mnt_a"; |
| 50 const char kMountPointB[] = "mnt_b"; | 46 const char kMountPointB[] = "mnt_b"; |
| 47 const char kMountPointC[] = "mnt_c"; |
| 51 | 48 |
| 52 std::string GetDCIMDeviceId(std::string unique_id) { | 49 struct TestDeviceData { |
| 53 return chrome::MediaStorageUtil::MakeDeviceId( | 50 const char* device_path; |
| 54 chrome::MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM, unique_id); | 51 const char* unique_id; |
| 52 const char* device_name; |
| 53 MediaStorageUtil::Type type; |
| 54 }; |
| 55 |
| 56 const TestDeviceData kTestDeviceData[] = { |
| 57 {kDevice1, "UUID:FFF0-000F", "TEST_USB_MODEL_1", |
| 58 MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM}, |
| 59 {kDevice2, "VendorModelSerial:ComName:Model2010:89898989", "TEST_USB_MODEL_2", |
| 60 MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM}, |
| 61 {kDevice3, "VendorModelSerial:::WEM319X792", "TEST_USB_MODEL_3", |
| 62 MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM}, |
| 63 {kDevice4, "UUID:ABCD-1234", "TEST_USB_MODEL_4", |
| 64 MediaStorageUtil::USB_MASS_STORAGE_NO_DCIM}, |
| 65 {kDevice5, "UUID:743A91FD2349", "TEST_USB_MODEL_5", |
| 66 MediaStorageUtil::OTHER_MASS_STORAGE}, |
| 67 }; |
| 68 |
| 69 bool GetDeviceInfo(const FilePath& device_path, std::string* id, |
| 70 string16* name, bool* usb) { |
| 71 for (size_t i = 0; i < arraysize(kTestDeviceData); i++) { |
| 72 if (device_path.value() == kTestDeviceData[i].device_path) { |
| 73 if (id) |
| 74 *id = kTestDeviceData[i].unique_id; |
| 75 if (name) |
| 76 *name = ASCIIToUTF16(kTestDeviceData[i].device_name); |
| 77 if (usb) { |
| 78 MediaStorageUtil::Type type = kTestDeviceData[i].type; |
| 79 *usb = (type == MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM) || |
| 80 (type == MediaStorageUtil::USB_MASS_STORAGE_NO_DCIM); |
| 81 } |
| 82 return true; |
| 83 } |
| 84 } |
| 85 return false; |
| 55 } | 86 } |
| 56 | 87 |
| 57 bool GetDeviceInfo(const std::string& dev_path, std::string* id, | 88 std::string GetDeviceId(const std::string& device) { |
| 58 string16* name) { | 89 for (size_t i = 0; i < arraysize(kTestDeviceData); i++) { |
| 59 std::string device_name; | 90 if (device == kTestDeviceData[i].device_path) { |
| 60 if (dev_path == kDevice1) { | 91 return MediaStorageUtil::MakeDeviceId(kTestDeviceData[i].type, |
| 61 *id = GetDCIMDeviceId(kDeviceId1); | 92 kTestDeviceData[i].unique_id); |
| 62 device_name = kDeviceLabel1; | 93 } |
| 63 } else if (dev_path == kDevice2) { | |
| 64 *id = GetDCIMDeviceId(kDeviceId2); | |
| 65 device_name = kDeviceLabel2; | |
| 66 } else if (dev_path == kDevice3) { | |
| 67 *id = GetDCIMDeviceId(kDeviceId3); | |
| 68 device_name = kDeviceLabel3; | |
| 69 } else { | |
| 70 return false; | |
| 71 } | 94 } |
| 72 | 95 return std::string(); |
| 73 *name = ASCIIToUTF16(device_name); | 96 } |
| 74 return true; | 97 string16 GetDeviceName(const std::string& device) { |
| 98 for (size_t i = 0; i < arraysize(kTestDeviceData); i++) { |
| 99 if (device == kTestDeviceData[i].device_path) |
| 100 return ASCIIToUTF16(kTestDeviceData[i].device_name); |
| 101 } |
| 102 return string16(); |
| 75 } | 103 } |
| 76 | 104 |
| 77 class MediaDeviceNotificationsLinuxTestWrapper | 105 class DiskMountWatcherLinuxTestWrapper : public DiskMountWatcherLinux { |
| 78 : public MediaDeviceNotificationsLinux { | |
| 79 public: | 106 public: |
| 80 MediaDeviceNotificationsLinuxTestWrapper(const FilePath& path, | 107 DiskMountWatcherLinuxTestWrapper(const FilePath& path, |
| 81 MessageLoop* message_loop) | 108 MessageLoop* message_loop) |
| 82 : MediaDeviceNotificationsLinux(path, &GetDeviceInfo), | 109 : DiskMountWatcherLinux(path, &GetDeviceInfo), |
| 83 message_loop_(message_loop) { | 110 message_loop_(message_loop) { |
| 84 } | 111 } |
| 85 | 112 |
| 86 private: | 113 private: |
| 87 // Avoids code deleting the object while there are references to it. | 114 // Avoids code deleting the object while there are references to it. |
| 88 // Aside from the base::RefCountedThreadSafe friend class, any attempts to | 115 // Aside from the base::RefCountedThreadSafe friend class, any attempts to |
| 89 // call this dtor will result in a compile-time error. | 116 // call this dtor will result in a compile-time error. |
| 90 ~MediaDeviceNotificationsLinuxTestWrapper() {} | 117 ~DiskMountWatcherLinuxTestWrapper() {} |
| 91 | 118 |
| 92 virtual void OnFilePathChanged(const FilePath& path, bool error) OVERRIDE { | 119 virtual void OnFilePathChanged(const FilePath& path, bool error) OVERRIDE { |
| 93 MediaDeviceNotificationsLinux::OnFilePathChanged(path, error); | 120 DiskMountWatcherLinux::OnFilePathChanged(path, error); |
| 94 message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 121 message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 95 } | 122 } |
| 96 | 123 |
| 97 MessageLoop* message_loop_; | 124 MessageLoop* message_loop_; |
| 98 | 125 |
| 99 DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinuxTestWrapper); | 126 DISALLOW_COPY_AND_ASSIGN(DiskMountWatcherLinuxTestWrapper); |
| 100 }; | 127 }; |
| 101 | 128 |
| 102 class MediaDeviceNotificationsLinuxTest : public testing::Test { | 129 class DiskMountWatcherLinuxTest : public testing::Test { |
| 103 public: | 130 public: |
| 104 struct MtabTestData { | 131 struct MtabTestData { |
| 105 MtabTestData(const std::string& mount_device, | 132 MtabTestData(const std::string& mount_device, |
| 106 const std::string& mount_point, | 133 const std::string& mount_point, |
| 107 const std::string& mount_type) | 134 const std::string& mount_type) |
| 108 : mount_device(mount_device), | 135 : mount_device(mount_device), |
| 109 mount_point(mount_point), | 136 mount_point(mount_point), |
| 110 mount_type(mount_type) { | 137 mount_type(mount_type) { |
| 111 } | 138 } |
| 112 | 139 |
| 113 const std::string mount_device; | 140 const std::string mount_device; |
| 114 const std::string mount_point; | 141 const std::string mount_point; |
| 115 const std::string mount_type; | 142 const std::string mount_type; |
| 116 }; | 143 }; |
| 117 | 144 |
| 118 MediaDeviceNotificationsLinuxTest() | 145 DiskMountWatcherLinuxTest() |
| 119 : message_loop_(MessageLoop::TYPE_IO), | 146 : message_loop_(MessageLoop::TYPE_IO), |
| 120 file_thread_(content::BrowserThread::FILE, &message_loop_) { | 147 file_thread_(content::BrowserThread::FILE, &message_loop_) { |
| 121 } | 148 } |
| 122 virtual ~MediaDeviceNotificationsLinuxTest() {} | 149 virtual ~DiskMountWatcherLinuxTest() {} |
| 123 | 150 |
| 124 protected: | 151 protected: |
| 125 virtual void SetUp() OVERRIDE { | 152 virtual void SetUp() OVERRIDE { |
| 126 mock_devices_changed_observer_.reset(new base::MockDevicesChangedObserver); | 153 mock_devices_changed_observer_.reset(new base::MockDevicesChangedObserver); |
| 127 system_monitor_.AddDevicesChangedObserver( | 154 system_monitor_.AddDevicesChangedObserver( |
| 128 mock_devices_changed_observer_.get()); | 155 mock_devices_changed_observer_.get()); |
| 129 | 156 |
| 130 // Create and set up a temp dir with files for the test. | 157 // Create and set up a temp dir with files for the test. |
| 131 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 158 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
| 132 FilePath test_dir = scoped_temp_dir_.path().AppendASCII("test_etc"); | 159 FilePath test_dir = scoped_temp_dir_.path().AppendASCII("test_etc"); |
| 133 ASSERT_TRUE(file_util::CreateDirectory(test_dir)); | 160 ASSERT_TRUE(file_util::CreateDirectory(test_dir)); |
| 134 mtab_file_ = test_dir.AppendASCII("test_mtab"); | 161 mtab_file_ = test_dir.AppendASCII("test_mtab"); |
| 135 MtabTestData initial_test_data[] = { | 162 MtabTestData initial_test_data[] = { |
| 136 MtabTestData("dummydevice", "dummydir", kInvalidFS), | 163 MtabTestData("dummydevice", "dummydir", kInvalidFS), |
| 137 }; | 164 }; |
| 138 WriteToMtab(initial_test_data, | 165 WriteToMtab(initial_test_data, |
| 139 arraysize(initial_test_data), | 166 arraysize(initial_test_data), |
| 140 true /* overwrite */); | 167 true /* overwrite */); |
| 141 | 168 |
| 142 // Initialize the test subject. | 169 // Initialize the test subject. |
| 143 notifications_ = | 170 mount_watcher_ = new DiskMountWatcherLinuxTestWrapper(mtab_file_, |
| 144 new MediaDeviceNotificationsLinuxTestWrapper(mtab_file_, | 171 &message_loop_); |
| 145 &message_loop_); | 172 mount_watcher_->Init(); |
| 146 notifications_->Init(); | |
| 147 message_loop_.RunAllPending(); | 173 message_loop_.RunAllPending(); |
| 148 } | 174 } |
| 149 | 175 |
| 150 virtual void TearDown() OVERRIDE { | 176 virtual void TearDown() OVERRIDE { |
| 151 message_loop_.RunAllPending(); | 177 message_loop_.RunAllPending(); |
| 152 notifications_ = NULL; | 178 mount_watcher_ = NULL; |
| 153 system_monitor_.RemoveDevicesChangedObserver( | 179 system_monitor_.RemoveDevicesChangedObserver( |
| 154 mock_devices_changed_observer_.get()); | 180 mock_devices_changed_observer_.get()); |
| 155 } | 181 } |
| 156 | 182 |
| 157 // Append mtab entries from the |data| array of size |data_size| to the mtab | 183 // Append mtab entries from the |data| array of size |data_size| to the mtab |
| 158 // file, and run the message loop. | 184 // file, and run the message loop. |
| 159 void AppendToMtabAndRunLoop(const MtabTestData* data, size_t data_size) { | 185 void AppendToMtabAndRunLoop(const MtabTestData* data, size_t data_size) { |
| 160 WriteToMtab(data, data_size, false /* do not overwrite */); | 186 WriteToMtab(data, data_size, false /* do not overwrite */); |
| 161 message_loop_.Run(); | 187 message_loop_.Run(); |
| 162 } | 188 } |
| 163 | 189 |
| 164 // Overwrite the mtab file with mtab entries from the |data| array of size | 190 // Overwrite the mtab file with mtab entries from the |data| array of size |
| 165 // |data_size|, and run the message loop. | 191 // |data_size|, and run the message loop. |
| 166 void OverwriteMtabAndRunLoop(const MtabTestData* data, size_t data_size) { | 192 void OverwriteMtabAndRunLoop(const MtabTestData* data, size_t data_size) { |
| 167 WriteToMtab(data, data_size, true /* overwrite */); | 193 WriteToMtab(data, data_size, true /* overwrite */); |
| 168 message_loop_.Run(); | 194 message_loop_.Run(); |
| 169 } | 195 } |
| 170 | 196 |
| 171 // Simplied version of OverwriteMtabAndRunLoop() that just deletes all the | 197 // Simplied version of OverwriteMtabAndRunLoop() that just deletes all the |
| 172 // entries in the mtab file. | 198 // entries in the mtab file. |
| 173 void WriteEmptyMtabAndRunLoop() { | 199 void WriteEmptyMtabAndRunLoop() { |
| 174 OverwriteMtabAndRunLoop(NULL, // No data. | 200 OverwriteMtabAndRunLoop(NULL, // No data. |
| 175 0); // No data length. | 201 0); // No data length. |
| 176 } | 202 } |
| 177 | 203 |
| 178 // Create a directory named |dir| relative to the test directory. | 204 // Create a directory named |dir| relative to the test directory. |
| 179 // It has a DCIM directory, so MediaDeviceNotificationsLinux recognizes it as | 205 // It has a DCIM directory, so DiskMountWatcherLinux recognizes it as |
| 180 // a media directory. | 206 // a media directory. |
| 181 FilePath CreateMountPointWithDCIMDir(const std::string& dir) { | 207 FilePath CreateMountPointWithDCIMDir(const std::string& dir) { |
| 182 return CreateMountPoint(dir, true /* create DCIM dir */); | 208 return CreateMountPoint(dir, true /* create DCIM dir */); |
| 183 } | 209 } |
| 184 | 210 |
| 185 // Create a directory named |dir| relative to the test directory. | 211 // Create a directory named |dir| relative to the test directory. |
| 186 // It does not have a DCIM directory, so MediaDeviceNotificationsLinux does | 212 // It does not have a DCIM directory, so DiskMountWatcherLinux does |
| 187 // not recognizes it as a media directory. | 213 // not recognizes it as a media directory. |
| 188 FilePath CreateMountPointWithoutDCIMDir(const std::string& dir) { | 214 FilePath CreateMountPointWithoutDCIMDir(const std::string& dir) { |
| 189 return CreateMountPoint(dir, false /* do not create DCIM dir */); | 215 return CreateMountPoint(dir, false /* do not create DCIM dir */); |
| 190 } | 216 } |
| 191 | 217 |
| 192 base::MockDevicesChangedObserver& observer() { | 218 base::MockDevicesChangedObserver& observer() { |
| 193 return *mock_devices_changed_observer_; | 219 return *mock_devices_changed_observer_; |
| 194 } | 220 } |
| 195 | 221 |
| 222 DiskMountWatcherLinux* watcher() { |
| 223 return mount_watcher_.get(); |
| 224 } |
| 225 |
| 196 private: | 226 private: |
| 197 // Create a directory named |dir| relative to the test directory. | 227 // Create a directory named |dir| relative to the test directory. |
| 198 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" | 228 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" |
| 199 // subdirectory. | 229 // subdirectory. |
| 200 // Returns the full path to the created directory on success, or an empty | 230 // Returns the full path to the created directory on success, or an empty |
| 201 // path on failure. | 231 // path on failure. |
| 202 FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir) { | 232 FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir) { |
| 203 FilePath return_path(scoped_temp_dir_.path()); | 233 FilePath return_path(scoped_temp_dir_.path()); |
| 204 return_path = return_path.AppendASCII(dir); | 234 return_path = return_path.AppendASCII(dir); |
| 205 FilePath path(return_path); | 235 FilePath path(return_path); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 279 |
| 250 // SystemMonitor and DevicesChangedObserver to hook together to test. | 280 // SystemMonitor and DevicesChangedObserver to hook together to test. |
| 251 base::SystemMonitor system_monitor_; | 281 base::SystemMonitor system_monitor_; |
| 252 scoped_ptr<base::MockDevicesChangedObserver> mock_devices_changed_observer_; | 282 scoped_ptr<base::MockDevicesChangedObserver> mock_devices_changed_observer_; |
| 253 | 283 |
| 254 // Temporary directory for created test data. | 284 // Temporary directory for created test data. |
| 255 ScopedTempDir scoped_temp_dir_; | 285 ScopedTempDir scoped_temp_dir_; |
| 256 // Path to the test mtab file. | 286 // Path to the test mtab file. |
| 257 FilePath mtab_file_; | 287 FilePath mtab_file_; |
| 258 | 288 |
| 259 scoped_refptr<MediaDeviceNotificationsLinuxTestWrapper> notifications_; | 289 scoped_refptr<DiskMountWatcherLinuxTestWrapper> mount_watcher_; |
| 260 | 290 |
| 261 DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinuxTest); | 291 DISALLOW_COPY_AND_ASSIGN(DiskMountWatcherLinuxTest); |
| 262 }; | 292 }; |
| 263 | 293 |
| 264 // Simple test case where we attach and detach a media device. | 294 // Simple test case where we attach and detach a media device. |
| 265 TEST_F(MediaDeviceNotificationsLinuxTest, BasicAttachDetach) { | 295 TEST_F(DiskMountWatcherLinuxTest, BasicAttachDetach) { |
| 266 testing::Sequence mock_sequence; | 296 testing::Sequence mock_sequence; |
| 267 FilePath test_path = CreateMountPointWithDCIMDir(kMountPointA); | 297 FilePath test_path = CreateMountPointWithDCIMDir(kMountPointA); |
| 268 ASSERT_FALSE(test_path.empty()); | 298 ASSERT_FALSE(test_path.empty()); |
| 269 MtabTestData test_data[] = { | 299 MtabTestData test_data[] = { |
| 270 MtabTestData(kDevice1, kInvalidPath, kValidFS), | 300 MtabTestData(kDevice1, kInvalidPath, kValidFS), |
| 271 MtabTestData(kDevice2, test_path.value(), kValidFS), | 301 MtabTestData(kDevice2, test_path.value(), kValidFS), |
| 272 }; | 302 }; |
| 273 // Only |kDevice2| should be attached, since |kDevice1| has a bad path. | 303 // Only |kDevice2| should be attached, since |kDevice1| has a bad path. |
| 274 EXPECT_CALL(observer(), | 304 EXPECT_CALL(observer(), OnMediaDeviceAttached(GetDeviceId(kDevice2), |
| 275 OnMediaDeviceAttached(GetDCIMDeviceId(kDeviceId2), | 305 GetDeviceName(kDevice2), |
| 276 ASCIIToUTF16(kDeviceLabel2), | 306 test_path.value())) |
| 277 test_path.value())) | |
| 278 .InSequence(mock_sequence); | 307 .InSequence(mock_sequence); |
| 279 AppendToMtabAndRunLoop(test_data, arraysize(test_data)); | 308 AppendToMtabAndRunLoop(test_data, arraysize(test_data)); |
| 280 | 309 |
| 281 // |kDevice2| should be detached here. | 310 // |kDevice2| should be detached here. |
| 282 EXPECT_CALL(observer(), OnMediaDeviceDetached(GetDCIMDeviceId(kDeviceId2))) | 311 EXPECT_CALL(observer(), OnMediaDeviceDetached(GetDeviceId(kDevice2))) |
| 283 .InSequence(mock_sequence); | 312 .InSequence(mock_sequence); |
| 284 WriteEmptyMtabAndRunLoop(); | 313 WriteEmptyMtabAndRunLoop(); |
| 285 } | 314 } |
| 286 | 315 |
| 287 // Only mount points with DCIM directories are recognized. | 316 // Only mount points with DCIM directories are recognized. |
| 288 TEST_F(MediaDeviceNotificationsLinuxTest, DCIM) { | 317 TEST_F(DiskMountWatcherLinuxTest, DCIM) { |
| 289 testing::Sequence mock_sequence; | 318 testing::Sequence mock_sequence; |
| 290 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); | 319 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); |
| 291 ASSERT_FALSE(test_path_a.empty()); | 320 ASSERT_FALSE(test_path_a.empty()); |
| 292 MtabTestData test_data1[] = { | 321 MtabTestData test_data1[] = { |
| 293 MtabTestData(kDevice1, test_path_a.value(), kValidFS), | 322 MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
| 294 }; | 323 }; |
| 295 // |kDevice1| should be attached as expected. | 324 // |kDevice1| should be attached as expected. |
| 296 EXPECT_CALL(observer(), | 325 EXPECT_CALL(observer(), OnMediaDeviceAttached(GetDeviceId(kDevice1), |
| 297 OnMediaDeviceAttached(GetDCIMDeviceId(kDeviceId1), | 326 GetDeviceName(kDevice1), |
| 298 ASCIIToUTF16(kDeviceLabel1), | 327 test_path_a.value())) |
| 299 test_path_a.value())) | |
| 300 .InSequence(mock_sequence); | 328 .InSequence(mock_sequence); |
| 301 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); | 329 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); |
| 302 | 330 |
| 303 // This should do nothing, since |kMountPointB| does not have a DCIM dir. | 331 // This should do nothing, since |kMountPointB| does not have a DCIM dir. |
| 304 FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB); | 332 FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB); |
| 305 ASSERT_FALSE(test_path_b.empty()); | 333 ASSERT_FALSE(test_path_b.empty()); |
| 306 MtabTestData test_data2[] = { | 334 MtabTestData test_data2[] = { |
| 307 MtabTestData(kDevice2, test_path_b.value(), kValidFS), | 335 MtabTestData(kDevice2, test_path_b.value(), kValidFS), |
| 308 }; | 336 }; |
| 309 AppendToMtabAndRunLoop(test_data2, arraysize(test_data2)); | 337 AppendToMtabAndRunLoop(test_data2, arraysize(test_data2)); |
| 310 | 338 |
| 311 // |kDevice1| should be detached as expected. | 339 // |kDevice1| should be detached as expected. |
| 312 EXPECT_CALL(observer(), OnMediaDeviceDetached(GetDCIMDeviceId(kDeviceId1))) | 340 EXPECT_CALL(observer(), OnMediaDeviceDetached(GetDeviceId(kDevice1))) |
| 313 .InSequence(mock_sequence); | 341 .InSequence(mock_sequence); |
| 314 WriteEmptyMtabAndRunLoop(); | 342 WriteEmptyMtabAndRunLoop(); |
| 315 } | 343 } |
| 316 | 344 |
| 317 // More complicated test case with multiple devices on multiple mount points. | 345 // More complicated test case with multiple devices on multiple mount points. |
| 318 TEST_F(MediaDeviceNotificationsLinuxTest, SwapMountPoints) { | 346 TEST_F(DiskMountWatcherLinuxTest, SwapMountPoints) { |
| 319 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); | 347 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); |
| 320 FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); | 348 FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); |
| 321 ASSERT_FALSE(test_path_a.empty()); | 349 ASSERT_FALSE(test_path_a.empty()); |
| 322 ASSERT_FALSE(test_path_b.empty()); | 350 ASSERT_FALSE(test_path_b.empty()); |
| 323 | 351 |
| 324 // Attach two devices. | 352 // Attach two devices. |
| 325 // kDevice1 -> kMountPointA | 353 // kDevice1 -> kMountPointA |
| 326 // kDevice2 -> kMountPointB | 354 // kDevice2 -> kMountPointB |
| 327 MtabTestData test_data1[] = { | 355 MtabTestData test_data1[] = { |
| 328 MtabTestData(kDevice1, test_path_a.value(), kValidFS), | 356 MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 344 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(2); | 372 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(2); |
| 345 OverwriteMtabAndRunLoop(test_data2, arraysize(test_data2)); | 373 OverwriteMtabAndRunLoop(test_data2, arraysize(test_data2)); |
| 346 | 374 |
| 347 // Detach all devices. | 375 // Detach all devices. |
| 348 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); | 376 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); |
| 349 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(2); | 377 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(2); |
| 350 WriteEmptyMtabAndRunLoop(); | 378 WriteEmptyMtabAndRunLoop(); |
| 351 } | 379 } |
| 352 | 380 |
| 353 // More complicated test case with multiple devices on multiple mount points. | 381 // More complicated test case with multiple devices on multiple mount points. |
| 354 TEST_F(MediaDeviceNotificationsLinuxTest, MultiDevicesMultiMountPoints) { | 382 TEST_F(DiskMountWatcherLinuxTest, MultiDevicesMultiMountPoints) { |
| 355 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); | 383 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); |
| 356 FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); | 384 FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); |
| 357 ASSERT_FALSE(test_path_a.empty()); | 385 ASSERT_FALSE(test_path_a.empty()); |
| 358 ASSERT_FALSE(test_path_b.empty()); | 386 ASSERT_FALSE(test_path_b.empty()); |
| 359 | 387 |
| 360 // Attach two devices. | 388 // Attach two devices. |
| 361 // kDevice1 -> kMountPointA | 389 // kDevice1 -> kMountPointA * |
| 362 // kDevice2 -> kMountPointB | 390 // kDevice2 -> kMountPointB * |
| 363 MtabTestData test_data1[] = { | 391 MtabTestData test_data1[] = { |
| 364 MtabTestData(kDevice1, test_path_a.value(), kValidFS), | 392 MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
| 365 MtabTestData(kDevice2, test_path_b.value(), kValidFS), | 393 MtabTestData(kDevice2, test_path_b.value(), kValidFS), |
| 366 }; | 394 }; |
| 367 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(2); | 395 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(2); |
| 368 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(0); | 396 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(0); |
| 369 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); | 397 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); |
| 370 | 398 |
| 371 // Attach |kDevice1| to |kMountPointB|. | 399 // Attach |kDevice1| to |kMountPointB|. |
| 372 // |kDevice2| is inaccessible, so it is detached. |kDevice1| has been | 400 // |kDevice2| is inaccessible, so it is detached. |kDevice1| has been |
| 373 // re-attached at |kMountPointB|, so it is 'detached' from kMountPointA. | 401 // attached at |kMountPointB|, but is still accessible from |kMountPointA|. |
| 374 // kDevice1 -> kMountPointA | 402 // kDevice1 -> kMountPointA * |
| 375 // kDevice2 -> kMountPointB | 403 // kDevice2 -> kMountPointB |
| 376 // kDevice1 -> kMountPointB | 404 // kDevice1 -> kMountPointB |
| 377 MtabTestData test_data2[] = { | 405 MtabTestData test_data2[] = { |
| 378 MtabTestData(kDevice1, test_path_b.value(), kValidFS), | 406 MtabTestData(kDevice1, test_path_b.value(), kValidFS), |
| 379 }; | 407 }; |
| 380 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(1); | 408 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); |
| 381 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(2); | 409 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(1); |
| 382 AppendToMtabAndRunLoop(test_data2, arraysize(test_data2)); | 410 AppendToMtabAndRunLoop(test_data2, arraysize(test_data2)); |
| 383 | 411 |
| 384 // Attach |kDevice2| to |kMountPointA|. | 412 // Detach |kDevice1| from |kMountPointA|, causing a detach and attach event. |
| 385 // kDevice1 -> kMountPointA | |
| 386 // kDevice2 -> kMountPointB | 413 // kDevice2 -> kMountPointB |
| 387 // kDevice1 -> kMountPointB | 414 // kDevice1 -> kMountPointB * |
| 388 // kDevice2 -> kMountPointA | |
| 389 MtabTestData test_data3[] = { | 415 MtabTestData test_data3[] = { |
| 390 MtabTestData(kDevice2, test_path_a.value(), kValidFS), | |
| 391 }; | |
| 392 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(1); | |
| 393 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(0); | |
| 394 AppendToMtabAndRunLoop(test_data3, arraysize(test_data3)); | |
| 395 | |
| 396 // Detach |kDevice2| from |kMountPointA|. | |
| 397 // kDevice1 -> kMountPointA | |
| 398 // kDevice2 -> kMountPointB | |
| 399 // kDevice1 -> kMountPointB | |
| 400 MtabTestData test_data4[] = { | |
| 401 MtabTestData(kDevice1, test_path_a.value(), kValidFS), | |
| 402 MtabTestData(kDevice2, test_path_b.value(), kValidFS), | 416 MtabTestData(kDevice2, test_path_b.value(), kValidFS), |
| 403 MtabTestData(kDevice1, test_path_b.value(), kValidFS), | 417 MtabTestData(kDevice1, test_path_b.value(), kValidFS), |
| 404 }; | 418 }; |
| 419 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(1); |
| 420 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(1); |
| 421 OverwriteMtabAndRunLoop(test_data3, arraysize(test_data3)); |
| 422 |
| 423 // Attach |kDevice1| to |kMountPointA|. |
| 424 // kDevice2 -> kMountPointB |
| 425 // kDevice1 -> kMountPointB * |
| 426 // kDevice1 -> kMountPointA |
| 427 MtabTestData test_data4[] = { |
| 428 MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
| 429 }; |
| 405 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); | 430 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); |
| 406 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(1); | 431 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(0); |
| 407 OverwriteMtabAndRunLoop(test_data4, arraysize(test_data4)); | 432 AppendToMtabAndRunLoop(test_data4, arraysize(test_data4)); |
| 408 | 433 |
| 409 // Detach |kDevice1| from |kMountPointB|. | 434 // Detach |kDevice1| from |kMountPointB|. |
| 410 // kDevice1 -> kMountPointA | 435 // kDevice1 -> kMountPointA * |
| 411 // kDevice2 -> kMountPointB | 436 // kDevice2 -> kMountPointB * |
| 412 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(2); | 437 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(2); |
| 413 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(1); | 438 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(1); |
| 414 OverwriteMtabAndRunLoop(test_data1, arraysize(test_data1)); | 439 OverwriteMtabAndRunLoop(test_data1, arraysize(test_data1)); |
| 415 | 440 |
| 416 // Detach all devices. | 441 // Detach all devices. |
| 417 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); | 442 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); |
| 418 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(2); | 443 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(2); |
| 419 WriteEmptyMtabAndRunLoop(); | 444 WriteEmptyMtabAndRunLoop(); |
| 420 } | 445 } |
| 421 | 446 |
| 422 // More complicated test case with multiple devices on one mount point. | 447 TEST_F(DiskMountWatcherLinuxTest, MultipleMountPointsWithNonDCIMDevices) { |
| 423 TEST_F(MediaDeviceNotificationsLinuxTest, MultiDevicesOneMountPoint) { | |
| 424 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); | 448 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); |
| 425 FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); | 449 FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); |
| 426 ASSERT_FALSE(test_path_a.empty()); | 450 ASSERT_FALSE(test_path_a.empty()); |
| 427 ASSERT_FALSE(test_path_b.empty()); | 451 ASSERT_FALSE(test_path_b.empty()); |
| 428 | 452 |
| 429 // |kDevice1| is most recently mounted at |kMountPointB|. | 453 // Attach to one first. |
| 454 // kDevice1 -> kMountPointA * |
| 455 MtabTestData test_data1[] = { |
| 456 MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
| 457 }; |
| 458 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(1); |
| 459 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(0); |
| 460 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); |
| 461 |
| 462 // Attach |kDevice1| to |kMountPointB|. |
| 463 // kDevice1 -> kMountPointA * |
| 464 // kDevice1 -> kMountPointB |
| 465 MtabTestData test_data2[] = { |
| 466 MtabTestData(kDevice1, test_path_b.value(), kValidFS), |
| 467 }; |
| 468 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); |
| 469 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(0); |
| 470 AppendToMtabAndRunLoop(test_data2, arraysize(test_data2)); |
| 471 |
| 472 // Attach |kDevice4| (a non-DCIM device) to |kMountPointA|. |
| 430 // kDevice1 -> kMountPointA | 473 // kDevice1 -> kMountPointA |
| 431 // kDevice2 -> kMountPointB | 474 // kDevice1 -> kMountPointB * |
| 475 // kDevice4 -> kMountPointA |
| 476 MtabTestData test_data3[] = { |
| 477 MtabTestData(kDevice4, test_path_a.value(), kValidFS), |
| 478 }; |
| 479 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(1); |
| 480 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(1); |
| 481 file_util::Delete(test_path_a.Append("DCIM"), false); |
| 482 AppendToMtabAndRunLoop(test_data3, arraysize(test_data3)); |
| 483 |
| 484 // Detach |kDevice4|. |
| 485 // kDevice1 -> kMountPointA |
| 486 // kDevice1 -> kMountPointB * |
| 487 MtabTestData test_data4[] = { |
| 488 MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
| 489 MtabTestData(kDevice1, test_path_b.value(), kValidFS), |
| 490 }; |
| 491 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); |
| 492 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(0); |
| 493 OverwriteMtabAndRunLoop(test_data4, arraysize(test_data4)); |
| 494 |
| 495 // Detach |kDevice1| from |kMountPointA|. |
| 496 // kDevice1 -> kMountPointB * |
| 497 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); |
| 498 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(0); |
| 499 OverwriteMtabAndRunLoop(test_data2, arraysize(test_data2)); |
| 500 |
| 501 // Detach all devices. |
| 502 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); |
| 503 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(1); |
| 504 WriteEmptyMtabAndRunLoop(); |
| 505 } |
| 506 |
| 507 TEST_F(DiskMountWatcherLinuxTest, MountLookUp) { |
| 508 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); |
| 509 FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB); |
| 510 FilePath test_path_c = CreateMountPointWithoutDCIMDir(kMountPointC); |
| 511 ASSERT_FALSE(test_path_a.empty()); |
| 512 ASSERT_FALSE(test_path_b.empty()); |
| 513 ASSERT_FALSE(test_path_c.empty()); |
| 514 |
| 515 // Attach to one first. |
| 516 // kDevice1 -> kMountPointA * |
| 517 // kDevice4 -> kMountPointB |
| 518 // kDevice5 -> kMountPointC |
| 519 MtabTestData test_data1[] = { |
| 520 MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
| 521 MtabTestData(kDevice4, test_path_b.value(), kValidFS), |
| 522 MtabTestData(kDevice5, test_path_c.value(), kValidFS), |
| 523 }; |
| 524 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(1); |
| 525 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(0); |
| 526 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); |
| 527 |
| 528 EXPECT_EQ(test_path_a, watcher()->GetDeviceMountPoint(GetDeviceId(kDevice1))); |
| 529 EXPECT_EQ(test_path_b, watcher()->GetDeviceMountPoint(GetDeviceId(kDevice4))); |
| 530 EXPECT_EQ(test_path_c, watcher()->GetDeviceMountPoint(GetDeviceId(kDevice5))); |
| 531 EXPECT_EQ(FilePath(), watcher()->GetDeviceMountPoint(kInvalidDevice)); |
| 532 |
| 533 // Make |kDevice1| mounted in multiple places. |
| 534 // kDevice1 -> kMountPointA * |
| 432 // kDevice1 -> kMountPointB | 535 // kDevice1 -> kMountPointB |
| 536 // kDevice1 -> kMountPointC |
| 537 MtabTestData test_data2[] = { |
| 538 MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
| 539 MtabTestData(kDevice1, test_path_b.value(), kValidFS), |
| 540 MtabTestData(kDevice1, test_path_c.value(), kValidFS), |
| 541 }; |
| 542 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); |
| 543 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(0); |
| 544 // Add DCIM dirs. |
| 545 CreateMountPointWithDCIMDir(kMountPointB); |
| 546 CreateMountPointWithDCIMDir(kMountPointC); |
| 547 OverwriteMtabAndRunLoop(test_data2, arraysize(test_data2)); |
| 548 |
| 549 EXPECT_EQ(test_path_a, watcher()->GetDeviceMountPoint(GetDeviceId(kDevice1))); |
| 550 |
| 551 // Unmount |kDevice1| from |kMountPointA|. |
| 552 // kDevice1 -> kMountPointB * |
| 553 // kDevice1 -> kMountPointC |
| 554 // Either |kMountPointB| or |kMountPointC| is a valid new default, but |
| 555 // it turns out that it will be B. |
| 556 MtabTestData test_data3[] = { |
| 557 MtabTestData(kDevice1, test_path_b.value(), kValidFS), |
| 558 }; |
| 559 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(1); |
| 560 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(1); |
| 561 OverwriteMtabAndRunLoop(test_data3, arraysize(test_data3)); |
| 562 |
| 563 EXPECT_EQ(test_path_b, watcher()->GetDeviceMountPoint(GetDeviceId(kDevice1))); |
| 564 |
| 565 // Mount a non-usb device in multiple places. |
| 566 // kDevice5 -> kMountPointA |
| 567 // kDevice5 -> kMountPointB |
| 568 // kDevice5 -> kMountPointC |
| 569 MtabTestData test_data4[] = { |
| 570 MtabTestData(kDevice5, test_path_a.value(), kValidFS), |
| 571 MtabTestData(kDevice5, test_path_b.value(), kValidFS), |
| 572 MtabTestData(kDevice5, test_path_c.value(), kValidFS), |
| 573 }; |
| 574 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); |
| 575 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(1); |
| 576 // Remove DCIM dirs. |
| 577 file_util::Delete(test_path_a.Append("DCIM"), false); |
| 578 file_util::Delete(test_path_b.Append("DCIM"), false); |
| 579 file_util::Delete(test_path_c.Append("DCIM"), false); |
| 580 OverwriteMtabAndRunLoop(test_data4, arraysize(test_data4)); |
| 581 |
| 582 // Any of the mount points would be valid. |
| 583 EXPECT_EQ(test_path_a.value(), |
| 584 watcher()->GetDeviceMountPoint(GetDeviceId(kDevice5)).value()); |
| 585 } |
| 586 |
| 587 TEST_F(DiskMountWatcherLinuxTest, DeviceLookUp) { |
| 588 FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); |
| 589 FilePath test_path_b = CreateMountPointWithoutDCIMDir(kMountPointB); |
| 590 FilePath test_path_c = CreateMountPointWithoutDCIMDir(kMountPointC); |
| 591 ASSERT_FALSE(test_path_a.empty()); |
| 592 ASSERT_FALSE(test_path_b.empty()); |
| 593 ASSERT_FALSE(test_path_c.empty()); |
| 594 |
| 595 // Attach to one first. |
| 596 // kDevice1 -> kMountPointA * |
| 597 // kDevice4 -> kMountPointB |
| 598 // kDevice5 -> kMountPointC |
| 433 MtabTestData test_data1[] = { | 599 MtabTestData test_data1[] = { |
| 434 MtabTestData(kDevice1, test_path_a.value(), kValidFS), | 600 MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
| 435 MtabTestData(kDevice2, test_path_b.value(), kValidFS), | 601 MtabTestData(kDevice4, test_path_b.value(), kValidFS), |
| 436 MtabTestData(kDevice1, test_path_b.value(), kValidFS), | 602 MtabTestData(kDevice5, test_path_c.value(), kValidFS), |
| 437 }; | 603 }; |
| 438 EXPECT_CALL(observer(), | 604 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(1); |
| 439 OnMediaDeviceAttached(GetDCIMDeviceId(kDeviceId1), | 605 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(0); |
| 440 ASCIIToUTF16(kDeviceLabel1), | 606 AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); |
| 441 test_path_b.value())) | 607 |
| 442 .Times(1); | 608 FilePath relative_path; |
| 443 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(0); | 609 EXPECT_EQ(GetDeviceId(kDevice1), |
| 444 OverwriteMtabAndRunLoop(test_data1, arraysize(test_data1)); | 610 watcher()->GetDeviceIdForPath(test_path_a, &relative_path)); |
| 445 | 611 EXPECT_EQ(FilePath().value(), relative_path.value()); |
| 446 // Attach |kDevice3| to |kMountPointB|. | 612 EXPECT_EQ(GetDeviceId(kDevice4), |
| 447 // |kDevice1| is inaccessible at its most recent mount point, so it is | 613 watcher()->GetDeviceIdForPath(test_path_b, &relative_path)); |
| 448 // detached and unavailable, even though it is still accessible via | 614 EXPECT_EQ(FilePath().value(), relative_path.value()); |
| 449 // |kMountPointA|. | 615 EXPECT_EQ(GetDeviceId(kDevice5), |
| 450 // kDevice1 -> kMountPointA | 616 watcher()->GetDeviceIdForPath(test_path_c, NULL)); |
| 451 // kDevice2 -> kMountPointB | 617 |
| 452 // kDevice1 -> kMountPointB | 618 // An invalid path. |
| 453 // kDevice3 -> kMountPointB | 619 EXPECT_EQ(std::string(), |
| 620 watcher()->GetDeviceIdForPath(FilePath(kInvalidPath), NULL)); |
| 621 |
| 622 // Test filling in of the relative path. |
| 623 FilePath extra_path("some/other/path"); |
| 624 EXPECT_EQ(GetDeviceId(kDevice1), |
| 625 watcher()->GetDeviceIdForPath(test_path_a.Append(extra_path), |
| 626 &relative_path)); |
| 627 EXPECT_EQ(extra_path.value(), relative_path.value()); |
| 628 |
| 629 // One device attached at multiple points. |
| 630 // kDevice1 -> kMountPointA * |
| 631 // kDevice5 -> kMountPointB |
| 632 // kDevice5 -> kMountPointC |
| 454 MtabTestData test_data2[] = { | 633 MtabTestData test_data2[] = { |
| 455 MtabTestData(kDevice3, test_path_b.value(), kValidFS), | 634 MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
| 456 }; | 635 MtabTestData(kDevice5, test_path_b.value(), kValidFS), |
| 457 EXPECT_CALL(observer(), OnMediaDeviceDetached(GetDCIMDeviceId(kDeviceId1))) | 636 MtabTestData(kDevice5, test_path_c.value(), kValidFS), |
| 458 .Times(1); | 637 }; |
| 459 EXPECT_CALL(observer(), | 638 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); |
| 460 OnMediaDeviceAttached(GetDCIMDeviceId(kDeviceId3), | 639 EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(0); |
| 461 ASCIIToUTF16(kDeviceLabel3), | |
| 462 test_path_b.value())) | |
| 463 .Times(1); | |
| 464 AppendToMtabAndRunLoop(test_data2, arraysize(test_data2)); | 640 AppendToMtabAndRunLoop(test_data2, arraysize(test_data2)); |
| 465 | 641 |
| 466 // Detach all devices. | 642 EXPECT_EQ(GetDeviceId(kDevice1), |
| 467 EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _)).Times(0); | 643 watcher()->GetDeviceIdForPath(test_path_a, NULL)); |
| 468 EXPECT_CALL(observer(), OnMediaDeviceDetached(GetDCIMDeviceId(kDeviceId3))) | 644 EXPECT_EQ(GetDeviceId(kDevice5), |
| 469 .Times(1); | 645 watcher()->GetDeviceIdForPath(test_path_b, NULL)); |
| 470 WriteEmptyMtabAndRunLoop(); | 646 EXPECT_EQ(GetDeviceId(kDevice5), |
| 647 watcher()->GetDeviceIdForPath(test_path_c, NULL)); |
| 471 } | 648 } |
| 472 | 649 |
| 473 } // namespace | 650 } // namespace |
| 474 | 651 |
| 475 } // namespace chrome | 652 } // namespace chrome |
| OLD | NEW |