diff options
author | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-14 22:27:07 +0000 |
---|---|---|
committer | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-14 22:27:07 +0000 |
commit | 6634b7db87117a9773b4f78b9747ff71a9849a3a (patch) | |
tree | 4590acdae86be72cb8d7be47679e582bee236b1e /base/system_monitor/system_monitor_unittest.cc | |
parent | 950067dda773220d4bbf175976bd622a5961726f (diff) | |
download | chromium_src-6634b7db87117a9773b4f78b9747ff71a9849a3a.zip chromium_src-6634b7db87117a9773b4f78b9747ff71a9849a3a.tar.gz chromium_src-6634b7db87117a9773b4f78b9747ff71a9849a3a.tar.bz2 |
Send WM_DEVICECHANGE message through SystemMonitor
WM_DEVICECHANGE is sent when there's been a change to devices or the computer;
specifically when a USB device is connected or disconnected. This is intended
for use in support of Gamepads for more performant polling and
connect/disconnect testing. Currently only on Windows, though seems reasonable
to add for other platforms in the future.
BUG=79050
Review URL: http://codereview.chromium.org/8523021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109960 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/system_monitor/system_monitor_unittest.cc')
-rw-r--r-- | base/system_monitor/system_monitor_unittest.cc | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/base/system_monitor/system_monitor_unittest.cc b/base/system_monitor/system_monitor_unittest.cc index f4a4e73..1d5d6af 100644 --- a/base/system_monitor/system_monitor_unittest.cc +++ b/base/system_monitor/system_monitor_unittest.cc @@ -55,7 +55,7 @@ TEST(SystemMonitor, PowerNotifications) { SystemMonitor system_monitor; PowerTest test[kObservers]; for (int index = 0; index < kObservers; ++index) - system_monitor.AddObserver(&test[index]); + system_monitor.AddPowerObserver(&test[index]); // Send a bunch of power changes. Since the battery power hasn't // actually changed, we shouldn't get notifications. @@ -90,4 +90,49 @@ TEST(SystemMonitor, PowerNotifications) { EXPECT_EQ(test[0].resumes(), 1); } +class DevicesChangedTest : public SystemMonitor::DevicesChangedObserver { + public: + DevicesChangedTest() + : changes_(0) { + } + + // DevicesChangedObserver callbacks. + virtual void OnDevicesChanged() OVERRIDE { + changes_++; + } + + // Test status counts. + int changes() const { return changes_; } + + private: + int changes_; // Count of OnDevicesChanged notifications. + + DISALLOW_COPY_AND_ASSIGN(DevicesChangedTest); +}; + +TEST(SystemMonitor, DeviceChangeNotifications) { + const int kObservers = 5; + + // Initialize a message loop for this to run on. + MessageLoop loop; + +#if defined(OS_MACOSX) + SystemMonitor::AllocateSystemIOPorts(); +#endif + + SystemMonitor system_monitor; + DevicesChangedTest test[kObservers]; + for (int index = 0; index < kObservers; ++index) + system_monitor.AddDevicesChangedObserver(&test[index]); + + system_monitor.ProcessDevicesChanged(); + loop.RunAllPending(); + EXPECT_EQ(1, test[0].changes()); + + system_monitor.ProcessDevicesChanged(); + system_monitor.ProcessDevicesChanged(); + loop.RunAllPending(); + EXPECT_EQ(3, test[0].changes()); +} + } // namespace base |