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

Unified Diff: device/hid/hid_connection_unittest.cc

Issue 660573007: Open HID connections asynchronously. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 | « no previous file | device/hid/hid_service.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 903cf5a5deed9417ba4a59a6a5c1e3108161b8ea..5654fc0a802ddb98a9a4b1e0babbdf8a3695bf0b 100644
--- a/device/hid/hid_connection_unittest.cc
+++ b/device/hid/hid_connection_unittest.cc
@@ -21,14 +21,39 @@ namespace {
using net::IOBufferWithSize;
-class TestCompletionCallback {
+class TestConnectCallback {
public:
- TestCompletionCallback()
- : read_callback_(base::Bind(&TestCompletionCallback::SetReadResult,
- base::Unretained(this))),
- write_callback_(base::Bind(&TestCompletionCallback::SetWriteResult,
+ TestConnectCallback()
+ : callback_(base::Bind(&TestConnectCallback::SetConnection,
+ base::Unretained(this))) {}
+ ~TestConnectCallback() {}
+
+ void SetConnection(scoped_refptr<HidConnection> connection) {
+ connection_ = connection;
+ run_loop_.Quit();
+ }
+
+ scoped_refptr<HidConnection> WaitForConnection() {
+ run_loop_.Run();
+ return connection_;
+ }
+
+ const HidService::ConnectCallback& callback() { return callback_; }
+
+ private:
+ HidService::ConnectCallback callback_;
+ base::RunLoop run_loop_;
+ scoped_refptr<HidConnection> connection_;
+};
+
+class TestIoCallback {
+ public:
+ TestIoCallback()
+ : read_callback_(
+ base::Bind(&TestIoCallback::SetReadResult, base::Unretained(this))),
+ write_callback_(base::Bind(&TestIoCallback::SetWriteResult,
base::Unretained(this))) {}
- ~TestCompletionCallback() {}
+ ~TestIoCallback() {}
void SetReadResult(bool success,
scoped_refptr<net::IOBuffer> buffer,
@@ -128,7 +153,9 @@ class HidConnectionTest : public testing::Test {
TEST_F(HidConnectionTest, ReadWrite) {
if (!UsbTestGadget::IsTestEnabled()) return;
- scoped_refptr<HidConnection> conn = service_->Connect(device_id_);
+ TestConnectCallback connect_callback;
+ service_->Connect(device_id_, connect_callback.callback());
+ scoped_refptr<HidConnection> conn = connect_callback.WaitForConnection();
ASSERT_TRUE(conn.get());
for (int i = 0; i < 8; ++i) {
@@ -138,11 +165,11 @@ TEST_F(HidConnectionTest, ReadWrite) {
buffer->data()[j] = i + j - 1;
}
- TestCompletionCallback write_callback;
+ TestIoCallback write_callback;
conn->Write(buffer, buffer->size(), write_callback.write_callback());
ASSERT_TRUE(write_callback.WaitForResult());
- TestCompletionCallback read_callback;
+ TestIoCallback read_callback;
conn->Read(read_callback.read_callback());
ASSERT_TRUE(read_callback.WaitForResult());
ASSERT_EQ(9UL, read_callback.size());
« no previous file with comments | « no previous file | device/hid/hid_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698