| 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..82803ed9747dcfedce10d213369b2b6854cabbb1 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,10 +10,12 @@
|
|
|
| #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/removable_device_notifications_linux.h"
|
| +#include "chrome/browser/system_monitor/removable_storage_notifications.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 {
|
| @@ -54,6 +56,41 @@ void GetStorageInfo(const std::string& storage_name,
|
| *location = kStorageLocation;
|
| }
|
|
|
| +class RemovableDeviceNotificationsLinuxTestWrapper
|
| + : public RemovableDeviceNotificationsLinux {
|
| + public:
|
| + RemovableDeviceNotificationsLinuxTestWrapper(const FilePath& path,
|
| + MessageLoop* message_loop)
|
| + : RemovableDeviceNotificationsLinux(path),
|
| + message_loop_(message_loop) {
|
| + }
|
| +
|
| + // 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.
|
| + ~RemovableDeviceNotificationsLinuxTestWrapper() {}
|
| +
|
| + virtual void OnFilePathChanged(const FilePath& path, bool error) OVERRIDE {
|
| + RemovableDeviceNotificationsLinux::OnFilePathChanged(path, error);
|
| + message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure());
|
| + }
|
| +
|
| + MessageLoop* message_loop_;
|
| +};
|
| +
|
| +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));
|
| +};
|
| +
|
| } // namespace
|
|
|
| // A class to test the functionality of MediaTransferProtocolDeviceObserverLinux
|
| @@ -63,26 +100,29 @@ class MediaTransferProtocolDeviceObserverLinuxTest
|
| public MediaTransferProtocolDeviceObserverLinux {
|
| public:
|
| MediaTransferProtocolDeviceObserverLinuxTest()
|
| - : MediaTransferProtocolDeviceObserverLinux(&GetStorageInfo) {
|
| - }
|
| + : MediaTransferProtocolDeviceObserverLinux(&GetStorageInfo),
|
| + message_loop_(MessageLoop::TYPE_IO),
|
| + file_thread_(content::BrowserThread::FILE, &message_loop_),
|
| + notifications_(new RemovableDeviceNotificationsLinuxTestWrapper(
|
| + FilePath("/etc/mtab"), &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 MockStorageObserver);
|
| + notifications_->AddRemovableStorageObserver(
|
| + mock_storage_observer_.get());
|
| }
|
|
|
| virtual void TearDown() OVERRIDE {
|
| - system_monitor_.RemoveDevicesChangedObserver(
|
| - mock_devices_changed_observer_.get());
|
| + notifications_->RemoveRemovableStorageObserver(
|
| + mock_storage_observer_.get());
|
| }
|
|
|
| // Returns the device changed observer object.
|
| - base::MockDevicesChangedObserver& observer() {
|
| - return *mock_devices_changed_observer_;
|
| + MockStorageObserver& observer() {
|
| + return *mock_storage_observer_;
|
| }
|
|
|
| // Notifies MediaTransferProtocolDeviceObserverLinux about the attachment of
|
| @@ -90,7 +130,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,16 +138,15 @@ 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_refptr<RemovableDeviceNotificationsLinuxTestWrapper> notifications_;
|
| + scoped_ptr<MockStorageObserver> mock_storage_observer_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDeviceObserverLinuxTest);
|
| };
|
|
|