summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/html_viewer/run_all_unittests.cc50
-rw-r--r--ipc/mojo/run_all_unittests.cc26
-rw-r--r--mojo/edk/embedder/embedder.cc8
-rw-r--r--mojo/edk/system/BUILD.gn2
-rw-r--r--mojo/edk/system/run_all_unittests.cc10
-rw-r--r--mojo/edk/system/simple_broker.cc81
-rw-r--r--mojo/edk/system/simple_broker.h38
-rw-r--r--mojo/edk/test/multiprocess_test_helper.cc20
-rw-r--r--mojo/edk/test/multiprocess_test_helper.h6
-rw-r--r--mojo/mojo_edk.gyp2
-rw-r--r--mojo/runner/host/child_process.cc3
11 files changed, 63 insertions, 183 deletions
diff --git a/components/html_viewer/run_all_unittests.cc b/components/html_viewer/run_all_unittests.cc
index 9a208e1..134c51e 100644
--- a/components/html_viewer/run_all_unittests.cc
+++ b/components/html_viewer/run_all_unittests.cc
@@ -30,48 +30,30 @@ std::vector<gfx::Display> GetTestDisplays() {
return displays;
}
-class NoAtExitBaseTestSuite : public base::TestSuite {
- public:
- NoAtExitBaseTestSuite(int argc, char** argv)
- : base::TestSuite(argc, argv, false), ui_init_(GetTestDisplays()) {
-#if defined(OS_ANDROID)
- base::MemoryMappedFile::Region resource_file_region;
- int fd = base::android::OpenApkAsset("assets/html_viewer.pak",
- &resource_file_region);
- CHECK_NE(fd, -1);
- ui::ResourceBundle::InitSharedInstanceWithPakPath(base::FilePath());
- ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion(
- base::File(fd), resource_file_region, ui::SCALE_FACTOR_100P);
-#else
- base::FilePath pak_path;
- CHECK(PathService::Get(base::DIR_MODULE, &pak_path));
- pak_path = pak_path.AppendASCII("html_viewer.pak");
- ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_path);
-#endif
- }
-
- private:
- ui::mojo::UIInit ui_init_;
-
- DISALLOW_COPY_AND_ASSIGN(NoAtExitBaseTestSuite);
-};
-
-int RunTestSuite(int argc, char** argv) {
- return NoAtExitBaseTestSuite(argc, argv).Run();
-}
-
} // namespace
int main(int argc, char** argv) {
+ base::TestSuite test_suite(argc, argv);
#if defined(OS_ANDROID)
JNIEnv* env = base::android::AttachCurrentThread();
base::RegisterContentUriTestUtils(env);
+ base::MemoryMappedFile::Region resource_file_region;
+ int fd = base::android::OpenApkAsset("assets/html_viewer.pak",
+ &resource_file_region);
+ CHECK_NE(fd, -1);
+ ui::ResourceBundle::InitSharedInstanceWithPakPath(base::FilePath());
+ ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion(
+ base::File(fd), resource_file_region, ui::SCALE_FACTOR_100P);
#else
- base::AtExitManager at_exit;
+ base::FilePath pak_path;
+ CHECK(PathService::Get(base::DIR_MODULE, &pak_path));
+ pak_path = pak_path.AppendASCII("html_viewer.pak");
+ ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_path);
#endif
+ ui::mojo::UIInit ui_init(GetTestDisplays());
mojo::embedder::Init();
- return base::LaunchUnitTests(argc,
- argv,
- base::Bind(&RunTestSuite, argc, argv));
+ return base::LaunchUnitTests(
+ argc, argv,
+ base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
}
diff --git a/ipc/mojo/run_all_unittests.cc b/ipc/mojo/run_all_unittests.cc
index 6382474..fd3c611 100644
--- a/ipc/mojo/run_all_unittests.cc
+++ b/ipc/mojo/run_all_unittests.cc
@@ -13,30 +13,14 @@
#include "base/test/test_file_util.h"
#endif
-namespace {
-
-class NoAtExitBaseTestSuite : public base::TestSuite {
- public:
- NoAtExitBaseTestSuite(int argc, char** argv)
- : base::TestSuite(argc, argv, false) {
- }
-};
-
-int RunTestSuite(int argc, char** argv) {
- return NoAtExitBaseTestSuite(argc, argv).Run();
-}
-
-} // namespace
-
int main(int argc, char** argv) {
- mojo::embedder::Init();
#if defined(OS_ANDROID)
JNIEnv* env = base::android::AttachCurrentThread();
base::RegisterContentUriTestUtils(env);
-#else
- base::AtExitManager at_exit;
#endif
- return base::LaunchUnitTestsSerially(argc,
- argv,
- base::Bind(&RunTestSuite, argc, argv));
+ base::TestSuite test_suite(argc, argv);
+ mojo::embedder::Init();
+ return base::LaunchUnitTestsSerially(
+ argc, argv,
+ base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
}
diff --git a/mojo/edk/embedder/embedder.cc b/mojo/edk/embedder/embedder.cc
index 5ab4ba6..f9b5c9d 100644
--- a/mojo/edk/embedder/embedder.cc
+++ b/mojo/edk/embedder/embedder.cc
@@ -7,6 +7,7 @@
#include "base/atomicops.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
+#include "base/command_line.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
@@ -23,7 +24,6 @@
#include "mojo/edk/system/core.h"
#include "mojo/edk/system/message_pipe_dispatcher.h"
#include "mojo/edk/system/platform_handle_dispatcher.h"
-#include "mojo/edk/system/simple_broker.h"
namespace mojo {
namespace edk {
@@ -118,8 +118,10 @@ void SetParentPipeHandle(ScopedPlatformHandle pipe) {
}
void Init() {
- if (!internal::g_broker)
- internal::g_broker = new SimpleBroker;
+ const base::CommandLine& command_line =
+ *base::CommandLine::ForCurrentProcess();
+ if (command_line.HasSwitch("use-new-edk") && !internal::g_broker)
+ BrokerState::GetInstance();
DCHECK(!internal::g_platform_support);
internal::g_platform_support = new SimplePlatformSupport();
diff --git a/mojo/edk/system/BUILD.gn b/mojo/edk/system/BUILD.gn
index 038d753..fe113d2 100644
--- a/mojo/edk/system/BUILD.gn
+++ b/mojo/edk/system/BUILD.gn
@@ -71,8 +71,6 @@ static_library("system") {
"raw_channel_win.cc",
"shared_buffer_dispatcher.cc",
"shared_buffer_dispatcher.h",
- "simple_broker.cc",
- "simple_broker.h",
"simple_dispatcher.cc",
"simple_dispatcher.h",
"transport_data.cc",
diff --git a/mojo/edk/system/run_all_unittests.cc b/mojo/edk/system/run_all_unittests.cc
index b68f6e2..71e1465 100644
--- a/mojo/edk/system/run_all_unittests.cc
+++ b/mojo/edk/system/run_all_unittests.cc
@@ -7,6 +7,7 @@
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/test_suite.h"
#include "mojo/edk/embedder/embedder.h"
+#include "mojo/edk/test/multiprocess_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
int main(int argc, char** argv) {
@@ -17,8 +18,15 @@ int main(int argc, char** argv) {
#if !defined(OS_ANDROID)
testing::GTEST_FLAG(death_test_style) = "threadsafe";
#endif
- mojo::edk::Init();
base::TestSuite test_suite(argc, argv);
+
+ // Must be run before mojo::edk::Init.
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ mojo::edk::test::kBrokerHandleSwitch)) {
+ mojo::edk::PreInitializeChildProcess();
+ }
+
+ mojo::edk::Init();
// TODO(use_chrome_edk): temporary to force new EDK.
base::CommandLine::ForCurrentProcess()->AppendSwitch("--use-new-edk");
diff --git a/mojo/edk/system/simple_broker.cc b/mojo/edk/system/simple_broker.cc
deleted file mode 100644
index 0760704..0000000
--- a/mojo/edk/system/simple_broker.cc
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/edk/system/simple_broker.h"
-
-#include "base/process/process.h"
-#include "mojo/edk/embedder/platform_channel_pair.h"
-
-#if defined(OS_WIN)
-#include <windows.h>
-#endif
-
-namespace mojo {
-namespace edk {
-
-SimpleBroker::SimpleBroker() {
-}
-
-SimpleBroker::~SimpleBroker() {
-}
-
-#if defined(OS_WIN)
-void SimpleBroker::CreatePlatformChannelPair(
- ScopedPlatformHandle* server, ScopedPlatformHandle* client) {
- PlatformChannelPair channel_pair;
- *server = channel_pair.PassServerHandle();
- *client = channel_pair.PassClientHandle();
-}
-
-void SimpleBroker::HandleToToken(const PlatformHandle* platform_handles,
- size_t count,
- uint64_t* tokens) {
- // Since we're not sure which process might ultimately deserialize the message
- // we can't duplicate the handle now. Instead, write the process ID and handle
- // now and let the receiver duplicate it.
- uint32_t current_process_id = base::GetCurrentProcId();
- for (size_t i = 0; i < count; ++i) {
- tokens[i] = current_process_id;
- tokens[i] = tokens[i] << 32;
- // Windows HANDLES are always 32 bit per
- // https://msdn.microsoft.com/en-us/library/windows/desktop/aa384203(v=vs.85).aspx
-#if defined(_WIN64)
- tokens[i] |= static_cast<int32_t>(
- reinterpret_cast<int64_t>(platform_handles[i].handle));
-#else
- tokens[i] |= reinterpret_cast<int32_t>(platform_handles[i].handle);
-#endif
- }
-}
-
-void SimpleBroker::TokenToHandle(const uint64_t* tokens,
- size_t count,
- PlatformHandle* handles) {
- for (size_t i = 0; i < count; ++i) {
- DWORD pid = tokens[i] >> 32;
-#if defined(_WIN64)
- // Sign-extend to preserve INVALID_HANDLE_VALUE.
- HANDLE source_handle = reinterpret_cast<HANDLE>(
- static_cast<int64_t>(static_cast<int32_t>(tokens[i] & 0xFFFFFFFF)));
-#else
- HANDLE source_handle = reinterpret_cast<HANDLE>(tokens[i] & 0xFFFFFFFF);
-#endif
- base::Process sender =
- base::Process::OpenWithAccess(pid, PROCESS_DUP_HANDLE);
- handles[i] = PlatformHandle();
- if (!sender.IsValid()) {
- // Sender died.
- } else {
- BOOL dup_result = DuplicateHandle(
- sender.Handle(), source_handle,
- base::GetCurrentProcessHandle(), &handles[i].handle, 0,
- FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
- DCHECK(dup_result);
- }
- }
-}
-#endif
-
-} // namespace edk
-} // namespace mojo
diff --git a/mojo/edk/system/simple_broker.h b/mojo/edk/system/simple_broker.h
deleted file mode 100644
index 93b22f6..0000000
--- a/mojo/edk/system/simple_broker.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_EDK_SYSTEM_SIMPLE_BROKER_H_
-#define MOJO_EDK_SYSTEM_SIMPLE_BROKER_H_
-
-#include "mojo/edk/system/broker.h"
-
-namespace mojo {
-namespace edk {
-
-// A simple implementation of Broker interface. This isn't meant for production
-// use (i.e. with multi-process, sandboxes). It's provided for use by unittests.
-// Implementation note: this default implementation works across processes
-// without a sandbox.
-class MOJO_SYSTEM_IMPL_EXPORT SimpleBroker : public Broker {
- public:
- SimpleBroker();
- ~SimpleBroker() override;
-
- // Broker implementation:
-#if defined(OS_WIN)
- void CreatePlatformChannelPair(ScopedPlatformHandle* server,
- ScopedPlatformHandle* client) override;
- void HandleToToken(const PlatformHandle* platform_handles,
- size_t count,
- uint64_t* tokens) override;
- void TokenToHandle(const uint64_t* tokens,
- size_t count,
- PlatformHandle* handles) override;
-#endif
-};
-
-} // namespace edk
-} // namespace mojo
-
-#endif // MOJO_EDK_SYSTEM_SIMPLE_BROKER_H_
diff --git a/mojo/edk/test/multiprocess_test_helper.cc b/mojo/edk/test/multiprocess_test_helper.cc
index b07866e..d82cbaf 100644
--- a/mojo/edk/test/multiprocess_test_helper.cc
+++ b/mojo/edk/test/multiprocess_test_helper.cc
@@ -9,6 +9,7 @@
#include "base/process/kill.h"
#include "base/process/process_handle.h"
#include "build/build_config.h"
+#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
#if defined(OS_WIN)
@@ -19,9 +20,12 @@ namespace mojo {
namespace edk {
namespace test {
+const char kBrokerHandleSwitch[] = "broker-handle";
+
MultiprocessTestHelper::MultiprocessTestHelper() {
platform_channel_pair_.reset(new PlatformChannelPair());
server_platform_handle = platform_channel_pair_->PassServerHandle();
+ broker_platform_channel_pair_.reset(new PlatformChannelPair());
}
MultiprocessTestHelper::~MultiprocessTestHelper() {
@@ -50,6 +54,10 @@ void MultiprocessTestHelper::StartChildWithExtraSwitch(
platform_channel_pair_->PrepareToPassClientHandleToChildProcess(
&command_line, &handle_passing_info);
+ std::string broker_handle = broker_platform_channel_pair_->
+ PrepareToPassClientHandleToChildProcessAsString(&handle_passing_info);
+ command_line.AppendSwitchASCII(kBrokerHandleSwitch, broker_handle);
+
if (!switch_string.empty()) {
CHECK(!command_line.HasSwitch(switch_string));
if (!switch_value.empty())
@@ -75,6 +83,10 @@ void MultiprocessTestHelper::StartChildWithExtraSwitch(
base::SpawnMultiProcessTestChild(test_child_main, command_line, options);
platform_channel_pair_->ChildProcessLaunched();
+ broker_platform_channel_pair_->ChildProcessLaunched();
+ ChildProcessLaunched(test_child_.Handle(),
+ broker_platform_channel_pair_->PassServerHandle());
+
CHECK(test_child_.IsValid());
}
@@ -98,6 +110,14 @@ void MultiprocessTestHelper::ChildSetup() {
client_platform_handle =
PlatformChannelPair::PassClientHandleFromParentProcess(
*base::CommandLine::ForCurrentProcess());
+
+ std::string broker_handle_str =
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ kBrokerHandleSwitch);
+ ScopedPlatformHandle broker_handle =
+ PlatformChannelPair::PassClientHandleFromParentProcessFromString(
+ broker_handle_str);
+ SetParentPipeHandle(broker_handle.Pass());
}
// static
diff --git a/mojo/edk/test/multiprocess_test_helper.h b/mojo/edk/test/multiprocess_test_helper.h
index 3ff8b85..55fef7c 100644
--- a/mojo/edk/test/multiprocess_test_helper.h
+++ b/mojo/edk/test/multiprocess_test_helper.h
@@ -21,6 +21,8 @@ class PlatformChannelPair;
namespace test {
+extern const char kBrokerHandleSwitch[];
+
class MultiprocessTestHelper {
public:
MultiprocessTestHelper();
@@ -60,8 +62,12 @@ class MultiprocessTestHelper {
static ScopedPlatformHandle client_platform_handle;
private:
+ // Used differently depending on the test.
scoped_ptr<PlatformChannelPair> platform_channel_pair_;
+ // Used by the broker.
+ scoped_ptr<PlatformChannelPair> broker_platform_channel_pair_;
+
// Valid after |StartChild()| and before |WaitForChildShutdown()|.
base::Process test_child_;
diff --git a/mojo/mojo_edk.gyp b/mojo/mojo_edk.gyp
index e8ce78a..07edb34 100644
--- a/mojo/mojo_edk.gyp
+++ b/mojo/mojo_edk.gyp
@@ -107,8 +107,6 @@
'edk/system/raw_channel_win.cc',
'edk/system/shared_buffer_dispatcher.cc',
'edk/system/shared_buffer_dispatcher.h',
- 'edk/system/simple_broker.cc',
- 'edk/system/simple_broker.h',
'edk/system/simple_dispatcher.cc',
'edk/system/simple_dispatcher.h',
'edk/system/transport_data.cc',
diff --git a/mojo/runner/host/child_process.cc b/mojo/runner/host/child_process.cc
index 659b508..f0bfd21 100644
--- a/mojo/runner/host/child_process.cc
+++ b/mojo/runner/host/child_process.cc
@@ -361,7 +361,8 @@ int ChildProcessMain() {
command_line.GetSwitchValuePath(switches::kChildProcess));
base::i18n::InitializeICU();
- CallLibraryEarlyInitialization(app_library);
+ if (app_library)
+ CallLibraryEarlyInitialization(app_library);
#if defined(OS_LINUX) && !defined(OS_ANDROID)
if (command_line.HasSwitch(switches::kEnableSandbox))
sandbox = InitializeSandbox();