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

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

Issue 12382005: Rename RemovableDeviceNotifications=>StorageMonitor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 10 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/storage_monitor_win_unittest.cc
diff --git a/chrome/browser/storage_monitor/removable_device_notifications_window_win_unittest.cc b/chrome/browser/storage_monitor/storage_monitor_win_unittest.cc
similarity index 76%
rename from chrome/browser/storage_monitor/removable_device_notifications_window_win_unittest.cc
rename to chrome/browser/storage_monitor/storage_monitor_win_unittest.cc
index 5f40a80a68fbf56e7232950ace58e9439dd4b52e..669deaa03e2a2373dd8a8c72cf8a9a7f816b1e15 100644
--- a/chrome/browser/storage_monitor/removable_device_notifications_window_win_unittest.cc
+++ b/chrome/browser/storage_monitor/storage_monitor_win_unittest.cc
@@ -17,9 +17,9 @@
#include "chrome/browser/storage_monitor/mock_removable_storage_observer.h"
#include "chrome/browser/storage_monitor/portable_device_watcher_win.h"
#include "chrome/browser/storage_monitor/removable_device_constants.h"
-#include "chrome/browser/storage_monitor/removable_device_notifications_window_win.h"
+#include "chrome/browser/storage_monitor/storage_monitor_win.h"
#include "chrome/browser/storage_monitor/test_portable_device_watcher_win.h"
-#include "chrome/browser/storage_monitor/test_removable_device_notifications_window_win.h"
+#include "chrome/browser/storage_monitor/test_storage_monitor_win.h"
#include "chrome/browser/storage_monitor/test_volume_mount_watcher_win.h"
#include "chrome/browser/storage_monitor/volume_mount_watcher_win.h"
#include "content/public/test/test_browser_thread.h"
@@ -32,12 +32,12 @@ using content::BrowserThread;
typedef std::vector<int> DeviceIndices;
-// RemovableDeviceNotificationsWindowWinTest -----------------------------------
+// StorageMonitorWinTest -------------------------------------------------------
-class RemovableDeviceNotificationsWindowWinTest : public testing::Test {
+class StorageMonitorWinTest : public testing::Test {
public:
- RemovableDeviceNotificationsWindowWinTest();
- virtual ~RemovableDeviceNotificationsWindowWinTest();
+ StorageMonitorWinTest();
+ virtual ~StorageMonitorWinTest();
protected:
// testing::Test:
@@ -63,7 +63,7 @@ class RemovableDeviceNotificationsWindowWinTest : public testing::Test {
string16* pnp_device_id,
string16* storage_object_id);
- scoped_ptr<TestRemovableDeviceNotificationsWindowWin> window_;
+ scoped_ptr<TestStorageMonitorWin> monitor_;
// Weak pointer; owned by the device notifications class.
TestVolumeMountWatcherWin* volume_mount_watcher_;
@@ -76,33 +76,31 @@ class RemovableDeviceNotificationsWindowWinTest : public testing::Test {
content::TestBrowserThread file_thread_;
};
-RemovableDeviceNotificationsWindowWinTest::
- RemovableDeviceNotificationsWindowWinTest()
- : ui_thread_(BrowserThread::UI, &message_loop_),
- file_thread_(BrowserThread::FILE, &message_loop_) {
+StorageMonitorWinTest::StorageMonitorWinTest()
+ : ui_thread_(BrowserThread::UI, &message_loop_),
+ file_thread_(BrowserThread::FILE, &message_loop_) {
}
-RemovableDeviceNotificationsWindowWinTest::
- ~RemovableDeviceNotificationsWindowWinTest() {
+StorageMonitorWinTest::~StorageMonitorWinTest() {
}
-void RemovableDeviceNotificationsWindowWinTest::SetUp() {
+void StorageMonitorWinTest::SetUp() {
ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
volume_mount_watcher_ = new TestVolumeMountWatcherWin;
- window_.reset(new TestRemovableDeviceNotificationsWindowWin(
- volume_mount_watcher_, new TestPortableDeviceWatcherWin));
- window_->Init();
+ monitor_.reset(new TestStorageMonitorWin(volume_mount_watcher_,
+ new TestPortableDeviceWatcherWin));
+ monitor_->Init();
RunUntilIdle();
- window_->AddObserver(&observer_);
+ monitor_->AddObserver(&observer_);
}
-void RemovableDeviceNotificationsWindowWinTest::TearDown() {
+void StorageMonitorWinTest::TearDown() {
RunUntilIdle();
- window_->RemoveObserver(&observer_);
+ monitor_->RemoveObserver(&observer_);
}
-void RemovableDeviceNotificationsWindowWinTest::PreAttachDevices() {
- window_.reset();
+void StorageMonitorWinTest::PreAttachDevices() {
+ monitor_.reset();
volume_mount_watcher_ = new TestVolumeMountWatcherWin;
volume_mount_watcher_->SetAttachedDevicesFake();
@@ -120,10 +118,10 @@ void RemovableDeviceNotificationsWindowWinTest::PreAttachDevices() {
expect_attach_calls++;
}
- window_.reset(new TestRemovableDeviceNotificationsWindowWin(
- volume_mount_watcher_, new TestPortableDeviceWatcherWin));
- window_->AddObserver(&observer_);
- window_->Init();
+ monitor_.reset(new TestStorageMonitorWin(volume_mount_watcher_,
+ new TestPortableDeviceWatcherWin));
+ monitor_->AddObserver(&observer_);
+ monitor_->Init();
EXPECT_EQ(0u, volume_mount_watcher_->devices_checked().size());
@@ -141,13 +139,13 @@ void RemovableDeviceNotificationsWindowWinTest::PreAttachDevices() {
EXPECT_EQ(0, observer_.detach_calls());
}
-void RemovableDeviceNotificationsWindowWinTest::RunUntilIdle() {
+void StorageMonitorWinTest::RunUntilIdle() {
volume_mount_watcher_->FlushWorkerPoolForTesting();
message_loop_.RunUntilIdle();
}
-void RemovableDeviceNotificationsWindowWinTest::
- DoMassStorageDeviceAttachedTest(const DeviceIndices& device_indices) {
+void StorageMonitorWinTest::DoMassStorageDeviceAttachedTest(
+ const DeviceIndices& device_indices) {
DEV_BROADCAST_VOLUME volume_broadcast;
volume_broadcast.dbcv_size = sizeof(volume_broadcast);
volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
@@ -165,8 +163,8 @@ void RemovableDeviceNotificationsWindowWinTest::
if (removable)
expect_attach_calls++;
}
- window_->InjectDeviceChange(DBT_DEVICEARRIVAL,
- reinterpret_cast<DWORD>(&volume_broadcast));
+ monitor_->InjectDeviceChange(DBT_DEVICEARRIVAL,
+ reinterpret_cast<DWORD>(&volume_broadcast));
RunUntilIdle();
volume_mount_watcher_->FlushWorkerPoolForTesting();
@@ -176,8 +174,8 @@ void RemovableDeviceNotificationsWindowWinTest::
EXPECT_EQ(0, observer_.detach_calls());
}
-void RemovableDeviceNotificationsWindowWinTest::
- DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices) {
+void StorageMonitorWinTest::DoMassStorageDevicesDetachedTest(
+ const DeviceIndices& device_indices) {
DEV_BROADCAST_VOLUME volume_broadcast;
volume_broadcast.dbcv_size = sizeof(volume_broadcast);
volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
@@ -196,15 +194,15 @@ void RemovableDeviceNotificationsWindowWinTest::
if (removable)
expect_detach_calls++;
}
- window_->InjectDeviceChange(DBT_DEVICEREMOVECOMPLETE,
- reinterpret_cast<DWORD>(&volume_broadcast));
+ monitor_->InjectDeviceChange(DBT_DEVICEREMOVECOMPLETE,
+ reinterpret_cast<DWORD>(&volume_broadcast));
RunUntilIdle();
EXPECT_EQ(pre_attach_calls, observer_.attach_calls());
EXPECT_EQ(expect_detach_calls, observer_.detach_calls());
}
-void RemovableDeviceNotificationsWindowWinTest::DoMTPDeviceTest(
- const string16& pnp_device_id, bool test_attach) {
+void StorageMonitorWinTest::DoMTPDeviceTest(const string16& pnp_device_id,
+ bool test_attach) {
GUID guidDevInterface = GUID_NULL;
HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface);
if (FAILED(hr))
@@ -240,7 +238,7 @@ void RemovableDeviceNotificationsWindowWinTest::DoMTPDeviceTest(
expect_detach_calls++;
}
- window_->InjectDeviceChange(
+ monitor_->InjectDeviceChange(
test_attach ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE,
reinterpret_cast<DWORD>(dev_interface_broadcast.get()));
@@ -249,21 +247,21 @@ void RemovableDeviceNotificationsWindowWinTest::DoMTPDeviceTest(
EXPECT_EQ(expect_detach_calls, observer_.detach_calls());
}
-bool RemovableDeviceNotificationsWindowWinTest::GetMTPStorageInfo(
+bool StorageMonitorWinTest::GetMTPStorageInfo(
const std::string& storage_device_id,
string16* pnp_device_id,
string16* storage_object_id) {
- return window_->GetMTPStorageInfoFromDeviceId(storage_device_id,
- pnp_device_id,
- storage_object_id);
+ return monitor_->GetMTPStorageInfoFromDeviceId(storage_device_id,
+ pnp_device_id,
+ storage_object_id);
}
-TEST_F(RemovableDeviceNotificationsWindowWinTest, RandomMessage) {
- window_->InjectDeviceChange(DBT_DEVICEQUERYREMOVE, NULL);
+TEST_F(StorageMonitorWinTest, RandomMessage) {
+ monitor_->InjectDeviceChange(DBT_DEVICEQUERYREMOVE, NULL);
RunUntilIdle();
}
-TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttached) {
+TEST_F(StorageMonitorWinTest, DevicesAttached) {
DeviceIndices device_indices;
device_indices.push_back(1); // B
device_indices.push_back(5); // F
@@ -275,7 +273,7 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttached) {
std::string unique_id;
string16 name;
bool removable;
- EXPECT_TRUE(window_->volume_mount_watcher()->GetDeviceInfo(
+ EXPECT_TRUE(monitor_->volume_mount_watcher()->GetDeviceInfo(
base::FilePath(ASCIIToUTF16("F:\\")),
&location, &unique_id, &name, &removable, NULL));
EXPECT_EQ(ASCIIToUTF16("F:\\"), location);
@@ -283,36 +281,36 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttached) {
EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), name);
StorageMonitor::StorageInfo info;
- EXPECT_FALSE(window_->GetStorageInfoForPath(
+ EXPECT_FALSE(monitor_->GetStorageInfoForPath(
base::FilePath(ASCIIToUTF16("G:\\")), &info));
- EXPECT_TRUE(window_->GetStorageInfoForPath(
+ EXPECT_TRUE(monitor_->GetStorageInfoForPath(
base::FilePath(ASCIIToUTF16("F:\\")), &info));
StorageMonitor::StorageInfo info1;
- EXPECT_TRUE(window_->GetStorageInfoForPath(
+ EXPECT_TRUE(monitor_->GetStorageInfoForPath(
base::FilePath(ASCIIToUTF16("F:\\subdir")), &info1));
StorageMonitor::StorageInfo info2;
- EXPECT_TRUE(window_->GetStorageInfoForPath(
+ EXPECT_TRUE(monitor_->GetStorageInfoForPath(
base::FilePath(ASCIIToUTF16("F:\\subdir\\sub")), &info2));
EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info.name);
EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info1.name);
EXPECT_EQ(ASCIIToUTF16("F:\\ Drive"), info2.name);
}
-TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttachedHighBoundary) {
+TEST_F(StorageMonitorWinTest, DevicesAttachedHighBoundary) {
DeviceIndices device_indices;
device_indices.push_back(25);
DoMassStorageDeviceAttachedTest(device_indices);
}
-TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttachedLowBoundary) {
+TEST_F(StorageMonitorWinTest, DevicesAttachedLowBoundary) {
DeviceIndices device_indices;
device_indices.push_back(0);
DoMassStorageDeviceAttachedTest(device_indices);
}
-TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttachedAdjacentBits) {
+TEST_F(StorageMonitorWinTest, DevicesAttachedAdjacentBits) {
DeviceIndices device_indices;
device_indices.push_back(0);
device_indices.push_back(1);
@@ -322,7 +320,7 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttachedAdjacentBits) {
DoMassStorageDeviceAttachedTest(device_indices);
}
-TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesDetached) {
+TEST_F(StorageMonitorWinTest, DevicesDetached) {
PreAttachDevices();
DeviceIndices device_indices;
@@ -334,8 +332,7 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesDetached) {
DoMassStorageDevicesDetachedTest(device_indices);
}
-TEST_F(RemovableDeviceNotificationsWindowWinTest,
- DevicesDetachedHighBoundary) {
+TEST_F(StorageMonitorWinTest, DevicesDetachedHighBoundary) {
PreAttachDevices();
DeviceIndices device_indices;
@@ -344,8 +341,7 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest,
DoMassStorageDevicesDetachedTest(device_indices);
}
-TEST_F(RemovableDeviceNotificationsWindowWinTest,
- DevicesDetachedLowBoundary) {
+TEST_F(StorageMonitorWinTest, DevicesDetachedLowBoundary) {
PreAttachDevices();
DeviceIndices device_indices;
@@ -354,8 +350,7 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest,
DoMassStorageDevicesDetachedTest(device_indices);
}
-TEST_F(RemovableDeviceNotificationsWindowWinTest,
- DevicesDetachedAdjacentBits) {
+TEST_F(StorageMonitorWinTest, DevicesDetachedAdjacentBits) {
PreAttachDevices();
DeviceIndices device_indices;
@@ -367,8 +362,7 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest,
DoMassStorageDevicesDetachedTest(device_indices);
}
-TEST_F(RemovableDeviceNotificationsWindowWinTest,
- DuplicateAttachCheckSuppressed) {
+TEST_F(StorageMonitorWinTest, DuplicateAttachCheckSuppressed) {
volume_mount_watcher_->BlockDeviceCheckForTesting();
base::FilePath kAttachedDevicePath =
VolumeMountWatcherWin::DriveNumberToFilePath(8); // I:
@@ -378,16 +372,16 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest,
volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
volume_broadcast.dbcv_flags = 0x0;
volume_broadcast.dbcv_unitmask = 0x100; // I: drive
- window_->InjectDeviceChange(DBT_DEVICEARRIVAL,
- reinterpret_cast<DWORD>(&volume_broadcast));
+ monitor_->InjectDeviceChange(DBT_DEVICEARRIVAL,
+ reinterpret_cast<DWORD>(&volume_broadcast));
EXPECT_EQ(0u, volume_mount_watcher_->devices_checked().size());
// Re-attach the same volume. We haven't released the mock device check
// event, so there'll be pending calls in the UI thread to finish the
// device check notification, blocking the duplicate device injection.
- window_->InjectDeviceChange(DBT_DEVICEARRIVAL,
- reinterpret_cast<DWORD>(&volume_broadcast));
+ monitor_->InjectDeviceChange(DBT_DEVICEARRIVAL,
+ reinterpret_cast<DWORD>(&volume_broadcast));
EXPECT_EQ(0u, volume_mount_watcher_->devices_checked().size());
volume_mount_watcher_->ReleaseDeviceCheck();
@@ -405,8 +399,8 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest,
EXPECT_EQ(kAttachedDevicePath, checked_devices[0]);
// We'll receive a duplicate check now that the first check has fully cleared.
- window_->InjectDeviceChange(DBT_DEVICEARRIVAL,
- reinterpret_cast<DWORD>(&volume_broadcast));
+ monitor_->InjectDeviceChange(DBT_DEVICEARRIVAL,
+ reinterpret_cast<DWORD>(&volume_broadcast));
volume_mount_watcher_->FlushWorkerPoolForTesting();
volume_mount_watcher_->ReleaseDeviceCheck();
RunUntilIdle();
@@ -417,20 +411,20 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest,
EXPECT_EQ(kAttachedDevicePath, checked_devices[1]);
}
-TEST_F(RemovableDeviceNotificationsWindowWinTest, DeviceInfoForPath) {
+TEST_F(StorageMonitorWinTest, DeviceInfoForPath) {
PreAttachDevices();
// An invalid path.
- EXPECT_FALSE(window_->GetStorageInfoForPath(base::FilePath(L"COM1:\\"),
- NULL));
+ EXPECT_FALSE(monitor_->GetStorageInfoForPath(base::FilePath(L"COM1:\\"),
+ NULL));
// An unconnected removable device.
- EXPECT_FALSE(window_->GetStorageInfoForPath(base::FilePath(L"E:\\"), NULL));
+ EXPECT_FALSE(monitor_->GetStorageInfoForPath(base::FilePath(L"E:\\"), NULL));
// A connected removable device.
base::FilePath removable_device(L"F:\\");
StorageMonitor::StorageInfo device_info;
- EXPECT_TRUE(window_->GetStorageInfoForPath(removable_device, &device_info));
+ EXPECT_TRUE(monitor_->GetStorageInfoForPath(removable_device, &device_info));
std::string unique_id;
string16 device_name;
@@ -450,7 +444,7 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest, DeviceInfoForPath) {
// A fixed device.
base::FilePath fixed_device(L"N:\\");
- EXPECT_TRUE(window_->GetStorageInfoForPath(fixed_device, &device_info));
+ EXPECT_TRUE(monitor_->GetStorageInfoForPath(fixed_device, &device_info));
ASSERT_TRUE(volume_mount_watcher_->GetDeviceInfo(
fixed_device, &location, &unique_id, &device_name, &removable, NULL));
@@ -463,7 +457,7 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest, DeviceInfoForPath) {
}
// Test to verify basic MTP storage attach and detach notifications.
-TEST_F(RemovableDeviceNotificationsWindowWinTest, MTPDeviceBasicAttachDetach) {
+TEST_F(StorageMonitorWinTest, MTPDeviceBasicAttachDetach) {
DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, true);
DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, false);
}
@@ -471,7 +465,7 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest, MTPDeviceBasicAttachDetach) {
// 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(RemovableDeviceNotificationsWindowWinTest, MTPDeviceWithInvalidInfo) {
+TEST_F(StorageMonitorWinTest, MTPDeviceWithInvalidInfo) {
DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithInvalidInfo,
true);
DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithInvalidInfo,
@@ -480,15 +474,14 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest, MTPDeviceWithInvalidInfo) {
// Attach a device with two data partitions. Verify that attach/detach
// notifications are sent out for each removable storage.
-TEST_F(RemovableDeviceNotificationsWindowWinTest,
- MTPDeviceWithMultipleStorageObjects) {
+TEST_F(StorageMonitorWinTest, MTPDeviceWithMultipleStorageObjects) {
DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithMultipleStorages,
true);
DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithMultipleStorages,
false);
}
-TEST_F(RemovableDeviceNotificationsWindowWinTest, DriveNumberToFilePath) {
+TEST_F(StorageMonitorWinTest, DriveNumberToFilePath) {
EXPECT_EQ(L"A:\\", VolumeMountWatcherWin::DriveNumberToFilePath(0).value());
EXPECT_EQ(L"Y:\\", VolumeMountWatcherWin::DriveNumberToFilePath(24).value());
EXPECT_EQ(L"", VolumeMountWatcherWin::DriveNumberToFilePath(-1).value());
@@ -497,8 +490,7 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest, DriveNumberToFilePath) {
// Given a MTP storage persistent id, GetMTPStorageInfo() should fetch the
// device interface path and local storage object identifier.
-TEST_F(RemovableDeviceNotificationsWindowWinTest,
- GetMTPStorageInfoFromDeviceId) {
+TEST_F(StorageMonitorWinTest, GetMTPStorageInfoFromDeviceId) {
DoMTPDeviceTest(TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo, true);
PortableDeviceWatcherWin::StorageObjects storage_objects =
TestPortableDeviceWatcherWin::GetDeviceStorageObjects(

Powered by Google App Engine
This is Rietveld 408576698