Index: chrome/browser/media_gallery/media_device_notifications_linux_unittest.cc |
diff --git a/chrome/browser/media_gallery/media_device_notifications_linux_unittest.cc b/chrome/browser/media_gallery/media_device_notifications_linux_unittest.cc |
index 0493a70713394a40f74f26d02d6781c898493342..d1898a0bdd655e4c00ff929599836a76b4190837 100644 |
--- a/chrome/browser/media_gallery/media_device_notifications_linux_unittest.cc |
+++ b/chrome/browser/media_gallery/media_device_notifications_linux_unittest.cc |
@@ -37,6 +37,14 @@ const char kDevice1[] = "d1"; |
const char kDevice2[] = "d2"; |
const char kDevice3[] = "d3"; |
+const char kDeviceId1[] = "FFF0-000F"; |
+const char kDeviceId2[] = "FFF0-00F0"; |
+const char kDeviceId3[] = "FFF0-0F00"; |
+ |
+const char kDeviceLabel1[] = "TEST_USB_MODEL_1"; |
+const char kDeviceLabel2[] = "TEST_USB_MODEL_2"; |
+const char kDeviceLabel3[] = "TEST_USB_MODEL_3"; |
+ |
const char kMountPointA[] = "mnt_a"; |
const char kMountPointB[] = "mnt_b"; |
@@ -47,9 +55,16 @@ class MediaDeviceNotificationsLinuxTestWrapper |
MessageLoop* message_loop) |
: MediaDeviceNotificationsLinux(path), |
message_loop_(message_loop) { |
+ PopulateMountDeviceInfoMap(); |
} |
private: |
+ // Device unique id and label information. |
+ typedef std::pair<std::string, string16> DeviceInfo; |
+ |
+ // (Mount device, DeviceInfo) |
+ typedef std::map<std::string, DeviceInfo> MountDeviceInfoMap; |
+ |
// Avoids code deleting the object while there are references to it. |
// Aside from the base::RefCountedThreadSafe friend class, any attempts to |
// call this dtor will result in a compile-time error. |
@@ -60,7 +75,36 @@ class MediaDeviceNotificationsLinuxTestWrapper |
message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
} |
+ virtual bool GetDeviceInfo(const std::string& dev_path, |
+ std::string* id, |
+ string16* name) OVERRIDE { |
+ MountDeviceInfoMap::const_iterator it = device_info_map_.find(dev_path); |
+ if (it == device_info_map_.end()) |
+ return false; |
+ |
+ id->assign(it->second.first); |
+ *name = it->second.second; |
+ return true; |
+ } |
+ |
+ // Helper function to populate test device information. |
+ void PopulateMountDeviceInfoMap() { |
+ device_info_map_.insert( |
+ std::make_pair(kDevice1, |
+ std::make_pair(kDeviceId1, |
+ UTF8ToUTF16(kDeviceLabel1)))); |
+ device_info_map_.insert( |
+ std::make_pair(kDevice2, |
+ std::make_pair(kDeviceId2, |
+ UTF8ToUTF16(kDeviceLabel2)))); |
+ device_info_map_.insert( |
+ std::make_pair(kDevice3, |
+ std::make_pair(kDeviceId3, |
+ UTF8ToUTF16(kDeviceLabel3)))); |
+ } |
+ |
MessageLoop* message_loop_; |
+ MountDeviceInfoMap device_info_map_; |
DISALLOW_COPY_AND_ASSIGN(MediaDeviceNotificationsLinuxTestWrapper); |
}; |
@@ -236,18 +280,17 @@ TEST_F(MediaDeviceNotificationsLinuxTest, BasicAttachDetach) { |
MtabTestData(kDevice1, kInvalidPath, kValidFS), |
MtabTestData(kDevice2, test_path.value(), kValidFS), |
}; |
- const std::string kDeviceId = "0"; |
// Only |kDevice2| should be attached, since |kDevice1| has a bad path. |
EXPECT_CALL(observer(), |
- OnMediaDeviceAttached(kDeviceId, |
- ASCIIToUTF16(kDevice2), |
+ OnMediaDeviceAttached(kDeviceId2, |
+ UTF8ToUTF16(kDeviceLabel2), |
Lei Zhang
2012/08/09 03:47:16
What I mean is, you can still use ASCIIToUTF16().
kmadhusu
2012/08/09 08:10:03
Done.
|
base::SystemMonitor::TYPE_PATH, |
test_path.value())) |
.InSequence(mock_sequence); |
AppendToMtabAndRunLoop(test_data, arraysize(test_data)); |
// |kDevice2| should be detached here. |
- EXPECT_CALL(observer(), OnMediaDeviceDetached(kDeviceId)) |
+ EXPECT_CALL(observer(), OnMediaDeviceDetached(kDeviceId2)) |
.InSequence(mock_sequence); |
WriteEmptyMtabAndRunLoop(); |
} |
@@ -260,11 +303,10 @@ TEST_F(MediaDeviceNotificationsLinuxTest, DCIM) { |
MtabTestData test_data1[] = { |
MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
}; |
- const std::string kDeviceId = "0"; |
// |kDevice1| should be attached as expected. |
EXPECT_CALL(observer(), |
- OnMediaDeviceAttached(kDeviceId, |
- ASCIIToUTF16(kDevice1), |
+ OnMediaDeviceAttached(kDeviceId1, |
+ UTF8ToUTF16(kDeviceLabel1), |
base::SystemMonitor::TYPE_PATH, |
test_path_a.value())) |
.InSequence(mock_sequence); |
@@ -279,12 +321,48 @@ TEST_F(MediaDeviceNotificationsLinuxTest, DCIM) { |
AppendToMtabAndRunLoop(test_data2, arraysize(test_data2)); |
// |kDevice1| should be detached as expected. |
- EXPECT_CALL(observer(), OnMediaDeviceDetached(kDeviceId)) |
+ EXPECT_CALL(observer(), OnMediaDeviceDetached(kDeviceId1)) |
.InSequence(mock_sequence); |
WriteEmptyMtabAndRunLoop(); |
} |
// More complicated test case with multiple devices on multiple mount points. |
+TEST_F(MediaDeviceNotificationsLinuxTest, SwapMountPoints) { |
+ FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); |
+ FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); |
+ ASSERT_FALSE(test_path_a.empty()); |
+ ASSERT_FALSE(test_path_b.empty()); |
+ |
+ // Attach two devices. |
+ // kDevice1 -> kMountPointA |
+ // kDevice2 -> kMountPointB |
+ MtabTestData test_data1[] = { |
+ MtabTestData(kDevice1, test_path_a.value(), kValidFS), |
+ MtabTestData(kDevice2, test_path_b.value(), kValidFS), |
+ }; |
+ EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(2); |
+ EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(0); |
+ AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); |
+ |
+ // Detach two devices from old mount points and attach the devices at new |
+ // mount points. |
+ // kDevice1 -> kMountPointB |
+ // kDevice2 -> kMountPointA |
+ MtabTestData test_data2[] = { |
+ MtabTestData(kDevice1, test_path_b.value(), kValidFS), |
+ MtabTestData(kDevice2, test_path_a.value(), kValidFS), |
+ }; |
+ EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(2); |
+ EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(2); |
+ OverwriteMtabAndRunLoop(test_data2, arraysize(test_data2)); |
+ |
+ // Detach all devices. |
+ EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0); |
+ EXPECT_CALL(observer(), OnMediaDeviceDetached(_)).Times(2); |
+ WriteEmptyMtabAndRunLoop(); |
+} |
+ |
+// More complicated test case with multiple devices on multiple mount points. |
TEST_F(MediaDeviceNotificationsLinuxTest, MultiDevicesMultiMountPoints) { |
FilePath test_path_a = CreateMountPointWithDCIMDir(kMountPointA); |
FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); |
@@ -359,8 +437,6 @@ TEST_F(MediaDeviceNotificationsLinuxTest, MultiDevicesOneMountPoint) { |
FilePath test_path_b = CreateMountPointWithDCIMDir(kMountPointB); |
ASSERT_FALSE(test_path_a.empty()); |
ASSERT_FALSE(test_path_b.empty()); |
- const std::string kDeviceId0 = "0"; |
- const std::string kDeviceId1 = "1"; |
// |kDevice1| is most recently mounted at |kMountPointB|. |
// kDevice1 -> kMountPointA |
@@ -372,8 +448,8 @@ TEST_F(MediaDeviceNotificationsLinuxTest, MultiDevicesOneMountPoint) { |
MtabTestData(kDevice1, test_path_b.value(), kValidFS), |
}; |
EXPECT_CALL(observer(), |
- OnMediaDeviceAttached(kDeviceId0, |
- ASCIIToUTF16(kDevice1), |
+ OnMediaDeviceAttached(kDeviceId1, |
+ UTF8ToUTF16(kDeviceLabel1), |
base::SystemMonitor::TYPE_PATH, |
test_path_b.value())) |
.Times(1); |
@@ -391,10 +467,10 @@ TEST_F(MediaDeviceNotificationsLinuxTest, MultiDevicesOneMountPoint) { |
MtabTestData test_data2[] = { |
MtabTestData(kDevice3, test_path_b.value(), kValidFS), |
}; |
- EXPECT_CALL(observer(), OnMediaDeviceDetached(kDeviceId0)).Times(1); |
+ EXPECT_CALL(observer(), OnMediaDeviceDetached(kDeviceId1)).Times(1); |
EXPECT_CALL(observer(), |
- OnMediaDeviceAttached(kDeviceId1, |
- ASCIIToUTF16(kDevice3), |
+ OnMediaDeviceAttached(kDeviceId3, |
+ UTF8ToUTF16(kDeviceLabel3), |
base::SystemMonitor::TYPE_PATH, |
test_path_b.value())) |
.Times(1); |
@@ -402,7 +478,7 @@ TEST_F(MediaDeviceNotificationsLinuxTest, MultiDevicesOneMountPoint) { |
// Detach all devices. |
EXPECT_CALL(observer(), OnMediaDeviceAttached(_, _, _, _)).Times(0); |
- EXPECT_CALL(observer(), OnMediaDeviceDetached(kDeviceId1)).Times(1); |
+ EXPECT_CALL(observer(), OnMediaDeviceDetached(kDeviceId3)).Times(1); |
WriteEmptyMtabAndRunLoop(); |
} |