diff options
Diffstat (limited to 'third_party/libwebrtc/build/config/android/test/classpath_order')
4 files changed, 160 insertions, 0 deletions
diff --git a/third_party/libwebrtc/build/config/android/test/classpath_order/BUILD.gn b/third_party/libwebrtc/build/config/android/test/classpath_order/BUILD.gn new file mode 100644 index 0000000000..decd1a84d2 --- /dev/null +++ b/third_party/libwebrtc/build/config/android/test/classpath_order/BUILD.gn @@ -0,0 +1,111 @@ +# Copyright 2021 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. + +import("//build/config/android/rules.gni") + +template("test_resources") { + jinja_template_resources(target_name) { + forward_variables_from(invoker, "*") + testonly = true + variables = [ "resource_name=$resource_name" ] + res_dir = "java/res_template" + resources = [ "java/res_template/values/values.xml" ] + } +} + +template("generate_dummy_android_library") { + # No underscores to avoid crbug.com/908819. + _generate_java_source_target_name = "${target_name}generatejavasource" + jinja_template(_generate_java_source_target_name) { + testonly = true + input = "java/src/org/chromium/build/classpath_order/Dummy.java.jinja2" + output = "$target_gen_dir/java/src/org/chromium/build/classpath_order/${invoker.class_name}.java" + variables = [ "class_name=${invoker.class_name}" ] + } + + android_library(target_name) { + forward_variables_from(invoker, "*") + + if (!defined(invoker.deps)) { + deps = [] + } + + sources = get_target_outputs(":${_generate_java_source_target_name}") + deps += [ ":${_generate_java_source_target_name}" ] + } +} + +# Test that classpath order keeps resources accessible when multiple targets generate +# resources for the same package. Specifically, test that an android_library precedes +# its dependencies regardless of the relative lexographic order. + +test_resources("a1_dependency_resources") { + resource_name = "a1_dependency_resource" +} + +generate_dummy_android_library("a1_dependency_java") { + testonly = true + class_name = "A1Dependency" + resources_package = "org.chromium.build.classpath_order.test1" + deps = [ ":a1_dependency_resources" ] +} + +test_resources("z1_master_resources") { + resource_name = "z1_master_resource" + deps = [ ":a1_dependency_resources" ] +} + +generate_dummy_android_library("z1_master_java") { + testonly = true + class_name = "Z1Master" + resources_package = "org.chromium.build.classpath_order.test1" + deps = [ + ":a1_dependency_java", + ":z1_master_resources", + ] +} + +test_resources("z2_dependency_resources") { + resource_name = "z2_dependency_resource" +} + +generate_dummy_android_library("z2_dependency_java") { + testonly = true + class_name = "Z2Dependency" + resources_package = "org.chromium.build.classpath_order.test2" + deps = [ ":z2_dependency_resources" ] +} + +test_resources("a2_master_resources") { + resource_name = "a2_master_resource" + deps = [ ":z2_dependency_resources" ] +} + +generate_dummy_android_library("a2_master_java") { + testonly = true + class_name = "A2Master" + resources_package = "org.chromium.build.classpath_order.test2" + deps = [ + ":a2_master_resources", + ":z2_dependency_java", + ] +} + +java_library("junit_tests") { + bypass_platform_checks = true + testonly = true + sources = + [ "java/src/org/chromium/build/classpath_order/ClassPathOrderTest.java" ] + deps = [ + ":a1_dependency_java", + ":a2_master_java", + ":z1_master_java", + ":z2_dependency_java", + "//testing/android/junit:junit_test_support", + "//third_party/android_deps:robolectric_all_java", + "//third_party/android_support_test_runner:runner_java", + "//third_party/androidx:androidx_test_runner_java", + "//third_party/junit", + ] +} diff --git a/third_party/libwebrtc/build/config/android/test/classpath_order/java/res_template/values/values.xml b/third_party/libwebrtc/build/config/android/test/classpath_order/java/res_template/values/values.xml new file mode 100644 index 0000000000..ee706b289b --- /dev/null +++ b/third_party/libwebrtc/build/config/android/test/classpath_order/java/res_template/values/values.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright 2021 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. --> + + +<resources xmlns:android="http://schemas.android.com/apk/res/android"> + <integer name="{{resource_name}}">42</integer> +</resources> diff --git a/third_party/libwebrtc/build/config/android/test/classpath_order/java/src/org/chromium/build/classpath_order/ClassPathOrderTest.java b/third_party/libwebrtc/build/config/android/test/classpath_order/java/src/org/chromium/build/classpath_order/ClassPathOrderTest.java new file mode 100644 index 0000000000..c5a9202605 --- /dev/null +++ b/third_party/libwebrtc/build/config/android/test/classpath_order/java/src/org/chromium/build/classpath_order/ClassPathOrderTest.java @@ -0,0 +1,32 @@ +// Copyright 2021 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.build.classpath_order; + +import static org.junit.Assert.assertTrue; + +import androidx.test.filters.SmallTest; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.annotation.Config; + +import org.chromium.testing.local.LocalRobolectricTestRunner; + +/** + * Test that resources defined in different android_resources() targets but with the same + * package are accessible. + */ +@RunWith(LocalRobolectricTestRunner.class) +@Config(manifest = Config.NONE) +public final class ClassPathOrderTest { + @Test + @SmallTest + public void testAll() { + assertTrue(org.chromium.build.classpath_order.test1.R.integer.a1_dependency_resource >= 0); + assertTrue(org.chromium.build.classpath_order.test1.R.integer.z1_master_resource >= 0); + assertTrue(org.chromium.build.classpath_order.test2.R.integer.z2_dependency_resource >= 0); + assertTrue(org.chromium.build.classpath_order.test2.R.integer.a2_master_resource >= 0); + } +} diff --git a/third_party/libwebrtc/build/config/android/test/classpath_order/java/src/org/chromium/build/classpath_order/Dummy.java.jinja2 b/third_party/libwebrtc/build/config/android/test/classpath_order/java/src/org/chromium/build/classpath_order/Dummy.java.jinja2 new file mode 100644 index 0000000000..0ccf28b284 --- /dev/null +++ b/third_party/libwebrtc/build/config/android/test/classpath_order/java/src/org/chromium/build/classpath_order/Dummy.java.jinja2 @@ -0,0 +1,8 @@ +// Copyright 2021 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.build.classpath_order; + +public class {{class_name}} { +} |