Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(822)

Side by Side Diff: extensions/renderer/api/serial/serial_api_unittest.cc

Issue 2326913003: Privatize StrongBinding lifetime management (Closed)
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h"
11 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
12 #include "device/serial/serial_device_enumerator.h" 13 #include "device/serial/serial_device_enumerator.h"
13 #include "device/serial/serial_service_impl.h" 14 #include "device/serial/serial_service_impl.h"
14 #include "device/serial/test_serial_io_handler.h" 15 #include "device/serial/test_serial_io_handler.h"
15 #include "extensions/browser/mojo/stash_backend.h" 16 #include "extensions/browser/mojo/stash_backend.h"
16 #include "extensions/common/mojo/keep_alive.mojom.h" 17 #include "extensions/common/mojo/keep_alive.mojom.h"
17 #include "extensions/renderer/api_test_base.h" 18 #include "extensions/renderer/api_test_base.h"
18 #include "grit/extensions_renderer_resources.h" 19 #include "grit/extensions_renderer_resources.h"
20 #include "mojo/public/cpp/bindings/strong_binding.h"
19 21
20 // A test launcher for tests for the serial API defined in 22 // A test launcher for tests for the serial API defined in
21 // extensions/test/data/serial_unittest.js. Each C++ test function sets up a 23 // extensions/test/data/serial_unittest.js. Each C++ test function sets up a
22 // fake DeviceEnumerator or SerialIoHandler expecting or returning particular 24 // fake DeviceEnumerator or SerialIoHandler expecting or returning particular
23 // values for that test. 25 // values for that test.
24 26
25 namespace extensions { 27 namespace extensions {
26 28
27 namespace { 29 namespace {
28 30
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 429
428 private: 430 private:
429 scoped_refptr<device::SerialIoHandler> GetIoHandler() { 431 scoped_refptr<device::SerialIoHandler> GetIoHandler() {
430 if (!io_handler_.get()) 432 if (!io_handler_.get())
431 io_handler_ = new TestIoHandlerBase; 433 io_handler_ = new TestIoHandlerBase;
432 return io_handler_; 434 return io_handler_;
433 } 435 }
434 436
435 void CreateSerialService( 437 void CreateSerialService(
436 mojo::InterfaceRequest<device::serial::SerialService> request) { 438 mojo::InterfaceRequest<device::serial::SerialService> request) {
437 new device::SerialServiceImpl( 439 mojo::MakeStrongBinding(base::MakeUnique<device::SerialServiceImpl>(
438 new device::SerialConnectionFactory( 440 new device::SerialConnectionFactory(
439 base::Bind(&SerialApiTest::GetIoHandler, base::Unretained(this)), 441 base::Bind(&SerialApiTest::GetIoHandler,
440 base::ThreadTaskRunnerHandle::Get()), 442 base::Unretained(this)),
441 std::unique_ptr<device::SerialDeviceEnumerator>( 443 base::ThreadTaskRunnerHandle::Get()),
442 new FakeSerialDeviceEnumerator), 444 base::MakeUnique<FakeSerialDeviceEnumerator>()),
443 std::move(request)); 445 std::move(request));
444 } 446 }
445 447
446 DISALLOW_COPY_AND_ASSIGN(SerialApiTest); 448 DISALLOW_COPY_AND_ASSIGN(SerialApiTest);
447 }; 449 };
448 450
449 TEST_F(SerialApiTest, GetDevices) { 451 TEST_F(SerialApiTest, GetDevices) {
450 RunTest("serial_unittest.js", "testGetDevices"); 452 RunTest("serial_unittest.js", "testGetDevices");
451 } 453 }
452 454
453 TEST_F(SerialApiTest, ConnectFail) { 455 TEST_F(SerialApiTest, ConnectFail) {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 ASSERT_NO_FATAL_FAILURE( 732 ASSERT_NO_FATAL_FAILURE(
731 RunTest("serial_unittest.js", "testStashNoConnections")); 733 RunTest("serial_unittest.js", "testStashNoConnections"));
732 io_handler_ = nullptr; 734 io_handler_ = nullptr;
733 std::unique_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment()); 735 std::unique_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment());
734 ApiTestEnvironment new_api_test_env(new_env.get()); 736 ApiTestEnvironment new_api_test_env(new_env.get());
735 PrepareEnvironment(&new_api_test_env, stash_backend_.get()); 737 PrepareEnvironment(&new_api_test_env, stash_backend_.get());
736 new_api_test_env.RunTest("serial_unittest.js", "testRestoreNoConnections"); 738 new_api_test_env.RunTest("serial_unittest.js", "testRestoreNoConnections");
737 } 739 }
738 740
739 } // namespace extensions 741 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/mojo/stash_backend.cc ('k') | extensions/renderer/mojo/keep_alive_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698