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

Unified Diff: chrome/browser/system_monitor/removable_device_notifications_window_win_unittest.cc

Issue 11573048: [Media Galleries] Move RemovableStorageInfo notifications to chrome namespace (part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Typedef, init observer Created 7 years, 11 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/system_monitor/removable_device_notifications_window_win_unittest.cc
diff --git a/chrome/browser/system_monitor/removable_device_notifications_window_win_unittest.cc b/chrome/browser/system_monitor/removable_device_notifications_window_win_unittest.cc
index 81514e2437a2071dbf6463260e1257bb81858cbc..4696f7f1ea5f3a78c222d414af2c1658e357be59 100644
--- a/chrome/browser/system_monitor/removable_device_notifications_window_win_unittest.cc
+++ b/chrome/browser/system_monitor/removable_device_notifications_window_win_unittest.cc
@@ -11,9 +11,8 @@
#include "base/memory/ref_counted.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 "chrome/browser/system_monitor/media_storage_util.h"
+#include "chrome/browser/system_monitor/mock_removable_storage_observer.h"
#include "chrome/browser/system_monitor/portable_device_watcher_win.h"
#include "chrome/browser/system_monitor/removable_device_constants.h"
#include "chrome/browser/system_monitor/test_portable_device_watcher_win.h"
@@ -21,7 +20,6 @@
#include "chrome/browser/system_monitor/test_volume_mount_watcher_win.h"
#include "chrome/browser/system_monitor/volume_mount_watcher_win.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 {
@@ -43,7 +41,6 @@ class RemovableDeviceNotificationsWindowWinTest : public testing::Test {
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
- void AddMassStorageDeviceAttachExpectation(const FilePath& drive);
void PreAttachDevices();
// Runs all the pending tasks on UI thread, FILE thread and blocking thread.
@@ -71,8 +68,7 @@ class RemovableDeviceNotificationsWindowWinTest : public testing::Test {
content::TestBrowserThread ui_thread_;
content::TestBrowserThread file_thread_;
- base::SystemMonitor system_monitor_;
- base::MockDevicesChangedObserver observer_;
+ MockRemovableStorageObserver observer_;
};
RemovableDeviceNotificationsWindowWinTest::
@@ -92,48 +88,40 @@ void RemovableDeviceNotificationsWindowWinTest::SetUp() {
volume_mount_watcher_.get(), new TestPortableDeviceWatcherWin));
window_->InitWithTestData(false);
RunUntilIdle();
- system_monitor_.AddDevicesChangedObserver(&observer_);
+ window_->AddObserver(&observer_);
}
void RemovableDeviceNotificationsWindowWinTest::TearDown() {
RunUntilIdle();
- system_monitor_.RemoveDevicesChangedObserver(&observer_);
-}
-
-void RemovableDeviceNotificationsWindowWinTest::
- AddMassStorageDeviceAttachExpectation(const FilePath& drive) {
- std::string unique_id;
- string16 device_name;
- bool removable;
- ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo(
- drive, NULL, &unique_id, &device_name, &removable));
- if (removable) {
- MediaStorageUtil::Type type =
- MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM;
- std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id);
- EXPECT_CALL(observer_, OnRemovableStorageAttached(device_id, device_name,
- drive.value()))
- .Times(1);
- }
+ window_->RemoveObserver(&observer_);
}
void RemovableDeviceNotificationsWindowWinTest::PreAttachDevices() {
window_.reset();
- {
- testing::InSequence sequence;
- ASSERT_TRUE(volume_mount_watcher_.get());
- volume_mount_watcher_->set_pre_attach_devices(true);
- std::vector<FilePath> initial_devices =
- volume_mount_watcher_->GetAttachedDevices();
- for (std::vector<FilePath>::const_iterator it = initial_devices.begin();
- it != initial_devices.end(); ++it) {
- AddMassStorageDeviceAttachExpectation(*it);
- }
+
+ int expect_attach_calls = 0;
+ ASSERT_TRUE(volume_mount_watcher_.get());
+ volume_mount_watcher_->set_pre_attach_devices(true);
+ std::vector<FilePath> initial_devices =
+ volume_mount_watcher_->GetAttachedDevices();
+ for (std::vector<FilePath>::const_iterator it = initial_devices.begin();
+ it != initial_devices.end(); ++it) {
+ std::string unique_id;
+ string16 device_name;
+ bool removable;
+ ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo(
+ *it, NULL, &unique_id, &device_name, &removable));
+ if (removable)
+ expect_attach_calls++;
}
+
window_.reset(new TestRemovableDeviceNotificationsWindowWin(
volume_mount_watcher_.get(), new TestPortableDeviceWatcherWin));
window_->InitWithTestData(true);
+
RunUntilIdle();
+ EXPECT_EQ(expect_attach_calls, observer_.attach_calls());
+ EXPECT_EQ(0, observer_.detach_calls());
}
void RemovableDeviceNotificationsWindowWinTest::RunUntilIdle() {
@@ -147,18 +135,26 @@ void RemovableDeviceNotificationsWindowWinTest::
volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
volume_broadcast.dbcv_unitmask = 0x0;
volume_broadcast.dbcv_flags = 0x0;
- {
- testing::InSequence sequence;
- for (DeviceIndices::const_iterator it = device_indices.begin();
- it != device_indices.end(); ++it) {
- volume_broadcast.dbcv_unitmask |= 0x1 << *it;
- AddMassStorageDeviceAttachExpectation(
- VolumeMountWatcherWin::DriveNumberToFilePath(*it));
- }
+
+ int expect_attach_calls = 0;
+ for (DeviceIndices::const_iterator it = device_indices.begin();
+ it != device_indices.end(); ++it) {
+ volume_broadcast.dbcv_unitmask |= 0x1 << *it;
+ std::string unique_id;
Lei Zhang 2013/01/26 01:27:49 Unlike the old code that expects an attachment for
Greg Billock 2013/01/26 01:42:07 Yeah, this is just to get 'removable' basically. I
+ string16 device_name;
+ bool removable;
+ ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo(
+ VolumeMountWatcherWin::DriveNumberToFilePath(*it),
+ NULL, &unique_id, &device_name, &removable));
+ if (removable)
+ expect_attach_calls++;
}
window_->InjectDeviceChange(DBT_DEVICEARRIVAL,
reinterpret_cast<DWORD>(&volume_broadcast));
+
RunUntilIdle();
+ EXPECT_EQ(expect_attach_calls, observer_.attach_calls());
+ EXPECT_EQ(0, observer_.detach_calls());
}
void RemovableDeviceNotificationsWindowWinTest::
@@ -168,27 +164,24 @@ void RemovableDeviceNotificationsWindowWinTest::
volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
volume_broadcast.dbcv_unitmask = 0x0;
volume_broadcast.dbcv_flags = 0x0;
- {
- testing::InSequence sequence;
- for (DeviceIndices::const_iterator it = device_indices.begin();
- it != device_indices.end(); ++it) {
- volume_broadcast.dbcv_unitmask |= 0x1 << *it;
- std::string unique_id;
- bool removable;
- ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo(
- VolumeMountWatcherWin::DriveNumberToFilePath(*it), NULL, &unique_id,
- NULL, &removable));
- if (removable) {
- MediaStorageUtil::Type type =
- MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM;
- std::string device_id = MediaStorageUtil::MakeDeviceId(type, unique_id);
- EXPECT_CALL(observer_, OnRemovableStorageDetached(device_id)).Times(1);
- }
- }
+
+ int expect_detach_calls = 0;
+ for (DeviceIndices::const_iterator it = device_indices.begin();
+ it != device_indices.end(); ++it) {
+ volume_broadcast.dbcv_unitmask |= 0x1 << *it;
+ std::string unique_id;
+ bool removable;
+ ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo(
+ VolumeMountWatcherWin::DriveNumberToFilePath(*it), NULL, &unique_id,
+ NULL, &removable));
+ if (removable)
+ expect_detach_calls++;
}
window_->InjectDeviceChange(DBT_DEVICEREMOVECOMPLETE,
reinterpret_cast<DWORD>(&volume_broadcast));
RunUntilIdle();
+ EXPECT_EQ(0, observer_.attach_calls());
+ EXPECT_EQ(expect_detach_calls, observer_.detach_calls());
}
void RemovableDeviceNotificationsWindowWinTest::DoMTPDeviceTest(
@@ -209,32 +202,32 @@ void RemovableDeviceNotificationsWindowWinTest::DoMTPDeviceTest(
dev_interface_broadcast->dbcc_classguid = guidDevInterface;
memcpy(dev_interface_broadcast->dbcc_name, pnp_device_id.data(),
device_id_size);
- {
- testing::InSequence sequence;
- PortableDeviceWatcherWin::StorageObjectIDs storage_object_ids =
- TestPortableDeviceWatcherWin::GetMTPStorageObjectIds(pnp_device_id);
- for (PortableDeviceWatcherWin::StorageObjectIDs::const_iterator it =
- storage_object_ids.begin(); it != storage_object_ids.end(); ++it) {
- std::string unique_id;
- string16 name;
- string16 location;
- TestPortableDeviceWatcherWin::GetMTPStorageDetails(pnp_device_id, *it,
- &location, &unique_id,
- &name);
- if (test_attach) {
- EXPECT_CALL(observer_, OnRemovableStorageAttached(unique_id, name,
- location))
- .Times((name.empty() || unique_id.empty()) ? 0 : 1);
- } else {
- EXPECT_CALL(observer_, OnRemovableStorageDetached(unique_id))
- .Times((name.empty() || unique_id.empty()) ? 0 : 1);
- }
- }
+
+ int expect_attach_calls = observer_.attach_calls();
+ int expect_detach_calls = observer_.detach_calls();
+ PortableDeviceWatcherWin::StorageObjectIDs storage_object_ids =
+ TestPortableDeviceWatcherWin::GetMTPStorageObjectIds(pnp_device_id);
+ for (PortableDeviceWatcherWin::StorageObjectIDs::const_iterator it =
+ storage_object_ids.begin(); it != storage_object_ids.end(); ++it) {
+ std::string unique_id;
+ string16 name;
+ string16 location;
+ TestPortableDeviceWatcherWin::GetMTPStorageDetails(pnp_device_id, *it,
+ &location, &unique_id,
+ &name);
+ if (test_attach && !name.empty() && !unique_id.empty())
+ expect_attach_calls++;
+ else if (!name.empty() && !unique_id.empty())
+ expect_detach_calls++;
}
+
window_->InjectDeviceChange(
test_attach ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE,
reinterpret_cast<DWORD>(dev_interface_broadcast.get()));
+
RunUntilIdle();
+ EXPECT_EQ(expect_attach_calls, observer_.attach_calls());
+ EXPECT_EQ(expect_detach_calls, observer_.detach_calls());
}
bool RemovableDeviceNotificationsWindowWinTest::GetMTPStorageInfo(
@@ -346,7 +339,7 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest, DISABLED_DeviceInfoForPath) {
// A connected removable device.
FilePath removable_device(L"F:\\");
- base::SystemMonitor::RemovableStorageInfo device_info;
+ RemovableStorageNotifications::StorageInfo device_info;
EXPECT_TRUE(window_->GetDeviceInfoForPath(removable_device, &device_info));
std::string unique_id;

Powered by Google App Engine
This is Rietveld 408576698