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
3 // found in the LICENSE file.
5 #include "content/shell/browser/shell_mojo_test_utils_android.h"
7 #include "base/memory/scoped_vector.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h"
10 #include "content/browser/mojo/service_registry_android.h"
11 #include "content/common/mojo/service_registry_impl.h"
12 #include "jni/ShellMojoTestUtils_jni.h"
16 struct TestEnvironment
{
17 base::MessageLoop message_loop
;
18 ScopedVector
<content::ServiceRegistryImpl
> registries
;
19 ScopedVector
<content::ServiceRegistryAndroid
> wrappers
;
26 static jlong
SetupTestEnvironment(JNIEnv
* env
, jclass jcaller
) {
27 return reinterpret_cast<intptr_t>(new TestEnvironment());
30 static void TearDownTestEnvironment(JNIEnv
* env
,
32 jlong test_environment
) {
33 delete reinterpret_cast<TestEnvironment
*>(test_environment
);
36 static jobject
CreateServiceRegistryPair(JNIEnv
* env
,
38 jlong native_test_environment
) {
39 TestEnvironment
* test_environment
=
40 reinterpret_cast<TestEnvironment
*>(native_test_environment
);
42 content::ServiceRegistryImpl
* registry_a
= new ServiceRegistryImpl();
43 test_environment
->registries
.push_back(registry_a
);
44 content::ServiceRegistryImpl
* registry_b
= new ServiceRegistryImpl();
45 test_environment
->registries
.push_back(registry_b
);
47 mojo::ServiceProviderPtr exposed_services_a
;
48 registry_a
->Bind(GetProxy(&exposed_services_a
));
49 registry_b
->BindRemoteServiceProvider(exposed_services_a
.Pass());
51 mojo::ServiceProviderPtr exposed_services_b
;
52 registry_b
->Bind(GetProxy(&exposed_services_b
));
53 registry_a
->BindRemoteServiceProvider(exposed_services_b
.Pass());
55 content::ServiceRegistryAndroid
* wrapper_a
=
56 new ServiceRegistryAndroid(registry_a
);
57 test_environment
->wrappers
.push_back(wrapper_a
);
58 content::ServiceRegistryAndroid
* wrapper_b
=
59 new ServiceRegistryAndroid(registry_b
);
60 test_environment
->wrappers
.push_back(wrapper_b
);
62 return Java_ShellMojoTestUtils_makePair(env
, wrapper_a
->GetObj().obj(),
63 wrapper_b
->GetObj().obj()).Release();
66 static void RunLoop(JNIEnv
* env
, jclass jcaller
, jlong timeout_ms
) {
67 base::MessageLoop::current()->PostDelayedTask(
69 base::MessageLoop::QuitClosure(),
70 base::TimeDelta::FromMilliseconds(timeout_ms
));
71 base::RunLoop run_loop
;
75 bool RegisterShellMojoTestUtils(JNIEnv
* env
) {
76 return RegisterNativesImpl(env
);
79 } // namespace content