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::serial::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(), |
84 api::serial::RECEIVE_ERROR_NONE); | 84 device::serial::RECEIVE_ERROR_NONE); |
85 QueueWriteCompleted(pending_write_buffer_len(), | 85 QueueWriteCompleted(pending_write_buffer_len(), |
86 api::serial::SEND_ERROR_NONE); | 86 device::serial::SEND_ERROR_NONE); |
87 } | 87 } |
88 | 88 |
89 virtual void CancelWriteImpl() OVERRIDE { | 89 virtual void CancelWriteImpl() OVERRIDE { |
90 QueueWriteCompleted(0, write_cancel_reason()); | 90 QueueWriteCompleted(0, write_cancel_reason()); |
91 } | 91 } |
92 | 92 |
93 virtual bool GetControlSignals( | 93 virtual device::serial::DeviceControlSignalsPtr GetControlSignals() |
94 api::serial::DeviceControlSignals* signals) const OVERRIDE { | 94 const OVERRIDE { |
| 95 device::serial::DeviceControlSignalsPtr signals( |
| 96 device::serial::DeviceControlSignals::New()); |
95 signals->dcd = true; | 97 signals->dcd = true; |
96 signals->cts = true; | 98 signals->cts = true; |
97 signals->ri = true; | 99 signals->ri = true; |
98 signals->dsr = true; | 100 signals->dsr = true; |
99 return true; | 101 return signals.Pass(); |
100 } | 102 } |
101 | 103 |
102 virtual bool GetPortInfo(api::serial::ConnectionInfo* info) const OVERRIDE { | 104 virtual device::serial::ConnectionInfoPtr GetPortInfo() const OVERRIDE { |
103 info->bitrate.reset(new int(9600)); | 105 device::serial::ConnectionInfoPtr info( |
104 info->data_bits = api::serial::DATA_BITS_EIGHT; | 106 device::serial::ConnectionInfo::New()); |
105 info->parity_bit = api::serial::PARITY_BIT_NO; | 107 info->bitrate = 9600; |
106 info->stop_bits = api::serial::STOP_BITS_ONE; | 108 info->data_bits = device::serial::DATA_BITS_EIGHT; |
107 info->cts_flow_control.reset(new bool(false)); | 109 info->parity_bit = device::serial::PARITY_BIT_NO; |
108 return true; | 110 info->stop_bits = device::serial::STOP_BITS_ONE; |
| 111 info->cts_flow_control = false; |
| 112 return info.Pass(); |
109 } | 113 } |
110 | 114 |
111 virtual bool Flush() const OVERRIDE { return true; } | 115 virtual bool Flush() const OVERRIDE { return true; } |
112 | 116 |
113 MOCK_METHOD1(SetControlSignals, bool(const api::serial::HostControlSignals&)); | 117 MOCK_METHOD1(SetControlSignals, |
| 118 bool(const device::serial::HostControlSignals&)); |
114 | 119 |
115 protected: | 120 protected: |
116 virtual ~FakeEchoSerialIoHandler() {} | 121 virtual ~FakeEchoSerialIoHandler() {} |
117 | 122 |
118 private: | 123 private: |
119 bool opened_; | 124 bool opened_; |
120 | 125 |
121 DISALLOW_COPY_AND_ASSIGN(FakeEchoSerialIoHandler); | 126 DISALLOW_COPY_AND_ASSIGN(FakeEchoSerialIoHandler); |
122 }; | 127 }; |
123 | 128 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 188 |
184 ASSERT_TRUE(RunExtensionTest("serial/api")) << message_; | 189 ASSERT_TRUE(RunExtensionTest("serial/api")) << message_; |
185 } | 190 } |
186 | 191 |
187 IN_PROC_BROWSER_TEST_F(SerialApiTest, SerialRealHardware) { | 192 IN_PROC_BROWSER_TEST_F(SerialApiTest, SerialRealHardware) { |
188 ResultCatcher catcher; | 193 ResultCatcher catcher; |
189 catcher.RestrictToProfile(browser()->profile()); | 194 catcher.RestrictToProfile(browser()->profile()); |
190 | 195 |
191 ASSERT_TRUE(RunExtensionTest("serial/real_hardware")) << message_; | 196 ASSERT_TRUE(RunExtensionTest("serial/real_hardware")) << message_; |
192 } | 197 } |
OLD | NEW |