Roll src/third_party/skia 2440fcd:4de8c3a
[chromium-blink-merge.git] / content / shell / browser / shell_mojo_test_utils_android.cc
blobba8f5e98a67c5d0a717bcc8cc0b7cde07d3db1c1
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"
14 namespace {
16 struct TestEnvironment {
17 base::MessageLoop message_loop;
18 ScopedVector<content::ServiceRegistryImpl> registries;
19 ScopedVector<content::ServiceRegistryAndroid> wrappers;
22 } // namespace
24 namespace content {
26 static jlong SetupTestEnvironment(JNIEnv* env,
27 const JavaParamRef<jclass>& jcaller) {
28 return reinterpret_cast<intptr_t>(new TestEnvironment());
31 static void TearDownTestEnvironment(JNIEnv* env,
32 const JavaParamRef<jclass>& jcaller,
33 jlong test_environment) {
34 delete reinterpret_cast<TestEnvironment*>(test_environment);
37 static ScopedJavaLocalRef<jobject> CreateServiceRegistryPair(
38 JNIEnv* env,
39 const JavaParamRef<jclass>& jcaller,
40 jlong native_test_environment) {
41 TestEnvironment* test_environment =
42 reinterpret_cast<TestEnvironment*>(native_test_environment);
44 content::ServiceRegistryImpl* registry_a = new ServiceRegistryImpl();
45 test_environment->registries.push_back(registry_a);
46 content::ServiceRegistryImpl* registry_b = new ServiceRegistryImpl();
47 test_environment->registries.push_back(registry_b);
49 mojo::ServiceProviderPtr exposed_services_a;
50 registry_a->Bind(GetProxy(&exposed_services_a));
51 registry_b->BindRemoteServiceProvider(exposed_services_a.Pass());
53 mojo::ServiceProviderPtr exposed_services_b;
54 registry_b->Bind(GetProxy(&exposed_services_b));
55 registry_a->BindRemoteServiceProvider(exposed_services_b.Pass());
57 content::ServiceRegistryAndroid* wrapper_a =
58 new ServiceRegistryAndroid(registry_a);
59 test_environment->wrappers.push_back(wrapper_a);
60 content::ServiceRegistryAndroid* wrapper_b =
61 new ServiceRegistryAndroid(registry_b);
62 test_environment->wrappers.push_back(wrapper_b);
64 return Java_ShellMojoTestUtils_makePair(env, wrapper_a->GetObj().obj(),
65 wrapper_b->GetObj().obj());
68 static void RunLoop(JNIEnv* env,
69 const JavaParamRef<jclass>& jcaller,
70 jlong timeout_ms) {
71 base::MessageLoop::current()->PostDelayedTask(
72 FROM_HERE,
73 base::MessageLoop::QuitClosure(),
74 base::TimeDelta::FromMilliseconds(timeout_ms));
75 base::RunLoop run_loop;
76 run_loop.Run();
79 bool RegisterShellMojoTestUtils(JNIEnv* env) {
80 return RegisterNativesImpl(env);
83 } // namespace content