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

Unified Diff: device/serial/serial_service_unittest.cc

Issue 488363002: Implement the host side of serial connection I/O on data pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix win x64 build Created 6 years, 4 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 | « device/serial/serial_service_impl.cc ('k') | device/serial/test_serial_io_handler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/serial/serial_service_unittest.cc
diff --git a/device/serial/serial_service_unittest.cc b/device/serial/serial_service_unittest.cc
index 18baec6ae33aace04bde0566677b2c256f094e24..b14d95f1f3e618aa459e4106a88826da4226bb91 100644
--- a/device/serial/serial_service_unittest.cc
+++ b/device/serial/serial_service_unittest.cc
@@ -27,10 +27,6 @@ class FakeSerialDeviceEnumerator : public SerialDeviceEnumerator {
class FailToOpenIoHandler : public TestSerialIoHandler {
public:
- static scoped_refptr<SerialIoHandler> Create() {
- return new FailToOpenIoHandler;
- }
-
virtual void Open(const std::string& port,
const OpenCompleteCallback& callback) OVERRIDE {
callback.Run(false);
@@ -44,7 +40,7 @@ class FailToOpenIoHandler : public TestSerialIoHandler {
class SerialServiceTest : public testing::Test, public mojo::ErrorHandler {
public:
- SerialServiceTest() {}
+ SerialServiceTest() : connected_(false), expecting_error_(false) {}
void StoreDevices(mojo::Array<serial::DeviceInfoPtr> devices) {
devices_ = devices.Pass();
@@ -66,12 +62,48 @@ class SerialServiceTest : public testing::Test, public mojo::ErrorHandler {
message_loop_.PostTask(FROM_HERE, run_loop_->QuitClosure());
}
- void OnGotInfo(serial::ConnectionInfoPtr options) { StopMessageLoop(); }
+ void OnGotInfo(serial::ConnectionInfoPtr options) {
+ connected_ = true;
+ StopMessageLoop();
+ }
+
+ scoped_refptr<SerialIoHandler> ReturnIoHandler() { return io_handler_; }
+
+ void RunConnectTest(const std::string& path, bool expecting_success) {
+ if (!io_handler_)
+ io_handler_ = new TestSerialIoHandler;
+ mojo::InterfacePtr<serial::SerialService> service;
+ mojo::BindToProxy(
+ new SerialServiceImpl(
+ new SerialConnectionFactory(
+ base::Bind(&SerialServiceTest::ReturnIoHandler,
+ base::Unretained(this)),
+ base::MessageLoopProxy::current()),
+ scoped_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator)),
+ &service);
+ mojo::InterfacePtr<serial::Connection> connection;
+ mojo::InterfacePtr<serial::DataSink> sink;
+ mojo::InterfacePtr<serial::DataSource> source;
+ service->Connect(path,
+ serial::ConnectionOptions::New(),
+ mojo::Get(&connection),
+ mojo::Get(&sink),
+ mojo::Get(&source));
+ connection.set_error_handler(this);
+ expecting_error_ = !expecting_success;
+ connection->GetInfo(
+ base::Bind(&SerialServiceTest::OnGotInfo, base::Unretained(this)));
+ RunMessageLoop();
+ EXPECT_EQ(!expecting_success, connection.encountered_error());
+ EXPECT_EQ(expecting_success, connected_);
+ connection.reset();
+ }
base::MessageLoop message_loop_;
scoped_ptr<base::RunLoop> run_loop_;
mojo::Array<serial::DeviceInfoPtr> devices_;
scoped_refptr<TestSerialIoHandler> io_handler_;
+ bool connected_;
bool expecting_error_;
serial::ConnectionInfoPtr info_;
@@ -94,56 +126,16 @@ TEST_F(SerialServiceTest, GetDevices) {
}
TEST_F(SerialServiceTest, Connect) {
- mojo::InterfacePtr<serial::SerialService> service;
- mojo::BindToProxy(
- new SerialServiceImpl(
- new SerialConnectionFactory(base::Bind(&TestSerialIoHandler::Create),
- base::MessageLoopProxy::current()),
- scoped_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator)),
- &service);
- service.set_error_handler(this);
- mojo::InterfacePtr<serial::Connection> connection;
- service->Connect(
- "device", serial::ConnectionOptions::New(), mojo::Get(&connection));
- connection.set_error_handler(this);
- connection->GetInfo(
- base::Bind(&SerialServiceTest::OnGotInfo, base::Unretained(this)));
- RunMessageLoop();
- connection.reset();
+ RunConnectTest("device", true);
}
TEST_F(SerialServiceTest, ConnectInvalidPath) {
- mojo::InterfacePtr<serial::SerialService> service;
- mojo::BindToProxy(
- new SerialServiceImpl(
- new SerialConnectionFactory(base::Bind(&TestSerialIoHandler::Create),
- base::MessageLoopProxy::current()),
- scoped_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator)),
- &service);
- mojo::InterfacePtr<serial::Connection> connection;
- service->Connect(
- "invalid_path", serial::ConnectionOptions::New(), mojo::Get(&connection));
- connection.set_error_handler(this);
- expecting_error_ = true;
- RunMessageLoop();
- EXPECT_TRUE(connection.encountered_error());
+ RunConnectTest("invalid_path", false);
}
TEST_F(SerialServiceTest, ConnectOpenFailed) {
- mojo::InterfacePtr<serial::SerialService> service;
- mojo::BindToProxy(
- new SerialServiceImpl(
- new SerialConnectionFactory(base::Bind(&FailToOpenIoHandler::Create),
- base::MessageLoopProxy::current()),
- scoped_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator)),
- &service);
- mojo::InterfacePtr<serial::Connection> connection;
- service->Connect(
- "device", serial::ConnectionOptions::New(), mojo::Get(&connection));
- expecting_error_ = true;
- connection.set_error_handler(this);
- RunMessageLoop();
- EXPECT_TRUE(connection.encountered_error());
+ io_handler_ = new FailToOpenIoHandler;
+ RunConnectTest("device", false);
}
} // namespace device
« no previous file with comments | « device/serial/serial_service_impl.cc ('k') | device/serial/test_serial_io_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698