Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1303)

Unified Diff: device/hid/hid_connection_unittest.cc

Issue 804643002: Enable USB gadget tests on OS X. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | device/test/usb_test_gadget.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/hid/hid_connection_unittest.cc
diff --git a/device/hid/hid_connection_unittest.cc b/device/hid/hid_connection_unittest.cc
index f4bf5de16f08009750fb11217fbcb86ea9cf32c2..ab3841caacbb6e515e0cfc8a522ecff07ede5551 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_;
« no previous file with comments | « no previous file | device/test/usb_test_gadget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698