summaryrefslogtreecommitdiffstats
path: root/device/hid
diff options
context:
space:
mode:
authorreillyg <reillyg@chromium.org>2014-12-12 17:18:52 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-13 01:19:22 +0000
commit67650d64ea56326fef63e5d9812b6fd2590a2a25 (patch)
tree9311b949761d88825a945012426a6f091694b4f4 /device/hid
parent66d48f350f12c2ecf65b2a002dcc930e85f8deba (diff)
downloadchromium_src-67650d64ea56326fef63e5d9812b6fd2590a2a25.zip
chromium_src-67650d64ea56326fef63e5d9812b6fd2590a2a25.tar.gz
chromium_src-67650d64ea56326fef63e5d9812b6fd2590a2a25.tar.bz2
Enable USB gadget tests on OS X.
This change fixes the USB device handle tests on OS X by claiming the necessary interfaces before using them and using the right endpoint numbers. It also enables the HID connection tests on OS X by creating a MessageLoopForUI on the main thread (to mimic the usual configuration in the Chrome browser process) and a separate thread running a MessageLoopForIO. Review URL: https://codereview.chromium.org/804643002 Cr-Commit-Position: refs/heads/master@{#308210}
Diffstat (limited to 'device/hid')
-rw-r--r--device/hid/hid_connection_unittest.cc36
1 files changed, 31 insertions, 5 deletions
diff --git a/device/hid/hid_connection_unittest.cc b/device/hid/hid_connection_unittest.cc
index f4bf5de..ab3841c 100644
--- a/device/hid/hid_connection_unittest.cc
+++ b/device/hid/hid_connection_unittest.cc
@@ -10,6 +10,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
#include "base/scoped_observer.h"
+#include "base/test/test_io_thread.h"
#include "device/hid/hid_connection.h"
#include "device/hid/hid_service.h"
#include "device/test/usb_test_gadget.h"
@@ -22,6 +23,20 @@ namespace {
using net::IOBufferWithSize;
+void ClaimTestDevice(scoped_ptr<UsbTestGadget>* gadget) {
+ base::MessageLoop::ScopedNestableTaskAllower allow(
+ base::MessageLoop::current());
+ *gadget = UsbTestGadget::Claim();
+ ASSERT_TRUE(*gadget);
+ ASSERT_TRUE((*gadget)->SetType(UsbTestGadget::HID_ECHO));
+}
+
+void UnclaimTestDevice(scoped_ptr<UsbTestGadget> gadget) {
+ base::MessageLoop::ScopedNestableTaskAllower allow(
+ base::MessageLoop::current());
+ ASSERT_TRUE(gadget->Unclaim());
+}
+
// Helper class that can be used to block until a HID device with a particular
// serial number is available. Example usage:
//
@@ -146,20 +161,31 @@ class HidConnectionTest : public testing::Test {
void SetUp() override {
if (!UsbTestGadget::IsTestEnabled()) return;
- message_loop_.reset(new base::MessageLoopForIO());
- service_ = HidService::GetInstance(message_loop_->message_loop_proxy());
+ message_loop_.reset(new base::MessageLoopForUI());
+ io_thread_.reset(new base::TestIOThread(base::TestIOThread::kAutoStart));
+
+ service_ = HidService::GetInstance(io_thread_->task_runner());
ASSERT_TRUE(service_);
- test_gadget_ = UsbTestGadget::Claim();
+ io_thread_->PostTaskAndWait(FROM_HERE,
+ base::Bind(&ClaimTestDevice, &test_gadget_));
ASSERT_TRUE(test_gadget_);
- ASSERT_TRUE(test_gadget_->SetType(UsbTestGadget::HID_ECHO));
DeviceCatcher device_catcher(test_gadget_->GetSerialNumber());
device_id_ = device_catcher.WaitForDevice();
ASSERT_NE(device_id_, kInvalidHidDeviceId);
}
- scoped_ptr<base::MessageLoopForIO> message_loop_;
+ void TearDown() override {
+ if (io_thread_) {
+ io_thread_->PostTaskAndWait(
+ FROM_HERE,
+ base::Bind(&UnclaimTestDevice, base::Passed(&test_gadget_)));
+ }
+ }
+
+ scoped_ptr<base::MessageLoopForUI> message_loop_;
+ scoped_ptr<base::TestIOThread> io_thread_;
HidService* service_;
scoped_ptr<UsbTestGadget> test_gadget_;
HidDeviceId device_id_;