Chromium Code Reviews| Index: base/system_monitor/system_monitor_unittest.cc |
| diff --git a/base/system_monitor/system_monitor_unittest.cc b/base/system_monitor/system_monitor_unittest.cc |
| index f4a4e73fae2113b8e5a131502a1bf9ed54eead46..bc4ee9618029ca0c1d5578ff1e50d78902368305 100644 |
| --- a/base/system_monitor/system_monitor_unittest.cc |
| +++ b/base/system_monitor/system_monitor_unittest.cc |
| @@ -90,4 +90,47 @@ TEST(SystemMonitor, PowerNotifications) { |
| EXPECT_EQ(test[0].resumes(), 1); |
| } |
| +class DeviceChangeTest : public SystemMonitor::DeviceChangeObserver { |
| + public: |
| + DeviceChangeTest() |
| + : changes_(0) { |
| + } |
| + |
| + // DeviceChangeObserver callbacks. |
| + void OnDeviceChange() { |
|
sky
2011/11/11 02:32:59
virtual and OVERRIDE
scottmg
2011/11/11 05:06:09
Done.
|
| + changes_++; |
| + } |
| + |
| + // Test status counts. |
| + int changes() { return changes_; } |
|
sky
2011/11/11 02:32:59
const
scottmg
2011/11/11 05:06:09
Done.
|
| + |
| + private: |
| + int changes_; // Count of OnDeviceChange notifications. |
|
sky
2011/11/11 02:32:59
DISALLOW_...
scottmg
2011/11/11 05:06:09
Done.
|
| +}; |
| + |
| +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; |
| + DeviceChangeTest test[kObservers]; |
| + for (int index = 0; index < kObservers; ++index) |
| + system_monitor.AddObserver(&test[index]); |
| + |
| + system_monitor.ProcessDeviceChange(); |
| + loop.RunAllPending(); |
| + EXPECT_EQ(test[0].changes(), 1); |
|
sky
2011/11/11 02:32:59
assertions should have expected first, then actual
scottmg
2011/11/11 05:06:09
Done.
|
| + |
| + system_monitor.ProcessDeviceChange(); |
| + system_monitor.ProcessDeviceChange(); |
| + loop.RunAllPending(); |
| + EXPECT_EQ(test[0].changes(), 3); |
| +} |
| + |
| } // namespace base |