• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifdef UNSAFE_BUFFERS_BUILD
6 // TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
7 #pragma allow_unsafe_buffers
8 #endif
9 
10 #include <memory>
11 
12 #include "base/system/system_monitor.h"
13 
14 #include "base/run_loop.h"
15 #include "base/test/mock_devices_changed_observer.h"
16 #include "base/test/task_environment.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 
20 namespace base {
21 
22 namespace {
23 
24 class SystemMonitorTest : public testing::Test {
25  public:
26   SystemMonitorTest(const SystemMonitorTest&) = delete;
27   SystemMonitorTest& operator=(const SystemMonitorTest&) = delete;
28 
29  protected:
SystemMonitorTest()30   SystemMonitorTest() { system_monitor_ = std::make_unique<SystemMonitor>(); }
31 
32   test::TaskEnvironment task_environment_;
33   std::unique_ptr<SystemMonitor> system_monitor_;
34 };
35 
TEST_F(SystemMonitorTest,DeviceChangeNotifications)36 TEST_F(SystemMonitorTest, DeviceChangeNotifications) {
37   const int kObservers = 5;
38 
39   testing::Sequence mock_sequencer[kObservers];
40   MockDevicesChangedObserver observers[kObservers];
41   for (int index = 0; index < kObservers; ++index) {
42     system_monitor_->AddDevicesChangedObserver(&observers[index]);
43 
44     EXPECT_CALL(observers[index],
45                 OnDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN))
46         .Times(3)
47         .InSequence(mock_sequencer[index]);
48   }
49 
50   system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN);
51   RunLoop().RunUntilIdle();
52 
53   system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN);
54   system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN);
55   RunLoop().RunUntilIdle();
56 }
57 
58 }  // namespace
59 
60 }  // namespace base
61