diff options
author | sammc <sammc@chromium.org> | 2015-02-09 23:45:53 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-10 07:46:43 +0000 |
commit | d3d01eebe4aa13a42e3a3a14f08cbc219bbef945 (patch) | |
tree | 9f0b6c317aeea24d7a3c1bf21c190ef5165b87ab /extensions/renderer/api | |
parent | a5b3eb75b80954fdb346d194419cd47f2ad6b981 (diff) | |
download | chromium_src-d3d01eebe4aa13a42e3a3a14f08cbc219bbef945.zip chromium_src-d3d01eebe4aa13a42e3a3a14f08cbc219bbef945.tar.gz chromium_src-d3d01eebe4aa13a42e3a3a14f08cbc219bbef945.tar.bz2 |
Use the JS stash client from the JS serial service.
This allows persistent serial connections to be supported on the
mojo-service-backed serial implementation.
BUG=389016
Review URL: https://codereview.chromium.org/908153002
Cr-Commit-Position: refs/heads/master@{#315514}
Diffstat (limited to 'extensions/renderer/api')
-rw-r--r-- | extensions/renderer/api/serial/serial_api_unittest.cc | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/extensions/renderer/api/serial/serial_api_unittest.cc b/extensions/renderer/api/serial/serial_api_unittest.cc index 81c5c35..0d247b9 100644 --- a/extensions/renderer/api/serial/serial_api_unittest.cc +++ b/extensions/renderer/api/serial/serial_api_unittest.cc @@ -5,6 +5,7 @@ #include "device/serial/serial_device_enumerator.h" #include "device/serial/serial_service_impl.h" #include "device/serial/test_serial_io_handler.h" +#include "extensions/browser/mojo/stash_backend.h" #include "extensions/common/mojo/keep_alive.mojom.h" #include "extensions/renderer/api_test_base.h" #include "grit/extensions_renderer_resources.h" @@ -406,14 +407,25 @@ class SerialApiTest : public ApiTestBase { void SetUp() override { ApiTestBase::SetUp(); - env()->RegisterModule("serial", IDR_SERIAL_CUSTOM_BINDINGS_JS); - service_provider()->AddService<device::serial::SerialService>(base::Bind( - &SerialApiTest::CreateSerialService, base::Unretained(this))); - service_provider()->IgnoreServiceRequests<KeepAlive>(); + stash_backend_.reset(new StashBackend(base::Closure())); + PrepareEnvironment(api_test_env(), stash_backend_.get()); + } + + void PrepareEnvironment(ApiTestEnvironment* environment, + StashBackend* stash_backend) { + environment->env()->RegisterModule("serial", IDR_SERIAL_CUSTOM_BINDINGS_JS); + environment->service_provider()->AddService<device::serial::SerialService>( + base::Bind(&SerialApiTest::CreateSerialService, + base::Unretained(this))); + environment->service_provider()->AddService(base::Bind( + &StashBackend::BindToRequest, base::Unretained(stash_backend))); + environment->service_provider()->IgnoreServiceRequests<KeepAlive>(); } scoped_refptr<TestIoHandlerBase> io_handler_; + scoped_ptr<StashBackend> stash_backend_; + private: scoped_refptr<device::SerialIoHandler> GetIoHandler() { if (!io_handler_.get()) @@ -640,4 +652,36 @@ TEST_F(SerialApiTest, SendUnknownConnectionId) { RunTest("serial_unittest.js", "testSendUnknownConnectionId"); } +TEST_F(SerialApiTest, StashAndRestoreDuringEcho) { + ASSERT_NO_FATAL_FAILURE(RunTest("serial_unittest.js", "testSendAndStash")); + env()->context()->DispatchOnUnloadEvent(); + scoped_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment()); + ApiTestEnvironment new_api_test_env(new_env.get()); + PrepareEnvironment(&new_api_test_env, stash_backend_.get()); + new_api_test_env.RunTest("serial_unittest.js", "testRestoreAndReceive"); +} + +TEST_F(SerialApiTest, StashAndRestoreDuringEchoError) { + io_handler_ = + new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_DEVICE_LOST); + ASSERT_NO_FATAL_FAILURE( + RunTest("serial_unittest.js", "testRestoreAndReceiveErrorSetUp")); + env()->context()->DispatchOnUnloadEvent(); + scoped_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment()); + ApiTestEnvironment new_api_test_env(new_env.get()); + PrepareEnvironment(&new_api_test_env, stash_backend_.get()); + new_api_test_env.RunTest("serial_unittest.js", "testRestoreAndReceiveError"); +} + +TEST_F(SerialApiTest, StashAndRestoreNoConnections) { + ASSERT_NO_FATAL_FAILURE( + RunTest("serial_unittest.js", "testStashNoConnections")); + env()->context()->DispatchOnUnloadEvent(); + io_handler_ = nullptr; + scoped_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment()); + ApiTestEnvironment new_api_test_env(new_env.get()); + PrepareEnvironment(&new_api_test_env, stash_backend_.get()); + new_api_test_env.RunTest("serial_unittest.js", "testRestoreNoConnections"); +} + } // namespace extensions |