OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/bind.h" |
| 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/run_loop.h" |
| 8 #include "device/serial/serial.mojom.h" |
| 9 #include "device/serial/serial_service_impl.h" |
| 10 #include "mojo/public/cpp/bindings/error_handler.h" |
| 11 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 12 #include "mojo/public/cpp/bindings/interface_request.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace device { |
| 16 |
| 17 class SerialServiceTest : public testing::Test, public mojo::ErrorHandler { |
| 18 public: |
| 19 SerialServiceTest() {} |
| 20 |
| 21 void StoreDevices(mojo::Array<serial::DeviceInfoPtr> devices) { |
| 22 devices_ = devices.Pass(); |
| 23 message_loop_.PostTask(FROM_HERE, run_loop_.QuitClosure()); |
| 24 } |
| 25 |
| 26 virtual void OnConnectionError() OVERRIDE { |
| 27 message_loop_.PostTask(FROM_HERE, run_loop_.QuitClosure()); |
| 28 FAIL() << "Connection error"; |
| 29 } |
| 30 |
| 31 base::MessageLoop message_loop_; |
| 32 base::RunLoop run_loop_; |
| 33 mojo::Array<serial::DeviceInfoPtr> devices_; |
| 34 |
| 35 private: |
| 36 DISALLOW_COPY_AND_ASSIGN(SerialServiceTest); |
| 37 }; |
| 38 |
| 39 TEST_F(SerialServiceTest, GetDevices) { |
| 40 mojo::InterfacePtr<serial::SerialService> service; |
| 41 SerialServiceImpl::Create(mojo::Get(&service)); |
| 42 service.set_error_handler(this); |
| 43 mojo::Array<serial::DeviceInfoPtr> result; |
| 44 service->GetDevices( |
| 45 base::Bind(&SerialServiceTest::StoreDevices, base::Unretained(this))); |
| 46 run_loop_.Run(); |
| 47 |
| 48 // Because we're running on unknown hardware, only check that we received a |
| 49 // non-null result. |
| 50 EXPECT_TRUE(devices_); |
| 51 } |
| 52 |
| 53 } // namespace device |
OLD | NEW |