OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 93 } |
94 | 94 |
95 virtual bool GetControlSignals(api::serial::ControlSignals* signals) const { | 95 virtual bool GetControlSignals(api::serial::ControlSignals* signals) const { |
96 signals->dcd.reset(new bool(true)); | 96 signals->dcd.reset(new bool(true)); |
97 signals->cts.reset(new bool(true)); | 97 signals->cts.reset(new bool(true)); |
98 signals->dtr.reset(new bool(true)); | 98 signals->dtr.reset(new bool(true)); |
99 signals->ri.reset(new bool(true)); | 99 signals->ri.reset(new bool(true)); |
100 return true; | 100 return true; |
101 } | 101 } |
102 | 102 |
| 103 virtual bool GetInfo(api::serial::ConnectionInfo* info) const { |
| 104 info->paused = false; |
| 105 info->persistent = false; |
| 106 info->buffer_size = 4096; |
| 107 info->receive_timeout = 0; |
| 108 info->send_timeout = 0; |
| 109 info->bitrate.reset(new int(9600)); |
| 110 info->data_bits = api::serial::DATA_BITS_EIGHT; |
| 111 info->parity_bit = api::serial::PARITY_BIT_NO; |
| 112 info->stop_bits = api::serial::STOP_BITS_ONE; |
| 113 info->cts_flow_control.reset(new bool(false)); |
| 114 return true; |
| 115 } |
| 116 |
103 MOCK_METHOD1(SetControlSignals, bool(const api::serial::ControlSignals&)); | 117 MOCK_METHOD1(SetControlSignals, bool(const api::serial::ControlSignals&)); |
104 | 118 |
105 private: | 119 private: |
106 bool opened_; | 120 bool opened_; |
107 ReceiveCompleteCallback read_callback_; | 121 ReceiveCompleteCallback read_callback_; |
108 | 122 |
109 DISALLOW_COPY_AND_ASSIGN(FakeEchoSerialConnection); | 123 DISALLOW_COPY_AND_ASSIGN(FakeEchoSerialConnection); |
110 }; | 124 }; |
111 | 125 |
112 class FakeSerialOpenFunction : public api::SerialOpenFunction { | 126 class FakeSerialConnectFunction : public api::SerialConnectFunction { |
113 protected: | 127 protected: |
114 virtual SerialConnection* CreateSerialConnection( | 128 virtual SerialConnection* CreateSerialConnection( |
115 const std::string& port, | 129 const std::string& port, |
116 const std::string& owner_extension_id) const OVERRIDE { | 130 const std::string& owner_extension_id) const OVERRIDE { |
117 FakeEchoSerialConnection* serial_connection = | 131 FakeEchoSerialConnection* serial_connection = |
118 new FakeEchoSerialConnection(port, owner_extension_id); | 132 new FakeEchoSerialConnection(port, owner_extension_id); |
119 EXPECT_CALL(*serial_connection, SetControlSignals(_)). | 133 EXPECT_CALL(*serial_connection, SetControlSignals(_)). |
120 Times(1).WillOnce(Return(true)); | 134 Times(1).WillOnce(Return(true)); |
121 return serial_connection; | 135 return serial_connection; |
122 } | 136 } |
123 | 137 |
124 protected: | 138 protected: |
125 virtual ~FakeSerialOpenFunction() {} | 139 virtual ~FakeSerialConnectFunction() {} |
126 }; | 140 }; |
127 | 141 |
128 } // namespace extensions | 142 } // namespace extensions |
129 | 143 |
130 ExtensionFunction* FakeSerialGetDevicesFunctionFactory() { | 144 ExtensionFunction* FakeSerialGetDevicesFunctionFactory() { |
131 return new extensions::FakeSerialGetDevicesFunction(); | 145 return new extensions::FakeSerialGetDevicesFunction(); |
132 } | 146 } |
133 | 147 |
134 ExtensionFunction* FakeSerialOpenFunctionFactory() { | 148 ExtensionFunction* FakeSerialConnectFunctionFactory() { |
135 return new extensions::FakeSerialOpenFunction(); | 149 return new extensions::FakeSerialConnectFunction(); |
136 } | 150 } |
137 | 151 |
138 // Disable SIMULATE_SERIAL_PORTS only if all the following are true: | 152 // Disable SIMULATE_SERIAL_PORTS only if all the following are true: |
139 // | 153 // |
140 // 1. You have an Arduino or compatible board attached to your machine and | 154 // 1. You have an Arduino or compatible board attached to your machine and |
141 // properly appearing as the first virtual serial port ("first" is very loosely | 155 // properly appearing as the first virtual serial port ("first" is very loosely |
142 // defined as whichever port shows up in serial.getPorts). We've tested only | 156 // defined as whichever port shows up in serial.getPorts). We've tested only |
143 // the Atmega32u4 Breakout Board and Arduino Leonardo; note that both these | 157 // the Atmega32u4 Breakout Board and Arduino Leonardo; note that both these |
144 // boards are based on the Atmel ATmega32u4, rather than the more common | 158 // boards are based on the Atmel ATmega32u4, rather than the more common |
145 // Arduino '328p with either FTDI or '8/16u2 USB interfaces. TODO: test more | 159 // Arduino '328p with either FTDI or '8/16u2 USB interfaces. TODO: test more |
(...skipping 11 matching lines...) Expand all Loading... |
157 #define SIMULATE_SERIAL_PORTS (1) | 171 #define SIMULATE_SERIAL_PORTS (1) |
158 IN_PROC_BROWSER_TEST_F(SerialApiTest, SerialFakeHardware) { | 172 IN_PROC_BROWSER_TEST_F(SerialApiTest, SerialFakeHardware) { |
159 ResultCatcher catcher; | 173 ResultCatcher catcher; |
160 catcher.RestrictToProfile(browser()->profile()); | 174 catcher.RestrictToProfile(browser()->profile()); |
161 | 175 |
162 #if SIMULATE_SERIAL_PORTS | 176 #if SIMULATE_SERIAL_PORTS |
163 ASSERT_TRUE(ExtensionFunctionDispatcher::OverrideFunction( | 177 ASSERT_TRUE(ExtensionFunctionDispatcher::OverrideFunction( |
164 "serial.getDevices", | 178 "serial.getDevices", |
165 FakeSerialGetDevicesFunctionFactory)); | 179 FakeSerialGetDevicesFunctionFactory)); |
166 ASSERT_TRUE(ExtensionFunctionDispatcher::OverrideFunction( | 180 ASSERT_TRUE(ExtensionFunctionDispatcher::OverrideFunction( |
167 "serial.open", | 181 "serial.connect", |
168 FakeSerialOpenFunctionFactory)); | 182 FakeSerialConnectFunctionFactory)); |
169 #endif | 183 #endif |
170 | 184 |
171 ASSERT_TRUE(RunExtensionTest("serial/api")) << message_; | 185 ASSERT_TRUE(RunExtensionTest("serial/api")) << message_; |
172 } | 186 } |
173 | 187 |
174 IN_PROC_BROWSER_TEST_F(SerialApiTest, SerialRealHardware) { | 188 IN_PROC_BROWSER_TEST_F(SerialApiTest, SerialRealHardware) { |
175 ResultCatcher catcher; | 189 ResultCatcher catcher; |
176 catcher.RestrictToProfile(browser()->profile()); | 190 catcher.RestrictToProfile(browser()->profile()); |
177 | 191 |
178 ASSERT_TRUE(RunExtensionTest("serial/real_hardware")) << message_; | 192 ASSERT_TRUE(RunExtensionTest("serial/real_hardware")) << message_; |
179 } | 193 } |
OLD | NEW |