• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/system_monitor/system_monitor.h"
6 
7 #include "base/macros.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h"
10 #include "base/test/mock_devices_changed_observer.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 
14 namespace base {
15 
16 namespace {
17 
18 class SystemMonitorTest : public testing::Test {
19  protected:
SystemMonitorTest()20   SystemMonitorTest() {
21     system_monitor_.reset(new SystemMonitor);
22   }
23 
24   MessageLoop message_loop_;
25   std::unique_ptr<SystemMonitor> system_monitor_;
26 
27  private:
28   DISALLOW_COPY_AND_ASSIGN(SystemMonitorTest);
29 };
30 
TEST_F(SystemMonitorTest,DeviceChangeNotifications)31 TEST_F(SystemMonitorTest, DeviceChangeNotifications) {
32   const int kObservers = 5;
33 
34   testing::Sequence mock_sequencer[kObservers];
35   MockDevicesChangedObserver observers[kObservers];
36   for (int index = 0; index < kObservers; ++index) {
37     system_monitor_->AddDevicesChangedObserver(&observers[index]);
38 
39     EXPECT_CALL(observers[index],
40                 OnDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN))
41         .Times(3)
42         .InSequence(mock_sequencer[index]);
43   }
44 
45   system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN);
46   RunLoop().RunUntilIdle();
47 
48   system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN);
49   system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN);
50   RunLoop().RunUntilIdle();
51 }
52 
53 }  // namespace
54 
55 }  // namespace base
56