Home | History | Annotate | Download | only in serial
      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
      3 // found in the LICENSE file.
      4 
      5 #include "device/serial/serial_device_enumerator.h"
      6 #include "device/serial/serial_service_impl.h"
      7 #include "device/serial/test_serial_io_handler.h"
      8 #include "extensions/renderer/api_test_base.h"
      9 #include "grit/extensions_renderer_resources.h"
     10 
     11 // A test launcher for tests for the serial API defined in
     12 // extensions/test/data/serial_unittest.js. Each C++ test function sets up a
     13 // fake DeviceEnumerator or SerialIoHandler expecting or returning particular
     14 // values for that test.
     15 
     16 namespace extensions {
     17 
     18 namespace {
     19 
     20 class FakeSerialDeviceEnumerator : public device::SerialDeviceEnumerator {
     21   virtual mojo::Array<device::serial::DeviceInfoPtr> GetDevices() OVERRIDE {
     22     mojo::Array<device::serial::DeviceInfoPtr> result(3);
     23     result[0] = device::serial::DeviceInfo::New();
     24     result[0]->path = "device";
     25     result[0]->vendor_id = 1234;
     26     result[0]->has_vendor_id = true;
     27     result[0]->product_id = 5678;
     28     result[0]->has_product_id = true;
     29     result[0]->display_name = "foo";
     30     result[1] = device::serial::DeviceInfo::New();
     31     result[1]->path = "another_device";
     32     // These IDs should be ignored.
     33     result[1]->vendor_id = 1234;
     34     result[1]->product_id = 5678;
     35     result[2] = device::serial::DeviceInfo::New();
     36     result[2]->path = "";
     37     result[2]->display_name = "";
     38     return result.Pass();
     39   }
     40 };
     41 
     42 enum OptionalValue {
     43   OPTIONAL_VALUE_UNSET,
     44   OPTIONAL_VALUE_FALSE,
     45   OPTIONAL_VALUE_TRUE,
     46 };
     47 
     48 device::serial::HostControlSignals GenerateControlSignals(OptionalValue dtr,
     49                                                           OptionalValue rts) {
     50   device::serial::HostControlSignals result;
     51   switch (dtr) {
     52     case OPTIONAL_VALUE_UNSET:
     53       break;
     54     case OPTIONAL_VALUE_FALSE:
     55       result.dtr = false;
     56       result.has_dtr = true;
     57       break;
     58     case OPTIONAL_VALUE_TRUE:
     59       result.dtr = true;
     60       result.has_dtr = true;
     61       break;
     62   }
     63   switch (rts) {
     64     case OPTIONAL_VALUE_UNSET:
     65       break;
     66     case OPTIONAL_VALUE_FALSE:
     67       result.rts = false;
     68       result.has_rts = true;
     69       break;
     70     case OPTIONAL_VALUE_TRUE:
     71       result.rts = true;
     72       result.has_rts = true;
     73       break;
     74   }
     75   return result;
     76 }
     77 
     78 device::serial::ConnectionOptions GenerateConnectionOptions(
     79     int bitrate,
     80     device::serial::DataBits data_bits,
     81     device::serial::ParityBit parity_bit,
     82     device::serial::StopBits stop_bits,
     83     OptionalValue cts_flow_control) {
     84   device::serial::ConnectionOptions result;
     85   result.bitrate = bitrate;
     86   result.data_bits = data_bits;
     87   result.parity_bit = parity_bit;
     88   result.stop_bits = stop_bits;
     89   switch (cts_flow_control) {
     90     case OPTIONAL_VALUE_UNSET:
     91       break;
     92     case OPTIONAL_VALUE_FALSE:
     93       result.cts_flow_control = false;
     94       result.has_cts_flow_control = true;
     95       break;
     96     case OPTIONAL_VALUE_TRUE:
     97       result.cts_flow_control = true;
     98       result.has_cts_flow_control = true;
     99       break;
    100   }
    101   return result;
    102 }
    103 
    104 class TestIoHandlerBase : public device::TestSerialIoHandler {
    105  public:
    106   TestIoHandlerBase() : calls_(0) {}
    107 
    108   size_t num_calls() const { return calls_; }
    109 
    110  protected:
    111   virtual ~TestIoHandlerBase() {}
    112   void record_call() const { calls_++; }
    113 
    114  private:
    115   mutable size_t calls_;
    116 
    117   DISALLOW_COPY_AND_ASSIGN(TestIoHandlerBase);
    118 };
    119 
    120 class SetControlSignalsTestIoHandler : public TestIoHandlerBase {
    121  public:
    122   SetControlSignalsTestIoHandler() {}
    123 
    124   virtual bool SetControlSignals(
    125       const device::serial::HostControlSignals& signals) OVERRIDE {
    126     static const device::serial::HostControlSignals expected_signals[] = {
    127         GenerateControlSignals(OPTIONAL_VALUE_UNSET, OPTIONAL_VALUE_UNSET),
    128         GenerateControlSignals(OPTIONAL_VALUE_FALSE, OPTIONAL_VALUE_UNSET),
    129         GenerateControlSignals(OPTIONAL_VALUE_TRUE, OPTIONAL_VALUE_UNSET),
    130         GenerateControlSignals(OPTIONAL_VALUE_UNSET, OPTIONAL_VALUE_FALSE),
    131         GenerateControlSignals(OPTIONAL_VALUE_FALSE, OPTIONAL_VALUE_FALSE),
    132         GenerateControlSignals(OPTIONAL_VALUE_TRUE, OPTIONAL_VALUE_FALSE),
    133         GenerateControlSignals(OPTIONAL_VALUE_UNSET, OPTIONAL_VALUE_TRUE),
    134         GenerateControlSignals(OPTIONAL_VALUE_FALSE, OPTIONAL_VALUE_TRUE),
    135         GenerateControlSignals(OPTIONAL_VALUE_TRUE, OPTIONAL_VALUE_TRUE),
    136     };
    137     if (num_calls() >= arraysize(expected_signals))
    138       return false;
    139 
    140     EXPECT_EQ(expected_signals[num_calls()].has_dtr, signals.has_dtr);
    141     EXPECT_EQ(expected_signals[num_calls()].dtr, signals.dtr);
    142     EXPECT_EQ(expected_signals[num_calls()].has_rts, signals.has_rts);
    143     EXPECT_EQ(expected_signals[num_calls()].rts, signals.rts);
    144     record_call();
    145     return true;
    146   }
    147 
    148  private:
    149   virtual ~SetControlSignalsTestIoHandler() {}
    150 
    151   DISALLOW_COPY_AND_ASSIGN(SetControlSignalsTestIoHandler);
    152 };
    153 
    154 class GetControlSignalsTestIoHandler : public TestIoHandlerBase {
    155  public:
    156   GetControlSignalsTestIoHandler() {}
    157 
    158   virtual device::serial::DeviceControlSignalsPtr GetControlSignals()
    159       const OVERRIDE {
    160     device::serial::DeviceControlSignalsPtr signals(
    161         device::serial::DeviceControlSignals::New());
    162     signals->dcd = num_calls() & 1;
    163     signals->cts = num_calls() & 2;
    164     signals->ri = num_calls() & 4;
    165     signals->dsr = num_calls() & 8;
    166     record_call();
    167     return signals.Pass();
    168   }
    169 
    170  private:
    171   virtual ~GetControlSignalsTestIoHandler() {}
    172 
    173   DISALLOW_COPY_AND_ASSIGN(GetControlSignalsTestIoHandler);
    174 };
    175 
    176 class ConfigurePortTestIoHandler : public TestIoHandlerBase {
    177  public:
    178   ConfigurePortTestIoHandler() {}
    179   virtual bool ConfigurePort(
    180       const device::serial::ConnectionOptions& options) OVERRIDE {
    181     static const device::serial::ConnectionOptions expected_options[] = {
    182         GenerateConnectionOptions(9600,
    183                                   device::serial::DATA_BITS_EIGHT,
    184                                   device::serial::PARITY_BIT_NO,
    185                                   device::serial::STOP_BITS_ONE,
    186                                   OPTIONAL_VALUE_FALSE),
    187         GenerateConnectionOptions(57600,
    188                                   device::serial::DATA_BITS_NONE,
    189                                   device::serial::PARITY_BIT_NONE,
    190                                   device::serial::STOP_BITS_NONE,
    191                                   OPTIONAL_VALUE_UNSET),
    192         GenerateConnectionOptions(0,
    193                                   device::serial::DATA_BITS_SEVEN,
    194                                   device::serial::PARITY_BIT_NONE,
    195                                   device::serial::STOP_BITS_NONE,
    196                                   OPTIONAL_VALUE_UNSET),
    197         GenerateConnectionOptions(0,
    198                                   device::serial::DATA_BITS_EIGHT,
    199                                   device::serial::PARITY_BIT_NONE,
    200                                   device::serial::STOP_BITS_NONE,
    201                                   OPTIONAL_VALUE_UNSET),
    202         GenerateConnectionOptions(0,
    203                                   device::serial::DATA_BITS_NONE,
    204                                   device::serial::PARITY_BIT_NO,
    205                                   device::serial::STOP_BITS_NONE,
    206                                   OPTIONAL_VALUE_UNSET),
    207         GenerateConnectionOptions(0,
    208                                   device::serial::DATA_BITS_NONE,
    209                                   device::serial::PARITY_BIT_ODD,
    210                                   device::serial::STOP_BITS_NONE,
    211                                   OPTIONAL_VALUE_UNSET),
    212         GenerateConnectionOptions(0,
    213                                   device::serial::DATA_BITS_NONE,
    214                                   device::serial::PARITY_BIT_EVEN,
    215                                   device::serial::STOP_BITS_NONE,
    216                                   OPTIONAL_VALUE_UNSET),
    217         GenerateConnectionOptions(0,
    218                                   device::serial::DATA_BITS_NONE,
    219                                   device::serial::PARITY_BIT_NONE,
    220                                   device::serial::STOP_BITS_ONE,
    221                                   OPTIONAL_VALUE_UNSET),
    222         GenerateConnectionOptions(0,
    223                                   device::serial::DATA_BITS_NONE,
    224                                   device::serial::PARITY_BIT_NONE,
    225                                   device::serial::STOP_BITS_TWO,
    226                                   OPTIONAL_VALUE_UNSET),
    227         GenerateConnectionOptions(0,
    228                                   device::serial::DATA_BITS_NONE,
    229                                   device::serial::PARITY_BIT_NONE,
    230                                   device::serial::STOP_BITS_NONE,
    231                                   OPTIONAL_VALUE_FALSE),
    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     };
    238     if (num_calls() >= arraysize(expected_options))
    239       return false;
    240 
    241     EXPECT_EQ(expected_options[num_calls()].bitrate, options.bitrate);
    242     EXPECT_EQ(expected_options[num_calls()].data_bits, options.data_bits);
    243     EXPECT_EQ(expected_options[num_calls()].parity_bit, options.parity_bit);
    244     EXPECT_EQ(expected_options[num_calls()].stop_bits, options.stop_bits);
    245     EXPECT_EQ(expected_options[num_calls()].has_cts_flow_control,
    246               options.has_cts_flow_control);
    247     EXPECT_EQ(expected_options[num_calls()].cts_flow_control,
    248               options.cts_flow_control);
    249     record_call();
    250     return TestSerialIoHandler::ConfigurePort(options);
    251   }
    252 
    253  private:
    254   virtual ~ConfigurePortTestIoHandler() {}
    255 
    256   DISALLOW_COPY_AND_ASSIGN(ConfigurePortTestIoHandler);
    257 };
    258 
    259 class FlushTestIoHandler : public TestIoHandlerBase {
    260  public:
    261   FlushTestIoHandler() {}
    262 
    263   virtual bool Flush() const OVERRIDE {
    264     record_call();
    265     return true;
    266   }
    267 
    268  private:
    269   virtual ~FlushTestIoHandler() {}
    270 
    271   DISALLOW_COPY_AND_ASSIGN(FlushTestIoHandler);
    272 };
    273 
    274 class FailToConnectTestIoHandler : public TestIoHandlerBase {
    275  public:
    276   FailToConnectTestIoHandler() {}
    277   virtual void Open(const std::string& port,
    278                     const OpenCompleteCallback& callback) OVERRIDE {
    279     callback.Run(false);
    280     return;
    281   }
    282 
    283  private:
    284   virtual ~FailToConnectTestIoHandler() {}
    285 
    286   DISALLOW_COPY_AND_ASSIGN(FailToConnectTestIoHandler);
    287 };
    288 
    289 class FailToGetInfoTestIoHandler : public TestIoHandlerBase {
    290  public:
    291   explicit FailToGetInfoTestIoHandler(int times_to_succeed)
    292       : times_to_succeed_(times_to_succeed) {}
    293   virtual device::serial::ConnectionInfoPtr GetPortInfo() const OVERRIDE {
    294     if (times_to_succeed_-- > 0)
    295       return device::TestSerialIoHandler::GetPortInfo();
    296     return device::serial::ConnectionInfoPtr();
    297   }
    298 
    299  private:
    300   virtual ~FailToGetInfoTestIoHandler() {}
    301 
    302   mutable int times_to_succeed_;
    303 
    304   DISALLOW_COPY_AND_ASSIGN(FailToGetInfoTestIoHandler);
    305 };
    306 
    307 class SendErrorTestIoHandler : public TestIoHandlerBase {
    308  public:
    309   explicit SendErrorTestIoHandler(device::serial::SendError error)
    310       : error_(error) {}
    311 
    312   virtual void WriteImpl() OVERRIDE { QueueWriteCompleted(0, error_); }
    313 
    314  private:
    315   virtual ~SendErrorTestIoHandler() {}
    316 
    317   device::serial::SendError error_;
    318 
    319   DISALLOW_COPY_AND_ASSIGN(SendErrorTestIoHandler);
    320 };
    321 
    322 class FixedDataReceiveTestIoHandler : public TestIoHandlerBase {
    323  public:
    324   explicit FixedDataReceiveTestIoHandler(const std::string& data)
    325       : data_(data) {}
    326 
    327   virtual void ReadImpl() OVERRIDE {
    328     if (pending_read_buffer_len() < data_.size())
    329       return;
    330     memcpy(pending_read_buffer(), data_.c_str(), data_.size());
    331     QueueReadCompleted(static_cast<uint32_t>(data_.size()),
    332                        device::serial::RECEIVE_ERROR_NONE);
    333   }
    334 
    335  private:
    336   virtual ~FixedDataReceiveTestIoHandler() {}
    337 
    338   const std::string data_;
    339 
    340   DISALLOW_COPY_AND_ASSIGN(FixedDataReceiveTestIoHandler);
    341 };
    342 
    343 class ReceiveErrorTestIoHandler : public TestIoHandlerBase {
    344  public:
    345   explicit ReceiveErrorTestIoHandler(device::serial::ReceiveError error)
    346       : error_(error) {}
    347 
    348   virtual void ReadImpl() OVERRIDE { QueueReadCompleted(0, error_); }
    349 
    350  private:
    351   virtual ~ReceiveErrorTestIoHandler() {}
    352 
    353   device::serial::ReceiveError error_;
    354 
    355   DISALLOW_COPY_AND_ASSIGN(ReceiveErrorTestIoHandler);
    356 };
    357 
    358 class SendDataWithErrorIoHandler : public TestIoHandlerBase {
    359  public:
    360   SendDataWithErrorIoHandler() : sent_error_(false) {}
    361   virtual void WriteImpl() OVERRIDE {
    362     if (sent_error_) {
    363       WriteCompleted(pending_write_buffer_len(),
    364                      device::serial::SEND_ERROR_NONE);
    365       return;
    366     }
    367     sent_error_ = true;
    368     // We expect the JS test code to send a 4 byte buffer.
    369     ASSERT_LT(2u, pending_write_buffer_len());
    370     WriteCompleted(2, device::serial::SEND_ERROR_SYSTEM_ERROR);
    371   }
    372 
    373  private:
    374   virtual ~SendDataWithErrorIoHandler() {}
    375 
    376   bool sent_error_;
    377 
    378   DISALLOW_COPY_AND_ASSIGN(SendDataWithErrorIoHandler);
    379 };
    380 
    381 class BlockSendsForeverSendIoHandler : public TestIoHandlerBase {
    382  public:
    383   BlockSendsForeverSendIoHandler() {}
    384   virtual void WriteImpl() OVERRIDE {}
    385 
    386  private:
    387   virtual ~BlockSendsForeverSendIoHandler() {}
    388 
    389   DISALLOW_COPY_AND_ASSIGN(BlockSendsForeverSendIoHandler);
    390 };
    391 
    392 }  // namespace
    393 
    394 class SerialApiTest : public ApiTestBase {
    395  public:
    396   SerialApiTest() {}
    397 
    398   virtual void SetUp() OVERRIDE {
    399     ApiTestBase::SetUp();
    400     env()->RegisterModule("async_waiter", IDR_ASYNC_WAITER_JS);
    401     env()->RegisterModule("data_receiver", IDR_DATA_RECEIVER_JS);
    402     env()->RegisterModule("data_sender", IDR_DATA_SENDER_JS);
    403     env()->RegisterModule("serial", IDR_SERIAL_CUSTOM_BINDINGS_JS);
    404     env()->RegisterModule("serial_service", IDR_SERIAL_SERVICE_JS);
    405     env()->RegisterModule("device/serial/data_stream.mojom",
    406                           IDR_DATA_STREAM_MOJOM_JS);
    407     env()->RegisterModule("device/serial/data_stream_serialization.mojom",
    408                           IDR_DATA_STREAM_SERIALIZATION_MOJOM_JS);
    409     env()->RegisterModule("device/serial/serial.mojom", IDR_SERIAL_MOJOM_JS);
    410     service_provider()->AddService<device::serial::SerialService>(base::Bind(
    411         &SerialApiTest::CreateSerialService, base::Unretained(this)));
    412   }
    413 
    414   scoped_refptr<TestIoHandlerBase> io_handler_;
    415 
    416  private:
    417   scoped_refptr<device::SerialIoHandler> GetIoHandler() {
    418     if (!io_handler_.get())
    419       io_handler_ = new TestIoHandlerBase;
    420     return io_handler_;
    421   }
    422 
    423   void CreateSerialService(
    424       mojo::InterfaceRequest<device::serial::SerialService> request) {
    425     mojo::BindToRequest(new device::SerialServiceImpl(
    426                             new device::SerialConnectionFactory(
    427                                 base::Bind(&SerialApiTest::GetIoHandler,
    428                                            base::Unretained(this)),
    429                                 base::MessageLoopProxy::current()),
    430                             scoped_ptr<device::SerialDeviceEnumerator>(
    431                                 new FakeSerialDeviceEnumerator)),
    432                         &request);
    433   }
    434 
    435   DISALLOW_COPY_AND_ASSIGN(SerialApiTest);
    436 };
    437 
    438 TEST_F(SerialApiTest, GetDevices) {
    439   RunTest("serial_unittest.js", "testGetDevices");
    440 }
    441 
    442 TEST_F(SerialApiTest, ConnectFail) {
    443   io_handler_ = new FailToConnectTestIoHandler;
    444   RunTest("serial_unittest.js", "testConnectFail");
    445 }
    446 
    447 TEST_F(SerialApiTest, GetInfoFailOnConnect) {
    448   io_handler_ = new FailToGetInfoTestIoHandler(0);
    449   RunTest("serial_unittest.js", "testGetInfoFailOnConnect");
    450 }
    451 
    452 TEST_F(SerialApiTest, Connect) {
    453   RunTest("serial_unittest.js", "testConnect");
    454 }
    455 
    456 TEST_F(SerialApiTest, ConnectDefaultOptions) {
    457   RunTest("serial_unittest.js", "testConnectDefaultOptions");
    458 }
    459 
    460 TEST_F(SerialApiTest, ConnectInvalidBitrate) {
    461   RunTest("serial_unittest.js", "testConnectInvalidBitrate");
    462 }
    463 
    464 TEST_F(SerialApiTest, GetInfo) {
    465   RunTest("serial_unittest.js", "testGetInfo");
    466 }
    467 
    468 TEST_F(SerialApiTest, GetInfoFailToGetPortInfo) {
    469   io_handler_ = new FailToGetInfoTestIoHandler(1);
    470   RunTest("serial_unittest.js", "testGetInfoFailToGetPortInfo");
    471 }
    472 
    473 TEST_F(SerialApiTest, GetConnections) {
    474   RunTest("serial_unittest.js", "testGetConnections");
    475 }
    476 
    477 TEST_F(SerialApiTest, GetControlSignals) {
    478   io_handler_ = new GetControlSignalsTestIoHandler;
    479   RunTest("serial_unittest.js", "testGetControlSignals");
    480   EXPECT_EQ(16u, io_handler_->num_calls());
    481 }
    482 
    483 TEST_F(SerialApiTest, SetControlSignals) {
    484   io_handler_ = new SetControlSignalsTestIoHandler;
    485   RunTest("serial_unittest.js", "testSetControlSignals");
    486   EXPECT_EQ(9u, io_handler_->num_calls());
    487 }
    488 
    489 TEST_F(SerialApiTest, Update) {
    490   io_handler_ = new ConfigurePortTestIoHandler;
    491   RunTest("serial_unittest.js", "testUpdate");
    492   EXPECT_EQ(11u, io_handler_->num_calls());
    493 }
    494 
    495 TEST_F(SerialApiTest, UpdateInvalidBitrate) {
    496   io_handler_ = new ConfigurePortTestIoHandler;
    497   RunTest("serial_unittest.js", "testUpdateInvalidBitrate");
    498   EXPECT_EQ(1u, io_handler_->num_calls());
    499 }
    500 
    501 TEST_F(SerialApiTest, Flush) {
    502   io_handler_ = new FlushTestIoHandler;
    503   RunTest("serial_unittest.js", "testFlush");
    504   EXPECT_EQ(1u, io_handler_->num_calls());
    505 }
    506 
    507 TEST_F(SerialApiTest, SetPaused) {
    508   RunTest("serial_unittest.js", "testSetPaused");
    509 }
    510 
    511 TEST_F(SerialApiTest, Echo) {
    512   RunTest("serial_unittest.js", "testEcho");
    513 }
    514 
    515 TEST_F(SerialApiTest, SendDuringExistingSend) {
    516   RunTest("serial_unittest.js", "testSendDuringExistingSend");
    517 }
    518 
    519 TEST_F(SerialApiTest, SendAfterSuccessfulSend) {
    520   RunTest("serial_unittest.js", "testSendAfterSuccessfulSend");
    521 }
    522 
    523 TEST_F(SerialApiTest, SendPartialSuccessWithError) {
    524   io_handler_ = new SendDataWithErrorIoHandler();
    525   RunTest("serial_unittest.js", "testSendPartialSuccessWithError");
    526 }
    527 
    528 TEST_F(SerialApiTest, SendTimeout) {
    529   io_handler_ = new BlockSendsForeverSendIoHandler();
    530   RunTest("serial_unittest.js", "testSendTimeout");
    531 }
    532 
    533 TEST_F(SerialApiTest, DisableSendTimeout) {
    534   io_handler_ = new BlockSendsForeverSendIoHandler();
    535   RunTest("serial_unittest.js", "testDisableSendTimeout");
    536 }
    537 
    538 TEST_F(SerialApiTest, PausedReceive) {
    539   io_handler_ = new FixedDataReceiveTestIoHandler("data");
    540   RunTest("serial_unittest.js", "testPausedReceive");
    541 }
    542 
    543 TEST_F(SerialApiTest, PausedReceiveError) {
    544   io_handler_ =
    545       new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_DEVICE_LOST);
    546   RunTest("serial_unittest.js", "testPausedReceiveError");
    547 }
    548 
    549 TEST_F(SerialApiTest, ReceiveTimeout) {
    550   RunTest("serial_unittest.js", "testReceiveTimeout");
    551 }
    552 
    553 TEST_F(SerialApiTest, DisableReceiveTimeout) {
    554   RunTest("serial_unittest.js", "testDisableReceiveTimeout");
    555 }
    556 
    557 TEST_F(SerialApiTest, ReceiveErrorDisconnected) {
    558   io_handler_ =
    559       new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_DISCONNECTED);
    560   RunTest("serial_unittest.js", "testReceiveErrorDisconnected");
    561 }
    562 
    563 TEST_F(SerialApiTest, ReceiveErrorDeviceLost) {
    564   io_handler_ =
    565       new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_DEVICE_LOST);
    566   RunTest("serial_unittest.js", "testReceiveErrorDeviceLost");
    567 }
    568 
    569 TEST_F(SerialApiTest, ReceiveErrorSystemError) {
    570   io_handler_ =
    571       new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_SYSTEM_ERROR);
    572   RunTest("serial_unittest.js", "testReceiveErrorSystemError");
    573 }
    574 
    575 TEST_F(SerialApiTest, SendErrorDisconnected) {
    576   io_handler_ =
    577       new SendErrorTestIoHandler(device::serial::SEND_ERROR_DISCONNECTED);
    578   RunTest("serial_unittest.js", "testSendErrorDisconnected");
    579 }
    580 
    581 TEST_F(SerialApiTest, SendErrorSystemError) {
    582   io_handler_ =
    583       new SendErrorTestIoHandler(device::serial::SEND_ERROR_SYSTEM_ERROR);
    584   RunTest("serial_unittest.js", "testSendErrorSystemError");
    585 }
    586 
    587 TEST_F(SerialApiTest, DisconnectUnknownConnectionId) {
    588   RunTest("serial_unittest.js", "testDisconnectUnknownConnectionId");
    589 }
    590 
    591 TEST_F(SerialApiTest, GetInfoUnknownConnectionId) {
    592   RunTest("serial_unittest.js", "testGetInfoUnknownConnectionId");
    593 }
    594 
    595 TEST_F(SerialApiTest, UpdateUnknownConnectionId) {
    596   RunTest("serial_unittest.js", "testUpdateUnknownConnectionId");
    597 }
    598 
    599 TEST_F(SerialApiTest, SetControlSignalsUnknownConnectionId) {
    600   RunTest("serial_unittest.js", "testSetControlSignalsUnknownConnectionId");
    601 }
    602 
    603 TEST_F(SerialApiTest, GetControlSignalsUnknownConnectionId) {
    604   RunTest("serial_unittest.js", "testGetControlSignalsUnknownConnectionId");
    605 }
    606 
    607 TEST_F(SerialApiTest, FlushUnknownConnectionId) {
    608   RunTest("serial_unittest.js", "testFlushUnknownConnectionId");
    609 }
    610 
    611 TEST_F(SerialApiTest, SetPausedUnknownConnectionId) {
    612   RunTest("serial_unittest.js", "testSetPausedUnknownConnectionId");
    613 }
    614 
    615 TEST_F(SerialApiTest, SendUnknownConnectionId) {
    616   RunTest("serial_unittest.js", "testSendUnknownConnectionId");
    617 }
    618 
    619 }  // namespace extensions
    620