hid_service_unittest.cc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2017 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 "services/device/hid/hid_service.h"
  5. #include "base/bind.h"
  6. #include "base/run_loop.h"
  7. #include "base/test/task_environment.h"
  8. #include "services/device/public/mojom/hid.mojom.h"
  9. #include "testing/gtest/include/gtest/gtest.h"
  10. namespace device {
  11. namespace {
  12. class HidServiceTest : public ::testing::Test {
  13. public:
  14. HidServiceTest()
  15. : task_environment_(base::test::TaskEnvironment::MainThreadType::UI) {}
  16. protected:
  17. base::test::TaskEnvironment task_environment_;
  18. std::unique_ptr<HidService> service_;
  19. };
  20. void OnGetDevices(base::OnceClosure quit_closure,
  21. std::vector<mojom::HidDeviceInfoPtr> devices) {
  22. // Since there's no guarantee that any devices are connected at the moment
  23. // this test doesn't assume anything about the result but it at least verifies
  24. // that devices can be enumerated without the application crashing.
  25. std::move(quit_closure).Run();
  26. }
  27. } // namespace
  28. TEST_F(HidServiceTest, GetDevices) {
  29. service_ = HidService::Create();
  30. ASSERT_TRUE(service_);
  31. base::RunLoop loop;
  32. service_->GetDevices(base::BindOnce(&OnGetDevices, loop.QuitClosure()));
  33. loop.Run();
  34. }
  35. } // namespace device