| 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..d5da47b843b19062c9ee12b23241305249d6b6d3 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,25 @@ class MediaTransferProtocolDeviceObserverLinuxTest
|
| public MediaTransferProtocolDeviceObserverLinux {
|
| public:
|
| MediaTransferProtocolDeviceObserverLinuxTest()
|
| - : MediaTransferProtocolDeviceObserverLinux(&GetStorageInfo) {
|
| - }
|
| + : MediaTransferProtocolDeviceObserverLinux(&GetStorageInfo),
|
| + message_loop_(MessageLoop::TYPE_IO),
|
| + file_thread_(content::BrowserThread::FILE, &message_loop_) {}
|
|
|
| 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 +89,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 +97,52 @@ 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_;
|
| + chrome::test::TestRemovableStorageNotifications notifications_;
|
| + 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());
|
| + EXPECT_EQ(0, observer().detach_calls());
|
| + 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().attach_calls());
|
| + EXPECT_EQ(1, observer().detach_calls());
|
| + 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
|
|
|