OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/browser/shell_mojo_test_utils_android.h" | 5 #include "content/shell/browser/shell_mojo_test_utils_android.h" |
6 | 6 |
7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "content/browser/mojo/service_registry_android.h" | 10 #include "content/browser/mojo/service_registry_android.h" |
11 #include "content/common/mojo/service_registry_impl.h" | 11 #include "content/common/mojo/service_registry_impl.h" |
12 #include "jni/ShellMojoTestUtils_jni.h" | 12 #include "jni/ShellMojoTestUtils_jni.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 struct TestEnvironment { | 16 struct TestEnvironment { |
17 base::MessageLoop message_loop; | 17 base::MessageLoop message_loop; |
18 ScopedVector<content::ServiceRegistryImpl> registries; | 18 ScopedVector<content::ServiceRegistryImpl> registries; |
19 ScopedVector<content::ServiceRegistryAndroid> wrappers; | 19 ScopedVector<content::ServiceRegistryAndroid> wrappers; |
20 }; | 20 }; |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 | 25 |
26 static jlong SetupTestEnvironment(JNIEnv* env, jclass jcaller) { | 26 static jlong SetupTestEnvironment(JNIEnv* env, |
| 27 const JavaParamRef<jclass>& jcaller) { |
27 return reinterpret_cast<intptr_t>(new TestEnvironment()); | 28 return reinterpret_cast<intptr_t>(new TestEnvironment()); |
28 } | 29 } |
29 | 30 |
30 static void TearDownTestEnvironment(JNIEnv* env, | 31 static void TearDownTestEnvironment(JNIEnv* env, |
31 jclass jcaller, | 32 const JavaParamRef<jclass>& jcaller, |
32 jlong test_environment) { | 33 jlong test_environment) { |
33 delete reinterpret_cast<TestEnvironment*>(test_environment); | 34 delete reinterpret_cast<TestEnvironment*>(test_environment); |
34 } | 35 } |
35 | 36 |
36 static ScopedJavaLocalRef<jobject> CreateServiceRegistryPair( | 37 static ScopedJavaLocalRef<jobject> CreateServiceRegistryPair( |
37 JNIEnv* env, | 38 JNIEnv* env, |
38 jclass jcaller, | 39 const JavaParamRef<jclass>& jcaller, |
39 jlong native_test_environment) { | 40 jlong native_test_environment) { |
40 TestEnvironment* test_environment = | 41 TestEnvironment* test_environment = |
41 reinterpret_cast<TestEnvironment*>(native_test_environment); | 42 reinterpret_cast<TestEnvironment*>(native_test_environment); |
42 | 43 |
43 content::ServiceRegistryImpl* registry_a = new ServiceRegistryImpl(); | 44 content::ServiceRegistryImpl* registry_a = new ServiceRegistryImpl(); |
44 test_environment->registries.push_back(registry_a); | 45 test_environment->registries.push_back(registry_a); |
45 content::ServiceRegistryImpl* registry_b = new ServiceRegistryImpl(); | 46 content::ServiceRegistryImpl* registry_b = new ServiceRegistryImpl(); |
46 test_environment->registries.push_back(registry_b); | 47 test_environment->registries.push_back(registry_b); |
47 | 48 |
48 mojo::ServiceProviderPtr exposed_services_a; | 49 mojo::ServiceProviderPtr exposed_services_a; |
49 registry_a->Bind(GetProxy(&exposed_services_a)); | 50 registry_a->Bind(GetProxy(&exposed_services_a)); |
50 registry_b->BindRemoteServiceProvider(exposed_services_a.Pass()); | 51 registry_b->BindRemoteServiceProvider(exposed_services_a.Pass()); |
51 | 52 |
52 mojo::ServiceProviderPtr exposed_services_b; | 53 mojo::ServiceProviderPtr exposed_services_b; |
53 registry_b->Bind(GetProxy(&exposed_services_b)); | 54 registry_b->Bind(GetProxy(&exposed_services_b)); |
54 registry_a->BindRemoteServiceProvider(exposed_services_b.Pass()); | 55 registry_a->BindRemoteServiceProvider(exposed_services_b.Pass()); |
55 | 56 |
56 content::ServiceRegistryAndroid* wrapper_a = | 57 content::ServiceRegistryAndroid* wrapper_a = |
57 new ServiceRegistryAndroid(registry_a); | 58 new ServiceRegistryAndroid(registry_a); |
58 test_environment->wrappers.push_back(wrapper_a); | 59 test_environment->wrappers.push_back(wrapper_a); |
59 content::ServiceRegistryAndroid* wrapper_b = | 60 content::ServiceRegistryAndroid* wrapper_b = |
60 new ServiceRegistryAndroid(registry_b); | 61 new ServiceRegistryAndroid(registry_b); |
61 test_environment->wrappers.push_back(wrapper_b); | 62 test_environment->wrappers.push_back(wrapper_b); |
62 | 63 |
63 return Java_ShellMojoTestUtils_makePair(env, wrapper_a->GetObj().obj(), | 64 return Java_ShellMojoTestUtils_makePair(env, wrapper_a->GetObj().obj(), |
64 wrapper_b->GetObj().obj()); | 65 wrapper_b->GetObj().obj()); |
65 } | 66 } |
66 | 67 |
67 static void RunLoop(JNIEnv* env, jclass jcaller, jlong timeout_ms) { | 68 static void RunLoop(JNIEnv* env, |
| 69 const JavaParamRef<jclass>& jcaller, |
| 70 jlong timeout_ms) { |
68 base::MessageLoop::current()->PostDelayedTask( | 71 base::MessageLoop::current()->PostDelayedTask( |
69 FROM_HERE, | 72 FROM_HERE, |
70 base::MessageLoop::QuitClosure(), | 73 base::MessageLoop::QuitClosure(), |
71 base::TimeDelta::FromMilliseconds(timeout_ms)); | 74 base::TimeDelta::FromMilliseconds(timeout_ms)); |
72 base::RunLoop run_loop; | 75 base::RunLoop run_loop; |
73 run_loop.Run(); | 76 run_loop.Run(); |
74 } | 77 } |
75 | 78 |
76 bool RegisterShellMojoTestUtils(JNIEnv* env) { | 79 bool RegisterShellMojoTestUtils(JNIEnv* env) { |
77 return RegisterNativesImpl(env); | 80 return RegisterNativesImpl(env); |
78 } | 81 } |
79 | 82 |
80 } // namespace content | 83 } // namespace content |
OLD | NEW |