summaryrefslogtreecommitdiffstats
path: root/extensions/renderer/api
diff options
context:
space:
mode:
authorreillyg <reillyg@chromium.org>2015-01-28 15:08:23 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-28 23:10:00 +0000
commitea2760c173e70ddcdcc64e0522a93d6a08785cae (patch)
treed8c05c1f8a012ea750cdd16252c5e2d047c715b3 /extensions/renderer/api
parent4867d6cc021aca57e5a327b7ca8ed365485c0caa (diff)
downloadchromium_src-ea2760c173e70ddcdcc64e0522a93d6a08785cae.zip
chromium_src-ea2760c173e70ddcdcc64e0522a93d6a08785cae.tar.gz
chromium_src-ea2760c173e70ddcdcc64e0522a93d6a08785cae.tar.bz2
Set serial connection parameters immediately on connect.
This change merges the initial call to SetCommState/tcsetattr with the call to ConfigurePort so that parameters such as baud rate are configured immediately when the port is opened. Default values for these parameters are now always applied. This works around an issue with some serial adapter drivers on Windows that report an invalid baud rate through GetCommState. Having the intended baud rate available for the first call to SetCommState allows an application to provide a valid value so that Chrome does not have to guess. BUG=448407 Review URL: https://codereview.chromium.org/873903002 Cr-Commit-Position: refs/heads/master@{#313604}
Diffstat (limited to 'extensions/renderer/api')
-rw-r--r--extensions/renderer/api/serial/serial_api_unittest.cc121
1 files changed, 65 insertions, 56 deletions
diff --git a/extensions/renderer/api/serial/serial_api_unittest.cc b/extensions/renderer/api/serial/serial_api_unittest.cc
index 36cbe45..81c5c35 100644
--- a/extensions/renderer/api/serial/serial_api_unittest.cc
+++ b/extensions/renderer/api/serial/serial_api_unittest.cc
@@ -176,78 +176,86 @@ class GetControlSignalsTestIoHandler : public TestIoHandlerBase {
class ConfigurePortTestIoHandler : public TestIoHandlerBase {
public:
ConfigurePortTestIoHandler() {}
- bool ConfigurePort(
- const device::serial::ConnectionOptions& options) override {
+ bool ConfigurePortImpl() override {
static const device::serial::ConnectionOptions expected_options[] = {
+ // Each JavaScript call to chrome.serial.update only modifies a single
+ // property of the connection however this function can only check the
+ // final value of all options. The modified option is marked with "set".
GenerateConnectionOptions(9600,
device::serial::DATA_BITS_EIGHT,
device::serial::PARITY_BIT_NO,
device::serial::STOP_BITS_ONE,
OPTIONAL_VALUE_FALSE),
- GenerateConnectionOptions(57600,
- device::serial::DATA_BITS_NONE,
- device::serial::PARITY_BIT_NONE,
- device::serial::STOP_BITS_NONE,
- OPTIONAL_VALUE_UNSET),
- GenerateConnectionOptions(0,
- device::serial::DATA_BITS_SEVEN,
- device::serial::PARITY_BIT_NONE,
- device::serial::STOP_BITS_NONE,
- OPTIONAL_VALUE_UNSET),
- GenerateConnectionOptions(0,
+ GenerateConnectionOptions(57600, // set
device::serial::DATA_BITS_EIGHT,
- device::serial::PARITY_BIT_NONE,
- device::serial::STOP_BITS_NONE,
- OPTIONAL_VALUE_UNSET),
- GenerateConnectionOptions(0,
- device::serial::DATA_BITS_NONE,
device::serial::PARITY_BIT_NO,
- device::serial::STOP_BITS_NONE,
- OPTIONAL_VALUE_UNSET),
- GenerateConnectionOptions(0,
- device::serial::DATA_BITS_NONE,
- device::serial::PARITY_BIT_ODD,
- device::serial::STOP_BITS_NONE,
- OPTIONAL_VALUE_UNSET),
- GenerateConnectionOptions(0,
- device::serial::DATA_BITS_NONE,
- device::serial::PARITY_BIT_EVEN,
- device::serial::STOP_BITS_NONE,
- OPTIONAL_VALUE_UNSET),
- GenerateConnectionOptions(0,
- device::serial::DATA_BITS_NONE,
- device::serial::PARITY_BIT_NONE,
device::serial::STOP_BITS_ONE,
- OPTIONAL_VALUE_UNSET),
- GenerateConnectionOptions(0,
- device::serial::DATA_BITS_NONE,
- device::serial::PARITY_BIT_NONE,
- device::serial::STOP_BITS_TWO,
- OPTIONAL_VALUE_UNSET),
- GenerateConnectionOptions(0,
- device::serial::DATA_BITS_NONE,
- device::serial::PARITY_BIT_NONE,
- device::serial::STOP_BITS_NONE,
OPTIONAL_VALUE_FALSE),
- GenerateConnectionOptions(0,
- device::serial::DATA_BITS_NONE,
- device::serial::PARITY_BIT_NONE,
- device::serial::STOP_BITS_NONE,
- OPTIONAL_VALUE_TRUE),
+ GenerateConnectionOptions(57600,
+ device::serial::DATA_BITS_SEVEN, // set
+ device::serial::PARITY_BIT_NO,
+ device::serial::STOP_BITS_ONE,
+ OPTIONAL_VALUE_FALSE),
+ GenerateConnectionOptions(57600,
+ device::serial::DATA_BITS_EIGHT, // set
+ device::serial::PARITY_BIT_NO,
+ device::serial::STOP_BITS_ONE,
+ OPTIONAL_VALUE_FALSE),
+ GenerateConnectionOptions(57600,
+ device::serial::DATA_BITS_EIGHT,
+ device::serial::PARITY_BIT_NO, // set
+ device::serial::STOP_BITS_ONE,
+ OPTIONAL_VALUE_FALSE),
+ GenerateConnectionOptions(57600,
+ device::serial::DATA_BITS_EIGHT,
+ device::serial::PARITY_BIT_ODD, // set
+ device::serial::STOP_BITS_ONE,
+ OPTIONAL_VALUE_FALSE),
+ GenerateConnectionOptions(57600,
+ device::serial::DATA_BITS_EIGHT,
+ device::serial::PARITY_BIT_EVEN, // set
+ device::serial::STOP_BITS_ONE,
+ OPTIONAL_VALUE_FALSE),
+ GenerateConnectionOptions(57600,
+ device::serial::DATA_BITS_EIGHT,
+ device::serial::PARITY_BIT_EVEN,
+ device::serial::STOP_BITS_ONE, // set
+ OPTIONAL_VALUE_FALSE),
+ GenerateConnectionOptions(57600,
+ device::serial::DATA_BITS_EIGHT,
+ device::serial::PARITY_BIT_EVEN,
+ device::serial::STOP_BITS_TWO, // set
+ OPTIONAL_VALUE_FALSE),
+ GenerateConnectionOptions(57600,
+ device::serial::DATA_BITS_EIGHT,
+ device::serial::PARITY_BIT_EVEN,
+ device::serial::STOP_BITS_TWO,
+ OPTIONAL_VALUE_FALSE), // set
+ GenerateConnectionOptions(57600,
+ device::serial::DATA_BITS_EIGHT,
+ device::serial::PARITY_BIT_EVEN,
+ device::serial::STOP_BITS_TWO,
+ OPTIONAL_VALUE_TRUE), // set
};
- if (num_calls() >= arraysize(expected_options))
+
+ if (!TestIoHandlerBase::ConfigurePortImpl()) {
return false;
+ }
- EXPECT_EQ(expected_options[num_calls()].bitrate, options.bitrate);
- EXPECT_EQ(expected_options[num_calls()].data_bits, options.data_bits);
- EXPECT_EQ(expected_options[num_calls()].parity_bit, options.parity_bit);
- EXPECT_EQ(expected_options[num_calls()].stop_bits, options.stop_bits);
+ if (num_calls() >= arraysize(expected_options)) {
+ return false;
+ }
+
+ EXPECT_EQ(expected_options[num_calls()].bitrate, options().bitrate);
+ EXPECT_EQ(expected_options[num_calls()].data_bits, options().data_bits);
+ EXPECT_EQ(expected_options[num_calls()].parity_bit, options().parity_bit);
+ EXPECT_EQ(expected_options[num_calls()].stop_bits, options().stop_bits);
EXPECT_EQ(expected_options[num_calls()].has_cts_flow_control,
- options.has_cts_flow_control);
+ options().has_cts_flow_control);
EXPECT_EQ(expected_options[num_calls()].cts_flow_control,
- options.cts_flow_control);
+ options().cts_flow_control);
record_call();
- return TestSerialIoHandler::ConfigurePort(options);
+ return true;
}
private:
@@ -275,6 +283,7 @@ class FailToConnectTestIoHandler : public TestIoHandlerBase {
public:
FailToConnectTestIoHandler() {}
void Open(const std::string& port,
+ const device::serial::ConnectionOptions& options,
const OpenCompleteCallback& callback) override {
callback.Run(false);
return;