Commit b40b0b04 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Revert native_java_unittest infra

Native Java Unittests have all been removed, and so it's time to revert
the infra changes they required.

Reverted:
https://crrev.com/ea65b1a1577f1fbba45e035f43e1c898a9874f9b
https://crrev.com/26dc9eefadac5e70cf3789abbfb1eead7c9f7b68
https://crrev.com/1265cac9f769d0460a84e3f906b93f62290fd117
https://crrev.com/d46596b1702517799459d4b6a9a26669b187c94b
https://crrev.com/04c511fd08177c915d5c267835110d0194bdd671

Bug: 1103344
Change-Id: I12ea68454c118de7860be6ba23c6e8263baceb99
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2406692
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807140}
parent 61e5135d
......@@ -3572,10 +3572,8 @@ if (is_android) {
"android/java/src/org/chromium/base/UserDataHost.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/CalledByNativeJavaTest.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/DisabledCalledByNativeJavaTest.java",
"android/java/src/org/chromium/base/annotations/DoNotInline.java",
"android/java/src/org/chromium/base/annotations/JNIAdditionalImport.java",
"android/java/src/org/chromium/base/annotations/JNINamespace.java",
......@@ -3583,7 +3581,6 @@ if (is_android) {
"android/java/src/org/chromium/base/annotations/MainDex.java",
"android/java/src/org/chromium/base/annotations/MockedInTests.java",
"android/java/src/org/chromium/base/annotations/NativeClassQualifiedName.java",
"android/java/src/org/chromium/base/annotations/NativeJavaTestFeatures.java",
"android/java/src/org/chromium/base/annotations/RemovableInRelease.java",
"android/java/src/org/chromium/base/annotations/UsedByReflection.java",
"android/java/src/org/chromium/base/annotations/VerifiesOnLollipop.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 "";
}
// 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;
/**
* See @CalledByNativeJavaTest. This annotation generates a disabled test instead.
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.CLASS)
public @interface DisabledCalledByNativeJavaTest {
/*
* If present, tells which inner class the method belongs to.
*/
public String value() default "";
}
// 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;
/**
* NativeJavaTestFeatures is used by the JNI generator in combination with @CalledByNativeJavaTest
* to generate a native test method that enabled or disables the specified feature for the scope
* of the test.
*/
public class NativeJavaTestFeatures {
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.CLASS)
public static @interface Enable {
/**
* If present, specifies which features to enable.
*/
public String[] value() default {};
}
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.CLASS)
public static @interface Disable {
/**
* If present, specifies which features to disable.
*/
public String[] value() default {};
}
}
......@@ -209,57 +209,6 @@ For other objects - use smart pointers to store them:
* `JavaParamRef<>` - Use to accept any of the above as a parameter to a
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());
#### Disabling @CalledByNativeJavaTest tests
In order to disabled a Native Java Unittest, replace the @CalledByNativeJavaTest
annotation with @DisabledCalledByNativeJavaTest. This will generate a native
test prefixed with DISABLED_.
Please note that unlike @DisabledTest, you should not provide a message in the
annotation as to why the test is disabled, as this will be interpreted as the
inner class name by the CalledByNative jni generator.
#### Feature flag support in @CalledByNativeJavaTest tests
Features may be enabled/disabled for the Java test methods by using the
@NativeJavaTestFeatures.Enabled or @NativeJavaTestFeatures.Disabled annotations.
Note that these annotations will re-initialize the feature list given they
initialize through the command line approach, and so will clear any features
set by, say, test setup.
### Additional Guidelines / Advice
Minimize the surface API between the two sides. Rather than calling multiple
......
// 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 foo;
class TestFeatureList {
public static final String MY_FEATURE = "MyFeature";
public static final String MY_FEATURE_WITH_A_REALLY_REALLY_ABSURDLY_LONG_NAME =
"MyFeatureWithAReallyReallyAbsurdlyLongName";
public static final String BAD_FEATURE = "BadFeature";
}
......@@ -262,7 +262,4 @@ JNI_GENERATOR_EXPORT jobjectArray Java_J_N_MPpCU1l5(
}
// Step 4: Generated test functions (optional).
#endif // org_chromium_example_jni_generator_SampleForAnnotationProcessor_JNI
......@@ -280,7 +280,4 @@ JNI_GENERATOR_EXPORT jobjectArray
}
// Step 4: Generated test functions (optional).
#endif // org_chromium_example_jni_generator_SampleForAnnotationProcessor_JNI
......@@ -524,7 +524,4 @@ static base::android::ScopedJavaLocalRef<jobject> Java_SampleForTests_getInnerEn
} // namespace android
} // namespace base
// Step 4: Generated test functions (optional).
#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_testFeatures(nullptr);
static void Java_TestJni_testFeatures(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,
"testFeatures",
"()V",
&g_org_chromium_TestJni_testFeatures);
env->CallVoidMethod(obj.obj(),
call_context.base.method_id);
}
static std::atomic<jmethodID> g_org_chromium_TestJni_testOtherFeatures(nullptr);
static void Java_TestJni_testOtherFeatures(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,
"testOtherFeatures",
"()V",
&g_org_chromium_TestJni_testOtherFeatures);
env->CallVoidMethod(obj.obj(),
call_context.base.method_id);
}
static std::atomic<jmethodID> g_org_chromium_TestJni_testDisabledFoo(nullptr);
static void Java_TestJni_testDisabledFoo(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,
"testDisabledFoo",
"()V",
&g_org_chromium_TestJni_testDisabledFoo);
env->CallVoidMethod(obj.obj(),
call_context.base.method_id);
}
static std::atomic<jmethodID>
g_org_chromium_TestJni_testLongNameActionServiceModelProducerDelegateProxyObserverMediatorFactoryConsumerImplForTesting(nullptr);
static void
Java_TestJni_testLongNameActionServiceModelProducerDelegateProxyObserverMediatorFactoryConsumerImplForTesting(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,
"testLongNameActionServiceModelProducerDelegateProxyObserverMediatorFactoryConsumerImplForTesting",
"()V",
&g_org_chromium_TestJni_testLongNameActionServiceModelProducerDelegateProxyObserverMediatorFactoryConsumerImplForTesting);
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);
}
static std::atomic<jmethodID> g_org_chromium_TestJni_testOneLine(nullptr);
static void Java_TestJni_testOneLine(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,
"testOneLine",
"()V",
&g_org_chromium_TestJni_testOneLine);
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, TestFeatures) { \
base::test::ScopedFeatureList feature_list; \
feature_list.InitFromCommandLine( \
"MyFeature,MyFeatureWithAReallyReallyAbsurdlyLongName", "BadFeature"); \
JNIEnv* env = base::android::AttachCurrentThread(); \
Java_TestJni_testFeatures(\
env, java_test_object); \
}\
TEST_F(test_fixture, TestOtherFeatures) { \
JNIEnv* env = base::android::AttachCurrentThread(); \
Java_TestJni_testOtherFeatures(\
env, java_test_object); \
}\
TEST_F(test_fixture, DISABLED_TestDisabledFoo) { \
JNIEnv* env = base::android::AttachCurrentThread(); \
Java_TestJni_testDisabledFoo(\
env, java_test_object); \
}\
TEST_F(test_fixture, TestLongNameActionServiceModelProducerDelegateProxyObserverMediatorFactoryConsumerImplForTesting) { \
JNIEnv* env = base::android::AttachCurrentThread(); \
Java_TestJni_testLongNameActionServiceModelProducerDelegateProxyObserverMediatorFactoryConsumerImplForTesting(\
env, java_test_object); \
}\
TEST_F(test_fixture, TestInnerFoo) { \
JNIEnv* env = base::android::AttachCurrentThread(); \
Java_MyInnerClass_testInnerFoo(\
env, java_test_object); \
}\
TEST_F(test_fixture, TestOneLine) { \
base::test::ScopedFeatureList feature_list; \
feature_list.InitFromCommandLine( \
"MyFeature", ""); \
JNIEnv* env = base::android::AttachCurrentThread(); \
Java_TestJni_testOneLine(\
env, java_test_object); \
}
#endif // org_chromium_TestJni_JNI
......@@ -475,7 +475,4 @@ static base::android::ScopedJavaLocalRef<jobject> Java_TestJni_getCompressFormat
return base::android::ScopedJavaLocalRef<jobject>(env, ret);
}
// Step 4: Generated test functions (optional).
#endif // org_chromium_TestJni_JNI
......@@ -2317,7 +2317,4 @@ static void Java_MotionEvent_writeToParcel(JNIEnv* env, const base::android::Jav
} // namespace JNI_MotionEvent
// Step 4: Generated test functions (optional).
#endif // android_view_MotionEvent_JNI
......@@ -273,7 +273,4 @@ static base::android::ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(J
} // namespace JNI_InputStream
// Step 4: Generated test functions (optional).
#endif // java_io_InputStream_JNI
......@@ -84,7 +84,4 @@ static base::android::ScopedJavaLocalRef<jclass> Java_HashSet_getClass(JNIEnv* e
} // namespace JNI_HashSet
// Step 4: Generated test functions (optional).
#endif // java_util_HashSet_JNI
......@@ -57,7 +57,4 @@ JNI_GENERATOR_EXPORT jint Java_org_chromium_TestJni_00024MyInnerClass_nativeInit
}
// Step 4: Generated test functions (optional).
#endif // org_chromium_TestJni_JNI
......@@ -67,7 +67,4 @@ JNI_GENERATOR_EXPORT jint Java_org_chromium_TestJni_00024MyOtherInnerClass_nativ
}
// Step 4: Generated test functions (optional).
#endif // org_chromium_TestJni_JNI
......@@ -80,7 +80,4 @@ JNI_GENERATOR_EXPORT jint Java_org_chromium_TestJni_00024MyOtherInnerClass_nativ
}
// Step 4: Generated test functions (optional).
#endif // org_chromium_TestJni_JNI
......@@ -68,7 +68,4 @@ static void Java_Foo_calledByNative(JNIEnv* env, const base::android::JavaRef<jo
call_context.base.method_id, callback1.obj(), callback2.obj());
}
// Step 4: Generated test functions (optional).
#endif // org_chromium_foo_Foo_JNI
......@@ -226,7 +226,4 @@ static base::android::ScopedJavaLocalRef<jstring>
return base::android::ScopedJavaLocalRef<jstring>(env, ret);
}
// Step 4: Generated test functions (optional).
#endif // org_chromium_example_jni_generator_SampleForTests_JNI
......@@ -213,7 +213,4 @@ JNI_GENERATOR_EXPORT jthrowable Java_org_chromium_TestJni_nativeMessWithJavaExce
}
// Step 4: Generated test functions (optional).
#endif // org_chromium_TestJni_JNI
......@@ -46,7 +46,4 @@ JNI_GENERATOR_EXPORT void Java_org_chromium_TestJni_nativeDestroy(
}
// Step 4: Generated test functions (optional).
#endif // org_chromium_TestJni_JNI
......@@ -60,7 +60,4 @@ JNI_GENERATOR_EXPORT jstring
}
// Step 4: Generated test functions (optional).
#endif // org_chromium_example_SampleProxyJni_JNI
......@@ -114,7 +114,4 @@ 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
......@@ -46,7 +46,4 @@ JNI_GENERATOR_EXPORT void Java_foo_bar_nativeSyncSetupEnded(
}
// Step 4: Generated test functions (optional).
#endif // foo_bar_JNI
......@@ -64,7 +64,4 @@ static void Java_Foo_calledByNative(JNIEnv* env, const base::android::JavaRef<jo
call_context.base.method_id, callback.obj());
}
// Step 4: Generated test functions (optional).
#endif // org_chromium_foo_Foo_JNI
......@@ -97,7 +97,4 @@ JNI_GENERATOR_EXPORT void Java_org_chromium_foo_Foo_nativeCallWithQualifiedObjec
}
// Step 4: Generated test functions (optional).
#endif // org_chromium_foo_Foo_JNI
......@@ -103,7 +103,4 @@ static void Java_Foo_callbackFromNative(JNIEnv* env, const base::android::JavaRe
} // namespace chromium_foo
} // namespace org
// Step 4: Generated test functions (optional).
#endif // org_chromium_foo_Foo_JNI
This diff is collapsed.
......@@ -52,12 +52,6 @@ class TestOptions(object):
self.enable_tracing = False
self.use_proxy_hash = False
self.always_mangle = False
self.feature_list_file = ''
def _FeatureListFile():
dir_name = os.path.dirname(os.path.realpath(__file__))
return dir_name + '/TestSampleFeatureList.java'
class BaseTest(unittest.TestCase):
......@@ -818,268 +812,7 @@ scooby doo
always_mangle=False)
self.fail('Expected a ParseError')
except jni_generator.ParseError as e:
self.assertEqual(('', '@CalledByNative', 'scooby doo'), e.context_lines)
def testCalledByNativeJavaTestImportErrors(self):
# Using banned imports
try:
jni_params = jni_generator.JniParams('')
jni_generator.ExtractCalledByNatives(
jni_params,
"""
import org.junit.Rule;
class MyClass {
@Rule
public JniMocker mocker = new JniMocker();
@CalledByNativeJavaTest
public void testStuff() {}
}
""",
always_mangle=False,
feature_list_file=_FeatureListFile())
self.fail('Expected a ParseError')
except jni_generator.ParseError as e:
self.assertEqual(('', 'import org.junit.Rule'), e.context_lines)
def testCalledByNativeJavaTestFeatureParseErrors(self):
# Using banned Features.Enable/Disable
try:
jni_params = jni_generator.JniParams('')
jni_generator.ExtractCalledByNatives(
jni_params,
"""
class MyClass {
@Features.Disable({ChromeFeatureList.SOME_FEATURE})
@CalledByNativeJavaTest
public void testMoreFeatures() {}
}
""",
always_mangle=False,
feature_list_file=_FeatureListFile())
self.fail('Expected a ParseError')
except jni_generator.ParseError as e:
self.assertEqual(
('', 'Features.Disable({ChromeFeatureList.SOME_FEATURE})\n '),
e.context_lines)
# Using NativeJavaTestFeatures outside of a test.
try:
jni_params = jni_generator.JniParams('')
jni_generator.ExtractCalledByNatives(
jni_params,
"""
class MyClass {
@CalledByNative @NativeJavaTestFeatures.Enable(TestFeatureList.MY_FEATURE) \
public void testNotActuallyATest() {}
}
""",
always_mangle=False,
feature_list_file=_FeatureListFile())
self.fail('Expected a ParseError')
except jni_generator.ParseError as e:
self.assertEqual((
'',
'@CalledByNative @NativeJavaTestFeatures.Enable('
'TestFeatureList.MY_FEATURE) ',
), e.context_lines)
# Not specifying a feature_list_file.
try:
jni_params = jni_generator.JniParams('')
jni_generator.ExtractCalledByNatives(
jni_params,
"""
class MyClass {
@CalledByNativeJavaTest
@NativeJavaTestFeatures.Disable(TestFeatureList.MY_FEATURE)
public void testMoreFeatures() {}
}
""",
always_mangle=False,
feature_list_file=None)
self.fail('Expected a ParseError')
except jni_generator.ParseError as e:
self.assertEqual(
'Your generate_jni target must specify a feature_list_file in order '
'to support feature annotations.', e.description)
# Specifying a feature that doesn't exist.
try:
jni_params = jni_generator.JniParams('')
jni_generator.ExtractCalledByNatives(
jni_params,
"""
class MyClass {
@CalledByNativeJavaTest
@NativeJavaTestFeatures.Disable(TestFeatureList.NOT_A_FEATURE)
public void testMoreFeatures() {}
}
""",
always_mangle=False,
feature_list_file=_FeatureListFile())
self.fail('Expected a ParseError')
except jni_generator.ParseError as e:
self.assertEqual(('TestFeatureList.NOT_A_FEATURE', ), e.context_lines)
def testCalledByNativeJavaTest(self):
test_data = """
class MyOuterClass {
@CalledByNative
public MyOuterClass() {}
@CalledByNativeJavaTest
public int testFoo() {}
@NativeJavaTestFeatures.Enable({TestFeatureList.MY_FEATURE,
TestFeatureList.MY_FEATURE_WITH_A_REALLY_REALLY_ABSURDLY_LONG_NAME})
@CalledByNativeJavaTest
@NativeJavaTestFeatures.Disable(TestFeatureList.BAD_FEATURE)
public void testFeatures() {}
@CalledByNativeJavaTest
@NativeJavaTestFeatures.Enable({})
@NativeJavaTestFeatures.Disable({})
public void testOtherFeatures() {}
@DisabledCalledByNativeJavaTest
public void testDisabledFoo() {}
@CalledByNativeJavaTest
public void testLongNameActionServiceModelProducerDelegateProxyObserver\
MediatorFactoryConsumerImplForTesting() {}
class MyInnerClass {
@CalledByNativeJavaTest("MyInnerClass")
public void testInnerFoo() {}
}
@CalledByNativeJavaTest @NativeJavaTestFeatures.Enable(\
TestFeatureList.MY_FEATURE) public void testOneLine() {}
}
"""
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,
feature_list_file=_FeatureListFile())
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='testFeatures',
method_id_var_name='testFeatures',
java_class_name='',
params=[],
env_call=('Void', ''),
unchecked=False,
gen_test_method=True,
enabled_features=
'MyFeature,MyFeatureWithAReallyReallyAbsurdlyLongName',
disabled_features='BadFeature',
),
CalledByNative(
return_type='void',
system_class=False,
static=False,
name='testOtherFeatures',
method_id_var_name='testOtherFeatures',
java_class_name='',
params=[],
env_call=('Void', ''),
unchecked=False,
gen_test_method=True,
enabled_features=None,
disabled_features=None,
),
CalledByNative(
return_type='void',
system_class=False,
static=False,
name='testDisabledFoo',
method_id_var_name='testDisabledFoo',
java_class_name='',
params=[],
env_call=('Void', ''),
unchecked=False,
gen_test_method=True,
test_disabled=True,
),
CalledByNative(
return_type='void',
system_class=False,
static=False,
name=
'testLongNameActionServiceModelProducerDelegateProxyObserverMediatorFactoryConsumerImplForTesting',
method_id_var_name=
'testLongNameActionServiceModelProducerDelegateProxyObserverMediatorFactoryConsumerImplForTesting',
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,
),
CalledByNative(
return_type='void',
system_class=False,
static=False,
name='testOneLine',
method_id_var_name='testOneLine',
java_class_name='',
params=[],
env_call=('Void', ''),
unchecked=False,
gen_test_method=True,
enabled_features='MyFeature',
disabled_features=None,
),
]
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())
self.assertEqual(('@CalledByNative', 'scooby doo'), e.context_lines)
def testFullyQualifiedClassName(self):
contents = """
......
......@@ -220,10 +220,6 @@ if (enable_java_templates) {
if (enable_jni_tracing) {
args += [ "--enable_tracing" ]
}
if (defined(invoker.feature_list_file)) {
file_path = rebase_path(invoker.feature_list_file, root_build_dir)
args += [ "--feature_list_file=$file_path" ]
}
}
}
......
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