blob: 1ad9426f7d02c5ad51452b5500a1f3ffca774aa3 [file] [log] [blame]
[email protected]b5508682014-04-22 17:10:011// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]cac10e62013-07-23 21:40:492// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
avi176e2692015-12-22 19:26:525#include "base/macros.h"
[email protected]99dcfca2013-08-05 01:28:596#include "base/threading/platform_thread.h"
[email protected]cac10e62013-07-23 21:40:497#include "build/build_config.h"
reillygd77718d2014-09-04 00:57:568#include "device/usb/usb_context.h"
[email protected]cac10e62013-07-23 21:40:499#include "testing/gtest/include/gtest/gtest.h"
[email protected]5764dcce2013-09-05 20:43:3910#include "third_party/libusb/src/libusb/libusb.h"
[email protected]cac10e62013-07-23 21:40:4911
reillygd77718d2014-09-04 00:57:5612namespace device {
[email protected]b5508682014-04-22 17:10:0113
[email protected]cac10e62013-07-23 21:40:4914namespace {
15
[email protected]99dcfca2013-08-05 01:28:5916class UsbContextTest : public testing::Test {
[email protected]96816d22013-07-26 11:33:1717 protected:
[email protected]99dcfca2013-08-05 01:28:5918 class UsbContextForTest : public UsbContext {
19 public:
[email protected]5764dcce2013-09-05 20:43:3920 explicit UsbContextForTest(PlatformUsbContext context)
21 : UsbContext(context) {}
[email protected]b5508682014-04-22 17:10:0122
[email protected]99dcfca2013-08-05 01:28:5923 private:
dchengb5aaf402014-10-22 23:07:5224 ~UsbContextForTest() override {}
[email protected]99dcfca2013-08-05 01:28:5925 DISALLOW_COPY_AND_ASSIGN(UsbContextForTest);
26 };
[email protected]96816d22013-07-26 11:33:1727};
[email protected]cac10e62013-07-23 21:40:4928
[email protected]99dcfca2013-08-05 01:28:5929} // namespace
30
[email protected]cac10e62013-07-23 21:40:4931#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]99dcfca2013-08-05 01:28:5941TEST_F(UsbContextTest, MAYBE_GracefulShutdown) {
[email protected]cac10e62013-07-23 21:40:4942 base::TimeTicks start = base::TimeTicks::Now();
[email protected]96816d22013-07-26 11:33:1743 {
[email protected]5764dcce2013-09-05 20:43:3944 PlatformUsbContext platform_context;
45 ASSERT_EQ(LIBUSB_SUCCESS, libusb_init(&platform_context));
46 scoped_refptr<UsbContextForTest> context(
47 new UsbContextForTest(platform_context));
[email protected]96816d22013-07-26 11:33:1748 }
[email protected]cac10e62013-07-23 21:40:4949 base::TimeDelta elapse = base::TimeTicks::Now() - start;
50 if (elapse > base::TimeDelta::FromSeconds(2)) {
51 FAIL();
52 }
53}
reillygd77718d2014-09-04 00:57:5654
55} // namespace device