| 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 "device/serial/serial_device_enumerator.h" | 5 #include "device/serial/serial_device_enumerator.h" |
| 6 #include "device/serial/serial_service_impl.h" | 6 #include "device/serial/serial_service_impl.h" |
| 7 #include "device/serial/test_serial_io_handler.h" | 7 #include "device/serial/test_serial_io_handler.h" |
| 8 #include "extensions/common/mojo/keep_alive.mojom.h" | 8 #include "extensions/common/mojo/keep_alive.mojom.h" |
| 9 #include "extensions/renderer/api_test_base.h" | 9 #include "extensions/renderer/api_test_base.h" |
| 10 #include "grit/extensions_renderer_resources.h" | 10 #include "grit/extensions_renderer_resources.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 169 |
| 170 private: | 170 private: |
| 171 ~GetControlSignalsTestIoHandler() override {} | 171 ~GetControlSignalsTestIoHandler() override {} |
| 172 | 172 |
| 173 DISALLOW_COPY_AND_ASSIGN(GetControlSignalsTestIoHandler); | 173 DISALLOW_COPY_AND_ASSIGN(GetControlSignalsTestIoHandler); |
| 174 }; | 174 }; |
| 175 | 175 |
| 176 class ConfigurePortTestIoHandler : public TestIoHandlerBase { | 176 class ConfigurePortTestIoHandler : public TestIoHandlerBase { |
| 177 public: | 177 public: |
| 178 ConfigurePortTestIoHandler() {} | 178 ConfigurePortTestIoHandler() {} |
| 179 bool ConfigurePort( | 179 bool ConfigurePortImpl() override { |
| 180 const device::serial::ConnectionOptions& options) override { | |
| 181 static const device::serial::ConnectionOptions expected_options[] = { | 180 static const device::serial::ConnectionOptions expected_options[] = { |
| 181 // Each JavaScript call to chrome.serial.update only modifies a single |
| 182 // property of the connection however this function can only check the |
| 183 // final value of all options. The modified option is marked with "set". |
| 182 GenerateConnectionOptions(9600, | 184 GenerateConnectionOptions(9600, |
| 183 device::serial::DATA_BITS_EIGHT, | 185 device::serial::DATA_BITS_EIGHT, |
| 184 device::serial::PARITY_BIT_NO, | 186 device::serial::PARITY_BIT_NO, |
| 185 device::serial::STOP_BITS_ONE, | 187 device::serial::STOP_BITS_ONE, |
| 186 OPTIONAL_VALUE_FALSE), | 188 OPTIONAL_VALUE_FALSE), |
| 189 GenerateConnectionOptions(57600, // set |
| 190 device::serial::DATA_BITS_EIGHT, |
| 191 device::serial::PARITY_BIT_NO, |
| 192 device::serial::STOP_BITS_ONE, |
| 193 OPTIONAL_VALUE_FALSE), |
| 187 GenerateConnectionOptions(57600, | 194 GenerateConnectionOptions(57600, |
| 188 device::serial::DATA_BITS_NONE, | 195 device::serial::DATA_BITS_SEVEN, // set |
| 189 device::serial::PARITY_BIT_NONE, | 196 device::serial::PARITY_BIT_NO, |
| 190 device::serial::STOP_BITS_NONE, | 197 device::serial::STOP_BITS_ONE, |
| 191 OPTIONAL_VALUE_UNSET), | 198 OPTIONAL_VALUE_FALSE), |
| 192 GenerateConnectionOptions(0, | 199 GenerateConnectionOptions(57600, |
| 193 device::serial::DATA_BITS_SEVEN, | 200 device::serial::DATA_BITS_EIGHT, // set |
| 194 device::serial::PARITY_BIT_NONE, | 201 device::serial::PARITY_BIT_NO, |
| 195 device::serial::STOP_BITS_NONE, | 202 device::serial::STOP_BITS_ONE, |
| 196 OPTIONAL_VALUE_UNSET), | 203 OPTIONAL_VALUE_FALSE), |
| 197 GenerateConnectionOptions(0, | 204 GenerateConnectionOptions(57600, |
| 198 device::serial::DATA_BITS_EIGHT, | 205 device::serial::DATA_BITS_EIGHT, |
| 199 device::serial::PARITY_BIT_NONE, | 206 device::serial::PARITY_BIT_NO, // set |
| 200 device::serial::STOP_BITS_NONE, | 207 device::serial::STOP_BITS_ONE, |
| 201 OPTIONAL_VALUE_UNSET), | 208 OPTIONAL_VALUE_FALSE), |
| 202 GenerateConnectionOptions(0, | 209 GenerateConnectionOptions(57600, |
| 203 device::serial::DATA_BITS_NONE, | 210 device::serial::DATA_BITS_EIGHT, |
| 204 device::serial::PARITY_BIT_NO, | 211 device::serial::PARITY_BIT_ODD, // set |
| 205 device::serial::STOP_BITS_NONE, | 212 device::serial::STOP_BITS_ONE, |
| 206 OPTIONAL_VALUE_UNSET), | 213 OPTIONAL_VALUE_FALSE), |
| 207 GenerateConnectionOptions(0, | 214 GenerateConnectionOptions(57600, |
| 208 device::serial::DATA_BITS_NONE, | 215 device::serial::DATA_BITS_EIGHT, |
| 209 device::serial::PARITY_BIT_ODD, | 216 device::serial::PARITY_BIT_EVEN, // set |
| 210 device::serial::STOP_BITS_NONE, | 217 device::serial::STOP_BITS_ONE, |
| 211 OPTIONAL_VALUE_UNSET), | 218 OPTIONAL_VALUE_FALSE), |
| 212 GenerateConnectionOptions(0, | 219 GenerateConnectionOptions(57600, |
| 213 device::serial::DATA_BITS_NONE, | 220 device::serial::DATA_BITS_EIGHT, |
| 214 device::serial::PARITY_BIT_EVEN, | 221 device::serial::PARITY_BIT_EVEN, |
| 215 device::serial::STOP_BITS_NONE, | 222 device::serial::STOP_BITS_ONE, // set |
| 216 OPTIONAL_VALUE_UNSET), | 223 OPTIONAL_VALUE_FALSE), |
| 217 GenerateConnectionOptions(0, | 224 GenerateConnectionOptions(57600, |
| 218 device::serial::DATA_BITS_NONE, | 225 device::serial::DATA_BITS_EIGHT, |
| 219 device::serial::PARITY_BIT_NONE, | 226 device::serial::PARITY_BIT_EVEN, |
| 220 device::serial::STOP_BITS_ONE, | 227 device::serial::STOP_BITS_TWO, // set |
| 221 OPTIONAL_VALUE_UNSET), | 228 OPTIONAL_VALUE_FALSE), |
| 222 GenerateConnectionOptions(0, | 229 GenerateConnectionOptions(57600, |
| 223 device::serial::DATA_BITS_NONE, | 230 device::serial::DATA_BITS_EIGHT, |
| 224 device::serial::PARITY_BIT_NONE, | 231 device::serial::PARITY_BIT_EVEN, |
| 225 device::serial::STOP_BITS_TWO, | 232 device::serial::STOP_BITS_TWO, |
| 226 OPTIONAL_VALUE_UNSET), | 233 OPTIONAL_VALUE_FALSE), // set |
| 227 GenerateConnectionOptions(0, | 234 GenerateConnectionOptions(57600, |
| 228 device::serial::DATA_BITS_NONE, | 235 device::serial::DATA_BITS_EIGHT, |
| 229 device::serial::PARITY_BIT_NONE, | 236 device::serial::PARITY_BIT_EVEN, |
| 230 device::serial::STOP_BITS_NONE, | 237 device::serial::STOP_BITS_TWO, |
| 231 OPTIONAL_VALUE_FALSE), | 238 OPTIONAL_VALUE_TRUE), // set |
| 232 GenerateConnectionOptions(0, | |
| 233 device::serial::DATA_BITS_NONE, | |
| 234 device::serial::PARITY_BIT_NONE, | |
| 235 device::serial::STOP_BITS_NONE, | |
| 236 OPTIONAL_VALUE_TRUE), | |
| 237 }; | 239 }; |
| 238 if (num_calls() >= arraysize(expected_options)) | 240 |
| 241 if (!TestIoHandlerBase::ConfigurePortImpl()) { |
| 239 return false; | 242 return false; |
| 243 } |
| 240 | 244 |
| 241 EXPECT_EQ(expected_options[num_calls()].bitrate, options.bitrate); | 245 if (num_calls() >= arraysize(expected_options)) { |
| 242 EXPECT_EQ(expected_options[num_calls()].data_bits, options.data_bits); | 246 return false; |
| 243 EXPECT_EQ(expected_options[num_calls()].parity_bit, options.parity_bit); | 247 } |
| 244 EXPECT_EQ(expected_options[num_calls()].stop_bits, options.stop_bits); | 248 |
| 249 EXPECT_EQ(expected_options[num_calls()].bitrate, options().bitrate); |
| 250 EXPECT_EQ(expected_options[num_calls()].data_bits, options().data_bits); |
| 251 EXPECT_EQ(expected_options[num_calls()].parity_bit, options().parity_bit); |
| 252 EXPECT_EQ(expected_options[num_calls()].stop_bits, options().stop_bits); |
| 245 EXPECT_EQ(expected_options[num_calls()].has_cts_flow_control, | 253 EXPECT_EQ(expected_options[num_calls()].has_cts_flow_control, |
| 246 options.has_cts_flow_control); | 254 options().has_cts_flow_control); |
| 247 EXPECT_EQ(expected_options[num_calls()].cts_flow_control, | 255 EXPECT_EQ(expected_options[num_calls()].cts_flow_control, |
| 248 options.cts_flow_control); | 256 options().cts_flow_control); |
| 249 record_call(); | 257 record_call(); |
| 250 return TestSerialIoHandler::ConfigurePort(options); | 258 return true; |
| 251 } | 259 } |
| 252 | 260 |
| 253 private: | 261 private: |
| 254 ~ConfigurePortTestIoHandler() override {} | 262 ~ConfigurePortTestIoHandler() override {} |
| 255 | 263 |
| 256 DISALLOW_COPY_AND_ASSIGN(ConfigurePortTestIoHandler); | 264 DISALLOW_COPY_AND_ASSIGN(ConfigurePortTestIoHandler); |
| 257 }; | 265 }; |
| 258 | 266 |
| 259 class FlushTestIoHandler : public TestIoHandlerBase { | 267 class FlushTestIoHandler : public TestIoHandlerBase { |
| 260 public: | 268 public: |
| 261 FlushTestIoHandler() {} | 269 FlushTestIoHandler() {} |
| 262 | 270 |
| 263 bool Flush() const override { | 271 bool Flush() const override { |
| 264 record_call(); | 272 record_call(); |
| 265 return true; | 273 return true; |
| 266 } | 274 } |
| 267 | 275 |
| 268 private: | 276 private: |
| 269 ~FlushTestIoHandler() override {} | 277 ~FlushTestIoHandler() override {} |
| 270 | 278 |
| 271 DISALLOW_COPY_AND_ASSIGN(FlushTestIoHandler); | 279 DISALLOW_COPY_AND_ASSIGN(FlushTestIoHandler); |
| 272 }; | 280 }; |
| 273 | 281 |
| 274 class FailToConnectTestIoHandler : public TestIoHandlerBase { | 282 class FailToConnectTestIoHandler : public TestIoHandlerBase { |
| 275 public: | 283 public: |
| 276 FailToConnectTestIoHandler() {} | 284 FailToConnectTestIoHandler() {} |
| 277 void Open(const std::string& port, | 285 void Open(const std::string& port, |
| 286 const device::serial::ConnectionOptions& options, |
| 278 const OpenCompleteCallback& callback) override { | 287 const OpenCompleteCallback& callback) override { |
| 279 callback.Run(false); | 288 callback.Run(false); |
| 280 return; | 289 return; |
| 281 } | 290 } |
| 282 | 291 |
| 283 private: | 292 private: |
| 284 ~FailToConnectTestIoHandler() override {} | 293 ~FailToConnectTestIoHandler() override {} |
| 285 | 294 |
| 286 DISALLOW_COPY_AND_ASSIGN(FailToConnectTestIoHandler); | 295 DISALLOW_COPY_AND_ASSIGN(FailToConnectTestIoHandler); |
| 287 }; | 296 }; |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 | 634 |
| 626 TEST_F(SerialApiTest, SetPausedUnknownConnectionId) { | 635 TEST_F(SerialApiTest, SetPausedUnknownConnectionId) { |
| 627 RunTest("serial_unittest.js", "testSetPausedUnknownConnectionId"); | 636 RunTest("serial_unittest.js", "testSetPausedUnknownConnectionId"); |
| 628 } | 637 } |
| 629 | 638 |
| 630 TEST_F(SerialApiTest, SendUnknownConnectionId) { | 639 TEST_F(SerialApiTest, SendUnknownConnectionId) { |
| 631 RunTest("serial_unittest.js", "testSendUnknownConnectionId"); | 640 RunTest("serial_unittest.js", "testSendUnknownConnectionId"); |
| 632 } | 641 } |
| 633 | 642 |
| 634 } // namespace extensions | 643 } // namespace extensions |
| OLD | NEW |