usb_context_unittest.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2014 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/usb/usb_context.h"
  5. #include "base/threading/platform_thread.h"
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. #include "third_party/libusb/src/libusb/libusb.h"
  8. namespace device {
  9. namespace {
  10. class UsbContextTest : public testing::Test {
  11. protected:
  12. class UsbContextForTest : public UsbContext {
  13. public:
  14. explicit UsbContextForTest(PlatformUsbContext context)
  15. : UsbContext(context) {}
  16. UsbContextForTest(const UsbContextForTest&) = delete;
  17. UsbContextForTest& operator=(const UsbContextForTest&) = delete;
  18. private:
  19. ~UsbContextForTest() override {}
  20. };
  21. };
  22. } // namespace
  23. TEST_F(UsbContextTest, GracefulShutdown) {
  24. base::TimeTicks start = base::TimeTicks::Now();
  25. {
  26. PlatformUsbContext platform_context;
  27. ASSERT_EQ(LIBUSB_SUCCESS, libusb_init(&platform_context));
  28. scoped_refptr<UsbContextForTest> context(
  29. new UsbContextForTest(platform_context));
  30. }
  31. base::TimeDelta elapse = base::TimeTicks::Now() - start;
  32. if (elapse > base::Seconds(2)) {
  33. FAIL();
  34. }
  35. }
  36. } // namespace device