Commit 04c511fd authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Generate test methods for native java unittests

Uses the JNI generator to generate test methods for native java
unittests that simply call java test methods.

Bug: 783819
Change-Id: I2ff4d87a1aa053847077bd3f418123be49174375
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1992247
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarEric Stevenson <estevenson@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#729913}
parent 978f1f27
...@@ -3305,6 +3305,7 @@ if (is_android) { ...@@ -3305,6 +3305,7 @@ if (is_android) {
"android/java/src/org/chromium/base/UserDataHost.java", "android/java/src/org/chromium/base/UserDataHost.java",
"android/java/src/org/chromium/base/annotations/AccessedByNative.java", "android/java/src/org/chromium/base/annotations/AccessedByNative.java",
"android/java/src/org/chromium/base/annotations/CalledByNative.java", "android/java/src/org/chromium/base/annotations/CalledByNative.java",
"android/java/src/org/chromium/base/annotations/CalledByNativeJavaTest.java",
"android/java/src/org/chromium/base/annotations/CalledByNativeUnchecked.java", "android/java/src/org/chromium/base/annotations/CalledByNativeUnchecked.java",
"android/java/src/org/chromium/base/annotations/CheckDiscard.java", "android/java/src/org/chromium/base/annotations/CheckDiscard.java",
"android/java/src/org/chromium/base/annotations/DoNotInline.java", "android/java/src/org/chromium/base/annotations/DoNotInline.java",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.base.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @CalledByNativeJavaTest is used by the JNI generator to create the necessary JNI
* bindings, expose this method to native code, and generate a native test proxy
* method for this Java Test method.
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.CLASS)
public @interface CalledByNativeJavaTest {
/*
* If present, tells which inner class the method belongs to.
*/
public String value() default "";
}
...@@ -214,6 +214,40 @@ For other objects - use smart pointers to store them: ...@@ -214,6 +214,40 @@ For other objects - use smart pointers to store them:
* `JavaParamRef<>` - Use to accept any of the above as a parameter to a * `JavaParamRef<>` - Use to accept any of the above as a parameter to a
function without creating a redundant registration. function without creating a redundant registration.
### Native Java Unittests and @CalledByNativeJavaTest
Native Java Unittests are Java unit tests that run on Android (not on the host
machine). Unlike junit and robolectric, these tests can use the native library,
and real Android APIs. Unlike unit tests in ChromePublicTestApk and similar, the
Activity is not restarted between tests, so the tests run much faster (and you
must be careful not to leave state behind). Example tests may be found in
chrome/android/native_java_unittests/.
The @CalledByNativeJavaTest annotation causes the JNI generator to generate
C++ test methods that simply call out to the Java test methods.
For Example:
```java
class FooTest {
@CalledByNative public FooTest() {}
@CalledByNativeJavaTest public void testFoo() { ... }
@CalledByNativeJavaTest public void testOtherFoo() { ... }
}
```
```c++
class FooTest : public ::testing::Test {
FooTest() : j_test_(Java_FooTest_Constructor(AttachCurrentThread())) {}
const ScopedJavaGlobalRef<jobject>& j_test() { return j_test_; }
private:
ScopedJavaGlobalRef<jobject> j_test_;
}
JAVA_TESTS(AndroidPaymentAppFinderUnitTest, j_test())
```
In some cases you may want to run custom C++ code before running the Java test,
in which case, use CalledByNative instead of CalledByNativeJavaTest and call the
test method yourself. eg. Java_FooTest_testFancyFoo(env, j_test());
### Additional Guidelines / Advice ### Additional Guidelines / Advice
Minimize the surface API between the two sides. Rather than calling multiple Minimize the surface API between the two sides. Rather than calling multiple
......
...@@ -262,4 +262,7 @@ JNI_GENERATOR_EXPORT jobjectArray Java_J_N_MPpCU1l5( ...@@ -262,4 +262,7 @@ JNI_GENERATOR_EXPORT jobjectArray Java_J_N_MPpCU1l5(
} }
// Step 4: Generated test functions (optional).
#endif // org_chromium_example_jni_generator_SampleForAnnotationProcessor_JNI #endif // org_chromium_example_jni_generator_SampleForAnnotationProcessor_JNI
...@@ -280,4 +280,7 @@ JNI_GENERATOR_EXPORT jobjectArray ...@@ -280,4 +280,7 @@ JNI_GENERATOR_EXPORT jobjectArray
} }
// Step 4: Generated test functions (optional).
#endif // org_chromium_example_jni_generator_SampleForAnnotationProcessor_JNI #endif // org_chromium_example_jni_generator_SampleForAnnotationProcessor_JNI
...@@ -524,4 +524,7 @@ static base::android::ScopedJavaLocalRef<jobject> Java_SampleForTests_getInnerEn ...@@ -524,4 +524,7 @@ static base::android::ScopedJavaLocalRef<jobject> Java_SampleForTests_getInnerEn
} // namespace android } // namespace android
} // namespace base } // namespace base
// Step 4: Generated test functions (optional).
#endif // org_chromium_example_jni_generator_SampleForTests_JNI #endif // org_chromium_example_jni_generator_SampleForTests_JNI
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is autogenerated by
// base/android/jni_generator/jni_generator.py
// For
// org/chromium/TestJni
#ifndef org_chromium_TestJni_JNI
#define org_chromium_TestJni_JNI
#include <jni.h>
#include "base/android/jni_generator/jni_generator_helper.h"
// Step 1: Forward declarations.
JNI_REGISTRATION_EXPORT extern const char kClassPath_org_chromium_TestJni[];
const char kClassPath_org_chromium_TestJni[] = "org/chromium/TestJni";
JNI_REGISTRATION_EXPORT extern const char kClassPath_org_chromium_TestJni_00024MyInnerClass[];
const char kClassPath_org_chromium_TestJni_00024MyInnerClass[] =
"org/chromium/TestJni$MyInnerClass";
// Leaking this jclass as we cannot use LazyInstance from some threads.
JNI_REGISTRATION_EXPORT std::atomic<jclass> g_org_chromium_TestJni_clazz(nullptr);
#ifndef org_chromium_TestJni_clazz_defined
#define org_chromium_TestJni_clazz_defined
inline jclass org_chromium_TestJni_clazz(JNIEnv* env) {
return base::android::LazyGetClass(env, kClassPath_org_chromium_TestJni,
&g_org_chromium_TestJni_clazz);
}
#endif
// Leaking this jclass as we cannot use LazyInstance from some threads.
JNI_REGISTRATION_EXPORT std::atomic<jclass> g_org_chromium_TestJni_00024MyInnerClass_clazz(nullptr);
#ifndef org_chromium_TestJni_00024MyInnerClass_clazz_defined
#define org_chromium_TestJni_00024MyInnerClass_clazz_defined
inline jclass org_chromium_TestJni_00024MyInnerClass_clazz(JNIEnv* env) {
return base::android::LazyGetClass(env, kClassPath_org_chromium_TestJni_00024MyInnerClass,
&g_org_chromium_TestJni_00024MyInnerClass_clazz);
}
#endif
// Step 2: Constants (optional).
// Step 3: Method stubs.
static std::atomic<jmethodID> g_org_chromium_TestJni_Constructor(nullptr);
static base::android::ScopedJavaLocalRef<jobject> Java_TestJni_Constructor(JNIEnv* env) {
jclass clazz = org_chromium_TestJni_clazz(env);
CHECK_CLAZZ(env, clazz,
org_chromium_TestJni_clazz(env), NULL);
jni_generator::JniJavaCallContextChecked call_context;
call_context.Init<
base::android::MethodID::TYPE_INSTANCE>(
env,
clazz,
"<init>",
"()V",
&g_org_chromium_TestJni_Constructor);
jobject ret =
env->NewObject(clazz,
call_context.base.method_id);
return base::android::ScopedJavaLocalRef<jobject>(env, ret);
}
static std::atomic<jmethodID> g_org_chromium_TestJni_testFoo(nullptr);
static jint Java_TestJni_testFoo(JNIEnv* env, const base::android::JavaRef<jobject>& obj) {
jclass clazz = org_chromium_TestJni_clazz(env);
CHECK_CLAZZ(env, obj.obj(),
org_chromium_TestJni_clazz(env), 0);
jni_generator::JniJavaCallContextChecked call_context;
call_context.Init<
base::android::MethodID::TYPE_INSTANCE>(
env,
clazz,
"testFoo",
"()I",
&g_org_chromium_TestJni_testFoo);
jint ret =
env->CallIntMethod(obj.obj(),
call_context.base.method_id);
return ret;
}
static std::atomic<jmethodID> g_org_chromium_TestJni_testOtherFoo(nullptr);
static void Java_TestJni_testOtherFoo(JNIEnv* env, const base::android::JavaRef<jobject>& obj) {
jclass clazz = org_chromium_TestJni_clazz(env);
CHECK_CLAZZ(env, obj.obj(),
org_chromium_TestJni_clazz(env));
jni_generator::JniJavaCallContextChecked call_context;
call_context.Init<
base::android::MethodID::TYPE_INSTANCE>(
env,
clazz,
"testOtherFoo",
"()V",
&g_org_chromium_TestJni_testOtherFoo);
env->CallVoidMethod(obj.obj(),
call_context.base.method_id);
}
static std::atomic<jmethodID> g_org_chromium_TestJni_00024MyInnerClass_testInnerFoo(nullptr);
static void Java_MyInnerClass_testInnerFoo(JNIEnv* env, const base::android::JavaRef<jobject>& obj)
{
jclass clazz = org_chromium_TestJni_00024MyInnerClass_clazz(env);
CHECK_CLAZZ(env, obj.obj(),
org_chromium_TestJni_00024MyInnerClass_clazz(env));
jni_generator::JniJavaCallContextChecked call_context;
call_context.Init<
base::android::MethodID::TYPE_INSTANCE>(
env,
clazz,
"testInnerFoo",
"()V",
&g_org_chromium_TestJni_00024MyInnerClass_testInnerFoo);
env->CallVoidMethod(obj.obj(),
call_context.base.method_id);
}
// Step 4: Generated test functions (optional).
#define JAVA_TESTS(test_fixture, java_test_object)\
TEST_F(test_fixture, TestFoo) { \
JNIEnv* env = base::android::AttachCurrentThread(); \
Java_TestJni_testFoo(\
env, java_test_object); \
}\
TEST_F(test_fixture, TestOtherFoo) { \
JNIEnv* env = base::android::AttachCurrentThread(); \
Java_TestJni_testOtherFoo(\
env, java_test_object); \
}\
TEST_F(test_fixture, TestInnerFoo) { \
JNIEnv* env = base::android::AttachCurrentThread(); \
Java_MyInnerClass_testInnerFoo(\
env, java_test_object); \
}
#endif // org_chromium_TestJni_JNI
...@@ -475,4 +475,7 @@ static base::android::ScopedJavaLocalRef<jobject> Java_TestJni_getCompressFormat ...@@ -475,4 +475,7 @@ static base::android::ScopedJavaLocalRef<jobject> Java_TestJni_getCompressFormat
return base::android::ScopedJavaLocalRef<jobject>(env, ret); return base::android::ScopedJavaLocalRef<jobject>(env, ret);
} }
// Step 4: Generated test functions (optional).
#endif // org_chromium_TestJni_JNI #endif // org_chromium_TestJni_JNI
...@@ -2317,4 +2317,7 @@ static void Java_MotionEvent_writeToParcel(JNIEnv* env, const base::android::Jav ...@@ -2317,4 +2317,7 @@ static void Java_MotionEvent_writeToParcel(JNIEnv* env, const base::android::Jav
} // namespace JNI_MotionEvent } // namespace JNI_MotionEvent
// Step 4: Generated test functions (optional).
#endif // android_view_MotionEvent_JNI #endif // android_view_MotionEvent_JNI
...@@ -273,4 +273,7 @@ static base::android::ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(J ...@@ -273,4 +273,7 @@ static base::android::ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(J
} // namespace JNI_InputStream } // namespace JNI_InputStream
// Step 4: Generated test functions (optional).
#endif // java_io_InputStream_JNI #endif // java_io_InputStream_JNI
...@@ -84,4 +84,7 @@ static base::android::ScopedJavaLocalRef<jclass> Java_HashSet_getClass(JNIEnv* e ...@@ -84,4 +84,7 @@ static base::android::ScopedJavaLocalRef<jclass> Java_HashSet_getClass(JNIEnv* e
} // namespace JNI_HashSet } // namespace JNI_HashSet
// Step 4: Generated test functions (optional).
#endif // java_util_HashSet_JNI #endif // java_util_HashSet_JNI
...@@ -57,4 +57,7 @@ JNI_GENERATOR_EXPORT jint Java_org_chromium_TestJni_00024MyInnerClass_nativeInit ...@@ -57,4 +57,7 @@ JNI_GENERATOR_EXPORT jint Java_org_chromium_TestJni_00024MyInnerClass_nativeInit
} }
// Step 4: Generated test functions (optional).
#endif // org_chromium_TestJni_JNI #endif // org_chromium_TestJni_JNI
...@@ -67,4 +67,7 @@ JNI_GENERATOR_EXPORT jint Java_org_chromium_TestJni_00024MyOtherInnerClass_nativ ...@@ -67,4 +67,7 @@ JNI_GENERATOR_EXPORT jint Java_org_chromium_TestJni_00024MyOtherInnerClass_nativ
} }
// Step 4: Generated test functions (optional).
#endif // org_chromium_TestJni_JNI #endif // org_chromium_TestJni_JNI
...@@ -80,4 +80,7 @@ JNI_GENERATOR_EXPORT jint Java_org_chromium_TestJni_00024MyOtherInnerClass_nativ ...@@ -80,4 +80,7 @@ JNI_GENERATOR_EXPORT jint Java_org_chromium_TestJni_00024MyOtherInnerClass_nativ
} }
// Step 4: Generated test functions (optional).
#endif // org_chromium_TestJni_JNI #endif // org_chromium_TestJni_JNI
...@@ -68,4 +68,7 @@ static void Java_Foo_calledByNative(JNIEnv* env, const base::android::JavaRef<jo ...@@ -68,4 +68,7 @@ static void Java_Foo_calledByNative(JNIEnv* env, const base::android::JavaRef<jo
call_context.base.method_id, callback1.obj(), callback2.obj()); call_context.base.method_id, callback1.obj(), callback2.obj());
} }
// Step 4: Generated test functions (optional).
#endif // org_chromium_foo_Foo_JNI #endif // org_chromium_foo_Foo_JNI
...@@ -226,4 +226,7 @@ static base::android::ScopedJavaLocalRef<jstring> ...@@ -226,4 +226,7 @@ static base::android::ScopedJavaLocalRef<jstring>
return base::android::ScopedJavaLocalRef<jstring>(env, ret); return base::android::ScopedJavaLocalRef<jstring>(env, ret);
} }
// Step 4: Generated test functions (optional).
#endif // org_chromium_example_jni_generator_SampleForTests_JNI #endif // org_chromium_example_jni_generator_SampleForTests_JNI
...@@ -213,4 +213,7 @@ JNI_GENERATOR_EXPORT jthrowable Java_org_chromium_TestJni_nativeMessWithJavaExce ...@@ -213,4 +213,7 @@ JNI_GENERATOR_EXPORT jthrowable Java_org_chromium_TestJni_nativeMessWithJavaExce
} }
// Step 4: Generated test functions (optional).
#endif // org_chromium_TestJni_JNI #endif // org_chromium_TestJni_JNI
...@@ -46,4 +46,7 @@ JNI_GENERATOR_EXPORT void Java_org_chromium_TestJni_nativeDestroy( ...@@ -46,4 +46,7 @@ JNI_GENERATOR_EXPORT void Java_org_chromium_TestJni_nativeDestroy(
} }
// Step 4: Generated test functions (optional).
#endif // org_chromium_TestJni_JNI #endif // org_chromium_TestJni_JNI
...@@ -60,4 +60,7 @@ JNI_GENERATOR_EXPORT jstring ...@@ -60,4 +60,7 @@ JNI_GENERATOR_EXPORT jstring
} }
// Step 4: Generated test functions (optional).
#endif // org_chromium_example_SampleProxyJni_JNI #endif // org_chromium_example_SampleProxyJni_JNI
...@@ -114,4 +114,7 @@ JNI_GENERATOR_EXPORT void Java_org_chromium_base_natives_GEN_1JNI_org_1chromium_ ...@@ -114,4 +114,7 @@ JNI_GENERATOR_EXPORT void Java_org_chromium_base_natives_GEN_1JNI_org_1chromium_
} }
// Step 4: Generated test functions (optional).
#endif // org_chromium_foo_Foo_JNI #endif // org_chromium_foo_Foo_JNI
...@@ -46,4 +46,7 @@ JNI_GENERATOR_EXPORT void Java_foo_bar_nativeSyncSetupEnded( ...@@ -46,4 +46,7 @@ JNI_GENERATOR_EXPORT void Java_foo_bar_nativeSyncSetupEnded(
} }
// Step 4: Generated test functions (optional).
#endif // foo_bar_JNI #endif // foo_bar_JNI
...@@ -64,4 +64,7 @@ static void Java_Foo_calledByNative(JNIEnv* env, const base::android::JavaRef<jo ...@@ -64,4 +64,7 @@ static void Java_Foo_calledByNative(JNIEnv* env, const base::android::JavaRef<jo
call_context.base.method_id, callback.obj()); call_context.base.method_id, callback.obj());
} }
// Step 4: Generated test functions (optional).
#endif // org_chromium_foo_Foo_JNI #endif // org_chromium_foo_Foo_JNI
...@@ -97,4 +97,7 @@ JNI_GENERATOR_EXPORT void Java_org_chromium_foo_Foo_nativeCallWithQualifiedObjec ...@@ -97,4 +97,7 @@ JNI_GENERATOR_EXPORT void Java_org_chromium_foo_Foo_nativeCallWithQualifiedObjec
} }
// Step 4: Generated test functions (optional).
#endif // org_chromium_foo_Foo_JNI #endif // org_chromium_foo_Foo_JNI
...@@ -103,4 +103,7 @@ static void Java_Foo_callbackFromNative(JNIEnv* env, const base::android::JavaRe ...@@ -103,4 +103,7 @@ static void Java_Foo_callbackFromNative(JNIEnv* env, const base::android::JavaRe
} // namespace chromium_foo } // namespace chromium_foo
} // namespace org } // namespace org
// Step 4: Generated test functions (optional).
#endif // org_chromium_foo_Foo_JNI #endif // org_chromium_foo_Foo_JNI
...@@ -173,6 +173,7 @@ class CalledByNative(object): ...@@ -173,6 +173,7 @@ class CalledByNative(object):
self.env_call = GetEnvCall(self.is_constructor, self.static, self.env_call = GetEnvCall(self.is_constructor, self.static,
self.return_type) self.return_type)
self.static_cast = GetStaticCastForReturnType(self.return_type) self.static_cast = GetStaticCastForReturnType(self.return_type)
self.gen_test_method = kwargs.get('gen_test_method', False)
class ConstantField(object): class ConstantField(object):
...@@ -670,7 +671,8 @@ RE_SCOPED_JNI_TYPES = re.compile('jobject|jclass|jstring|jthrowable|.*Array') ...@@ -670,7 +671,8 @@ RE_SCOPED_JNI_TYPES = re.compile('jobject|jclass|jstring|jthrowable|.*Array')
# Regex to match a string like "@CalledByNative public void foo(int bar)". # Regex to match a string like "@CalledByNative public void foo(int bar)".
RE_CALLED_BY_NATIVE = re.compile( RE_CALLED_BY_NATIVE = re.compile(
r'@CalledByNative(?P<Unchecked>(?:Unchecked)?)(?:\("(?P<annotation>.*)"\))?' r'@CalledByNative(?P<Unchecked>(?:Unchecked)?)(?P<JavaTest>(?:JavaTest)?)'
r'(?:\("(?P<annotation>.*)"\))?'
r'(?:\s+@\w+(?:\(.*\))?)*' # Ignore any other annotations. r'(?:\s+@\w+(?:\(.*\))?)*' # Ignore any other annotations.
r'\s+(?P<prefix>(' r'\s+(?P<prefix>('
r'(private|protected|public|static|abstract|final|default|synchronized)' r'(private|protected|public|static|abstract|final|default|synchronized)'
...@@ -721,7 +723,8 @@ def ExtractCalledByNatives(jni_params, contents, always_mangle): ...@@ -721,7 +723,8 @@ def ExtractCalledByNatives(jni_params, contents, always_mangle):
return_type=return_type, return_type=return_type,
name=name, name=name,
is_constructor=is_constructor, is_constructor=is_constructor,
params=JniParams.Parse(match.group('params'))) params=JniParams.Parse(match.group('params')),
gen_test_method='JavaTest' in match.group('JavaTest'))
] ]
# Check for any @CalledByNative occurrences that weren't matched. # Check for any @CalledByNative occurrences that weren't matched.
unmatched_lines = re.sub(RE_CALLED_BY_NATIVE, '', contents).split('\n') unmatched_lines = re.sub(RE_CALLED_BY_NATIVE, '', contents).split('\n')
...@@ -1122,6 +1125,9 @@ $CONSTANT_FIELDS\ ...@@ -1122,6 +1125,9 @@ $CONSTANT_FIELDS\
// Step 3: Method stubs. // Step 3: Method stubs.
$METHOD_STUBS $METHOD_STUBS
// Step 4: Generated test functions (optional).
$TEST_METHODS
#endif // ${HEADER_GUARD} #endif // ${HEADER_GUARD}
""") """)
values = { values = {
...@@ -1132,6 +1138,7 @@ $METHOD_STUBS ...@@ -1132,6 +1138,7 @@ $METHOD_STUBS
'METHOD_STUBS': self.GetMethodStubsString(), 'METHOD_STUBS': self.GetMethodStubsString(),
'HEADER_GUARD': self.header_guard, 'HEADER_GUARD': self.header_guard,
'INCLUDES': self.GetIncludesString(), 'INCLUDES': self.GetIncludesString(),
'TEST_METHODS': self.GetTestMethodsString(),
} }
open_namespace = self.GetOpenNamespaceString() open_namespace = self.GetOpenNamespaceString()
if open_namespace: if open_namespace:
...@@ -1174,6 +1181,17 @@ $METHOD_STUBS ...@@ -1174,6 +1181,17 @@ $METHOD_STUBS
for called_by_native in self.called_by_natives for called_by_native in self.called_by_natives
] ]
def GetTestMethodsString(self):
strings = []
for called_by_native in self.called_by_natives:
if not called_by_native.gen_test_method:
continue
strings += [self.GetTestMethodString(called_by_native)]
if strings:
strings.insert(0, "#define JAVA_TESTS(test_fixture, java_test_object)\\")
ret = '\n'.join(strings)
return ret[:-1] # Drop trailing '\'.
def GetIncludesString(self): def GetIncludesString(self):
if not self.options.includes: if not self.options.includes:
return '' return ''
...@@ -1454,6 +1472,20 @@ ${PROFILING_LEAVING_NATIVE}\ ...@@ -1454,6 +1472,20 @@ ${PROFILING_LEAVING_NATIVE}\
values['TRACE_EVENT'] = '' values['TRACE_EVENT'] = ''
return RemoveIndentedEmptyLines(template.substitute(values)) return RemoveIndentedEmptyLines(template.substitute(values))
def GetTestMethodString(self, called_by_native):
method_template = Template("""\
TEST_F(test_fixture, ${METHOD_ID_VAR_NAME_UPPERCASE}) { \\
JNIEnv* env = base::android::AttachCurrentThread(); \\
Java_${JAVA_CLASS_ONLY}_${METHOD_ID_VAR_NAME}(\\
env, java_test_object); \\
}\\""")
values = self.GetCalledByNativeValues(called_by_native)
method_name = values['METHOD_ID_VAR_NAME']
values['METHOD_ID_VAR_NAME_UPPERCASE'] = method_name[0].upper(
) + method_name[1:]
return RemoveIndentedEmptyLines(method_template.substitute(values))
def GetTraceEventForNameTemplate(self, name_template, values): def GetTraceEventForNameTemplate(self, name_template, values):
name = Template(name_template).substitute(values) name = Template(name_template).substitute(values)
return ' TRACE_EVENT0("jni", "%s");\n' % name return ' TRACE_EVENT0("jni", "%s");\n' % name
......
...@@ -814,6 +814,85 @@ scooby doo ...@@ -814,6 +814,85 @@ scooby doo
except jni_generator.ParseError as e: except jni_generator.ParseError as e:
self.assertEqual(('@CalledByNative', 'scooby doo'), e.context_lines) self.assertEqual(('@CalledByNative', 'scooby doo'), e.context_lines)
def testCalledByNativeJavaTest(self):
test_data = """
class MyOuterClass {
@CalledByNative
public MyOuterClass() {}
@CalledByNativeJavaTest
public int testFoo() {}
@CalledByNativeJavaTest
public void testOtherFoo() {}
class MyInnerClass {
@CalledByNativeJavaTest("MyInnerClass")
public void testInnerFoo() {}
}
}
"""
jni_params = jni_generator.JniParams('org/chromium/Foo')
jni_params.ExtractImportsAndInnerClasses(test_data)
called_by_natives = jni_generator.ExtractCalledByNatives(
jni_params, test_data, always_mangle=False)
golden_called_by_natives = [
CalledByNative(
return_type='MyOuterClass',
system_class=False,
static=False,
name='Constructor',
method_id_var_name='Constructor',
java_class_name='',
params=[],
env_call=('Void', ''),
unchecked=False,
gen_test_method=False,
is_constructor=True,
),
CalledByNative(
return_type='int',
system_class=False,
static=False,
name='testFoo',
method_id_var_name='testFoo',
java_class_name='',
params=[],
env_call=('Void', ''),
unchecked=False,
gen_test_method=True,
),
CalledByNative(
return_type='void',
system_class=False,
static=False,
name='testOtherFoo',
method_id_var_name='testOtherFoo',
java_class_name='',
params=[],
env_call=('Void', ''),
unchecked=False,
gen_test_method=True,
),
CalledByNative(
return_type='void',
system_class=False,
static=False,
name='testInnerFoo',
method_id_var_name='testInnerFoo',
java_class_name='MyInnerClass',
params=[],
env_call=('Void', ''),
unchecked=False,
gen_test_method=True,
)
]
self.AssertListEquals(golden_called_by_natives, called_by_natives)
h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', [],
called_by_natives, [], jni_params,
TestOptions())
self.AssertGoldenTextEquals(h.GetContent())
def testFullyQualifiedClassName(self): def testFullyQualifiedClassName(self):
contents = """ contents = """
// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Copyright (c) 2010 The Chromium Authors. All rights reserved.
......
...@@ -17,6 +17,7 @@ import org.mockito.MockitoAnnotations; ...@@ -17,6 +17,7 @@ import org.mockito.MockitoAnnotations;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.CalledByNativeJavaTest;
import org.chromium.blink_public.common.ContextMenuDataMediaType; import org.chromium.blink_public.common.ContextMenuDataMediaType;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList; import org.chromium.chrome.browser.ChromeFeatureList;
...@@ -50,10 +51,6 @@ public class ChromeContextMenuPopulatorTest { ...@@ -50,10 +51,6 @@ public class ChromeContextMenuPopulatorTest {
private ChromeContextMenuPopulator mPopulator; private ChromeContextMenuPopulator mPopulator;
@CalledByNative @CalledByNative
public static ChromeContextMenuPopulatorTest create() {
return new ChromeContextMenuPopulatorTest();
}
private ChromeContextMenuPopulatorTest() {} private ChromeContextMenuPopulatorTest() {}
@CalledByNative @CalledByNative
...@@ -109,7 +106,7 @@ public class ChromeContextMenuPopulatorTest { ...@@ -109,7 +106,7 @@ public class ChromeContextMenuPopulatorTest {
} }
} }
@CalledByNative @CalledByNativeJavaTest
public void testHttpLink() { public void testHttpLink() {
FirstRunStatus.setFirstRunFlowComplete(false); FirstRunStatus.setFirstRunFlowComplete(false);
ContextMenuParams contextMenuParams = new ContextMenuParams(0, PAGE_URL, LINK_URL, ContextMenuParams contextMenuParams = new ContextMenuParams(0, PAGE_URL, LINK_URL,
...@@ -146,7 +143,7 @@ public class ChromeContextMenuPopulatorTest { ...@@ -146,7 +143,7 @@ public class ChromeContextMenuPopulatorTest {
checkMenuOptions(contextMenuParams, expected4); checkMenuOptions(contextMenuParams, expected4);
} }
@CalledByNative @CalledByNativeJavaTest
public void testMailLink() { public void testMailLink() {
FirstRunStatus.setFirstRunFlowComplete(false); FirstRunStatus.setFirstRunFlowComplete(false);
ContextMenuParams contextMenuParams = ContextMenuParams contextMenuParams =
...@@ -182,7 +179,7 @@ public class ChromeContextMenuPopulatorTest { ...@@ -182,7 +179,7 @@ public class ChromeContextMenuPopulatorTest {
checkMenuOptions(contextMenuParams, expected4); checkMenuOptions(contextMenuParams, expected4);
} }
@CalledByNative @CalledByNativeJavaTest
public void testTelLink() { public void testTelLink() {
FirstRunStatus.setFirstRunFlowComplete(false); FirstRunStatus.setFirstRunFlowComplete(false);
ContextMenuParams contextMenuParams = ContextMenuParams contextMenuParams =
...@@ -219,7 +216,7 @@ public class ChromeContextMenuPopulatorTest { ...@@ -219,7 +216,7 @@ public class ChromeContextMenuPopulatorTest {
checkMenuOptions(contextMenuParams, expected4); checkMenuOptions(contextMenuParams, expected4);
} }
@CalledByNative @CalledByNativeJavaTest
public void testVideoLink() { public void testVideoLink() {
FirstRunStatus.setFirstRunFlowComplete(false); FirstRunStatus.setFirstRunFlowComplete(false);
String sourceUrl = "http://www.blah.com/"; String sourceUrl = "http://www.blah.com/";
...@@ -260,7 +257,7 @@ public class ChromeContextMenuPopulatorTest { ...@@ -260,7 +257,7 @@ public class ChromeContextMenuPopulatorTest {
checkMenuOptions(contextMenuParams, expected4Tab1, expected4Tab2); checkMenuOptions(contextMenuParams, expected4Tab1, expected4Tab2);
} }
@CalledByNative @CalledByNativeJavaTest
public void testImageHiFi() { public void testImageHiFi() {
FirstRunStatus.setFirstRunFlowComplete(false); FirstRunStatus.setFirstRunFlowComplete(false);
ContextMenuParams contextMenuParams = new ContextMenuParams(ContextMenuDataMediaType.IMAGE, ContextMenuParams contextMenuParams = new ContextMenuParams(ContextMenuDataMediaType.IMAGE,
...@@ -294,7 +291,7 @@ public class ChromeContextMenuPopulatorTest { ...@@ -294,7 +291,7 @@ public class ChromeContextMenuPopulatorTest {
checkMenuOptions(contextMenuParams, expected4); checkMenuOptions(contextMenuParams, expected4);
} }
@CalledByNative @CalledByNativeJavaTest
public void testHttpLinkWithImageHiFi() { public void testHttpLinkWithImageHiFi() {
FirstRunStatus.setFirstRunFlowComplete(false); FirstRunStatus.setFirstRunFlowComplete(false);
ContextMenuParams contextMenuParams = new ContextMenuParams(ContextMenuDataMediaType.IMAGE, ContextMenuParams contextMenuParams = new ContextMenuParams(ContextMenuDataMediaType.IMAGE,
......
...@@ -16,6 +16,7 @@ import android.util.Pair; ...@@ -16,6 +16,7 @@ import android.util.Pair;
import org.junit.Assert; import org.junit.Assert;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.CalledByNativeJavaTest;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.TimeoutTimer; import org.chromium.base.test.util.TimeoutTimer;
import org.chromium.chrome.browser.instantapps.InstantAppsHandler; import org.chromium.chrome.browser.instantapps.InstantAppsHandler;
...@@ -344,10 +345,6 @@ public class InstalledAppProviderTest { ...@@ -344,10 +345,6 @@ public class InstalledAppProviderTest {
} }
@CalledByNative @CalledByNative
public static InstalledAppProviderTest create() {
return new InstalledAppProviderTest();
}
private InstalledAppProviderTest() {} private InstalledAppProviderTest() {}
@CalledByNative @CalledByNative
...@@ -361,7 +358,7 @@ public class InstalledAppProviderTest { ...@@ -361,7 +358,7 @@ public class InstalledAppProviderTest {
/** Origin of the page using the API is missing certain parts of the URI. */ /** Origin of the page using the API is missing certain parts of the URI. */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testOriginMissingParts() throws Exception { public void testOriginMissingParts() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -377,7 +374,7 @@ public class InstalledAppProviderTest { ...@@ -377,7 +374,7 @@ public class InstalledAppProviderTest {
/** Incognito mode with one related Android app. */ /** Incognito mode with one related Android app. */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testIncognitoWithOneInstalledRelatedApp() throws Exception { public void testIncognitoWithOneInstalledRelatedApp() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -394,7 +391,7 @@ public class InstalledAppProviderTest { ...@@ -394,7 +391,7 @@ public class InstalledAppProviderTest {
* <p>An Android app relates to the web app, but not mutual. * <p>An Android app relates to the web app, but not mutual.
*/ */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testNoRelatedApps() throws Exception { public void testNoRelatedApps() throws Exception {
// The web manifest has no related apps. // The web manifest has no related apps.
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {}; RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {};
...@@ -413,7 +410,7 @@ public class InstalledAppProviderTest { ...@@ -413,7 +410,7 @@ public class InstalledAppProviderTest {
* <p>An Android app relates to the web app, but not mutual. * <p>An Android app relates to the web app, but not mutual.
*/ */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testOneRelatedAppNoId() throws Exception { public void testOneRelatedAppNoId() throws Exception {
RelatedApplication manifestRelatedApps[] = RelatedApplication manifestRelatedApps[] =
new RelatedApplication[] {createRelatedApplication(PLATFORM_ANDROID, null, null)}; new RelatedApplication[] {createRelatedApplication(PLATFORM_ANDROID, null, null)};
...@@ -431,7 +428,7 @@ public class InstalledAppProviderTest { ...@@ -431,7 +428,7 @@ public class InstalledAppProviderTest {
* manifest doesn't mention the Android app. * manifest doesn't mention the Android app.
*/ */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testOneRelatedNonAndroidApp() throws Exception { public void testOneRelatedNonAndroidApp() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_OTHER, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_OTHER, PACKAGE_NAME_1, null)};
...@@ -448,7 +445,7 @@ public class InstalledAppProviderTest { ...@@ -448,7 +445,7 @@ public class InstalledAppProviderTest {
* <p>Another Android app relates to the web app, but not mutual. * <p>Another Android app relates to the web app, but not mutual.
*/ */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testOneRelatedAppNotInstalled() throws Exception { public void testOneRelatedAppNotInstalled() throws Exception {
// The web manifest has a related Android app named |PACKAGE_NAME_1|. // The web manifest has a related Android app named |PACKAGE_NAME_1|.
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
...@@ -466,7 +463,7 @@ public class InstalledAppProviderTest { ...@@ -466,7 +463,7 @@ public class InstalledAppProviderTest {
* Android app manifest has an asset_statements key, but the resource it links to is missing. * Android app manifest has an asset_statements key, but the resource it links to is missing.
*/ */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testOneRelatedAppBrokenAssetStatementsResource() throws Exception { public void testOneRelatedAppBrokenAssetStatementsResource() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -482,7 +479,7 @@ public class InstalledAppProviderTest { ...@@ -482,7 +479,7 @@ public class InstalledAppProviderTest {
/** One related Android app; Android app is not mutually related (has no asset_statements). */ /** One related Android app; Android app is not mutually related (has no asset_statements). */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testOneRelatedAppNoAssetStatements() throws Exception { public void testOneRelatedAppNoAssetStatements() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -494,7 +491,7 @@ public class InstalledAppProviderTest { ...@@ -494,7 +491,7 @@ public class InstalledAppProviderTest {
/** One related Android app; Android app is not mutually related (has no asset_statements). */ /** One related Android app; Android app is not mutually related (has no asset_statements). */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testOneRelatedAppNoAssetStatementsNullMetadata() throws Exception { public void testOneRelatedAppNoAssetStatementsNullMetadata() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -513,7 +510,7 @@ public class InstalledAppProviderTest { ...@@ -513,7 +510,7 @@ public class InstalledAppProviderTest {
* to a web app with a different port. * to a web app with a different port.
*/ */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testOneRelatedAppRelatedToDifferentOrigins() throws Exception { public void testOneRelatedAppRelatedToDifferentOrigins() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -534,7 +531,7 @@ public class InstalledAppProviderTest { ...@@ -534,7 +531,7 @@ public class InstalledAppProviderTest {
/** One related Android app; Android app is installed and mutually related. */ /** One related Android app; Android app is installed and mutually related. */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testOneInstalledRelatedApp() throws Exception { public void testOneInstalledRelatedApp() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -551,7 +548,7 @@ public class InstalledAppProviderTest { ...@@ -551,7 +548,7 @@ public class InstalledAppProviderTest {
* <p>This simulates navigating the frame while keeping the same Mojo service open. * <p>This simulates navigating the frame while keeping the same Mojo service open.
*/ */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testDynamicallyChangingUrl() throws Exception { public void testDynamicallyChangingUrl() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -579,7 +576,7 @@ public class InstalledAppProviderTest { ...@@ -579,7 +576,7 @@ public class InstalledAppProviderTest {
/** One related Android app (installed and mutually related), with a non-null URL field. */ /** One related Android app (installed and mutually related), with a non-null URL field. */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testInstalledRelatedAppWithUrl() throws Exception { public void testInstalledRelatedAppWithUrl() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, URL_UNRELATED)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, URL_UNRELATED)};
...@@ -592,7 +589,7 @@ public class InstalledAppProviderTest { ...@@ -592,7 +589,7 @@ public class InstalledAppProviderTest {
/** One related Android app; Android app is related to multiple origins. */ /** One related Android app; Android app is related to multiple origins. */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testMultipleAssetStatements() throws Exception { public void testMultipleAssetStatements() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -612,7 +609,7 @@ public class InstalledAppProviderTest { ...@@ -612,7 +609,7 @@ public class InstalledAppProviderTest {
/** A JSON syntax error in the Android app's asset statement. */ /** A JSON syntax error in the Android app's asset statement. */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testAssetStatementSyntaxError() throws Exception { public void testAssetStatementSyntaxError() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -626,7 +623,7 @@ public class InstalledAppProviderTest { ...@@ -626,7 +623,7 @@ public class InstalledAppProviderTest {
/** The Android app's asset statement is not an array. */ /** The Android app's asset statement is not an array. */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testAssetStatementNotArray() throws Exception { public void testAssetStatementNotArray() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -640,7 +637,7 @@ public class InstalledAppProviderTest { ...@@ -640,7 +637,7 @@ public class InstalledAppProviderTest {
/** The Android app's asset statement array contains non-objects. */ /** The Android app's asset statement array contains non-objects. */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testAssetStatementArrayNoObjects() throws Exception { public void testAssetStatementArrayNoObjects() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -661,7 +658,7 @@ public class InstalledAppProviderTest { ...@@ -661,7 +658,7 @@ public class InstalledAppProviderTest {
* the app is still returned as "installed". * the app is still returned as "installed".
*/ */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testAssetStatementNoRelation() throws Exception { public void testAssetStatementNoRelation() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -683,7 +680,7 @@ public class InstalledAppProviderTest { ...@@ -683,7 +680,7 @@ public class InstalledAppProviderTest {
* any will do. Is this desirable, or do we want to require a specific relation string? * any will do. Is this desirable, or do we want to require a specific relation string?
*/ */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testAssetStatementNonStandardRelation() throws Exception { public void testAssetStatementNonStandardRelation() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -698,7 +695,7 @@ public class InstalledAppProviderTest { ...@@ -698,7 +695,7 @@ public class InstalledAppProviderTest {
/** Android app has no "target" in the asset statement. */ /** Android app has no "target" in the asset statement. */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testAssetStatementNoTarget() throws Exception { public void testAssetStatementNoTarget() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -712,7 +709,7 @@ public class InstalledAppProviderTest { ...@@ -712,7 +709,7 @@ public class InstalledAppProviderTest {
/** Android app has no "namespace" in the asset statement. */ /** Android app has no "namespace" in the asset statement. */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testAssetStatementNoNamespace() throws Exception { public void testAssetStatementNoNamespace() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -728,7 +725,7 @@ public class InstalledAppProviderTest { ...@@ -728,7 +725,7 @@ public class InstalledAppProviderTest {
/** Android app is related, but not to the web namespace. */ /** Android app is related, but not to the web namespace. */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testNonWebAssetStatement() throws Exception { public void testNonWebAssetStatement() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -741,7 +738,7 @@ public class InstalledAppProviderTest { ...@@ -741,7 +738,7 @@ public class InstalledAppProviderTest {
/** Android app has no "site" in the asset statement. */ /** Android app has no "site" in the asset statement. */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testAssetStatementNoSite() throws Exception { public void testAssetStatementNoSite() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -757,7 +754,7 @@ public class InstalledAppProviderTest { ...@@ -757,7 +754,7 @@ public class InstalledAppProviderTest {
/** Android app has a syntax error in the "site" field of the asset statement. */ /** Android app has a syntax error in the "site" field of the asset statement. */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testAssetStatementSiteSyntaxError() throws Exception { public void testAssetStatementSiteSyntaxError() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -771,7 +768,7 @@ public class InstalledAppProviderTest { ...@@ -771,7 +768,7 @@ public class InstalledAppProviderTest {
/** Android app has a "site" field missing certain parts of the URI (scheme, host, port). */ /** Android app has a "site" field missing certain parts of the URI (scheme, host, port). */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testAssetStatementSiteMissingParts() throws Exception { public void testAssetStatementSiteMissingParts() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -797,7 +794,7 @@ public class InstalledAppProviderTest { ...@@ -797,7 +794,7 @@ public class InstalledAppProviderTest {
* if it is, we are lenient and just ignore it (matching only the origin). * if it is, we are lenient and just ignore it (matching only the origin).
*/ */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testAssetStatementSiteHasPath() throws Exception { public void testAssetStatementSiteHasPath() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -815,7 +812,7 @@ public class InstalledAppProviderTest { ...@@ -815,7 +812,7 @@ public class InstalledAppProviderTest {
* <p>Another Android app relates to the web app, but not mutual. * <p>Another Android app relates to the web app, but not mutual.
*/ */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testExtraInstalledApp() throws Exception { public void testExtraInstalledApp() throws Exception {
RelatedApplication manifestRelatedApps[] = new RelatedApplication[] { RelatedApplication manifestRelatedApps[] = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)}; createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null)};
...@@ -834,7 +831,7 @@ public class InstalledAppProviderTest { ...@@ -834,7 +831,7 @@ public class InstalledAppProviderTest {
* app which is not installed. * app which is not installed.
*/ */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testMultipleInstalledRelatedApps() throws Exception { public void testMultipleInstalledRelatedApps() throws Exception {
RelatedApplication[] manifestRelatedApps = new RelatedApplication[] { RelatedApplication[] manifestRelatedApps = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null), createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null),
...@@ -851,7 +848,7 @@ public class InstalledAppProviderTest { ...@@ -851,7 +848,7 @@ public class InstalledAppProviderTest {
/** Tests the pseudo-random artificial delay to counter a timing attack. */ /** Tests the pseudo-random artificial delay to counter a timing attack. */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testArtificialDelay() throws Exception { public void testArtificialDelay() throws Exception {
byte[] salt = {0x64, 0x09, -0x68, -0x25, 0x70, 0x11, 0x25, 0x24, 0x68, -0x1a, 0x08, 0x79, byte[] salt = {0x64, 0x09, -0x68, -0x25, 0x70, 0x11, 0x25, 0x24, 0x68, -0x1a, 0x08, 0x79,
-0x12, -0x50, 0x3b, -0x57, -0x17, -0x4d, 0x46, 0x02}; -0x12, -0x50, 0x3b, -0x57, -0x17, -0x4d, 0x46, 0x02};
...@@ -878,7 +875,7 @@ public class InstalledAppProviderTest { ...@@ -878,7 +875,7 @@ public class InstalledAppProviderTest {
} }
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testMultipleAppsIncludingInstantApps() throws Exception { public void testMultipleAppsIncludingInstantApps() throws Exception {
RelatedApplication[] manifestRelatedApps = new RelatedApplication[] { RelatedApplication[] manifestRelatedApps = new RelatedApplication[] {
createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null), createRelatedApplication(PLATFORM_ANDROID, PACKAGE_NAME_1, null),
...@@ -901,7 +898,7 @@ public class InstalledAppProviderTest { ...@@ -901,7 +898,7 @@ public class InstalledAppProviderTest {
* app which is installed and mutually related. * app which is installed and mutually related.
*/ */
@Feature({"InstalledApp"}) @Feature({"InstalledApp"})
@CalledByNative @CalledByNativeJavaTest
public void testRelatedAppsOverAllowedThreshold() throws Exception { public void testRelatedAppsOverAllowedThreshold() throws Exception {
RelatedApplication manifestRelatedApps[] = RelatedApplication manifestRelatedApps[] =
new RelatedApplication[MAX_ALLOWED_RELATED_APPS + 1]; new RelatedApplication[MAX_ALLOWED_RELATED_APPS + 1];
......
...@@ -10,14 +10,12 @@ using base::android::AttachCurrentThread; ...@@ -10,14 +10,12 @@ using base::android::AttachCurrentThread;
class ChromeContextMenuPopulatorTest : public ::testing::Test { class ChromeContextMenuPopulatorTest : public ::testing::Test {
public: public:
ChromeContextMenuPopulatorTest() { ChromeContextMenuPopulatorTest()
JNIEnv* env = AttachCurrentThread(); : j_test_(Java_ChromeContextMenuPopulatorTest_Constructor(
j_test_.Reset(Java_ChromeContextMenuPopulatorTest_create(env)); AttachCurrentThread())) {}
}
void SetUp() override { void SetUp() override {
JNIEnv* env = AttachCurrentThread(); Java_ChromeContextMenuPopulatorTest_setUp(AttachCurrentThread(), j_test_);
Java_ChromeContextMenuPopulatorTest_setUp(env, j_test_);
} }
const base::android::ScopedJavaGlobalRef<jobject>& j_test() { const base::android::ScopedJavaGlobalRef<jobject>& j_test() {
...@@ -28,32 +26,4 @@ class ChromeContextMenuPopulatorTest : public ::testing::Test { ...@@ -28,32 +26,4 @@ class ChromeContextMenuPopulatorTest : public ::testing::Test {
base::android::ScopedJavaGlobalRef<jobject> j_test_; base::android::ScopedJavaGlobalRef<jobject> j_test_;
}; };
TEST_F(ChromeContextMenuPopulatorTest, TestHttpLink) { JAVA_TESTS(ChromeContextMenuPopulatorTest, j_test())
JNIEnv* env = AttachCurrentThread();
Java_ChromeContextMenuPopulatorTest_testHttpLink(env, j_test());
}
TEST_F(ChromeContextMenuPopulatorTest, TestMailLink) {
JNIEnv* env = AttachCurrentThread();
Java_ChromeContextMenuPopulatorTest_testMailLink(env, j_test());
}
TEST_F(ChromeContextMenuPopulatorTest, TestTelLink) {
JNIEnv* env = AttachCurrentThread();
Java_ChromeContextMenuPopulatorTest_testTelLink(env, j_test());
}
TEST_F(ChromeContextMenuPopulatorTest, TestVideoLink) {
JNIEnv* env = AttachCurrentThread();
Java_ChromeContextMenuPopulatorTest_testVideoLink(env, j_test());
}
TEST_F(ChromeContextMenuPopulatorTest, TestImageHiFi) {
JNIEnv* env = AttachCurrentThread();
Java_ChromeContextMenuPopulatorTest_testImageHiFi(env, j_test());
}
TEST_F(ChromeContextMenuPopulatorTest, TestHttpLinkWithImageHiFi) {
JNIEnv* env = AttachCurrentThread();
Java_ChromeContextMenuPopulatorTest_testHttpLinkWithImageHiFi(env, j_test());
}
...@@ -10,14 +10,12 @@ using base::android::AttachCurrentThread; ...@@ -10,14 +10,12 @@ using base::android::AttachCurrentThread;
class InstalledAppProviderTest : public ::testing::Test { class InstalledAppProviderTest : public ::testing::Test {
public: public:
InstalledAppProviderTest() { InstalledAppProviderTest()
JNIEnv* env = AttachCurrentThread(); : j_test_(
j_test_.Reset(Java_InstalledAppProviderTest_create(env)); Java_InstalledAppProviderTest_Constructor(AttachCurrentThread())) {}
}
void SetUp() override { void SetUp() override {
JNIEnv* env = AttachCurrentThread(); Java_InstalledAppProviderTest_setUp(AttachCurrentThread(), j_test_);
Java_InstalledAppProviderTest_setUp(env, j_test_);
} }
const base::android::ScopedJavaGlobalRef<jobject>& j_test() { const base::android::ScopedJavaGlobalRef<jobject>& j_test() {
...@@ -28,169 +26,4 @@ class InstalledAppProviderTest : public ::testing::Test { ...@@ -28,169 +26,4 @@ class InstalledAppProviderTest : public ::testing::Test {
base::android::ScopedJavaGlobalRef<jobject> j_test_; base::android::ScopedJavaGlobalRef<jobject> j_test_;
}; };
TEST_F(InstalledAppProviderTest, TestOriginMissingParts) { JAVA_TESTS(InstalledAppProviderTest, j_test())
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testOriginMissingParts(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestIncognitoWithOneInstalledRelatedApp) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testIncognitoWithOneInstalledRelatedApp(
env, j_test());
}
TEST_F(InstalledAppProviderTest, TestNoRelatedApps) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testNoRelatedApps(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestOneRelatedAppNoId) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testOneRelatedAppNoId(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestOneRelatedNonAndroidApp) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testOneRelatedNonAndroidApp(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestOneRelatedAppNotInstalled) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testOneRelatedAppNotInstalled(env, j_test());
}
TEST_F(InstalledAppProviderTest,
TestOneRelatedAppBrokenAssetStatementsResource) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testOneRelatedAppBrokenAssetStatementsResource(
env, j_test());
}
TEST_F(InstalledAppProviderTest, TestOneRelatedAppNoAssetStatements) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testOneRelatedAppNoAssetStatements(env,
j_test());
}
TEST_F(InstalledAppProviderTest,
TestOneRelatedAppNoAssetStatementsNullMetadata) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testOneRelatedAppNoAssetStatementsNullMetadata(
env, j_test());
}
TEST_F(InstalledAppProviderTest, TestOneRelatedAppRelatedToDifferentOrigins) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testOneRelatedAppRelatedToDifferentOrigins(
env, j_test());
}
TEST_F(InstalledAppProviderTest, TestOneInstalledRelatedApp) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testOneInstalledRelatedApp(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestDynamicallyChangingUrl) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testDynamicallyChangingUrl(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestInstalledRelatedAppWithUrl) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testInstalledRelatedAppWithUrl(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestMultipleAssetStatements) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testMultipleAssetStatements(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestAssetStatementSyntaxError) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testAssetStatementSyntaxError(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestAssetStatementNotArray) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testAssetStatementNotArray(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestAssetStatementArrayNoObjects) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testAssetStatementArrayNoObjects(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestAssetStatementNoRelation) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testAssetStatementNoRelation(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestAssetStatementNonStandardRelation) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testAssetStatementNonStandardRelation(env,
j_test());
}
TEST_F(InstalledAppProviderTest, TestAssetStatementNoTarget) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testAssetStatementNoTarget(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestAssetStatementNoNamespace) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testAssetStatementNoNamespace(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestNonWebAssetStatement) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testNonWebAssetStatement(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestAssetStatementNoSite) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testAssetStatementNoSite(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestAssetStatementSiteSyntaxError) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testAssetStatementSiteSyntaxError(env,
j_test());
}
TEST_F(InstalledAppProviderTest, TestAssetStatementSiteMissingParts) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testAssetStatementSiteMissingParts(env,
j_test());
}
TEST_F(InstalledAppProviderTest, TestAssetStatementSiteHasPath) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testAssetStatementSiteHasPath(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestExtraInstalledApp) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testExtraInstalledApp(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestMultipleInstalledRelatedApps) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testMultipleInstalledRelatedApps(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestArtificialDelay) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testArtificialDelay(env, j_test());
}
TEST_F(InstalledAppProviderTest, TestMultipleAppsIncludingInstantApps) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testMultipleAppsIncludingInstantApps(env,
j_test());
}
TEST_F(InstalledAppProviderTest, TestRelatedAppsOverAllowedThreshold) {
JNIEnv* env = AttachCurrentThread();
Java_InstalledAppProviderTest_testRelatedAppsOverAllowedThreshold(env,
j_test());
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment