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
{
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();
39 result
[2]->display_name
= "";
50 device::serial::HostControlSignals
GenerateControlSignals(OptionalValue dtr
,
52 device::serial::HostControlSignals result
;
54 case OPTIONAL_VALUE_UNSET
:
56 case OPTIONAL_VALUE_FALSE
:
58 result
.has_dtr
= true;
60 case OPTIONAL_VALUE_TRUE
:
62 result
.has_dtr
= true;
66 case OPTIONAL_VALUE_UNSET
:
68 case OPTIONAL_VALUE_FALSE
:
70 result
.has_rts
= true;
72 case OPTIONAL_VALUE_TRUE
:
74 result
.has_rts
= true;
80 device::serial::ConnectionOptions
GenerateConnectionOptions(
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
:
94 case OPTIONAL_VALUE_FALSE
:
95 result
.cts_flow_control
= false;
96 result
.has_cts_flow_control
= true;
98 case OPTIONAL_VALUE_TRUE
:
99 result
.cts_flow_control
= true;
100 result
.has_cts_flow_control
= true;
106 class TestIoHandlerBase
: public device::TestSerialIoHandler
{
108 TestIoHandlerBase() : calls_(0) {}
110 size_t num_calls() const { return calls_
; }
113 ~TestIoHandlerBase() override
{}
114 void record_call() const { calls_
++; }
117 mutable size_t calls_
;
119 DISALLOW_COPY_AND_ASSIGN(TestIoHandlerBase
);
122 class SetControlSignalsTestIoHandler
: public TestIoHandlerBase
{
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
))
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
);
151 ~SetControlSignalsTestIoHandler() override
{}
153 DISALLOW_COPY_AND_ASSIGN(SetControlSignalsTestIoHandler
);
156 class GetControlSignalsTestIoHandler
: public TestIoHandlerBase
{
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;
168 return signals
.Pass();
172 ~GetControlSignalsTestIoHandler() override
{}
174 DISALLOW_COPY_AND_ASSIGN(GetControlSignalsTestIoHandler
);
177 class ConfigurePortTestIoHandler
: public TestIoHandlerBase
{
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()) {
246 if (num_calls() >= arraysize(expected_options
)) {
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
);
263 ~ConfigurePortTestIoHandler() override
{}
265 DISALLOW_COPY_AND_ASSIGN(ConfigurePortTestIoHandler
);
268 class FlushTestIoHandler
: public TestIoHandlerBase
{
270 FlushTestIoHandler() {}
272 bool Flush() const override
{
278 ~FlushTestIoHandler() override
{}
280 DISALLOW_COPY_AND_ASSIGN(FlushTestIoHandler
);
283 class FailToConnectTestIoHandler
: public TestIoHandlerBase
{
285 FailToConnectTestIoHandler() {}
286 void Open(const std::string
& port
,
287 const device::serial::ConnectionOptions
& options
,
288 const OpenCompleteCallback
& callback
) override
{
294 ~FailToConnectTestIoHandler() override
{}
296 DISALLOW_COPY_AND_ASSIGN(FailToConnectTestIoHandler
);
299 class FailToGetInfoTestIoHandler
: public TestIoHandlerBase
{
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();
310 ~FailToGetInfoTestIoHandler() override
{}
312 mutable int times_to_succeed_
;
314 DISALLOW_COPY_AND_ASSIGN(FailToGetInfoTestIoHandler
);
317 class SendErrorTestIoHandler
: public TestIoHandlerBase
{
319 explicit SendErrorTestIoHandler(device::serial::SendError error
)
322 void WriteImpl() override
{ QueueWriteCompleted(0, error_
); }
325 ~SendErrorTestIoHandler() override
{}
327 device::serial::SendError error_
;
329 DISALLOW_COPY_AND_ASSIGN(SendErrorTestIoHandler
);
332 class FixedDataReceiveTestIoHandler
: public TestIoHandlerBase
{
334 explicit FixedDataReceiveTestIoHandler(const std::string
& data
)
337 void ReadImpl() override
{
338 if (pending_read_buffer_len() < data_
.size())
340 memcpy(pending_read_buffer(), data_
.c_str(), data_
.size());
341 QueueReadCompleted(static_cast<uint32_t>(data_
.size()),
342 device::serial::RECEIVE_ERROR_NONE
);
346 ~FixedDataReceiveTestIoHandler() override
{}
348 const std::string data_
;
350 DISALLOW_COPY_AND_ASSIGN(FixedDataReceiveTestIoHandler
);
353 class ReceiveErrorTestIoHandler
: public TestIoHandlerBase
{
355 explicit ReceiveErrorTestIoHandler(device::serial::ReceiveError error
)
358 void ReadImpl() override
{ QueueReadCompleted(0, error_
); }
361 ~ReceiveErrorTestIoHandler() override
{}
363 device::serial::ReceiveError error_
;
365 DISALLOW_COPY_AND_ASSIGN(ReceiveErrorTestIoHandler
);
368 class SendDataWithErrorIoHandler
: public TestIoHandlerBase
{
370 SendDataWithErrorIoHandler() : sent_error_(false) {}
371 void WriteImpl() override
{
373 WriteCompleted(pending_write_buffer_len(),
374 device::serial::SEND_ERROR_NONE
);
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
);
384 ~SendDataWithErrorIoHandler() override
{}
388 DISALLOW_COPY_AND_ASSIGN(SendDataWithErrorIoHandler
);
391 class BlockSendsForeverSendIoHandler
: public TestIoHandlerBase
{
393 BlockSendsForeverSendIoHandler() {}
394 void WriteImpl() override
{}
397 ~BlockSendsForeverSendIoHandler() override
{}
399 DISALLOW_COPY_AND_ASSIGN(BlockSendsForeverSendIoHandler
);
404 class SerialApiTest
: public ApiTestBase
{
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_
;
430 scoped_refptr
<device::SerialIoHandler
> GetIoHandler() {
431 if (!io_handler_
.get())
432 io_handler_
= new TestIoHandlerBase
;
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
)),
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
) {
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
) {
595 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_DISCONNECTED
);
596 RunTest("serial_unittest.js", "testReceiveErrorDisconnected");
599 TEST_F(SerialApiTest
, ReceiveErrorDeviceLost
) {
601 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_DEVICE_LOST
);
602 RunTest("serial_unittest.js", "testReceiveErrorDeviceLost");
605 TEST_F(SerialApiTest
, ReceiveErrorSystemError
) {
607 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_SYSTEM_ERROR
);
608 RunTest("serial_unittest.js", "testReceiveErrorSystemError");
611 TEST_F(SerialApiTest
, SendErrorDisconnected
) {
613 new SendErrorTestIoHandler(device::serial::SEND_ERROR_DISCONNECTED
);
614 RunTest("serial_unittest.js", "testSendErrorDisconnected");
617 TEST_F(SerialApiTest
, SendErrorSystemError
) {
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
) {
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