OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/usb/usb_context.h" | 5 #include "chrome/browser/usb/usb_context.h" |
6 | 6 |
7 #include "base/threading/platform_thread.h" | 7 #include "base/threading/platform_thread.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/libusb/src/libusb/libusb.h" |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
13 class UsbContextTest : public testing::Test { | 14 class UsbContextTest : public testing::Test { |
14 protected: | 15 protected: |
15 class UsbContextForTest : public UsbContext { | 16 class UsbContextForTest : public UsbContext { |
16 public: | 17 public: |
17 UsbContextForTest() : UsbContext() {} | 18 explicit UsbContextForTest(PlatformUsbContext context) |
| 19 : UsbContext(context) {} |
18 private: | 20 private: |
19 virtual ~UsbContextForTest() {} | 21 virtual ~UsbContextForTest() {} |
20 DISALLOW_COPY_AND_ASSIGN(UsbContextForTest); | 22 DISALLOW_COPY_AND_ASSIGN(UsbContextForTest); |
21 }; | 23 }; |
22 }; | 24 }; |
23 | 25 |
24 } // namespace | 26 } // namespace |
25 | 27 |
26 #if defined(OS_LINUX) | 28 #if defined(OS_LINUX) |
27 // Linux trybot does not support usb. | 29 // Linux trybot does not support usb. |
28 #define MAYBE_GracefulShutdown DISABLED_GracefulShutdown | 30 #define MAYBE_GracefulShutdown DISABLED_GracefulShutdown |
29 #elif defined(OS_ANDROID) | 31 #elif defined(OS_ANDROID) |
30 // Android build does not include usb support. | 32 // Android build does not include usb support. |
31 #define MAYBE_GracefulShutdown DISABLED_GracefulShutdown | 33 #define MAYBE_GracefulShutdown DISABLED_GracefulShutdown |
32 #else | 34 #else |
33 #define MAYBE_GracefulShutdown GracefulShutdown | 35 #define MAYBE_GracefulShutdown GracefulShutdown |
34 #endif | 36 #endif |
35 | 37 |
36 TEST_F(UsbContextTest, MAYBE_GracefulShutdown) { | 38 TEST_F(UsbContextTest, MAYBE_GracefulShutdown) { |
37 base::TimeTicks start = base::TimeTicks::Now(); | 39 base::TimeTicks start = base::TimeTicks::Now(); |
38 { | 40 { |
39 scoped_refptr<UsbContextForTest> context(new UsbContextForTest()); | 41 PlatformUsbContext platform_context; |
| 42 ASSERT_EQ(LIBUSB_SUCCESS, libusb_init(&platform_context)); |
| 43 scoped_refptr<UsbContextForTest> context( |
| 44 new UsbContextForTest(platform_context)); |
40 } | 45 } |
41 base::TimeDelta elapse = base::TimeTicks::Now() - start; | 46 base::TimeDelta elapse = base::TimeTicks::Now() - start; |
42 if (elapse > base::TimeDelta::FromSeconds(2)) { | 47 if (elapse > base::TimeDelta::FromSeconds(2)) { |
43 FAIL(); | 48 FAIL(); |
44 } | 49 } |
45 } | 50 } |
OLD | NEW |