Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / device / usb / usb_context_unittest.cc
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
5 #include "base/threading/platform_thread.h"
6 #include "build/build_config.h"
7 #include "device/usb/usb_context.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/libusb/src/libusb/libusb.h"
10
11 namespace device {
12
13 namespace {
14
15 class UsbContextTest : public testing::Test {
16  protected:
17   class UsbContextForTest : public UsbContext {
18    public:
19     explicit UsbContextForTest(PlatformUsbContext context)
20         : UsbContext(context) {}
21
22    private:
23     ~UsbContextForTest() override {}
24     DISALLOW_COPY_AND_ASSIGN(UsbContextForTest);
25   };
26 };
27
28 }  // namespace
29
30 #if defined(OS_LINUX)
31 // Linux trybot does not support usb.
32 #define MAYBE_GracefulShutdown DISABLED_GracefulShutdown
33 #elif defined(OS_ANDROID)
34 // Android build does not include usb support.
35 #define MAYBE_GracefulShutdown DISABLED_GracefulShutdown
36 #else
37 #define MAYBE_GracefulShutdown GracefulShutdown
38 #endif
39
40 TEST_F(UsbContextTest, MAYBE_GracefulShutdown) {
41   base::TimeTicks start = base::TimeTicks::Now();
42   {
43     PlatformUsbContext platform_context;
44     ASSERT_EQ(LIBUSB_SUCCESS, libusb_init(&platform_context));
45     scoped_refptr<UsbContextForTest> context(
46         new UsbContextForTest(platform_context));
47   }
48   base::TimeDelta elapse = base::TimeTicks::Now() - start;
49   if (elapse > base::TimeDelta::FromSeconds(2)) {
50     FAIL();
51   }
52 }
53
54 }  // namespace device