Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Unified Diff: chrome/browser/storage_monitor/media_transfer_protocol_device_observer_linux_unittest.cc

Issue 13533009: Storage Monitor: Remove MediaTransferProtocolDeviceObserverLinux::GetInstance() and access it only … (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/storage_monitor/media_transfer_protocol_device_observer_linux_unittest.cc
===================================================================
--- chrome/browser/storage_monitor/media_transfer_protocol_device_observer_linux_unittest.cc (revision 192467)
+++ chrome/browser/storage_monitor/media_transfer_protocol_device_observer_linux_unittest.cc (working copy)
@@ -10,6 +10,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
+#include "base/run_loop.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/storage_monitor/media_storage_util.h"
#include "chrome/browser/storage_monitor/mock_removable_storage_observer.h"
@@ -54,17 +55,40 @@
*location = kStorageLocation;
}
+class TestMediaTransferProtocolDeviceObserverLinux
+ : public MediaTransferProtocolDeviceObserverLinux {
+ public:
+ TestMediaTransferProtocolDeviceObserverLinux(
+ StorageMonitor::Receiver* receiver)
+ : MediaTransferProtocolDeviceObserverLinux(receiver, &GetStorageInfo) {
+ }
+
+ // Notifies MediaTransferProtocolDeviceObserverLinux about the attachment of
+ // mtp storage device given the |storage_name|.
+ void MtpStorageAttached(const std::string& storage_name) {
+ StorageChanged(true, storage_name);
+ base::RunLoop().RunUntilIdle();
+ }
+
+ // Notifies MediaTransferProtocolDeviceObserverLinux about the detachment of
+ // mtp storage device given the |storage_name|.
+ void MtpStorageDetached(const std::string& storage_name) {
+ StorageChanged(false, storage_name);
+ base::RunLoop().RunUntilIdle();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestMediaTransferProtocolDeviceObserverLinux);
+};
+
} // namespace
// A class to test the functionality of MediaTransferProtocolDeviceObserverLinux
// member functions.
-class MediaTransferProtocolDeviceObserverLinuxTest
- : public testing::Test,
- public MediaTransferProtocolDeviceObserverLinux {
+class MediaTransferProtocolDeviceObserverLinuxTest : public testing::Test {
public:
MediaTransferProtocolDeviceObserverLinuxTest()
- : MediaTransferProtocolDeviceObserverLinux(&GetStorageInfo),
- message_loop_(MessageLoop::TYPE_IO),
+ : message_loop_(MessageLoop::TYPE_IO),
file_thread_(content::BrowserThread::FILE, &message_loop_) {}
virtual ~MediaTransferProtocolDeviceObserverLinuxTest() {}
@@ -72,12 +96,14 @@
protected:
virtual void SetUp() OVERRIDE {
mock_storage_observer_.reset(new MockRemovableStorageObserver);
+ mtp_device_observer_.reset(
+ new TestMediaTransferProtocolDeviceObserverLinux(monitor_.receiver()));
monitor_.AddObserver(mock_storage_observer_.get());
- SetNotifications(monitor_.receiver());
}
virtual void TearDown() OVERRIDE {
monitor_.RemoveObserver(mock_storage_observer_.get());
+ mtp_device_observer_.reset();
}
// Returns the device changed observer object.
@@ -85,27 +111,16 @@
return *mock_storage_observer_;
}
- // Notifies MediaTransferProtocolDeviceObserverLinux about the attachment of
- // mtp storage device given the |storage_name|.
- void MtpStorageAttached(const std::string& storage_name) {
- MediaTransferProtocolDeviceObserverLinux::StorageChanged(true,
- storage_name);
- message_loop_.RunUntilIdle();
+ TestMediaTransferProtocolDeviceObserverLinux* mtp_device_observer() {
+ return mtp_device_observer_.get();
}
- // Notifies MediaTransferProtocolDeviceObserverLinux about the detachment of
- // mtp storage device given the |storage_name|.
- void MtpStorageDetached(const std::string& storage_name) {
- MediaTransferProtocolDeviceObserverLinux::StorageChanged(false,
- storage_name);
- message_loop_.RunUntilIdle();
- }
-
private:
MessageLoop message_loop_;
content::TestBrowserThread file_thread_;
chrome::test::TestStorageMonitor monitor_;
+ scoped_ptr<TestMediaTransferProtocolDeviceObserverLinux> mtp_device_observer_;
scoped_ptr<MockRemovableStorageObserver> mock_storage_observer_;
DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDeviceObserverLinuxTest);
@@ -116,7 +131,7 @@
std::string device_id = GetMtpDeviceId(kStorageUniqueId);
// Attach a mtp storage.
- MtpStorageAttached(kStorageWithValidInfo);
+ mtp_device_observer()->MtpStorageAttached(kStorageWithValidInfo);
EXPECT_EQ(1, observer().attach_calls());
EXPECT_EQ(0, observer().detach_calls());
@@ -125,7 +140,7 @@
EXPECT_EQ(kStorageLocation, observer().last_attached().location);
// Detach the attached storage.
- MtpStorageDetached(kStorageWithValidInfo);
+ mtp_device_observer()->MtpStorageDetached(kStorageWithValidInfo);
EXPECT_EQ(1, observer().attach_calls());
EXPECT_EQ(1, observer().detach_calls());
@@ -137,10 +152,10 @@
// notifications.
TEST_F(MediaTransferProtocolDeviceObserverLinuxTest, StorageWithInvalidInfo) {
// Attach the mtp storage with invalid storage info.
- MtpStorageAttached(kStorageWithInvalidInfo);
+ mtp_device_observer()->MtpStorageAttached(kStorageWithInvalidInfo);
// Detach the attached storage.
- MtpStorageDetached(kStorageWithInvalidInfo);
+ mtp_device_observer()->MtpStorageDetached(kStorageWithInvalidInfo);
EXPECT_EQ(0, observer().attach_calls());
EXPECT_EQ(0, observer().detach_calls());

Powered by Google App Engine
This is Rietveld 408576698