Chromium Code Reviews| Index: chrome/browser/system_monitor/removable_device_notifications_linux_unittest.cc |
| diff --git a/chrome/browser/system_monitor/removable_device_notifications_linux_unittest.cc b/chrome/browser/system_monitor/removable_device_notifications_linux_unittest.cc |
| index c0cacf6a939d2776de34674143952625d73a80a3..e3a44bcbdf97cf30da860e4960f62f7117b1e915 100644 |
| --- a/chrome/browser/system_monitor/removable_device_notifications_linux_unittest.cc |
| +++ b/chrome/browser/system_monitor/removable_device_notifications_linux_unittest.cc |
| @@ -16,13 +16,12 @@ |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/message_loop.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_device_notifications_utils.h" |
| #include "chrome/browser/system_monitor/media_storage_util.h" |
| #include "chrome/browser/system_monitor/removable_device_constants.h" |
| #include "content/public/test/test_browser_thread.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace chrome { |
| @@ -161,6 +160,19 @@ class RemovableDeviceNotificationsLinuxTestWrapper |
| DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsLinuxTestWrapper); |
| }; |
| +class MockStorageObserver |
| + : 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)); |
| +}; |
| + |
| class RemovableDeviceNotificationLinuxTest : public testing::Test { |
| public: |
| struct MtabTestData { |
| @@ -185,10 +197,6 @@ class RemovableDeviceNotificationLinuxTest : public testing::Test { |
| protected: |
| virtual void SetUp() OVERRIDE { |
| - mock_devices_changed_observer_.reset(new base::MockDevicesChangedObserver); |
| - system_monitor_.AddDevicesChangedObserver( |
| - mock_devices_changed_observer_.get()); |
| - |
| // Create and set up a temp dir with files for the test. |
| ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
| FilePath test_dir = scoped_temp_dir_.path().AppendASCII("test_etc"); |
| @@ -206,13 +214,17 @@ class RemovableDeviceNotificationLinuxTest : public testing::Test { |
| mtab_file_, &message_loop_); |
| notifications_->Init(); |
| message_loop_.RunUntilIdle(); |
| + |
|
vandebo (ex-Chrome)
2013/01/04 21:06:03
Why move this below the implementation set up? Th
Greg Billock
2013/01/07 21:55:18
I don't recall doing this deliberately. Perhaps a
|
| + mock_storage_observer_.reset(new MockStorageObserver); |
| + notifications_->AddRemovableStorageObserver( |
| + mock_storage_observer_.get()); |
| } |
| virtual void TearDown() OVERRIDE { |
| message_loop_.RunUntilIdle(); |
| + notifications_->RemoveRemovableStorageObserver( |
| + mock_storage_observer_.get()); |
| notifications_ = NULL; |
| - system_monitor_.RemoveDevicesChangedObserver( |
| - mock_devices_changed_observer_.get()); |
| } |
| // Append mtab entries from the |data| array of size |data_size| to the mtab |
| @@ -256,8 +268,8 @@ class RemovableDeviceNotificationLinuxTest : public testing::Test { |
| file_util::Delete(dcim, false); |
| } |
| - base::MockDevicesChangedObserver& observer() { |
| - return *mock_devices_changed_observer_; |
| + MockStorageObserver& observer() { |
| + return *mock_storage_observer_; |
| } |
| RemovableDeviceNotificationsLinux* notifier() { |
| @@ -318,9 +330,7 @@ class RemovableDeviceNotificationLinuxTest : public testing::Test { |
| MessageLoop message_loop_; |
| content::TestBrowserThread file_thread_; |
| - // SystemMonitor and DevicesChangedObserver to hook together to test. |
| - base::SystemMonitor system_monitor_; |
| - scoped_ptr<base::MockDevicesChangedObserver> mock_devices_changed_observer_; |
| + scoped_ptr<MockStorageObserver> mock_storage_observer_; |
| // Temporary directory for created test data. |
| base::ScopedTempDir scoped_temp_dir_; |
| @@ -413,7 +423,8 @@ TEST_F(RemovableDeviceNotificationLinuxTest, SwapMountPoints) { |
| ASSERT_FALSE(test_path_a.empty()); |
| ASSERT_FALSE(test_path_b.empty()); |
| - // Attach two devices. (*'d mounts are those SystemMonitor knows about.) |
| + // Attach two devices. |
| + // (*'d mounts are those RemovableStorageNotifications knows about.) |
| // kDeviceDCIM1 -> kMountPointA * |
| // kDeviceDCIM2 -> kMountPointB * |
| MtabTestData test_data1[] = { |
| @@ -449,7 +460,8 @@ TEST_F(RemovableDeviceNotificationLinuxTest, MultiDevicesMultiMountPoints) { |
| ASSERT_FALSE(test_path_a.empty()); |
| ASSERT_FALSE(test_path_b.empty()); |
| - // Attach two devices. (*'d mounts are those SystemMonitor knows about.) |
| + // Attach two devices. |
| + // (*'d mounts are those RemovableStorageNotifications knows about.) |
| // kDeviceDCIM1 -> kMountPointA * |
| // kDeviceDCIM2 -> kMountPointB * |
| MtabTestData test_data1[] = { |
| @@ -516,7 +528,8 @@ TEST_F(RemovableDeviceNotificationLinuxTest, |
| ASSERT_FALSE(test_path_a.empty()); |
| ASSERT_FALSE(test_path_b.empty()); |
| - // Attach to one first. (*'d mounts are those SystemMonitor knows about.) |
| + // Attach to one first. |
| + // (*'d mounts are those RemovableStorageNotifications knows about.) |
| // kDeviceDCIM1 -> kMountPointA * |
| MtabTestData test_data1[] = { |
| MtabTestData(kDeviceDCIM1, test_path_a.value(), kValidFS), |
| @@ -603,7 +616,8 @@ TEST_F(RemovableDeviceNotificationLinuxTest, DeviceLookUp) { |
| ASSERT_FALSE(test_path_b.empty()); |
| ASSERT_FALSE(test_path_c.empty()); |
| - // Attach to one first. (*'d mounts are those SystemMonitor knows about.) |
| + // Attach to one first. |
| + // (*'d mounts are those RemovableStorageNotifications knows about.) |
| // kDeviceDCIM1 -> kMountPointA * |
| // kDeviceNoDCIM -> kMountPointB * |
| // kDeviceFixed -> kMountPointC |
| @@ -616,7 +630,7 @@ TEST_F(RemovableDeviceNotificationLinuxTest, DeviceLookUp) { |
| EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); |
| AppendToMtabAndRunLoop(test_data1, arraysize(test_data1)); |
| - base::SystemMonitor::RemovableStorageInfo device_info; |
| + RemovableStorageNotifications::RemovableStorageInfo device_info; |
| EXPECT_TRUE(notifier()->GetDeviceInfoForPath(test_path_a, &device_info)); |
| EXPECT_EQ(GetDeviceId(kDeviceDCIM1), device_info.device_id); |
| EXPECT_EQ(test_path_a.value(), device_info.location); |