| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "content/shell/browser/shell_mojo_test_utils_android.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/location.h" | |
| 10 #include "base/memory/scoped_vector.h" | |
| 11 #include "base/message_loop/message_loop.h" | |
| 12 #include "base/run_loop.h" | |
| 13 #include "base/single_thread_task_runner.h" | |
| 14 #include "base/threading/thread_task_runner_handle.h" | |
| 15 #include "content/public/browser/android/interface_provider_android.h" | |
| 16 #include "content/public/browser/android/interface_registry_android.h" | |
| 17 #include "jni/ShellMojoTestUtils_jni.h" | |
| 18 #include "services/shell/public/cpp/interface_provider.h" | |
| 19 #include "services/shell/public/cpp/interface_registry.h" | |
| 20 | |
| 21 using base::android::JavaParamRef; | |
| 22 using base::android::ScopedJavaLocalRef; | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 struct TestEnvironment { | |
| 27 base::MessageLoop message_loop; | |
| 28 std::vector<std::unique_ptr<shell::InterfaceRegistry>> registries; | |
| 29 std::vector<std::unique_ptr<shell::InterfaceProvider>> providers; | |
| 30 std::vector<std::unique_ptr<content::InterfaceRegistryAndroid>> | |
| 31 registry_wrappers; | |
| 32 std::vector<std::unique_ptr<content::InterfaceProviderAndroid>> | |
| 33 provider_wrappers; | |
| 34 }; | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 namespace content { | |
| 39 | |
| 40 static jlong SetupTestEnvironment(JNIEnv* env, | |
| 41 const JavaParamRef<jclass>& jcaller) { | |
| 42 return reinterpret_cast<intptr_t>(new TestEnvironment()); | |
| 43 } | |
| 44 | |
| 45 static void TearDownTestEnvironment(JNIEnv* env, | |
| 46 const JavaParamRef<jclass>& jcaller, | |
| 47 jlong test_environment) { | |
| 48 delete reinterpret_cast<TestEnvironment*>(test_environment); | |
| 49 } | |
| 50 | |
| 51 static ScopedJavaLocalRef<jobject> CreateInterfaceRegistryAndProvider( | |
| 52 JNIEnv* env, | |
| 53 const JavaParamRef<jclass>& jcaller, | |
| 54 jlong native_test_environment) { | |
| 55 TestEnvironment* test_environment = | |
| 56 reinterpret_cast<TestEnvironment*>(native_test_environment); | |
| 57 | |
| 58 std::unique_ptr<shell::InterfaceRegistry> registry( | |
| 59 new shell::InterfaceRegistry); | |
| 60 std::unique_ptr<shell::InterfaceProvider> provider( | |
| 61 new shell::InterfaceProvider); | |
| 62 | |
| 63 shell::mojom::InterfaceProviderPtr provider_proxy; | |
| 64 shell::mojom::InterfaceProviderRequest provider_request = | |
| 65 mojo::GetProxy(&provider_proxy); | |
| 66 provider->Bind(std::move(provider_proxy)); | |
| 67 registry->Bind(std::move(provider_request)); | |
| 68 | |
| 69 std::unique_ptr<content::InterfaceRegistryAndroid> registry_android( | |
| 70 InterfaceRegistryAndroid::Create(registry.get())); | |
| 71 std::unique_ptr<content::InterfaceProviderAndroid> provider_android( | |
| 72 InterfaceProviderAndroid::Create(provider.get())); | |
| 73 | |
| 74 ScopedJavaLocalRef<jobject> obj = Java_ShellMojoTestUtils_makePair( | |
| 75 env, registry_android->GetObj(), provider_android->GetObj()); | |
| 76 | |
| 77 test_environment->registry_wrappers.push_back(std::move(registry_android)); | |
| 78 test_environment->provider_wrappers.push_back(std::move(provider_android)); | |
| 79 test_environment->registries.push_back(std::move(registry)); | |
| 80 test_environment->providers.push_back(std::move(provider)); | |
| 81 | |
| 82 return obj; | |
| 83 } | |
| 84 | |
| 85 static void RunLoop(JNIEnv* env, | |
| 86 const JavaParamRef<jclass>& jcaller, | |
| 87 jlong timeout_ms) { | |
| 88 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 89 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | |
| 90 base::TimeDelta::FromMilliseconds(timeout_ms)); | |
| 91 base::RunLoop run_loop; | |
| 92 run_loop.Run(); | |
| 93 } | |
| 94 | |
| 95 bool RegisterShellMojoTestUtils(JNIEnv* env) { | |
| 96 return RegisterNativesImpl(env); | |
| 97 } | |
| 98 | |
| 99 } // namespace content | |
| OLD | NEW |