blob: 391e953055ab684426ec287e42b9d63b9db804b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// Copyright 2014 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 "ipc/mojo/ipc_mojo_bootstrap.h"
#include "base/base_paths.h"
#include "base/files/file.h"
#include "base/message_loop/message_loop.h"
#include "ipc/ipc_test_base.h"
#if defined(OS_POSIX)
#include "base/file_descriptor_posix.h"
#endif
namespace {
class IPCMojoBootstrapTest : public IPCTestBase {
protected:
};
class TestingDelegate : public IPC::MojoBootstrap::Delegate {
public:
TestingDelegate() : passed_(false) {}
void OnPipeAvailable(mojo::embedder::ScopedPlatformHandle handle,
int32 peer_pid) override;
void OnBootstrapError() override;
bool passed() const { return passed_; }
private:
bool passed_;
};
void TestingDelegate::OnPipeAvailable(
mojo::embedder::ScopedPlatformHandle handle,
int32 peer_pid) {
passed_ = true;
base::MessageLoop::current()->QuitWhenIdle();
}
void TestingDelegate::OnBootstrapError() {
base::MessageLoop::current()->QuitWhenIdle();
}
// Times out on Android; see http://crbug.com/502290
#if defined(OS_ANDROID)
#define MAYBE_Connect DISABLED_Connect
#else
#define MAYBE_Connect Connect
#endif
TEST_F(IPCMojoBootstrapTest, MAYBE_Connect) {
Init("IPCMojoBootstrapTestClient");
TestingDelegate delegate;
scoped_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create(
GetTestChannelHandle(), IPC::Channel::MODE_SERVER, &delegate);
ASSERT_TRUE(bootstrap->Connect());
#if defined(OS_POSIX)
ASSERT_TRUE(StartClientWithFD(bootstrap->GetClientFileDescriptor()));
#else
ASSERT_TRUE(StartClient());
#endif
base::MessageLoop::current()->Run();
EXPECT_TRUE(delegate.passed());
EXPECT_TRUE(WaitForClientShutdown());
}
// A long running process that connects to us.
MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCMojoBootstrapTestClient) {
base::MessageLoopForIO main_message_loop;
TestingDelegate delegate;
scoped_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create(
IPCTestBase::GetChannelName("IPCMojoBootstrapTestClient"),
IPC::Channel::MODE_CLIENT, &delegate);
bootstrap->Connect();
base::MessageLoop::current()->Run();
EXPECT_TRUE(delegate.passed());
return 0;
}
} // namespace
|