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" |
(...skipping 15 matching lines...) Expand all Loading... |
26 static jlong SetupTestEnvironment(JNIEnv* env, jclass jcaller) { | 26 static jlong SetupTestEnvironment(JNIEnv* env, jclass jcaller) { |
27 return reinterpret_cast<intptr_t>(new TestEnvironment()); | 27 return reinterpret_cast<intptr_t>(new TestEnvironment()); |
28 } | 28 } |
29 | 29 |
30 static void TearDownTestEnvironment(JNIEnv* env, | 30 static void TearDownTestEnvironment(JNIEnv* env, |
31 jclass jcaller, | 31 jclass jcaller, |
32 jlong test_environment) { | 32 jlong test_environment) { |
33 delete reinterpret_cast<TestEnvironment*>(test_environment); | 33 delete reinterpret_cast<TestEnvironment*>(test_environment); |
34 } | 34 } |
35 | 35 |
36 static ScopedJavaLocalRef<jobject> CreateServiceRegistryPair( | 36 static jobject CreateServiceRegistryPair(JNIEnv* env, |
37 JNIEnv* env, | 37 jclass jcaller, |
38 jclass jcaller, | 38 jlong native_test_environment) { |
39 jlong native_test_environment) { | |
40 TestEnvironment* test_environment = | 39 TestEnvironment* test_environment = |
41 reinterpret_cast<TestEnvironment*>(native_test_environment); | 40 reinterpret_cast<TestEnvironment*>(native_test_environment); |
42 | 41 |
43 content::ServiceRegistryImpl* registry_a = new ServiceRegistryImpl(); | 42 content::ServiceRegistryImpl* registry_a = new ServiceRegistryImpl(); |
44 test_environment->registries.push_back(registry_a); | 43 test_environment->registries.push_back(registry_a); |
45 content::ServiceRegistryImpl* registry_b = new ServiceRegistryImpl(); | 44 content::ServiceRegistryImpl* registry_b = new ServiceRegistryImpl(); |
46 test_environment->registries.push_back(registry_b); | 45 test_environment->registries.push_back(registry_b); |
47 | 46 |
48 mojo::ServiceProviderPtr exposed_services_a; | 47 mojo::ServiceProviderPtr exposed_services_a; |
49 registry_a->Bind(GetProxy(&exposed_services_a)); | 48 registry_a->Bind(GetProxy(&exposed_services_a)); |
50 registry_b->BindRemoteServiceProvider(exposed_services_a.Pass()); | 49 registry_b->BindRemoteServiceProvider(exposed_services_a.Pass()); |
51 | 50 |
52 mojo::ServiceProviderPtr exposed_services_b; | 51 mojo::ServiceProviderPtr exposed_services_b; |
53 registry_b->Bind(GetProxy(&exposed_services_b)); | 52 registry_b->Bind(GetProxy(&exposed_services_b)); |
54 registry_a->BindRemoteServiceProvider(exposed_services_b.Pass()); | 53 registry_a->BindRemoteServiceProvider(exposed_services_b.Pass()); |
55 | 54 |
56 content::ServiceRegistryAndroid* wrapper_a = | 55 content::ServiceRegistryAndroid* wrapper_a = |
57 new ServiceRegistryAndroid(registry_a); | 56 new ServiceRegistryAndroid(registry_a); |
58 test_environment->wrappers.push_back(wrapper_a); | 57 test_environment->wrappers.push_back(wrapper_a); |
59 content::ServiceRegistryAndroid* wrapper_b = | 58 content::ServiceRegistryAndroid* wrapper_b = |
60 new ServiceRegistryAndroid(registry_b); | 59 new ServiceRegistryAndroid(registry_b); |
61 test_environment->wrappers.push_back(wrapper_b); | 60 test_environment->wrappers.push_back(wrapper_b); |
62 | 61 |
63 return Java_ShellMojoTestUtils_makePair(env, wrapper_a->GetObj().obj(), | 62 return Java_ShellMojoTestUtils_makePair(env, wrapper_a->GetObj().obj(), |
64 wrapper_b->GetObj().obj()); | 63 wrapper_b->GetObj().obj()).Release(); |
65 } | 64 } |
66 | 65 |
67 static void RunLoop(JNIEnv* env, jclass jcaller, jlong timeout_ms) { | 66 static void RunLoop(JNIEnv* env, jclass jcaller, jlong timeout_ms) { |
68 base::MessageLoop::current()->PostDelayedTask( | 67 base::MessageLoop::current()->PostDelayedTask( |
69 FROM_HERE, | 68 FROM_HERE, |
70 base::MessageLoop::QuitClosure(), | 69 base::MessageLoop::QuitClosure(), |
71 base::TimeDelta::FromMilliseconds(timeout_ms)); | 70 base::TimeDelta::FromMilliseconds(timeout_ms)); |
72 base::RunLoop run_loop; | 71 base::RunLoop run_loop; |
73 run_loop.Run(); | 72 run_loop.Run(); |
74 } | 73 } |
75 | 74 |
76 bool RegisterShellMojoTestUtils(JNIEnv* env) { | 75 bool RegisterShellMojoTestUtils(JNIEnv* env) { |
77 return RegisterNativesImpl(env); | 76 return RegisterNativesImpl(env); |
78 } | 77 } |
79 | 78 |
80 } // namespace content | 79 } // namespace content |
OLD | NEW |