Chromium Code Reviews| Index: chrome/browser/system_monitor/media_transfer_protocol_device_observer_linux_unittest.cc |
| diff --git a/chrome/browser/system_monitor/media_transfer_protocol_device_observer_linux_unittest.cc b/chrome/browser/system_monitor/media_transfer_protocol_device_observer_linux_unittest.cc |
| index b4db1261e86baf5f209493412e926bd620d170a6..61dc9676a1445b6923b63ce5241a5dc220ca6f9d 100644 |
| --- a/chrome/browser/system_monitor/media_transfer_protocol_device_observer_linux_unittest.cc |
| +++ b/chrome/browser/system_monitor/media_transfer_protocol_device_observer_linux_unittest.cc |
| @@ -10,16 +10,16 @@ |
| #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_storage_util.h" |
| +#include "chrome/browser/system_monitor/mock_removable_storage_observer.h" |
| +#include "chrome/browser/system_monitor/removable_storage_notifications.h" |
| +#include "chrome/browser/system_monitor/test_removable_storage_notifications.h" |
| +#include "content/public/test/test_browser_thread.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace chrome { |
| -using testing::_; |
| - |
| namespace { |
| // Sample mtp device storage information. |
| @@ -63,26 +63,26 @@ class MediaTransferProtocolDeviceObserverLinuxTest |
| public MediaTransferProtocolDeviceObserverLinux { |
| public: |
| MediaTransferProtocolDeviceObserverLinuxTest() |
| - : MediaTransferProtocolDeviceObserverLinux(&GetStorageInfo) { |
| - } |
| + : MediaTransferProtocolDeviceObserverLinux(&GetStorageInfo), |
| + message_loop_(MessageLoop::TYPE_IO), |
| + file_thread_(content::BrowserThread::FILE, &message_loop_), |
| + notifications_(new chrome::test::TestRemovableStorageNotifications()) {} |
| virtual ~MediaTransferProtocolDeviceObserverLinuxTest() {} |
| protected: |
| virtual void SetUp() OVERRIDE { |
| - mock_devices_changed_observer_.reset(new base::MockDevicesChangedObserver); |
| - system_monitor_.AddDevicesChangedObserver( |
| - mock_devices_changed_observer_.get()); |
| + mock_storage_observer_.reset(new MockRemovableStorageObserver); |
| + notifications_->AddObserver(mock_storage_observer_.get()); |
| } |
| virtual void TearDown() OVERRIDE { |
| - system_monitor_.RemoveDevicesChangedObserver( |
| - mock_devices_changed_observer_.get()); |
| + notifications_->RemoveObserver(mock_storage_observer_.get()); |
| } |
| // Returns the device changed observer object. |
| - base::MockDevicesChangedObserver& observer() { |
| - return *mock_devices_changed_observer_; |
| + MockRemovableStorageObserver& observer() { |
| + return *mock_storage_observer_; |
| } |
| // Notifies MediaTransferProtocolDeviceObserverLinux about the attachment of |
| @@ -90,7 +90,7 @@ class MediaTransferProtocolDeviceObserverLinuxTest |
| void MtpStorageAttached(const std::string& storage_name) { |
| MediaTransferProtocolDeviceObserverLinux::StorageChanged(true, |
| storage_name); |
| - ui_loop_.RunUntilIdle(); |
| + message_loop_.RunUntilIdle(); |
| } |
| // Notifies MediaTransferProtocolDeviceObserverLinux about the detachment of |
| @@ -98,54 +98,50 @@ class MediaTransferProtocolDeviceObserverLinuxTest |
| void MtpStorageDetached(const std::string& storage_name) { |
| MediaTransferProtocolDeviceObserverLinux::StorageChanged(false, |
| storage_name); |
| - ui_loop_.RunUntilIdle(); |
| + message_loop_.RunUntilIdle(); |
| } |
| private: |
| - // Message loop to run the test on. |
| - MessageLoop ui_loop_; |
| + 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<chrome::test::TestRemovableStorageNotifications> notifications_; |
|
vandebo (ex-Chrome)
2013/01/24 19:19:10
Does this need to be a scoped_ptr, can it just be
Greg Billock
2013/01/24 20:46:03
Done.
|
| + scoped_ptr<MockRemovableStorageObserver> mock_storage_observer_; |
| DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDeviceObserverLinuxTest); |
| }; |
| // Test to verify basic mtp storage attach and detach notifications. |
| TEST_F(MediaTransferProtocolDeviceObserverLinuxTest, BasicAttachDetach) { |
| - testing::Sequence mock_sequence; |
| std::string device_id = GetMtpDeviceId(kStorageUniqueId); |
| - EXPECT_CALL(observer(), |
| - OnRemovableStorageAttached(device_id, |
| - ASCIIToUTF16(kStorageLabel), |
| - kStorageLocation)) |
| - .InSequence(mock_sequence); |
| - |
| // Attach a mtp storage. |
| MtpStorageAttached(kStorageWithValidInfo); |
| - EXPECT_CALL(observer(), OnRemovableStorageDetached(device_id)) |
| - .InSequence(mock_sequence); |
| + EXPECT_EQ(1, observer().attach_calls()); |
|
vandebo (ex-Chrome)
2013/01/24 19:19:10
nit: check detach count here.
Greg Billock
2013/01/24 20:46:03
Done.
|
| + EXPECT_EQ(device_id, observer().last_attached().device_id); |
| + EXPECT_EQ(ASCIIToUTF16(kStorageLabel), observer().last_attached().name); |
| + EXPECT_EQ(kStorageLocation, observer().last_attached().location); |
| // Detach the attached storage. |
| MtpStorageDetached(kStorageWithValidInfo); |
| + |
| + EXPECT_EQ(1, observer().detach_calls()); |
|
vandebo (ex-Chrome)
2013/01/24 19:19:10
nit: check attach count here.
Greg Billock
2013/01/24 20:46:03
Done.
|
| + EXPECT_EQ(device_id, observer().last_detached().device_id); |
| } |
| // When a mtp storage device with invalid storage label and id is |
| // attached/detached, there should not be any device attach/detach |
| // notifications. |
| TEST_F(MediaTransferProtocolDeviceObserverLinuxTest, StorageWithInvalidInfo) { |
| - EXPECT_CALL(observer(), OnRemovableStorageAttached(_, _, _)).Times(0); |
| - |
| // Attach the mtp storage with invalid storage info. |
| MtpStorageAttached(kStorageWithInvalidInfo); |
| - EXPECT_CALL(observer(), OnRemovableStorageDetached(_)).Times(0); |
| - |
| // Detach the attached storage. |
| MtpStorageDetached(kStorageWithInvalidInfo); |
| + |
| + EXPECT_EQ(0, observer().attach_calls()); |
| + EXPECT_EQ(0, observer().detach_calls()); |
| } |
| } // namespace chrome |