[email protected] | b550868 | 2014-04-22 17:10:01 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | cac10e6 | 2013-07-23 21:40:49 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
avi | 176e269 | 2015-12-22 19:26:52 | [diff] [blame] | 5 | #include "base/macros.h" |
[email protected] | 99dcfca | 2013-08-05 01:28:59 | [diff] [blame] | 6 | #include "base/threading/platform_thread.h" |
[email protected] | cac10e6 | 2013-07-23 21:40:49 | [diff] [blame] | 7 | #include "build/build_config.h" |
reillyg | d77718d | 2014-09-04 00:57:56 | [diff] [blame] | 8 | #include "device/usb/usb_context.h" |
[email protected] | cac10e6 | 2013-07-23 21:40:49 | [diff] [blame] | 9 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 5764dcce | 2013-09-05 20:43:39 | [diff] [blame] | 10 | #include "third_party/libusb/src/libusb/libusb.h" |
[email protected] | cac10e6 | 2013-07-23 21:40:49 | [diff] [blame] | 11 | |
reillyg | d77718d | 2014-09-04 00:57:56 | [diff] [blame] | 12 | namespace device { |
[email protected] | b550868 | 2014-04-22 17:10:01 | [diff] [blame] | 13 | |
[email protected] | cac10e6 | 2013-07-23 21:40:49 | [diff] [blame] | 14 | namespace { |
15 | |||||
[email protected] | 99dcfca | 2013-08-05 01:28:59 | [diff] [blame] | 16 | class UsbContextTest : public testing::Test { |
[email protected] | 96816d2 | 2013-07-26 11:33:17 | [diff] [blame] | 17 | protected: |
[email protected] | 99dcfca | 2013-08-05 01:28:59 | [diff] [blame] | 18 | class UsbContextForTest : public UsbContext { |
19 | public: | ||||
[email protected] | 5764dcce | 2013-09-05 20:43:39 | [diff] [blame] | 20 | explicit UsbContextForTest(PlatformUsbContext context) |
21 | : UsbContext(context) {} | ||||
[email protected] | b550868 | 2014-04-22 17:10:01 | [diff] [blame] | 22 | |
[email protected] | 99dcfca | 2013-08-05 01:28:59 | [diff] [blame] | 23 | private: |
dcheng | b5aaf40 | 2014-10-22 23:07:52 | [diff] [blame] | 24 | ~UsbContextForTest() override {} |
[email protected] | 99dcfca | 2013-08-05 01:28:59 | [diff] [blame] | 25 | DISALLOW_COPY_AND_ASSIGN(UsbContextForTest); |
26 | }; | ||||
[email protected] | 96816d2 | 2013-07-26 11:33:17 | [diff] [blame] | 27 | }; |
[email protected] | cac10e6 | 2013-07-23 21:40:49 | [diff] [blame] | 28 | |
[email protected] | 99dcfca | 2013-08-05 01:28:59 | [diff] [blame] | 29 | } // namespace |
30 | |||||
[email protected] | cac10e6 | 2013-07-23 21:40:49 | [diff] [blame] | 31 | #if defined(OS_LINUX) |
32 | // Linux trybot does not support usb. | ||||
33 | #define MAYBE_GracefulShutdown DISABLED_GracefulShutdown | ||||
34 | #elif defined(OS_ANDROID) | ||||
35 | // Android build does not include usb support. | ||||
36 | #define MAYBE_GracefulShutdown DISABLED_GracefulShutdown | ||||
37 | #else | ||||
38 | #define MAYBE_GracefulShutdown GracefulShutdown | ||||
39 | #endif | ||||
40 | |||||
[email protected] | 99dcfca | 2013-08-05 01:28:59 | [diff] [blame] | 41 | TEST_F(UsbContextTest, MAYBE_GracefulShutdown) { |
[email protected] | cac10e6 | 2013-07-23 21:40:49 | [diff] [blame] | 42 | base::TimeTicks start = base::TimeTicks::Now(); |
[email protected] | 96816d2 | 2013-07-26 11:33:17 | [diff] [blame] | 43 | { |
[email protected] | 5764dcce | 2013-09-05 20:43:39 | [diff] [blame] | 44 | PlatformUsbContext platform_context; |
45 | ASSERT_EQ(LIBUSB_SUCCESS, libusb_init(&platform_context)); | ||||
46 | scoped_refptr<UsbContextForTest> context( | ||||
47 | new UsbContextForTest(platform_context)); | ||||
[email protected] | 96816d2 | 2013-07-26 11:33:17 | [diff] [blame] | 48 | } |
[email protected] | cac10e6 | 2013-07-23 21:40:49 | [diff] [blame] | 49 | base::TimeDelta elapse = base::TimeTicks::Now() - start; |
50 | if (elapse > base::TimeDelta::FromSeconds(2)) { | ||||
51 | FAIL(); | ||||
52 | } | ||||
53 | } | ||||
reillyg | d77718d | 2014-09-04 00:57:56 | [diff] [blame] | 54 | |
55 | } // namespace device |