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