| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 12 #include "device/serial/serial.mojom.h" | 13 #include "device/serial/serial.mojom.h" |
| 13 #include "device/serial/serial_service_impl.h" | 14 #include "device/serial/serial_service_impl.h" |
| 14 #include "device/serial/test_serial_io_handler.h" | 15 #include "device/serial/test_serial_io_handler.h" |
| 15 #include "mojo/public/cpp/bindings/interface_ptr.h" | 16 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 16 #include "mojo/public/cpp/bindings/interface_request.h" | 17 #include "mojo/public/cpp/bindings/interface_request.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace device { | 20 namespace device { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 EXPECT_TRUE(expecting_error_); | 57 EXPECT_TRUE(expecting_error_); |
| 57 } | 58 } |
| 58 | 59 |
| 59 void RunMessageLoop() { | 60 void RunMessageLoop() { |
| 60 run_loop_.reset(new base::RunLoop); | 61 run_loop_.reset(new base::RunLoop); |
| 61 run_loop_->Run(); | 62 run_loop_->Run(); |
| 62 } | 63 } |
| 63 | 64 |
| 64 void StopMessageLoop() { | 65 void StopMessageLoop() { |
| 65 ASSERT_TRUE(run_loop_); | 66 ASSERT_TRUE(run_loop_); |
| 66 message_loop_.PostTask(FROM_HERE, run_loop_->QuitClosure()); | 67 message_loop_.task_runner()->PostTask(FROM_HERE, run_loop_->QuitClosure()); |
| 67 } | 68 } |
| 68 | 69 |
| 69 void OnGotInfo(serial::ConnectionInfoPtr options) { | 70 void OnGotInfo(serial::ConnectionInfoPtr options) { |
| 70 connected_ = true; | 71 connected_ = true; |
| 71 StopMessageLoop(); | 72 StopMessageLoop(); |
| 72 } | 73 } |
| 73 | 74 |
| 74 scoped_refptr<SerialIoHandler> ReturnIoHandler() { return io_handler_; } | 75 scoped_refptr<SerialIoHandler> ReturnIoHandler() { return io_handler_; } |
| 75 | 76 |
| 76 void RunConnectTest(const std::string& path, bool expecting_success) { | 77 void RunConnectTest(const std::string& path, bool expecting_success) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 TEST_F(SerialServiceTest, ConnectInvalidPath) { | 138 TEST_F(SerialServiceTest, ConnectInvalidPath) { |
| 138 RunConnectTest("invalid_path", false); | 139 RunConnectTest("invalid_path", false); |
| 139 } | 140 } |
| 140 | 141 |
| 141 TEST_F(SerialServiceTest, ConnectOpenFailed) { | 142 TEST_F(SerialServiceTest, ConnectOpenFailed) { |
| 142 io_handler_ = new FailToOpenIoHandler; | 143 io_handler_ = new FailToOpenIoHandler; |
| 143 RunConnectTest("device", false); | 144 RunConnectTest("device", false); |
| 144 } | 145 } |
| 145 | 146 |
| 146 } // namespace device | 147 } // namespace device |
| OLD | NEW |