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 #include <memory> 6 7 #include "base/system/system_monitor.h" 8 9 #include "base/run_loop.h" 10 #include "base/test/mock_devices_changed_observer.h" 11 #include "base/test/task_environment.h" 12 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gtest/include/gtest/gtest.h" 14 15 namespace base { 16 17 namespace { 18 19 class SystemMonitorTest : public testing::Test { 20 public: 21 SystemMonitorTest(const SystemMonitorTest&) = delete; 22 SystemMonitorTest& operator=(const SystemMonitorTest&) = delete; 23 24 protected: SystemMonitorTest()25 SystemMonitorTest() { system_monitor_ = std::make_unique<SystemMonitor>(); } 26 27 test::TaskEnvironment task_environment_; 28 std::unique_ptr<SystemMonitor> system_monitor_; 29 }; 30 TEST_F(SystemMonitorTest,DeviceChangeNotifications)31TEST_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