Remove linux_chromium_gn_dbg from the chromium CQ.
[chromium-blink-merge.git] / extensions / renderer / api / serial / serial_api_unittest.cc
blob8ba15f08fa73bff32e296432dd0a43e8546117ef
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.
5 #include "base/thread_task_runner_handle.h"
6 #include "device/serial/serial_device_enumerator.h"
7 #include "device/serial/serial_service_impl.h"
8 #include "device/serial/test_serial_io_handler.h"
9 #include "extensions/browser/mojo/stash_backend.h"
10 #include "extensions/common/mojo/keep_alive.mojom.h"
11 #include "extensions/renderer/api_test_base.h"
12 #include "grit/extensions_renderer_resources.h"
14 // A test launcher for tests for the serial API defined in
15 // extensions/test/data/serial_unittest.js. Each C++ test function sets up a
16 // fake DeviceEnumerator or SerialIoHandler expecting or returning particular
17 // values for that test.
19 namespace extensions {
21 namespace {
23 class FakeSerialDeviceEnumerator : public device::SerialDeviceEnumerator {
24 mojo::Array<device::serial::DeviceInfoPtr> GetDevices() override {
25 mojo::Array<device::serial::DeviceInfoPtr> result(3);
26 result[0] = device::serial::DeviceInfo::New();
27 result[0]->path = "device";
28 result[0]->vendor_id = 1234;
29 result[0]->has_vendor_id = true;
30 result[0]->product_id = 5678;
31 result[0]->has_product_id = true;
32 result[0]->display_name = "foo";
33 result[1] = device::serial::DeviceInfo::New();
34 result[1]->path = "another_device";
35 // These IDs should be ignored.
36 result[1]->vendor_id = 1234;
37 result[1]->product_id = 5678;
38 result[2] = device::serial::DeviceInfo::New();
39 result[2]->path = "";
40 result[2]->display_name = "";
41 return result.Pass();
45 enum OptionalValue {
46 OPTIONAL_VALUE_UNSET,
47 OPTIONAL_VALUE_FALSE,
48 OPTIONAL_VALUE_TRUE,
51 device::serial::HostControlSignals GenerateControlSignals(OptionalValue dtr,
52 OptionalValue rts) {
53 device::serial::HostControlSignals result;
54 switch (dtr) {
55 case OPTIONAL_VALUE_UNSET:
56 break;
57 case OPTIONAL_VALUE_FALSE:
58 result.dtr = false;
59 result.has_dtr = true;
60 break;
61 case OPTIONAL_VALUE_TRUE:
62 result.dtr = true;
63 result.has_dtr = true;
64 break;
66 switch (rts) {
67 case OPTIONAL_VALUE_UNSET:
68 break;
69 case OPTIONAL_VALUE_FALSE:
70 result.rts = false;
71 result.has_rts = true;
72 break;
73 case OPTIONAL_VALUE_TRUE:
74 result.rts = true;
75 result.has_rts = true;
76 break;
78 return result;
81 device::serial::ConnectionOptions GenerateConnectionOptions(
82 int bitrate,
83 device::serial::DataBits data_bits,
84 device::serial::ParityBit parity_bit,
85 device::serial::StopBits stop_bits,
86 OptionalValue cts_flow_control) {
87 device::serial::ConnectionOptions result;
88 result.bitrate = bitrate;
89 result.data_bits = data_bits;
90 result.parity_bit = parity_bit;
91 result.stop_bits = stop_bits;
92 switch (cts_flow_control) {
93 case OPTIONAL_VALUE_UNSET:
94 break;
95 case OPTIONAL_VALUE_FALSE:
96 result.cts_flow_control = false;
97 result.has_cts_flow_control = true;
98 break;
99 case OPTIONAL_VALUE_TRUE:
100 result.cts_flow_control = true;
101 result.has_cts_flow_control = true;
102 break;
104 return result;
107 class TestIoHandlerBase : public device::TestSerialIoHandler {
108 public:
109 TestIoHandlerBase() : calls_(0) {}
111 size_t num_calls() const { return calls_; }
113 protected:
114 ~TestIoHandlerBase() override {}
115 void record_call() const { calls_++; }
117 private:
118 mutable size_t calls_;
120 DISALLOW_COPY_AND_ASSIGN(TestIoHandlerBase);
123 class SetControlSignalsTestIoHandler : public TestIoHandlerBase {
124 public:
125 SetControlSignalsTestIoHandler() {}
127 bool SetControlSignals(
128 const device::serial::HostControlSignals& signals) override {
129 static const device::serial::HostControlSignals expected_signals[] = {
130 GenerateControlSignals(OPTIONAL_VALUE_UNSET, OPTIONAL_VALUE_UNSET),
131 GenerateControlSignals(OPTIONAL_VALUE_FALSE, OPTIONAL_VALUE_UNSET),
132 GenerateControlSignals(OPTIONAL_VALUE_TRUE, OPTIONAL_VALUE_UNSET),
133 GenerateControlSignals(OPTIONAL_VALUE_UNSET, OPTIONAL_VALUE_FALSE),
134 GenerateControlSignals(OPTIONAL_VALUE_FALSE, OPTIONAL_VALUE_FALSE),
135 GenerateControlSignals(OPTIONAL_VALUE_TRUE, OPTIONAL_VALUE_FALSE),
136 GenerateControlSignals(OPTIONAL_VALUE_UNSET, OPTIONAL_VALUE_TRUE),
137 GenerateControlSignals(OPTIONAL_VALUE_FALSE, OPTIONAL_VALUE_TRUE),
138 GenerateControlSignals(OPTIONAL_VALUE_TRUE, OPTIONAL_VALUE_TRUE),
140 if (num_calls() >= arraysize(expected_signals))
141 return false;
143 EXPECT_EQ(expected_signals[num_calls()].has_dtr, signals.has_dtr);
144 EXPECT_EQ(expected_signals[num_calls()].dtr, signals.dtr);
145 EXPECT_EQ(expected_signals[num_calls()].has_rts, signals.has_rts);
146 EXPECT_EQ(expected_signals[num_calls()].rts, signals.rts);
147 record_call();
148 return true;
151 private:
152 ~SetControlSignalsTestIoHandler() override {}
154 DISALLOW_COPY_AND_ASSIGN(SetControlSignalsTestIoHandler);
157 class GetControlSignalsTestIoHandler : public TestIoHandlerBase {
158 public:
159 GetControlSignalsTestIoHandler() {}
161 device::serial::DeviceControlSignalsPtr GetControlSignals() const override {
162 device::serial::DeviceControlSignalsPtr signals(
163 device::serial::DeviceControlSignals::New());
164 signals->dcd = num_calls() & 1;
165 signals->cts = num_calls() & 2;
166 signals->ri = num_calls() & 4;
167 signals->dsr = num_calls() & 8;
168 record_call();
169 return signals.Pass();
172 private:
173 ~GetControlSignalsTestIoHandler() override {}
175 DISALLOW_COPY_AND_ASSIGN(GetControlSignalsTestIoHandler);
178 class ConfigurePortTestIoHandler : public TestIoHandlerBase {
179 public:
180 ConfigurePortTestIoHandler() {}
181 bool ConfigurePortImpl() override {
182 static const device::serial::ConnectionOptions expected_options[] = {
183 // Each JavaScript call to chrome.serial.update only modifies a single
184 // property of the connection however this function can only check the
185 // final value of all options. The modified option is marked with "set".
186 GenerateConnectionOptions(9600,
187 device::serial::DATA_BITS_EIGHT,
188 device::serial::PARITY_BIT_NO,
189 device::serial::STOP_BITS_ONE,
190 OPTIONAL_VALUE_FALSE),
191 GenerateConnectionOptions(57600, // set
192 device::serial::DATA_BITS_EIGHT,
193 device::serial::PARITY_BIT_NO,
194 device::serial::STOP_BITS_ONE,
195 OPTIONAL_VALUE_FALSE),
196 GenerateConnectionOptions(57600,
197 device::serial::DATA_BITS_SEVEN, // set
198 device::serial::PARITY_BIT_NO,
199 device::serial::STOP_BITS_ONE,
200 OPTIONAL_VALUE_FALSE),
201 GenerateConnectionOptions(57600,
202 device::serial::DATA_BITS_EIGHT, // set
203 device::serial::PARITY_BIT_NO,
204 device::serial::STOP_BITS_ONE,
205 OPTIONAL_VALUE_FALSE),
206 GenerateConnectionOptions(57600,
207 device::serial::DATA_BITS_EIGHT,
208 device::serial::PARITY_BIT_NO, // set
209 device::serial::STOP_BITS_ONE,
210 OPTIONAL_VALUE_FALSE),
211 GenerateConnectionOptions(57600,
212 device::serial::DATA_BITS_EIGHT,
213 device::serial::PARITY_BIT_ODD, // set
214 device::serial::STOP_BITS_ONE,
215 OPTIONAL_VALUE_FALSE),
216 GenerateConnectionOptions(57600,
217 device::serial::DATA_BITS_EIGHT,
218 device::serial::PARITY_BIT_EVEN, // set
219 device::serial::STOP_BITS_ONE,
220 OPTIONAL_VALUE_FALSE),
221 GenerateConnectionOptions(57600,
222 device::serial::DATA_BITS_EIGHT,
223 device::serial::PARITY_BIT_EVEN,
224 device::serial::STOP_BITS_ONE, // set
225 OPTIONAL_VALUE_FALSE),
226 GenerateConnectionOptions(57600,
227 device::serial::DATA_BITS_EIGHT,
228 device::serial::PARITY_BIT_EVEN,
229 device::serial::STOP_BITS_TWO, // set
230 OPTIONAL_VALUE_FALSE),
231 GenerateConnectionOptions(57600,
232 device::serial::DATA_BITS_EIGHT,
233 device::serial::PARITY_BIT_EVEN,
234 device::serial::STOP_BITS_TWO,
235 OPTIONAL_VALUE_FALSE), // set
236 GenerateConnectionOptions(57600,
237 device::serial::DATA_BITS_EIGHT,
238 device::serial::PARITY_BIT_EVEN,
239 device::serial::STOP_BITS_TWO,
240 OPTIONAL_VALUE_TRUE), // set
243 if (!TestIoHandlerBase::ConfigurePortImpl()) {
244 return false;
247 if (num_calls() >= arraysize(expected_options)) {
248 return false;
251 EXPECT_EQ(expected_options[num_calls()].bitrate, options().bitrate);
252 EXPECT_EQ(expected_options[num_calls()].data_bits, options().data_bits);
253 EXPECT_EQ(expected_options[num_calls()].parity_bit, options().parity_bit);
254 EXPECT_EQ(expected_options[num_calls()].stop_bits, options().stop_bits);
255 EXPECT_EQ(expected_options[num_calls()].has_cts_flow_control,
256 options().has_cts_flow_control);
257 EXPECT_EQ(expected_options[num_calls()].cts_flow_control,
258 options().cts_flow_control);
259 record_call();
260 return true;
263 private:
264 ~ConfigurePortTestIoHandler() override {}
266 DISALLOW_COPY_AND_ASSIGN(ConfigurePortTestIoHandler);
269 class FlushTestIoHandler : public TestIoHandlerBase {
270 public:
271 FlushTestIoHandler() {}
273 bool Flush() const override {
274 record_call();
275 return true;
278 private:
279 ~FlushTestIoHandler() override {}
281 DISALLOW_COPY_AND_ASSIGN(FlushTestIoHandler);
284 class FailToConnectTestIoHandler : public TestIoHandlerBase {
285 public:
286 FailToConnectTestIoHandler() {}
287 void Open(const std::string& port,
288 const device::serial::ConnectionOptions& options,
289 const OpenCompleteCallback& callback) override {
290 callback.Run(false);
291 return;
294 private:
295 ~FailToConnectTestIoHandler() override {}
297 DISALLOW_COPY_AND_ASSIGN(FailToConnectTestIoHandler);
300 class FailToGetInfoTestIoHandler : public TestIoHandlerBase {
301 public:
302 explicit FailToGetInfoTestIoHandler(int times_to_succeed)
303 : times_to_succeed_(times_to_succeed) {}
304 device::serial::ConnectionInfoPtr GetPortInfo() const override {
305 if (times_to_succeed_-- > 0)
306 return device::TestSerialIoHandler::GetPortInfo();
307 return device::serial::ConnectionInfoPtr();
310 private:
311 ~FailToGetInfoTestIoHandler() override {}
313 mutable int times_to_succeed_;
315 DISALLOW_COPY_AND_ASSIGN(FailToGetInfoTestIoHandler);
318 class SendErrorTestIoHandler : public TestIoHandlerBase {
319 public:
320 explicit SendErrorTestIoHandler(device::serial::SendError error)
321 : error_(error) {}
323 void WriteImpl() override { QueueWriteCompleted(0, error_); }
325 private:
326 ~SendErrorTestIoHandler() override {}
328 device::serial::SendError error_;
330 DISALLOW_COPY_AND_ASSIGN(SendErrorTestIoHandler);
333 class FixedDataReceiveTestIoHandler : public TestIoHandlerBase {
334 public:
335 explicit FixedDataReceiveTestIoHandler(const std::string& data)
336 : data_(data) {}
338 void ReadImpl() override {
339 if (pending_read_buffer_len() < data_.size())
340 return;
341 memcpy(pending_read_buffer(), data_.c_str(), data_.size());
342 QueueReadCompleted(static_cast<uint32_t>(data_.size()),
343 device::serial::RECEIVE_ERROR_NONE);
346 private:
347 ~FixedDataReceiveTestIoHandler() override {}
349 const std::string data_;
351 DISALLOW_COPY_AND_ASSIGN(FixedDataReceiveTestIoHandler);
354 class ReceiveErrorTestIoHandler : public TestIoHandlerBase {
355 public:
356 explicit ReceiveErrorTestIoHandler(device::serial::ReceiveError error)
357 : error_(error) {}
359 void ReadImpl() override { QueueReadCompleted(0, error_); }
361 private:
362 ~ReceiveErrorTestIoHandler() override {}
364 device::serial::ReceiveError error_;
366 DISALLOW_COPY_AND_ASSIGN(ReceiveErrorTestIoHandler);
369 class SendDataWithErrorIoHandler : public TestIoHandlerBase {
370 public:
371 SendDataWithErrorIoHandler() : sent_error_(false) {}
372 void WriteImpl() override {
373 if (sent_error_) {
374 WriteCompleted(pending_write_buffer_len(),
375 device::serial::SEND_ERROR_NONE);
376 return;
378 sent_error_ = true;
379 // We expect the JS test code to send a 4 byte buffer.
380 ASSERT_LT(2u, pending_write_buffer_len());
381 WriteCompleted(2, device::serial::SEND_ERROR_SYSTEM_ERROR);
384 private:
385 ~SendDataWithErrorIoHandler() override {}
387 bool sent_error_;
389 DISALLOW_COPY_AND_ASSIGN(SendDataWithErrorIoHandler);
392 class BlockSendsForeverSendIoHandler : public TestIoHandlerBase {
393 public:
394 BlockSendsForeverSendIoHandler() {}
395 void WriteImpl() override {}
397 private:
398 ~BlockSendsForeverSendIoHandler() override {}
400 DISALLOW_COPY_AND_ASSIGN(BlockSendsForeverSendIoHandler);
403 } // namespace
405 class SerialApiTest : public ApiTestBase {
406 public:
407 SerialApiTest() {}
409 void SetUp() override {
410 ApiTestBase::SetUp();
411 stash_backend_.reset(new StashBackend(base::Closure()));
412 PrepareEnvironment(api_test_env(), stash_backend_.get());
415 void PrepareEnvironment(ApiTestEnvironment* environment,
416 StashBackend* stash_backend) {
417 environment->env()->RegisterModule("serial", IDR_SERIAL_CUSTOM_BINDINGS_JS);
418 environment->service_provider()->AddService<device::serial::SerialService>(
419 base::Bind(&SerialApiTest::CreateSerialService,
420 base::Unretained(this)));
421 environment->service_provider()->AddService(base::Bind(
422 &StashBackend::BindToRequest, base::Unretained(stash_backend)));
423 environment->service_provider()->IgnoreServiceRequests<KeepAlive>();
426 scoped_refptr<TestIoHandlerBase> io_handler_;
428 scoped_ptr<StashBackend> stash_backend_;
430 private:
431 scoped_refptr<device::SerialIoHandler> GetIoHandler() {
432 if (!io_handler_.get())
433 io_handler_ = new TestIoHandlerBase;
434 return io_handler_;
437 void CreateSerialService(
438 mojo::InterfaceRequest<device::serial::SerialService> request) {
439 new device::SerialServiceImpl(
440 new device::SerialConnectionFactory(
441 base::Bind(&SerialApiTest::GetIoHandler, base::Unretained(this)),
442 base::ThreadTaskRunnerHandle::Get()),
443 scoped_ptr<device::SerialDeviceEnumerator>(
444 new FakeSerialDeviceEnumerator),
445 request.Pass());
448 DISALLOW_COPY_AND_ASSIGN(SerialApiTest);
451 TEST_F(SerialApiTest, GetDevices) {
452 RunTest("serial_unittest.js", "testGetDevices");
455 TEST_F(SerialApiTest, ConnectFail) {
456 io_handler_ = new FailToConnectTestIoHandler;
457 RunTest("serial_unittest.js", "testConnectFail");
460 TEST_F(SerialApiTest, GetInfoFailOnConnect) {
461 io_handler_ = new FailToGetInfoTestIoHandler(0);
462 RunTest("serial_unittest.js", "testGetInfoFailOnConnect");
465 TEST_F(SerialApiTest, Connect) {
466 RunTest("serial_unittest.js", "testConnect");
469 TEST_F(SerialApiTest, ConnectDefaultOptions) {
470 RunTest("serial_unittest.js", "testConnectDefaultOptions");
473 TEST_F(SerialApiTest, ConnectInvalidBitrate) {
474 RunTest("serial_unittest.js", "testConnectInvalidBitrate");
477 TEST_F(SerialApiTest, GetInfo) {
478 RunTest("serial_unittest.js", "testGetInfo");
481 TEST_F(SerialApiTest, GetInfoAfterSerialization) {
482 RunTest("serial_unittest.js", "testGetInfoAfterSerialization");
485 TEST_F(SerialApiTest, GetInfoFailToGetPortInfo) {
486 io_handler_ = new FailToGetInfoTestIoHandler(1);
487 RunTest("serial_unittest.js", "testGetInfoFailToGetPortInfo");
490 TEST_F(SerialApiTest, GetConnections) {
491 RunTest("serial_unittest.js", "testGetConnections");
494 TEST_F(SerialApiTest, GetControlSignals) {
495 io_handler_ = new GetControlSignalsTestIoHandler;
496 RunTest("serial_unittest.js", "testGetControlSignals");
497 EXPECT_EQ(16u, io_handler_->num_calls());
500 TEST_F(SerialApiTest, SetControlSignals) {
501 io_handler_ = new SetControlSignalsTestIoHandler;
502 RunTest("serial_unittest.js", "testSetControlSignals");
503 EXPECT_EQ(9u, io_handler_->num_calls());
506 TEST_F(SerialApiTest, Update) {
507 io_handler_ = new ConfigurePortTestIoHandler;
508 RunTest("serial_unittest.js", "testUpdate");
509 EXPECT_EQ(11u, io_handler_->num_calls());
512 TEST_F(SerialApiTest, UpdateAcrossSerialization) {
513 io_handler_ = new ConfigurePortTestIoHandler;
514 RunTest("serial_unittest.js", "testUpdateAcrossSerialization");
515 EXPECT_EQ(11u, io_handler_->num_calls());
518 TEST_F(SerialApiTest, UpdateInvalidBitrate) {
519 io_handler_ = new ConfigurePortTestIoHandler;
520 RunTest("serial_unittest.js", "testUpdateInvalidBitrate");
521 EXPECT_EQ(1u, io_handler_->num_calls());
524 TEST_F(SerialApiTest, Flush) {
525 io_handler_ = new FlushTestIoHandler;
526 RunTest("serial_unittest.js", "testFlush");
527 EXPECT_EQ(1u, io_handler_->num_calls());
530 TEST_F(SerialApiTest, SetPaused) {
531 RunTest("serial_unittest.js", "testSetPaused");
534 TEST_F(SerialApiTest, Echo) {
535 RunTest("serial_unittest.js", "testEcho");
538 TEST_F(SerialApiTest, EchoAfterSerialization) {
539 RunTest("serial_unittest.js", "testEchoAfterSerialization");
542 TEST_F(SerialApiTest, SendDuringExistingSend) {
543 RunTest("serial_unittest.js", "testSendDuringExistingSend");
546 TEST_F(SerialApiTest, SendAfterSuccessfulSend) {
547 RunTest("serial_unittest.js", "testSendAfterSuccessfulSend");
550 TEST_F(SerialApiTest, SendPartialSuccessWithError) {
551 io_handler_ = new SendDataWithErrorIoHandler();
552 RunTest("serial_unittest.js", "testSendPartialSuccessWithError");
555 TEST_F(SerialApiTest, SendTimeout) {
556 io_handler_ = new BlockSendsForeverSendIoHandler();
557 RunTest("serial_unittest.js", "testSendTimeout");
560 TEST_F(SerialApiTest, SendTimeoutAfterSerialization) {
561 io_handler_ = new BlockSendsForeverSendIoHandler();
562 RunTest("serial_unittest.js", "testSendTimeoutAfterSerialization");
565 TEST_F(SerialApiTest, DisableSendTimeout) {
566 io_handler_ = new BlockSendsForeverSendIoHandler();
567 RunTest("serial_unittest.js", "testDisableSendTimeout");
570 TEST_F(SerialApiTest, PausedReceive) {
571 io_handler_ = new FixedDataReceiveTestIoHandler("data");
572 RunTest("serial_unittest.js", "testPausedReceive");
575 TEST_F(SerialApiTest, PausedReceiveError) {
576 io_handler_ =
577 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_DEVICE_LOST);
578 RunTest("serial_unittest.js", "testPausedReceiveError");
581 TEST_F(SerialApiTest, ReceiveTimeout) {
582 RunTest("serial_unittest.js", "testReceiveTimeout");
585 TEST_F(SerialApiTest, ReceiveTimeoutAfterSerialization) {
586 RunTest("serial_unittest.js", "testReceiveTimeoutAfterSerialization");
589 TEST_F(SerialApiTest, DisableReceiveTimeout) {
590 RunTest("serial_unittest.js", "testDisableReceiveTimeout");
593 TEST_F(SerialApiTest, ReceiveErrorDisconnected) {
594 io_handler_ =
595 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_DISCONNECTED);
596 RunTest("serial_unittest.js", "testReceiveErrorDisconnected");
599 TEST_F(SerialApiTest, ReceiveErrorDeviceLost) {
600 io_handler_ =
601 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_DEVICE_LOST);
602 RunTest("serial_unittest.js", "testReceiveErrorDeviceLost");
605 TEST_F(SerialApiTest, ReceiveErrorBreak) {
606 io_handler_ =
607 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_BREAK);
608 RunTest("serial_unittest.js", "testReceiveErrorBreak");
611 TEST_F(SerialApiTest, ReceiveErrorFrameError) {
612 io_handler_ =
613 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_FRAME_ERROR);
614 RunTest("serial_unittest.js", "testReceiveErrorFrameError");
617 TEST_F(SerialApiTest, ReceiveErrorOverrun) {
618 io_handler_ =
619 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_OVERRUN);
620 RunTest("serial_unittest.js", "testReceiveErrorOverrun");
623 TEST_F(SerialApiTest, ReceiveErrorBufferOverflow) {
624 io_handler_ = new ReceiveErrorTestIoHandler(
625 device::serial::RECEIVE_ERROR_BUFFER_OVERFLOW);
626 RunTest("serial_unittest.js", "testReceiveErrorBufferOverflow");
629 TEST_F(SerialApiTest, ReceiveErrorParityError) {
630 io_handler_ =
631 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_PARITY_ERROR);
632 RunTest("serial_unittest.js", "testReceiveErrorParityError");
635 TEST_F(SerialApiTest, ReceiveErrorSystemError) {
636 io_handler_ =
637 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_SYSTEM_ERROR);
638 RunTest("serial_unittest.js", "testReceiveErrorSystemError");
641 TEST_F(SerialApiTest, SendErrorDisconnected) {
642 io_handler_ =
643 new SendErrorTestIoHandler(device::serial::SEND_ERROR_DISCONNECTED);
644 RunTest("serial_unittest.js", "testSendErrorDisconnected");
647 TEST_F(SerialApiTest, SendErrorSystemError) {
648 io_handler_ =
649 new SendErrorTestIoHandler(device::serial::SEND_ERROR_SYSTEM_ERROR);
650 RunTest("serial_unittest.js", "testSendErrorSystemError");
653 TEST_F(SerialApiTest, DisconnectUnknownConnectionId) {
654 RunTest("serial_unittest.js", "testDisconnectUnknownConnectionId");
657 TEST_F(SerialApiTest, GetInfoUnknownConnectionId) {
658 RunTest("serial_unittest.js", "testGetInfoUnknownConnectionId");
661 TEST_F(SerialApiTest, UpdateUnknownConnectionId) {
662 RunTest("serial_unittest.js", "testUpdateUnknownConnectionId");
665 TEST_F(SerialApiTest, SetControlSignalsUnknownConnectionId) {
666 RunTest("serial_unittest.js", "testSetControlSignalsUnknownConnectionId");
669 TEST_F(SerialApiTest, GetControlSignalsUnknownConnectionId) {
670 RunTest("serial_unittest.js", "testGetControlSignalsUnknownConnectionId");
673 TEST_F(SerialApiTest, FlushUnknownConnectionId) {
674 RunTest("serial_unittest.js", "testFlushUnknownConnectionId");
677 TEST_F(SerialApiTest, SetPausedUnknownConnectionId) {
678 RunTest("serial_unittest.js", "testSetPausedUnknownConnectionId");
681 TEST_F(SerialApiTest, SendUnknownConnectionId) {
682 RunTest("serial_unittest.js", "testSendUnknownConnectionId");
685 TEST_F(SerialApiTest, StashAndRestoreDuringEcho) {
686 ASSERT_NO_FATAL_FAILURE(RunTest("serial_unittest.js", "testSendAndStash"));
687 env()->context()->DispatchOnUnloadEvent();
688 scoped_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment());
689 ApiTestEnvironment new_api_test_env(new_env.get());
690 PrepareEnvironment(&new_api_test_env, stash_backend_.get());
691 new_api_test_env.RunTest("serial_unittest.js", "testRestoreAndReceive");
694 TEST_F(SerialApiTest, StashAndRestoreDuringEchoError) {
695 io_handler_ =
696 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_DEVICE_LOST);
697 ASSERT_NO_FATAL_FAILURE(
698 RunTest("serial_unittest.js", "testRestoreAndReceiveErrorSetUp"));
699 env()->context()->DispatchOnUnloadEvent();
700 scoped_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment());
701 ApiTestEnvironment new_api_test_env(new_env.get());
702 PrepareEnvironment(&new_api_test_env, stash_backend_.get());
703 new_api_test_env.RunTest("serial_unittest.js", "testRestoreAndReceiveError");
706 TEST_F(SerialApiTest, StashAndRestoreNoConnections) {
707 ASSERT_NO_FATAL_FAILURE(
708 RunTest("serial_unittest.js", "testStashNoConnections"));
709 env()->context()->DispatchOnUnloadEvent();
710 io_handler_ = nullptr;
711 scoped_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment());
712 ApiTestEnvironment new_api_test_env(new_env.get());
713 PrepareEnvironment(&new_api_test_env, stash_backend_.get());
714 new_api_test_env.RunTest("serial_unittest.js", "testRestoreNoConnections");
717 } // namespace extensions