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 1d5d6af86467c834b1f40172e0ef73c3e76262b3..eaed974c1107daa6ecde40a16fe4c103e5eca2c9 100644 |
--- a/base/system_monitor/system_monitor_unittest.cc |
+++ b/base/system_monitor/system_monitor_unittest.cc |
@@ -1,8 +1,11 @@ |
-// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "base/file_path.h" |
+#include "base/test/mock_devices_changed_observer.h" |
#include "base/system_monitor/system_monitor.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace base { |
@@ -90,26 +93,6 @@ 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; |
@@ -120,19 +103,38 @@ TEST(SystemMonitor, DeviceChangeNotifications) { |
SystemMonitor::AllocateSystemIOPorts(); |
#endif |
+ testing::Sequence mock_sequencer[kObservers]; |
SystemMonitor system_monitor; |
- DevicesChangedTest test[kObservers]; |
- for (int index = 0; index < kObservers; ++index) |
- system_monitor.AddDevicesChangedObserver(&test[index]); |
+ MockDevicesChangedObserver observers[kObservers]; |
+ for (int index = 0; index < kObservers; ++index) { |
+ system_monitor.AddDevicesChangedObserver(&observers[index]); |
+ |
+ EXPECT_CALL(observers[index], OnDevicesChanged()) |
+ .Times(3) |
+ .InSequence(mock_sequencer[index]); |
+ EXPECT_CALL(observers[index], OnMediaDeviceAttached(1, "media device", |
+ testing::_)) |
+ .InSequence(mock_sequencer[index]); |
+ EXPECT_CALL(observers[index], OnMediaDeviceDetached(1)) |
+ .InSequence(mock_sequencer[index]); |
+ EXPECT_CALL(observers[index], OnMediaDeviceDetached(2)) |
+ .InSequence(mock_sequencer[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()); |
+ |
+ system_monitor.ProcessMediaDeviceAttached( |
+ 1, "media device", FilePath(FILE_PATH_LITERAL("path"))); |
+ loop.RunAllPending(); |
+ |
+ system_monitor.ProcessMediaDeviceDetached(1); |
+ system_monitor.ProcessMediaDeviceDetached(2); |
+ loop.RunAllPending(); |
} |
} // namespace base |