summaryrefslogtreecommitdiffstats
path: root/device/usb/usb_context_unittest.cc
blob: e3fb017f429b0572328e128f9931ad3ea3881023 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/threading/platform_thread.h"
#include "build/build_config.h"
#include "device/usb/usb_context.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libusb/src/libusb/libusb.h"

namespace device {

namespace {

class UsbContextTest : public testing::Test {
 protected:
  class UsbContextForTest : public UsbContext {
   public:
    explicit UsbContextForTest(PlatformUsbContext context)
        : UsbContext(context) {}

   private:
    ~UsbContextForTest() override {}
    DISALLOW_COPY_AND_ASSIGN(UsbContextForTest);
  };
};

}  // namespace

#if defined(OS_LINUX)
// Linux trybot does not support usb.
#define MAYBE_GracefulShutdown DISABLED_GracefulShutdown
#elif defined(OS_ANDROID)
// Android build does not include usb support.
#define MAYBE_GracefulShutdown DISABLED_GracefulShutdown
#else
#define MAYBE_GracefulShutdown GracefulShutdown
#endif

TEST_F(UsbContextTest, MAYBE_GracefulShutdown) {
  base::TimeTicks start = base::TimeTicks::Now();
  {
    PlatformUsbContext platform_context;
    ASSERT_EQ(LIBUSB_SUCCESS, libusb_init(&platform_context));
    scoped_refptr<UsbContextForTest> context(
        new UsbContextForTest(platform_context));
  }
  base::TimeDelta elapse = base::TimeTicks::Now() - start;
  if (elapse > base::TimeDelta::FromSeconds(2)) {
    FAIL();
  }
}

}  // namespace device