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

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: Fixing up tests 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..416e6eeef8c5b3f25320dc824a2096b9ea7e7583 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,39 @@ 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();
+ int expect_attach_calls = 0;
{
vandebo (ex-Chrome) 2013/01/24 19:19:10 Remove the scope too now that InSequence is gone
Greg Billock 2013/01/24 20:46:03 Done.
- 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);
+ 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());
vandebo (ex-Chrome) 2013/01/24 19:19:10 nit: check detach count
Greg Billock 2013/01/24 20:46:03 Done.
}
void RemovableDeviceNotificationsWindowWinTest::RunUntilIdle() {
@@ -147,18 +134,26 @@ void RemovableDeviceNotificationsWindowWinTest::
volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
volume_broadcast.dbcv_unitmask = 0x0;
volume_broadcast.dbcv_flags = 0x0;
+ int expect_attach_calls = 0;
{
vandebo (ex-Chrome) 2013/01/24 19:19:10 Remove the scope too now that InSequence is gone
Greg Billock 2013/01/24 20:46:03 Done.
- 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));
+ std::string unique_id;
+ 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());
vandebo (ex-Chrome) 2013/01/24 19:19:10 nit: check detach count
Greg Billock 2013/01/24 20:46:03 Done.
}
void RemovableDeviceNotificationsWindowWinTest::
@@ -168,8 +163,8 @@ void RemovableDeviceNotificationsWindowWinTest::
volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
volume_broadcast.dbcv_unitmask = 0x0;
volume_broadcast.dbcv_flags = 0x0;
+ int expect_detach_calls = 0;
{
vandebo (ex-Chrome) 2013/01/24 19:19:10 Remove the scope too now that InSequence is gone
Greg Billock 2013/01/24 20:46:03 Done.
- testing::InSequence sequence;
for (DeviceIndices::const_iterator it = device_indices.begin();
it != device_indices.end(); ++it) {
volume_broadcast.dbcv_unitmask |= 0x1 << *it;
@@ -178,17 +173,14 @@ void RemovableDeviceNotificationsWindowWinTest::
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);
- }
+ if (removable)
+ expect_detach_calls++;
}
}
window_->InjectDeviceChange(DBT_DEVICEREMOVECOMPLETE,
reinterpret_cast<DWORD>(&volume_broadcast));
RunUntilIdle();
+ EXPECT_EQ(expect_detach_calls, observer_.detach_calls());
vandebo (ex-Chrome) 2013/01/24 19:19:10 nit: check attach count
Greg Billock 2013/01/24 20:46:03 Done.
}
void RemovableDeviceNotificationsWindowWinTest::DoMTPDeviceTest(
@@ -209,8 +201,10 @@ void RemovableDeviceNotificationsWindowWinTest::DoMTPDeviceTest(
dev_interface_broadcast->dbcc_classguid = guidDevInterface;
memcpy(dev_interface_broadcast->dbcc_name, pnp_device_id.data(),
device_id_size);
+
+ int expect_attach_calls = observer_.attach_calls();
+ int expect_detach_calls = observer_.detach_calls();
{
vandebo (ex-Chrome) 2013/01/24 19:19:10 Remove the scope too now that InSequence is gone
Greg Billock 2013/01/24 20:46:03 Done.
- testing::InSequence sequence;
PortableDeviceWatcherWin::StorageObjectIDs storage_object_ids =
TestPortableDeviceWatcherWin::GetMTPStorageObjectIds(pnp_device_id);
for (PortableDeviceWatcherWin::StorageObjectIDs::const_iterator it =
@@ -221,20 +215,20 @@ void RemovableDeviceNotificationsWindowWinTest::DoMTPDeviceTest(
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);
- }
+ 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 +340,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