Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / extensions / renderer / api / serial / serial_api_unittest.cc
blob0d247b94aed6acbf2a75c8a4947867df5d537055
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 "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/browser/mojo/stash_backend.h"
9 #include "extensions/common/mojo/keep_alive.mojom.h"
10 #include "extensions/renderer/api_test_base.h"
11 #include "grit/extensions_renderer_resources.h"
13 // A test launcher for tests for the serial API defined in
14 // extensions/test/data/serial_unittest.js. Each C++ test function sets up a
15 // fake DeviceEnumerator or SerialIoHandler expecting or returning particular
16 // values for that test.
18 namespace extensions {
20 namespace {
22 class FakeSerialDeviceEnumerator : public device::SerialDeviceEnumerator {
23 mojo::Array<device::serial::DeviceInfoPtr> GetDevices() override {
24 mojo::Array<device::serial::DeviceInfoPtr> result(3);
25 result[0] = device::serial::DeviceInfo::New();
26 result[0]->path = "device";
27 result[0]->vendor_id = 1234;
28 result[0]->has_vendor_id = true;
29 result[0]->product_id = 5678;
30 result[0]->has_product_id = true;
31 result[0]->display_name = "foo";
32 result[1] = device::serial::DeviceInfo::New();
33 result[1]->path = "another_device";
34 // These IDs should be ignored.
35 result[1]->vendor_id = 1234;
36 result[1]->product_id = 5678;
37 result[2] = device::serial::DeviceInfo::New();
38 result[2]->path = "";
39 result[2]->display_name = "";
40 return result.Pass();
44 enum OptionalValue {
45 OPTIONAL_VALUE_UNSET,
46 OPTIONAL_VALUE_FALSE,
47 OPTIONAL_VALUE_TRUE,
50 device::serial::HostControlSignals GenerateControlSignals(OptionalValue dtr,
51 OptionalValue rts) {
52 device::serial::HostControlSignals result;
53 switch (dtr) {
54 case OPTIONAL_VALUE_UNSET:
55 break;
56 case OPTIONAL_VALUE_FALSE:
57 result.dtr = false;
58 result.has_dtr = true;
59 break;
60 case OPTIONAL_VALUE_TRUE:
61 result.dtr = true;
62 result.has_dtr = true;
63 break;
65 switch (rts) {
66 case OPTIONAL_VALUE_UNSET:
67 break;
68 case OPTIONAL_VALUE_FALSE:
69 result.rts = false;
70 result.has_rts = true;
71 break;
72 case OPTIONAL_VALUE_TRUE:
73 result.rts = true;
74 result.has_rts = true;
75 break;
77 return result;
80 device::serial::ConnectionOptions GenerateConnectionOptions(
81 int bitrate,
82 device::serial::DataBits data_bits,
83 device::serial::ParityBit parity_bit,
84 device::serial::StopBits stop_bits,
85 OptionalValue cts_flow_control) {
86 device::serial::ConnectionOptions result;
87 result.bitrate = bitrate;
88 result.data_bits = data_bits;
89 result.parity_bit = parity_bit;
90 result.stop_bits = stop_bits;
91 switch (cts_flow_control) {
92 case OPTIONAL_VALUE_UNSET:
93 break;
94 case OPTIONAL_VALUE_FALSE:
95 result.cts_flow_control = false;
96 result.has_cts_flow_control = true;
97 break;
98 case OPTIONAL_VALUE_TRUE:
99 result.cts_flow_control = true;
100 result.has_cts_flow_control = true;
101 break;
103 return result;
106 class TestIoHandlerBase : public device::TestSerialIoHandler {
107 public:
108 TestIoHandlerBase() : calls_(0) {}
110 size_t num_calls() const { return calls_; }
112 protected:
113 ~TestIoHandlerBase() override {}
114 void record_call() const { calls_++; }
116 private:
117 mutable size_t calls_;
119 DISALLOW_COPY_AND_ASSIGN(TestIoHandlerBase);
122 class SetControlSignalsTestIoHandler : public TestIoHandlerBase {
123 public:
124 SetControlSignalsTestIoHandler() {}
126 bool SetControlSignals(
127 const device::serial::HostControlSignals& signals) override {
128 static const device::serial::HostControlSignals expected_signals[] = {
129 GenerateControlSignals(OPTIONAL_VALUE_UNSET, OPTIONAL_VALUE_UNSET),
130 GenerateControlSignals(OPTIONAL_VALUE_FALSE, OPTIONAL_VALUE_UNSET),
131 GenerateControlSignals(OPTIONAL_VALUE_TRUE, OPTIONAL_VALUE_UNSET),
132 GenerateControlSignals(OPTIONAL_VALUE_UNSET, OPTIONAL_VALUE_FALSE),
133 GenerateControlSignals(OPTIONAL_VALUE_FALSE, OPTIONAL_VALUE_FALSE),
134 GenerateControlSignals(OPTIONAL_VALUE_TRUE, OPTIONAL_VALUE_FALSE),
135 GenerateControlSignals(OPTIONAL_VALUE_UNSET, OPTIONAL_VALUE_TRUE),
136 GenerateControlSignals(OPTIONAL_VALUE_FALSE, OPTIONAL_VALUE_TRUE),
137 GenerateControlSignals(OPTIONAL_VALUE_TRUE, OPTIONAL_VALUE_TRUE),
139 if (num_calls() >= arraysize(expected_signals))
140 return false;
142 EXPECT_EQ(expected_signals[num_calls()].has_dtr, signals.has_dtr);
143 EXPECT_EQ(expected_signals[num_calls()].dtr, signals.dtr);
144 EXPECT_EQ(expected_signals[num_calls()].has_rts, signals.has_rts);
145 EXPECT_EQ(expected_signals[num_calls()].rts, signals.rts);
146 record_call();
147 return true;
150 private:
151 ~SetControlSignalsTestIoHandler() override {}
153 DISALLOW_COPY_AND_ASSIGN(SetControlSignalsTestIoHandler);
156 class GetControlSignalsTestIoHandler : public TestIoHandlerBase {
157 public:
158 GetControlSignalsTestIoHandler() {}
160 device::serial::DeviceControlSignalsPtr GetControlSignals() const override {
161 device::serial::DeviceControlSignalsPtr signals(
162 device::serial::DeviceControlSignals::New());
163 signals->dcd = num_calls() & 1;
164 signals->cts = num_calls() & 2;
165 signals->ri = num_calls() & 4;
166 signals->dsr = num_calls() & 8;
167 record_call();
168 return signals.Pass();
171 private:
172 ~GetControlSignalsTestIoHandler() override {}
174 DISALLOW_COPY_AND_ASSIGN(GetControlSignalsTestIoHandler);
177 class ConfigurePortTestIoHandler : public TestIoHandlerBase {
178 public:
179 ConfigurePortTestIoHandler() {}
180 bool ConfigurePortImpl() override {
181 static const device::serial::ConnectionOptions expected_options[] = {
182 // Each JavaScript call to chrome.serial.update only modifies a single
183 // property of the connection however this function can only check the
184 // final value of all options. The modified option is marked with "set".
185 GenerateConnectionOptions(9600,
186 device::serial::DATA_BITS_EIGHT,
187 device::serial::PARITY_BIT_NO,
188 device::serial::STOP_BITS_ONE,
189 OPTIONAL_VALUE_FALSE),
190 GenerateConnectionOptions(57600, // set
191 device::serial::DATA_BITS_EIGHT,
192 device::serial::PARITY_BIT_NO,
193 device::serial::STOP_BITS_ONE,
194 OPTIONAL_VALUE_FALSE),
195 GenerateConnectionOptions(57600,
196 device::serial::DATA_BITS_SEVEN, // set
197 device::serial::PARITY_BIT_NO,
198 device::serial::STOP_BITS_ONE,
199 OPTIONAL_VALUE_FALSE),
200 GenerateConnectionOptions(57600,
201 device::serial::DATA_BITS_EIGHT, // set
202 device::serial::PARITY_BIT_NO,
203 device::serial::STOP_BITS_ONE,
204 OPTIONAL_VALUE_FALSE),
205 GenerateConnectionOptions(57600,
206 device::serial::DATA_BITS_EIGHT,
207 device::serial::PARITY_BIT_NO, // set
208 device::serial::STOP_BITS_ONE,
209 OPTIONAL_VALUE_FALSE),
210 GenerateConnectionOptions(57600,
211 device::serial::DATA_BITS_EIGHT,
212 device::serial::PARITY_BIT_ODD, // set
213 device::serial::STOP_BITS_ONE,
214 OPTIONAL_VALUE_FALSE),
215 GenerateConnectionOptions(57600,
216 device::serial::DATA_BITS_EIGHT,
217 device::serial::PARITY_BIT_EVEN, // set
218 device::serial::STOP_BITS_ONE,
219 OPTIONAL_VALUE_FALSE),
220 GenerateConnectionOptions(57600,
221 device::serial::DATA_BITS_EIGHT,
222 device::serial::PARITY_BIT_EVEN,
223 device::serial::STOP_BITS_ONE, // set
224 OPTIONAL_VALUE_FALSE),
225 GenerateConnectionOptions(57600,
226 device::serial::DATA_BITS_EIGHT,
227 device::serial::PARITY_BIT_EVEN,
228 device::serial::STOP_BITS_TWO, // set
229 OPTIONAL_VALUE_FALSE),
230 GenerateConnectionOptions(57600,
231 device::serial::DATA_BITS_EIGHT,
232 device::serial::PARITY_BIT_EVEN,
233 device::serial::STOP_BITS_TWO,
234 OPTIONAL_VALUE_FALSE), // set
235 GenerateConnectionOptions(57600,
236 device::serial::DATA_BITS_EIGHT,
237 device::serial::PARITY_BIT_EVEN,
238 device::serial::STOP_BITS_TWO,
239 OPTIONAL_VALUE_TRUE), // set
242 if (!TestIoHandlerBase::ConfigurePortImpl()) {
243 return false;
246 if (num_calls() >= arraysize(expected_options)) {
247 return false;
250 EXPECT_EQ(expected_options[num_calls()].bitrate, options().bitrate);
251 EXPECT_EQ(expected_options[num_calls()].data_bits, options().data_bits);
252 EXPECT_EQ(expected_options[num_calls()].parity_bit, options().parity_bit);
253 EXPECT_EQ(expected_options[num_calls()].stop_bits, options().stop_bits);
254 EXPECT_EQ(expected_options[num_calls()].has_cts_flow_control,
255 options().has_cts_flow_control);
256 EXPECT_EQ(expected_options[num_calls()].cts_flow_control,
257 options().cts_flow_control);
258 record_call();
259 return true;
262 private:
263 ~ConfigurePortTestIoHandler() override {}
265 DISALLOW_COPY_AND_ASSIGN(ConfigurePortTestIoHandler);
268 class FlushTestIoHandler : public TestIoHandlerBase {
269 public:
270 FlushTestIoHandler() {}
272 bool Flush() const override {
273 record_call();
274 return true;
277 private:
278 ~FlushTestIoHandler() override {}
280 DISALLOW_COPY_AND_ASSIGN(FlushTestIoHandler);
283 class FailToConnectTestIoHandler : public TestIoHandlerBase {
284 public:
285 FailToConnectTestIoHandler() {}
286 void Open(const std::string& port,
287 const device::serial::ConnectionOptions& options,
288 const OpenCompleteCallback& callback) override {
289 callback.Run(false);
290 return;
293 private:
294 ~FailToConnectTestIoHandler() override {}
296 DISALLOW_COPY_AND_ASSIGN(FailToConnectTestIoHandler);
299 class FailToGetInfoTestIoHandler : public TestIoHandlerBase {
300 public:
301 explicit FailToGetInfoTestIoHandler(int times_to_succeed)
302 : times_to_succeed_(times_to_succeed) {}
303 device::serial::ConnectionInfoPtr GetPortInfo() const override {
304 if (times_to_succeed_-- > 0)
305 return device::TestSerialIoHandler::GetPortInfo();
306 return device::serial::ConnectionInfoPtr();
309 private:
310 ~FailToGetInfoTestIoHandler() override {}
312 mutable int times_to_succeed_;
314 DISALLOW_COPY_AND_ASSIGN(FailToGetInfoTestIoHandler);
317 class SendErrorTestIoHandler : public TestIoHandlerBase {
318 public:
319 explicit SendErrorTestIoHandler(device::serial::SendError error)
320 : error_(error) {}
322 void WriteImpl() override { QueueWriteCompleted(0, error_); }
324 private:
325 ~SendErrorTestIoHandler() override {}
327 device::serial::SendError error_;
329 DISALLOW_COPY_AND_ASSIGN(SendErrorTestIoHandler);
332 class FixedDataReceiveTestIoHandler : public TestIoHandlerBase {
333 public:
334 explicit FixedDataReceiveTestIoHandler(const std::string& data)
335 : data_(data) {}
337 void ReadImpl() override {
338 if (pending_read_buffer_len() < data_.size())
339 return;
340 memcpy(pending_read_buffer(), data_.c_str(), data_.size());
341 QueueReadCompleted(static_cast<uint32_t>(data_.size()),
342 device::serial::RECEIVE_ERROR_NONE);
345 private:
346 ~FixedDataReceiveTestIoHandler() override {}
348 const std::string data_;
350 DISALLOW_COPY_AND_ASSIGN(FixedDataReceiveTestIoHandler);
353 class ReceiveErrorTestIoHandler : public TestIoHandlerBase {
354 public:
355 explicit ReceiveErrorTestIoHandler(device::serial::ReceiveError error)
356 : error_(error) {}
358 void ReadImpl() override { QueueReadCompleted(0, error_); }
360 private:
361 ~ReceiveErrorTestIoHandler() override {}
363 device::serial::ReceiveError error_;
365 DISALLOW_COPY_AND_ASSIGN(ReceiveErrorTestIoHandler);
368 class SendDataWithErrorIoHandler : public TestIoHandlerBase {
369 public:
370 SendDataWithErrorIoHandler() : sent_error_(false) {}
371 void WriteImpl() override {
372 if (sent_error_) {
373 WriteCompleted(pending_write_buffer_len(),
374 device::serial::SEND_ERROR_NONE);
375 return;
377 sent_error_ = true;
378 // We expect the JS test code to send a 4 byte buffer.
379 ASSERT_LT(2u, pending_write_buffer_len());
380 WriteCompleted(2, device::serial::SEND_ERROR_SYSTEM_ERROR);
383 private:
384 ~SendDataWithErrorIoHandler() override {}
386 bool sent_error_;
388 DISALLOW_COPY_AND_ASSIGN(SendDataWithErrorIoHandler);
391 class BlockSendsForeverSendIoHandler : public TestIoHandlerBase {
392 public:
393 BlockSendsForeverSendIoHandler() {}
394 void WriteImpl() override {}
396 private:
397 ~BlockSendsForeverSendIoHandler() override {}
399 DISALLOW_COPY_AND_ASSIGN(BlockSendsForeverSendIoHandler);
402 } // namespace
404 class SerialApiTest : public ApiTestBase {
405 public:
406 SerialApiTest() {}
408 void SetUp() override {
409 ApiTestBase::SetUp();
410 stash_backend_.reset(new StashBackend(base::Closure()));
411 PrepareEnvironment(api_test_env(), stash_backend_.get());
414 void PrepareEnvironment(ApiTestEnvironment* environment,
415 StashBackend* stash_backend) {
416 environment->env()->RegisterModule("serial", IDR_SERIAL_CUSTOM_BINDINGS_JS);
417 environment->service_provider()->AddService<device::serial::SerialService>(
418 base::Bind(&SerialApiTest::CreateSerialService,
419 base::Unretained(this)));
420 environment->service_provider()->AddService(base::Bind(
421 &StashBackend::BindToRequest, base::Unretained(stash_backend)));
422 environment->service_provider()->IgnoreServiceRequests<KeepAlive>();
425 scoped_refptr<TestIoHandlerBase> io_handler_;
427 scoped_ptr<StashBackend> stash_backend_;
429 private:
430 scoped_refptr<device::SerialIoHandler> GetIoHandler() {
431 if (!io_handler_.get())
432 io_handler_ = new TestIoHandlerBase;
433 return io_handler_;
436 void CreateSerialService(
437 mojo::InterfaceRequest<device::serial::SerialService> request) {
438 mojo::BindToRequest(new device::SerialServiceImpl(
439 new device::SerialConnectionFactory(
440 base::Bind(&SerialApiTest::GetIoHandler,
441 base::Unretained(this)),
442 base::MessageLoopProxy::current()),
443 scoped_ptr<device::SerialDeviceEnumerator>(
444 new FakeSerialDeviceEnumerator)),
445 &request);
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, ReceiveErrorSystemError) {
606 io_handler_ =
607 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_SYSTEM_ERROR);
608 RunTest("serial_unittest.js", "testReceiveErrorSystemError");
611 TEST_F(SerialApiTest, SendErrorDisconnected) {
612 io_handler_ =
613 new SendErrorTestIoHandler(device::serial::SEND_ERROR_DISCONNECTED);
614 RunTest("serial_unittest.js", "testSendErrorDisconnected");
617 TEST_F(SerialApiTest, SendErrorSystemError) {
618 io_handler_ =
619 new SendErrorTestIoHandler(device::serial::SEND_ERROR_SYSTEM_ERROR);
620 RunTest("serial_unittest.js", "testSendErrorSystemError");
623 TEST_F(SerialApiTest, DisconnectUnknownConnectionId) {
624 RunTest("serial_unittest.js", "testDisconnectUnknownConnectionId");
627 TEST_F(SerialApiTest, GetInfoUnknownConnectionId) {
628 RunTest("serial_unittest.js", "testGetInfoUnknownConnectionId");
631 TEST_F(SerialApiTest, UpdateUnknownConnectionId) {
632 RunTest("serial_unittest.js", "testUpdateUnknownConnectionId");
635 TEST_F(SerialApiTest, SetControlSignalsUnknownConnectionId) {
636 RunTest("serial_unittest.js", "testSetControlSignalsUnknownConnectionId");
639 TEST_F(SerialApiTest, GetControlSignalsUnknownConnectionId) {
640 RunTest("serial_unittest.js", "testGetControlSignalsUnknownConnectionId");
643 TEST_F(SerialApiTest, FlushUnknownConnectionId) {
644 RunTest("serial_unittest.js", "testFlushUnknownConnectionId");
647 TEST_F(SerialApiTest, SetPausedUnknownConnectionId) {
648 RunTest("serial_unittest.js", "testSetPausedUnknownConnectionId");
651 TEST_F(SerialApiTest, SendUnknownConnectionId) {
652 RunTest("serial_unittest.js", "testSendUnknownConnectionId");
655 TEST_F(SerialApiTest, StashAndRestoreDuringEcho) {
656 ASSERT_NO_FATAL_FAILURE(RunTest("serial_unittest.js", "testSendAndStash"));
657 env()->context()->DispatchOnUnloadEvent();
658 scoped_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment());
659 ApiTestEnvironment new_api_test_env(new_env.get());
660 PrepareEnvironment(&new_api_test_env, stash_backend_.get());
661 new_api_test_env.RunTest("serial_unittest.js", "testRestoreAndReceive");
664 TEST_F(SerialApiTest, StashAndRestoreDuringEchoError) {
665 io_handler_ =
666 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_DEVICE_LOST);
667 ASSERT_NO_FATAL_FAILURE(
668 RunTest("serial_unittest.js", "testRestoreAndReceiveErrorSetUp"));
669 env()->context()->DispatchOnUnloadEvent();
670 scoped_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment());
671 ApiTestEnvironment new_api_test_env(new_env.get());
672 PrepareEnvironment(&new_api_test_env, stash_backend_.get());
673 new_api_test_env.RunTest("serial_unittest.js", "testRestoreAndReceiveError");
676 TEST_F(SerialApiTest, StashAndRestoreNoConnections) {
677 ASSERT_NO_FATAL_FAILURE(
678 RunTest("serial_unittest.js", "testStashNoConnections"));
679 env()->context()->DispatchOnUnloadEvent();
680 io_handler_ = nullptr;
681 scoped_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment());
682 ApiTestEnvironment new_api_test_env(new_env.get());
683 PrepareEnvironment(&new_api_test_env, stash_backend_.get());
684 new_api_test_env.RunTest("serial_unittest.js", "testRestoreNoConnections");
687 } // namespace extensions