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

Unified Diff: device/hid/hid_connection_unittest.cc

Issue 980023002: Move device/usb classes from the FILE thread to UI thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add more thread assertions. Created 5 years, 8 months 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 | « chrome/browser/extensions/api/device_permissions_manager_unittest.cc ('k') | device/hid/hid_service.cc » ('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 e474a6259c875d903adfb0e528ac2ed28455b3e2..b0361982a15391643f09eac22ac9af95a7a8b221 100644
--- a/device/hid/hid_connection_unittest.cc
+++ b/device/hid/hid_connection_unittest.cc
@@ -10,10 +10,12 @@
#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
#include "base/scoped_observer.h"
+#include "base/strings/utf_string_conversions.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"
+#include "device/usb/usb_device.h"
#include "net/base/io_buffer.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -23,20 +25,6 @@ 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:
//
@@ -46,10 +34,8 @@ void UnclaimTestDevice(scoped_ptr<UsbTestGadget> gadget) {
//
class DeviceCatcher : HidService::Observer {
public:
- DeviceCatcher(const std::string& serial_number)
- : serial_number_(serial_number), observer_(this) {
- HidService* hid_service = HidService::GetInstance(
- base::MessageLoop::current()->message_loop_proxy());
+ DeviceCatcher(HidService* hid_service, const base::string16& serial_number)
+ : serial_number_(base::UTF16ToUTF8(serial_number)), observer_(this) {
observer_.Add(hid_service);
hid_service->GetDevices(base::Bind(&DeviceCatcher::OnEnumerationComplete,
base::Unretained(this)));
@@ -168,23 +154,16 @@ class HidConnectionTest : public testing::Test {
service_ = HidService::GetInstance(io_thread_->task_runner());
ASSERT_TRUE(service_);
- io_thread_->PostTaskAndWait(FROM_HERE,
- base::Bind(&ClaimTestDevice, &test_gadget_));
+ test_gadget_ = UsbTestGadget::Claim(io_thread_->task_runner());
ASSERT_TRUE(test_gadget_);
+ ASSERT_TRUE(test_gadget_->SetType(UsbTestGadget::HID_ECHO));
- DeviceCatcher device_catcher(test_gadget_->GetSerialNumber());
+ DeviceCatcher device_catcher(service_,
+ test_gadget_->GetDevice()->serial_number());
device_id_ = device_catcher.WaitForDevice();
ASSERT_NE(device_id_, kInvalidHidDeviceId);
}
- 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_;
« no previous file with comments | « chrome/browser/extensions/api/device_permissions_manager_unittest.cc ('k') | device/hid/hid_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698