0

[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
This commit is contained in:
reillyg@chromium.org
2014-08-01 18:39:17 +00:00
parent 1c7fa0c5d9
commit 2a0262ff30
4 changed files with 55 additions and 2 deletions

@ -154,7 +154,6 @@ void UsbServiceImpl::RefreshDevices() {
// static
UsbService* UsbService::GetInstance() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
UsbService* instance = g_usb_service_instance.Get().get();
if (!instance) {
PlatformUsbContext context = NULL;
@ -175,7 +174,6 @@ UsbService* UsbService::GetInstance() {
// static
void UsbService::SetInstanceForTest(UsbService* instance) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
g_usb_service_instance.Get().reset(instance);
}

@ -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',

3
device/usb/DEPS Normal file

@ -0,0 +1,3 @@
include_rules = [
"+components/usb_service",
]

@ -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