system_monitor_unittest.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include <memory>
  5. #include "base/system/system_monitor.h"
  6. #include "base/run_loop.h"
  7. #include "base/test/mock_devices_changed_observer.h"
  8. #include "base/test/task_environment.h"
  9. #include "testing/gmock/include/gmock/gmock.h"
  10. #include "testing/gtest/include/gtest/gtest.h"
  11. namespace base {
  12. namespace {
  13. class SystemMonitorTest : public testing::Test {
  14. public:
  15. SystemMonitorTest(const SystemMonitorTest&) = delete;
  16. SystemMonitorTest& operator=(const SystemMonitorTest&) = delete;
  17. protected:
  18. SystemMonitorTest() { system_monitor_ = std::make_unique<SystemMonitor>(); }
  19. test::TaskEnvironment task_environment_;
  20. std::unique_ptr<SystemMonitor> system_monitor_;
  21. };
  22. TEST_F(SystemMonitorTest, DeviceChangeNotifications) {
  23. const int kObservers = 5;
  24. testing::Sequence mock_sequencer[kObservers];
  25. MockDevicesChangedObserver observers[kObservers];
  26. for (int index = 0; index < kObservers; ++index) {
  27. system_monitor_->AddDevicesChangedObserver(&observers[index]);
  28. EXPECT_CALL(observers[index],
  29. OnDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN))
  30. .Times(3)
  31. .InSequence(mock_sequencer[index]);
  32. }
  33. system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN);
  34. RunLoop().RunUntilIdle();
  35. system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN);
  36. system_monitor_->ProcessDevicesChanged(SystemMonitor::DEVTYPE_UNKNOWN);
  37. RunLoop().RunUntilIdle();
  38. }
  39. } // namespace
  40. } // namespace base