summaryrefslogtreecommitdiffstats
path: root/device
diff options
context:
space:
mode:
authorreillyg@chromium.org <reillyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-01 18:39:17 +0000
committerreillyg@chromium.org <reillyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-01 18:39:17 +0000
commit2a0262ff309d82c61d1c2d53c103091cdebbe0c7 (patch)
treee8351f11ac23b4fbb3c78f6e3efcb97af4f0417e /device
parent1c7fa0c5d9e09b356fad1d241b7e39407a34fc2f (diff)
downloadchromium_src-2a0262ff309d82c61d1c2d53c103091cdebbe0c7.zip
chromium_src-2a0262ff309d82c61d1c2d53c103091cdebbe0c7.tar.gz
chromium_src-2a0262ff309d82c61d1c2d53c103091cdebbe0c7.tar.bz2
[usb_gadget p12] Basic tests of usb_service using the USB test gadget.
Two optional tests for usb_service::UsbService that use the new USB test gadget to verify that we can enumerate devices and detect connect and disconnect events. Since not all testers have this hardware the tests are only run when the --enable-gadget-tests flag is provided. BUG=396682 Review URL: https://codereview.chromium.org/420563008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287051 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device')
-rw-r--r--device/device_tests.gyp1
-rw-r--r--device/usb/DEPS3
-rw-r--r--device/usb/usb_service_unittest.cc51
3 files changed, 55 insertions, 0 deletions
diff --git a/device/device_tests.gyp b/device/device_tests.gyp
index c3d35b1..b5303c8 100644
--- a/device/device_tests.gyp
+++ b/device/device_tests.gyp
@@ -42,6 +42,7 @@
'nfc/nfc_chromeos_unittest.cc',
'nfc/nfc_ndef_record_unittest.cc',
'usb/usb_ids_unittest.cc',
+ 'usb/usb_service_unittest.cc',
'hid/hid_connection_unittest.cc',
'hid/hid_report_descriptor_unittest.cc',
'hid/hid_service_unittest.cc',
diff --git a/device/usb/DEPS b/device/usb/DEPS
new file mode 100644
index 0000000..70ac41d
--- /dev/null
+++ b/device/usb/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+ "+components/usb_service",
+]
diff --git a/device/usb/usb_service_unittest.cc b/device/usb/usb_service_unittest.cc
new file mode 100644
index 0000000..79a5bb7
--- /dev/null
+++ b/device/usb/usb_service_unittest.cc
@@ -0,0 +1,51 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/message_loop/message_loop.h"
+#include "base/strings/utf_string_conversions.h"
+#include "components/usb_service/usb_device.h"
+#include "components/usb_service/usb_device_handle.h"
+#include "device/test/usb_test_gadget.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::usb_service::UsbDeviceHandle;
+
+namespace device {
+
+namespace {
+
+class UsbServiceTest : public ::testing::Test {
+ public:
+ virtual void SetUp() {
+ message_loop_.reset(new base::MessageLoopForIO);
+ }
+
+ private:
+ scoped_ptr<base::MessageLoop> message_loop_;
+};
+
+TEST_F(UsbServiceTest, ClaimGadget) {
+ if (!UsbTestGadget::IsTestEnabled()) return;
+
+ scoped_ptr<UsbTestGadget> gadget = UsbTestGadget::Claim();
+ ASSERT_TRUE(gadget.get());
+
+ scoped_refptr<UsbDeviceHandle> handle = gadget->GetDevice()->Open();
+ base::string16 serial_utf16;
+ ASSERT_TRUE(handle->GetSerial(&serial_utf16));
+ ASSERT_EQ(gadget->GetSerial(), base::UTF16ToUTF8(serial_utf16));
+}
+
+TEST_F(UsbServiceTest, DisconnectAndReconnect) {
+ if (!UsbTestGadget::IsTestEnabled()) return;
+
+ scoped_ptr<UsbTestGadget> gadget = UsbTestGadget::Claim();
+ ASSERT_TRUE(gadget.get());
+ ASSERT_TRUE(gadget->Disconnect());
+ ASSERT_TRUE(gadget->Reconnect());
+}
+
+} // namespace
+
+} // namespace device