1 // Copyright 2018 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. 4 5 #include <stdio.h> 6 7 #include "base/bind.h" 8 #include "base/logging.h" 9 #include "base/message_loop/message_pump_type.h" 10 #include "base/test/launcher/unit_test_launcher.h" 11 #include "base/test/test_suite.h" 12 #include "base/threading/thread.h" 13 #include "mojo/core/embedder/embedder.h" 14 #include "mojo/core/embedder/scoped_ipc_support.h" 15 #include "testing/gtest/include/gtest/gtest.h" 16 17 class MojoEnabledTestEnvironment final : public testing::Environment { 18 public: MojoEnabledTestEnvironment()19 MojoEnabledTestEnvironment() : mojo_ipc_thread_("MojoIpcThread") {} 20 21 ~MojoEnabledTestEnvironment() final = default; 22 SetUp()23 void SetUp() final { 24 mojo::core::Init(); 25 mojo_ipc_thread_.StartWithOptions( 26 base::Thread::Options(base::MessagePumpType::IO, 0)); 27 mojo_ipc_support_.reset(new mojo::core::ScopedIPCSupport( 28 mojo_ipc_thread_.task_runner(), 29 mojo::core::ScopedIPCSupport::ShutdownPolicy::FAST)); 30 VLOG(1) << "Mojo initialized"; 31 } 32 TearDown()33 void TearDown() final { 34 mojo_ipc_support_.reset(); 35 VLOG(1) << "Mojo IPC tear down"; 36 } 37 38 private: 39 base::Thread mojo_ipc_thread_; 40 std::unique_ptr<mojo::core::ScopedIPCSupport> mojo_ipc_support_; 41 }; 42 main(int argc,char * argv[])43int main(int argc, char* argv[]) { 44 base::TestSuite test_suite(argc, argv); 45 testing::AddGlobalTestEnvironment(new MojoEnabledTestEnvironment()); 46 return base::LaunchUnitTests( 47 argc, argv, 48 base::BindOnce(&base::TestSuite::Run, base::Unretained(&test_suite))); 49 } 50