summaryrefslogtreecommitdiffstats
path: root/device/hid/hid_connection_unittest.cc
diff options
context:
space:
mode:
authorrockot@chromium.org <rockot@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-27 17:29:10 +0000
committerrockot@chromium.org <rockot@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-27 17:29:10 +0000
commit26958d1d63547e6ff5f9f254e718905709fb6daf (patch)
tree2cc5f9553d8bd8d56f8d438fec805e11c2e2e01c /device/hid/hid_connection_unittest.cc
parent76d03f895522ae0ea5106c31618115b1a1d2c575 (diff)
downloadchromium_src-26958d1d63547e6ff5f9f254e718905709fb6daf.zip
chromium_src-26958d1d63547e6ff5f9f254e718905709fb6daf.tar.gz
chromium_src-26958d1d63547e6ff5f9f254e718905709fb6daf.tar.bz2
Clean up HID backend and API.
The Mac backend no longer creates its own thread and instead simply enforces single-threaded usage on any thread which supports I/O. Ref management has also been sanitized. The Linux backend now implements feature report support. The backend interface no longer expects implicit report IDs in buffers passed to Write or SetFeatureReport. Instead these interfaces (as well as GetFeatureReport) take explicit report ID arguments. The API interface has been updated to reflect the improved report ID treatment. Finally, the API also now exposes opaque device identifiers on enumeration, rather than exposing raw system paths or other information that could be potentially sensitive. BUG=347294 Review URL: https://codereview.chromium.org/161823002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253853 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device/hid/hid_connection_unittest.cc')
-rw-r--r--device/hid/hid_connection_unittest.cc24
1 files changed, 11 insertions, 13 deletions
diff --git a/device/hid/hid_connection_unittest.cc b/device/hid/hid_connection_unittest.cc
index 14a2ef9..2725481 100644
--- a/device/hid/hid_connection_unittest.cc
+++ b/device/hid/hid_connection_unittest.cc
@@ -17,7 +17,7 @@ namespace device {
namespace {
-using net::IOBuffer;
+using net::IOBufferWithSize;
const int kUSBLUFADemoVID = 0x03eb;
const int kUSBLUFADemoPID = 0x204f;
@@ -27,7 +27,7 @@ int g_read_times = 0;
void Read(scoped_refptr<HidConnection> conn);
void OnRead(scoped_refptr<HidConnection> conn,
- scoped_refptr<net::IOBuffer> buffer,
+ scoped_refptr<IOBufferWithSize> buffer,
bool success,
size_t bytes) {
EXPECT_TRUE(success);
@@ -53,8 +53,8 @@ void OnRead(scoped_refptr<HidConnection> conn,
}
void Read(scoped_refptr<HidConnection> conn) {
- scoped_refptr<IOBuffer> buffer(new IOBuffer(8));
- conn->Read(buffer, 8, base::Bind(OnRead, conn, buffer));
+ scoped_refptr<IOBufferWithSize> buffer(new IOBufferWithSize(8));
+ conn->Read(buffer, base::Bind(OnRead, conn, buffer));
}
void OnWriteNormal(bool success,
@@ -64,10 +64,10 @@ void OnWriteNormal(bool success,
}
void WriteNormal(scoped_refptr<HidConnection> conn) {
- scoped_refptr<IOBuffer> buffer(new IOBuffer(8));
+ scoped_refptr<IOBufferWithSize> buffer(new IOBufferWithSize(8));
*(int64_t*)buffer->data() = kReport;
- conn->Write(buffer, 8, base::Bind(OnWriteNormal));
+ conn->Write(0, buffer, base::Bind(OnWriteNormal));
}
} // namespace
@@ -81,6 +81,7 @@ class HidConnectionTest : public testing::Test {
std::vector<HidDeviceInfo> devices;
service_->GetDevices(&devices);
+ device_id_ = kInvalidHidDeviceId;
for (std::vector<HidDeviceInfo>::iterator it = devices.begin();
it != devices.end();
++it) {
@@ -97,21 +98,19 @@ class HidConnectionTest : public testing::Test {
message_loop_.reset(NULL);
}
- std::string device_id_;
+ HidDeviceId device_id_;
scoped_ptr<base::MessageLoopForIO> message_loop_;
scoped_ptr<HidService> service_;
};
TEST_F(HidConnectionTest, Create) {
scoped_refptr<HidConnection> connection = service_->Connect(device_id_);
- ASSERT_TRUE(connection || device_id_.empty());
+ ASSERT_TRUE(connection || device_id_ == kInvalidHidDeviceId);
}
TEST_F(HidConnectionTest, Read) {
scoped_refptr<HidConnection> connection = service_->Connect(device_id_);
-
- if (!device_id_.empty()) {
- ASSERT_TRUE(connection);
+ if (connection) {
message_loop_->PostTask(FROM_HERE, base::Bind(Read, connection));
message_loop_->Run();
}
@@ -120,8 +119,7 @@ TEST_F(HidConnectionTest, Read) {
TEST_F(HidConnectionTest, Write) {
scoped_refptr<HidConnection> connection = service_->Connect(device_id_);
- if (!device_id_.empty()) {
- ASSERT_TRUE(connection);
+ if (connection) {
message_loop_->PostTask(FROM_HERE, base::Bind(WriteNormal, connection));
message_loop_->Run();
}