Chromium Code Reviews| Index: chrome/browser/system_monitor/removable_device_notifications_mac_unittest.mm |
| diff --git a/chrome/browser/system_monitor/removable_device_notifications_mac_unittest.mm b/chrome/browser/system_monitor/removable_device_notifications_mac_unittest.mm |
| index ace68ef7855a33c3fe6d0be4efbe0379fc73130c..833595e7b29e27752b3218541e3a37d445c6e0b1 100644 |
| --- a/chrome/browser/system_monitor/removable_device_notifications_mac_unittest.mm |
| +++ b/chrome/browser/system_monitor/removable_device_notifications_mac_unittest.mm |
| @@ -9,8 +9,6 @@ |
| #include "base/mac/foundation_util.h" |
| #include "base/message_loop.h" |
| #include "base/sys_string_conversions.h" |
| -#include "base/system_monitor/system_monitor.h" |
| -#include "base/test/mock_devices_changed_observer.h" |
| #include "base/utf_string_conversions.h" |
| #include "chrome/browser/system_monitor/media_storage_util.h" |
| #include "chrome/browser/system_monitor/removable_device_constants.h" |
| @@ -49,6 +47,19 @@ DiskInfoMac CreateDiskInfoMac(const std::string& unique_id, |
| return DiskInfoMac::BuildDiskInfoOnFileThread(base::mac::NSToCFCast(dict)); |
| } |
| +class MockStorageObserver |
|
vandebo (ex-Chrome)
2013/01/04 21:06:03
Duplicate... pull this into a test util file.
Greg Billock
2013/01/07 21:55:18
Done.
|
| + : public RemovableStorageNotifications::RemovableStorageObserver { |
| + public: |
| + MockStorageObserver() {} |
| + ~MockStorageObserver() {} |
| + |
| + MOCK_METHOD3(OnRemovableStorageAttached, |
| + void(const std::string& id, |
| + const string16& name, |
| + const FilePath::StringType& location)); |
| + MOCK_METHOD1(OnRemovableStorageDetached, void(const std::string& id)); |
| +}; |
| + |
| } // namespace |
| class RemovableDeviceNotificationsMacTest : public testing::Test { |
| @@ -59,14 +70,13 @@ class RemovableDeviceNotificationsMacTest : public testing::Test { |
| } |
| virtual void SetUp() OVERRIDE { |
| + notifications_ = new RemovableDeviceNotificationsMac; |
| base::SystemMonitor::AllocateSystemIOPorts(); |
| - system_monitor_.reset(new base::SystemMonitor()); |
| - mock_devices_changed_observer_.reset(new base::MockDevicesChangedObserver); |
| - system_monitor_->AddDevicesChangedObserver( |
| - mock_devices_changed_observer_.get()); |
| + mock_storage_observer_.reset(new MockStorageObserver); |
| + notifications_->AddRemovableStorageObserver( |
| + mock_storage_observer_.get()); |
| - notifications_ = new RemovableDeviceNotificationsMac; |
| unique_id_ = "test_id"; |
| display_name_ = ASCIIToUTF16("977 KB Test Display Name"); |
| @@ -83,9 +93,7 @@ class RemovableDeviceNotificationsMacTest : public testing::Test { |
| MessageLoop message_loop_; |
| content::TestBrowserThread file_thread_; |
| - // SystemMonitor and DevicesChangedObserver to hook together to test. |
| - scoped_ptr<base::SystemMonitor> system_monitor_; |
| - scoped_ptr<base::MockDevicesChangedObserver> mock_devices_changed_observer_; |
| + scoped_ptr<MockStorageObserver> mock_storage_observer_; |
| // Information about the disk. |
| std::string unique_id_; |
| @@ -99,7 +107,7 @@ class RemovableDeviceNotificationsMacTest : public testing::Test { |
| TEST_F(RemovableDeviceNotificationsMacTest, AddRemove) { |
| { |
| - EXPECT_CALL(*mock_devices_changed_observer_, |
| + EXPECT_CALL(*mock_storage_observer_, |
| OnRemovableStorageAttached(device_id_, |
| display_name_, |
| mount_point_.value())); |
| @@ -109,7 +117,7 @@ TEST_F(RemovableDeviceNotificationsMacTest, AddRemove) { |
| } |
| { |
| - EXPECT_CALL(*mock_devices_changed_observer_, |
| + EXPECT_CALL(*mock_storage_observer_, |
| OnRemovableStorageDetached(device_id_)); |
| notifications_->UpdateDisk( |
| disk_info_, RemovableDeviceNotificationsMac::UPDATE_DEVICE_REMOVED); |
| @@ -119,7 +127,7 @@ TEST_F(RemovableDeviceNotificationsMacTest, AddRemove) { |
| TEST_F(RemovableDeviceNotificationsMacTest, UpdateVolumeName) { |
| { |
| - EXPECT_CALL(*mock_devices_changed_observer_, |
| + EXPECT_CALL(*mock_storage_observer_, |
| OnRemovableStorageAttached(device_id_, |
| display_name_, |
| mount_point_.value())); |
| @@ -133,9 +141,9 @@ TEST_F(RemovableDeviceNotificationsMacTest, UpdateVolumeName) { |
| DiskInfoMac info2 = CreateDiskInfoMac( |
| unique_id_, "", ASCIIToUTF16("Test Display Name"), mount_point_, |
| kTestSize); |
| - EXPECT_CALL(*mock_devices_changed_observer_, |
| + EXPECT_CALL(*mock_storage_observer_, |
| OnRemovableStorageDetached(device_id_)); |
| - EXPECT_CALL(*mock_devices_changed_observer_, |
| + EXPECT_CALL(*mock_storage_observer_, |
| OnRemovableStorageAttached(device_id_, |
| new_display_name, |
| mount_point_.value())); |
| @@ -158,7 +166,7 @@ TEST_F(RemovableDeviceNotificationsMacTest, DCIM) { |
| MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM, unique_id_); |
| { |
| - EXPECT_CALL(*mock_devices_changed_observer_, |
| + EXPECT_CALL(*mock_storage_observer_, |
| OnRemovableStorageAttached(device_id, |
| display_name_, |
| mount_point.value())); |
| @@ -170,7 +178,7 @@ TEST_F(RemovableDeviceNotificationsMacTest, DCIM) { |
| TEST_F(RemovableDeviceNotificationsMacTest, GetDeviceInfo) { |
| { |
| - EXPECT_CALL(*mock_devices_changed_observer_, |
| + EXPECT_CALL(*mock_storage_observer_, |
| OnRemovableStorageAttached(device_id_, |
| display_name_, |
| mount_point_.value())); |
| @@ -179,7 +187,7 @@ TEST_F(RemovableDeviceNotificationsMacTest, GetDeviceInfo) { |
| message_loop_.RunUntilIdle(); |
| } |
| - base::SystemMonitor::RemovableStorageInfo info; |
| + RemovableStorageNotifications::RemovableStorageInfo info; |
| EXPECT_TRUE(notifications_->GetDeviceInfoForPath( |
| mount_point_.AppendASCII("foo"), &info)); |
| EXPECT_EQ(info.device_id, device_id_); |
| @@ -191,7 +199,7 @@ TEST_F(RemovableDeviceNotificationsMacTest, GetDeviceInfo) { |
| } |
| TEST_F(RemovableDeviceNotificationsMacTest, GetStorageSize) { |
| - EXPECT_CALL(*mock_devices_changed_observer_, |
| + EXPECT_CALL(*mock_storage_observer_, |
| OnRemovableStorageAttached(testing::_, |
| testing::_, |
| testing::_)); |
| @@ -205,7 +213,7 @@ TEST_F(RemovableDeviceNotificationsMacTest, GetStorageSize) { |
| // Test that mounting a DMG doesn't send a notification. |
| TEST_F(RemovableDeviceNotificationsMacTest, DMG) { |
| - EXPECT_CALL(*mock_devices_changed_observer_, |
| + EXPECT_CALL(*mock_storage_observer_, |
| OnRemovableStorageAttached(testing::_, |
| testing::_, |
| testing::_)).Times(0); |