| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "device/serial/test_serial_io_handler.h" |
| 8 #include "extensions/browser/api/serial/serial_api.h" | 9 #include "extensions/browser/api/serial/serial_api.h" |
| 9 #include "extensions/browser/api/serial/serial_connection.h" | 10 #include "extensions/browser/api/serial/serial_connection.h" |
| 10 #include "extensions/browser/extension_function.h" | 11 #include "extensions/browser/extension_function.h" |
| 11 #include "extensions/common/api/serial.h" | 12 #include "extensions/common/api/serial.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 13 | 14 |
| 14 using testing::_; | 15 using testing::_; |
| 15 using testing::Return; | 16 using testing::Return; |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 37 devices->Append(device1); | 38 devices->Append(device1); |
| 38 SetResult(devices); | 39 SetResult(devices); |
| 39 SendResponse(true); | 40 SendResponse(true); |
| 40 return true; | 41 return true; |
| 41 } | 42 } |
| 42 | 43 |
| 43 protected: | 44 protected: |
| 44 virtual ~FakeSerialGetDevicesFunction() {} | 45 virtual ~FakeSerialGetDevicesFunction() {} |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 class FakeEchoSerialIoHandler : public device::SerialIoHandler { | 48 class FakeEchoSerialIoHandler : public device::TestSerialIoHandler { |
| 48 public: | 49 public: |
| 49 explicit FakeEchoSerialIoHandler() : opened_(false) {} | 50 explicit FakeEchoSerialIoHandler() { |
| 50 | 51 device_control_signals()->dcd = true; |
| 51 virtual void Open(const std::string& port, | 52 device_control_signals()->cts = true; |
| 52 const OpenCompleteCallback& callback) OVERRIDE { | 53 device_control_signals()->ri = true; |
| 53 DCHECK(!opened_); | 54 device_control_signals()->dsr = true; |
| 54 opened_ = true; | |
| 55 callback.Run(true); | |
| 56 } | 55 } |
| 57 | 56 |
| 58 virtual bool ConfigurePort( | |
| 59 const device::serial::ConnectionOptions& options) OVERRIDE { | |
| 60 return true; | |
| 61 } | |
| 62 | |
| 63 virtual void ReadImpl() OVERRIDE {} | |
| 64 | |
| 65 virtual void CancelReadImpl() OVERRIDE { | |
| 66 QueueReadCompleted(0, read_cancel_reason()); | |
| 67 } | |
| 68 | |
| 69 virtual void WriteImpl() OVERRIDE { | |
| 70 DCHECK(pending_read_buffer()); | |
| 71 DCHECK_LE(pending_write_buffer_len(), pending_read_buffer_len()); | |
| 72 memcpy(pending_read_buffer()->data(), | |
| 73 pending_write_buffer()->data(), | |
| 74 pending_write_buffer_len()); | |
| 75 QueueReadCompleted(pending_write_buffer_len(), | |
| 76 device::serial::RECEIVE_ERROR_NONE); | |
| 77 QueueWriteCompleted(pending_write_buffer_len(), | |
| 78 device::serial::SEND_ERROR_NONE); | |
| 79 } | |
| 80 | |
| 81 virtual void CancelWriteImpl() OVERRIDE { | |
| 82 QueueWriteCompleted(0, write_cancel_reason()); | |
| 83 } | |
| 84 | |
| 85 virtual device::serial::DeviceControlSignalsPtr GetControlSignals() | |
| 86 const OVERRIDE { | |
| 87 device::serial::DeviceControlSignalsPtr signals( | |
| 88 device::serial::DeviceControlSignals::New()); | |
| 89 signals->dcd = true; | |
| 90 signals->cts = true; | |
| 91 signals->ri = true; | |
| 92 signals->dsr = true; | |
| 93 return signals.Pass(); | |
| 94 } | |
| 95 | |
| 96 virtual device::serial::ConnectionInfoPtr GetPortInfo() const OVERRIDE { | |
| 97 device::serial::ConnectionInfoPtr info( | |
| 98 device::serial::ConnectionInfo::New()); | |
| 99 info->bitrate = 9600; | |
| 100 info->data_bits = device::serial::DATA_BITS_EIGHT; | |
| 101 info->parity_bit = device::serial::PARITY_BIT_NO; | |
| 102 info->stop_bits = device::serial::STOP_BITS_ONE; | |
| 103 info->cts_flow_control = false; | |
| 104 return info.Pass(); | |
| 105 } | |
| 106 | |
| 107 virtual bool Flush() const OVERRIDE { return true; } | |
| 108 | |
| 109 MOCK_METHOD1(SetControlSignals, | 57 MOCK_METHOD1(SetControlSignals, |
| 110 bool(const device::serial::HostControlSignals&)); | 58 bool(const device::serial::HostControlSignals&)); |
| 111 | 59 |
| 112 protected: | 60 protected: |
| 113 virtual ~FakeEchoSerialIoHandler() {} | 61 virtual ~FakeEchoSerialIoHandler() {} |
| 114 | 62 |
| 115 private: | 63 private: |
| 116 bool opened_; | |
| 117 | |
| 118 DISALLOW_COPY_AND_ASSIGN(FakeEchoSerialIoHandler); | 64 DISALLOW_COPY_AND_ASSIGN(FakeEchoSerialIoHandler); |
| 119 }; | 65 }; |
| 120 | 66 |
| 121 class FakeSerialConnectFunction : public core_api::SerialConnectFunction { | 67 class FakeSerialConnectFunction : public core_api::SerialConnectFunction { |
| 122 protected: | 68 protected: |
| 123 virtual SerialConnection* CreateSerialConnection( | 69 virtual SerialConnection* CreateSerialConnection( |
| 124 const std::string& port, | 70 const std::string& port, |
| 125 const std::string& owner_extension_id) const OVERRIDE { | 71 const std::string& owner_extension_id) const OVERRIDE { |
| 126 scoped_refptr<FakeEchoSerialIoHandler> io_handler = | 72 scoped_refptr<FakeEchoSerialIoHandler> io_handler = |
| 127 new FakeEchoSerialIoHandler; | 73 new FakeEchoSerialIoHandler; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 126 |
| 181 ASSERT_TRUE(RunExtensionTest("serial/api")) << message_; | 127 ASSERT_TRUE(RunExtensionTest("serial/api")) << message_; |
| 182 } | 128 } |
| 183 | 129 |
| 184 IN_PROC_BROWSER_TEST_F(SerialApiTest, SerialRealHardware) { | 130 IN_PROC_BROWSER_TEST_F(SerialApiTest, SerialRealHardware) { |
| 185 ResultCatcher catcher; | 131 ResultCatcher catcher; |
| 186 catcher.RestrictToProfile(browser()->profile()); | 132 catcher.RestrictToProfile(browser()->profile()); |
| 187 | 133 |
| 188 ASSERT_TRUE(RunExtensionTest("serial/real_hardware")) << message_; | 134 ASSERT_TRUE(RunExtensionTest("serial/real_hardware")) << message_; |
| 189 } | 135 } |
| OLD | NEW |