| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 <deque> | 5 #include <deque> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/browser/extensions/api/serial/serial_api.h" | 10 #include "chrome/browser/extensions/api/serial/serial_api.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 explicit FakeEchoSerialIoHandler() : opened_(false) {} | 57 explicit FakeEchoSerialIoHandler() : opened_(false) {} |
| 58 | 58 |
| 59 virtual void Open(const std::string& port, | 59 virtual void Open(const std::string& port, |
| 60 const OpenCompleteCallback& callback) OVERRIDE { | 60 const OpenCompleteCallback& callback) OVERRIDE { |
| 61 DCHECK(!opened_); | 61 DCHECK(!opened_); |
| 62 opened_ = true; | 62 opened_ = true; |
| 63 callback.Run(true); | 63 callback.Run(true); |
| 64 } | 64 } |
| 65 | 65 |
| 66 virtual bool ConfigurePort( | 66 virtual bool ConfigurePort( |
| 67 const api::serial::ConnectionOptions& options) OVERRIDE { | 67 const device::ConnectionOptions& options) OVERRIDE { |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 | 70 |
| 71 virtual void ReadImpl() OVERRIDE {} | 71 virtual void ReadImpl() OVERRIDE {} |
| 72 | 72 |
| 73 virtual void CancelReadImpl() OVERRIDE { | 73 virtual void CancelReadImpl() OVERRIDE { |
| 74 QueueReadCompleted(0, read_cancel_reason()); | 74 QueueReadCompleted(0, read_cancel_reason()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 virtual void WriteImpl() OVERRIDE { | 77 virtual void WriteImpl() OVERRIDE { |
| 78 DCHECK(pending_read_buffer()); | 78 DCHECK(pending_read_buffer()); |
| 79 DCHECK_LE(pending_write_buffer_len(), pending_read_buffer_len()); | 79 DCHECK_LE(pending_write_buffer_len(), pending_read_buffer_len()); |
| 80 memcpy(pending_read_buffer()->data(), | 80 memcpy(pending_read_buffer()->data(), |
| 81 pending_write_buffer()->data(), | 81 pending_write_buffer()->data(), |
| 82 pending_write_buffer_len()); | 82 pending_write_buffer_len()); |
| 83 QueueReadCompleted(pending_write_buffer_len(), | 83 QueueReadCompleted(pending_write_buffer_len(), device::RECEIVE_ERROR_NONE); |
| 84 api::serial::RECEIVE_ERROR_NONE); | 84 QueueWriteCompleted(pending_write_buffer_len(), device::SEND_ERROR_NONE); |
| 85 QueueWriteCompleted(pending_write_buffer_len(), | |
| 86 api::serial::SEND_ERROR_NONE); | |
| 87 } | 85 } |
| 88 | 86 |
| 89 virtual void CancelWriteImpl() OVERRIDE { | 87 virtual void CancelWriteImpl() OVERRIDE { |
| 90 QueueWriteCompleted(0, write_cancel_reason()); | 88 QueueWriteCompleted(0, write_cancel_reason()); |
| 91 } | 89 } |
| 92 | 90 |
| 93 virtual bool GetControlSignals( | 91 virtual device::DeviceControlSignalsPtr GetControlSignals() const OVERRIDE { |
| 94 api::serial::DeviceControlSignals* signals) const OVERRIDE { | 92 device::DeviceControlSignalsPtr signals( |
| 93 device::DeviceControlSignals::New()); |
| 95 signals->dcd = true; | 94 signals->dcd = true; |
| 96 signals->cts = true; | 95 signals->cts = true; |
| 97 signals->ri = true; | 96 signals->ri = true; |
| 98 signals->dsr = true; | 97 signals->dsr = true; |
| 99 return true; | 98 return signals.Pass(); |
| 100 } | 99 } |
| 101 | 100 |
| 102 virtual bool GetPortInfo(api::serial::ConnectionInfo* info) const OVERRIDE { | 101 virtual device::ConnectionInfoPtr GetPortInfo() const OVERRIDE { |
| 103 info->bitrate.reset(new int(9600)); | 102 device::ConnectionInfoPtr info(device::ConnectionInfo::New()); |
| 104 info->data_bits = api::serial::DATA_BITS_EIGHT; | 103 info->bitrate = 9600; |
| 105 info->parity_bit = api::serial::PARITY_BIT_NO; | 104 info->data_bits = device::DATA_BITS_EIGHT; |
| 106 info->stop_bits = api::serial::STOP_BITS_ONE; | 105 info->parity_bit = device::PARITY_BIT_NO; |
| 107 info->cts_flow_control.reset(new bool(false)); | 106 info->stop_bits = device::STOP_BITS_ONE; |
| 108 return true; | 107 info->cts_flow_control = false; |
| 108 return info.Pass(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 virtual bool Flush() const OVERRIDE { return true; } | 111 virtual bool Flush() const OVERRIDE { return true; } |
| 112 | 112 |
| 113 MOCK_METHOD1(SetControlSignals, bool(const api::serial::HostControlSignals&)); | 113 MOCK_METHOD1(SetControlSignals, bool(const device::HostControlSignals&)); |
| 114 | 114 |
| 115 protected: | 115 protected: |
| 116 virtual ~FakeEchoSerialIoHandler() {} | 116 virtual ~FakeEchoSerialIoHandler() {} |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 bool opened_; | 119 bool opened_; |
| 120 | 120 |
| 121 DISALLOW_COPY_AND_ASSIGN(FakeEchoSerialIoHandler); | 121 DISALLOW_COPY_AND_ASSIGN(FakeEchoSerialIoHandler); |
| 122 }; | 122 }; |
| 123 | 123 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 183 |
| 184 ASSERT_TRUE(RunExtensionTest("serial/api")) << message_; | 184 ASSERT_TRUE(RunExtensionTest("serial/api")) << message_; |
| 185 } | 185 } |
| 186 | 186 |
| 187 IN_PROC_BROWSER_TEST_F(SerialApiTest, SerialRealHardware) { | 187 IN_PROC_BROWSER_TEST_F(SerialApiTest, SerialRealHardware) { |
| 188 ResultCatcher catcher; | 188 ResultCatcher catcher; |
| 189 catcher.RestrictToProfile(browser()->profile()); | 189 catcher.RestrictToProfile(browser()->profile()); |
| 190 | 190 |
| 191 ASSERT_TRUE(RunExtensionTest("serial/real_hardware")) << message_; | 191 ASSERT_TRUE(RunExtensionTest("serial/real_hardware")) << message_; |
| 192 } | 192 } |
| OLD | NEW |