summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/build/config/android/test
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/libwebrtc/build/config/android/test')
-rw-r--r--third_party/libwebrtc/build/config/android/test/classpath_order/BUILD.gn111
-rw-r--r--third_party/libwebrtc/build/config/android/test/classpath_order/java/res_template/values/values.xml9
-rw-r--r--third_party/libwebrtc/build/config/android/test/classpath_order/java/src/org/chromium/build/classpath_order/ClassPathOrderTest.java32
-rw-r--r--third_party/libwebrtc/build/config/android/test/classpath_order/java/src/org/chromium/build/classpath_order/Dummy.java.jinja28
-rw-r--r--third_party/libwebrtc/build/config/android/test/proto/BUILD.gn103
-rw-r--r--third_party/libwebrtc/build/config/android/test/proto/absolute_dep/absolute_dep.proto10
-rw-r--r--third_party/libwebrtc/build/config/android/test/proto/relative_dep/relative_dep.proto10
-rw-r--r--third_party/libwebrtc/build/config/android/test/proto/root/absolute_child.proto10
-rw-r--r--third_party/libwebrtc/build/config/android/test/proto/root/absolute_root.proto18
-rw-r--r--third_party/libwebrtc/build/config/android/test/proto/root/relative_child.proto10
-rw-r--r--third_party/libwebrtc/build/config/android/test/proto/root/relative_root.proto18
-rw-r--r--third_party/libwebrtc/build/config/android/test/resource_overlay/BUILD.gn60
-rw-r--r--third_party/libwebrtc/build/config/android/test/resource_overlay/java/res_template/values/values.xml10
-rw-r--r--third_party/libwebrtc/build/config/android/test/resource_overlay/java/src/org/chromium/build/resource_overlay/ResourceOverlayTest.java49
14 files changed, 458 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}} {
+}
diff --git a/third_party/libwebrtc/build/config/android/test/proto/BUILD.gn b/third_party/libwebrtc/build/config/android/test/proto/BUILD.gn
new file mode 100644
index 0000000000..a28111a66a
--- /dev/null
+++ b/third_party/libwebrtc/build/config/android/test/proto/BUILD.gn
@@ -0,0 +1,103 @@
+# 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.
+
+import("//build/config/android/rules.gni")
+import("//third_party/protobuf/proto_library.gni")
+
+# The purpose of these targets is test that |deps| satisfies java compilation
+# dependencies, and that |import_dirs| allows us to deal with various relative
+# imports to other proto dependencies. Although we should strive to avoid using
+# |import_dirs| and relative import paths, preferring to use absolute imports
+# whenever possible. See https://crbug.com/691451. While this target is
+# primarily to test that the Java proto targets build correctly, also build the
+# C++ versions of the protos as well. There are currently some configurations of
+# Java protos that can be built but will not work for C++, see
+# https://crbug.com/1039014, so make sure we don't create any tests that would
+# violate that.
+group("test_build_protos") {
+ deps = [
+ ":absolute_root_proto",
+ ":absolute_root_proto_java",
+ ":relative_root_proto",
+ ":relative_root_proto_java",
+ ]
+}
+
+proto_java_library("absolute_root_proto_java") {
+ proto_path = "//"
+ import_dirs = [ "relative_dep/" ]
+ sources = [
+ "root/absolute_child.proto",
+ "root/absolute_root.proto",
+ ]
+ deps = [
+ ":absolute_dep_proto_java",
+ ":relative_dep_proto_java",
+ ]
+}
+
+proto_java_library("relative_root_proto_java") {
+ proto_path = "root/"
+ import_dirs = [
+ "relative_dep/",
+ "//",
+ ]
+ sources = [
+ "root/relative_child.proto",
+ "root/relative_root.proto",
+ ]
+ deps = [
+ ":absolute_dep_proto_java",
+ ":relative_dep_proto_java",
+ ]
+}
+
+proto_java_library("absolute_dep_proto_java") {
+ proto_path = "//"
+ sources = [ "absolute_dep/absolute_dep.proto" ]
+}
+
+proto_java_library("relative_dep_proto_java") {
+ proto_path = "relative_dep/"
+ sources = [ "relative_dep/relative_dep.proto" ]
+}
+
+proto_library("absolute_root_proto") {
+ proto_in_dir = "//"
+ import_dirs = [ "relative_dep/" ]
+ sources = [
+ "root/absolute_child.proto",
+ "root/absolute_root.proto",
+ ]
+ link_deps = [
+ ":absolute_dep_proto",
+ ":relative_dep_proto",
+ ]
+}
+
+proto_library("relative_root_proto") {
+ proto_in_dir = "root/"
+ import_dirs = [
+ "relative_dep/",
+ "//",
+ ]
+ sources = [
+ "root/relative_child.proto",
+ "root/relative_root.proto",
+ ]
+ link_deps = [
+ ":absolute_dep_proto",
+ ":relative_dep_proto",
+ ]
+}
+
+proto_library("absolute_dep_proto") {
+ proto_in_dir = "//"
+ sources = [ "absolute_dep/absolute_dep.proto" ]
+}
+
+proto_library("relative_dep_proto") {
+ proto_in_dir = "relative_dep/"
+ sources = [ "relative_dep/relative_dep.proto" ]
+}
diff --git a/third_party/libwebrtc/build/config/android/test/proto/absolute_dep/absolute_dep.proto b/third_party/libwebrtc/build/config/android/test/proto/absolute_dep/absolute_dep.proto
new file mode 100644
index 0000000000..46dcce7679
--- /dev/null
+++ b/third_party/libwebrtc/build/config/android/test/proto/absolute_dep/absolute_dep.proto
@@ -0,0 +1,10 @@
+// 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.
+
+syntax = "proto2";
+
+package build.config.android.test;
+option java_package = "build.config.android.test";
+
+message AbsoluteDep {}
diff --git a/third_party/libwebrtc/build/config/android/test/proto/relative_dep/relative_dep.proto b/third_party/libwebrtc/build/config/android/test/proto/relative_dep/relative_dep.proto
new file mode 100644
index 0000000000..600b6ca7fe
--- /dev/null
+++ b/third_party/libwebrtc/build/config/android/test/proto/relative_dep/relative_dep.proto
@@ -0,0 +1,10 @@
+// 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.
+
+syntax = "proto2";
+
+package build.config.android.test;
+option java_package = "build.config.android.test";
+
+message RelativeDep {}
diff --git a/third_party/libwebrtc/build/config/android/test/proto/root/absolute_child.proto b/third_party/libwebrtc/build/config/android/test/proto/root/absolute_child.proto
new file mode 100644
index 0000000000..d6a6a13f36
--- /dev/null
+++ b/third_party/libwebrtc/build/config/android/test/proto/root/absolute_child.proto
@@ -0,0 +1,10 @@
+// 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.
+
+syntax = "proto2";
+
+package build.config.android.test;
+option java_package = "build.config.android.test";
+
+message AbsoluteChild {}
diff --git a/third_party/libwebrtc/build/config/android/test/proto/root/absolute_root.proto b/third_party/libwebrtc/build/config/android/test/proto/root/absolute_root.proto
new file mode 100644
index 0000000000..3e200978d9
--- /dev/null
+++ b/third_party/libwebrtc/build/config/android/test/proto/root/absolute_root.proto
@@ -0,0 +1,18 @@
+// 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.
+
+syntax = "proto2";
+
+package build.config.android.test;
+option java_package = "build.config.android.test";
+
+import "build/config/android/test/proto/root/absolute_child.proto";
+import "build/config/android/test/proto/absolute_dep/absolute_dep.proto";
+import "relative_dep.proto";
+
+message AbsoluteRoot {
+ optional AbsoluteChild absolute_child = 1;
+ optional AbsoluteDep absolute_dep = 2;
+ optional RelativeDep relative_dep = 3;
+}
diff --git a/third_party/libwebrtc/build/config/android/test/proto/root/relative_child.proto b/third_party/libwebrtc/build/config/android/test/proto/root/relative_child.proto
new file mode 100644
index 0000000000..10f7ed4277
--- /dev/null
+++ b/third_party/libwebrtc/build/config/android/test/proto/root/relative_child.proto
@@ -0,0 +1,10 @@
+// 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.
+
+syntax = "proto2";
+
+package build.config.android.test;
+option java_package = "build.config.android.test";
+
+message RelativeChild {}
diff --git a/third_party/libwebrtc/build/config/android/test/proto/root/relative_root.proto b/third_party/libwebrtc/build/config/android/test/proto/root/relative_root.proto
new file mode 100644
index 0000000000..a37a268b4f
--- /dev/null
+++ b/third_party/libwebrtc/build/config/android/test/proto/root/relative_root.proto
@@ -0,0 +1,18 @@
+// 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.
+
+syntax = "proto2";
+
+package build.config.android.test;
+option java_package = "build.config.android.test";
+
+import "relative_child.proto";
+import "build/config/android/test/proto/absolute_dep/absolute_dep.proto";
+import "relative_dep.proto";
+
+message RelativeRoot {
+ optional RelativeChild relative_child = 1;
+ optional AbsoluteDep absolute_dep = 2;
+ optional RelativeDep relative_dep = 3;
+}
diff --git a/third_party/libwebrtc/build/config/android/test/resource_overlay/BUILD.gn b/third_party/libwebrtc/build/config/android/test/resource_overlay/BUILD.gn
new file mode 100644
index 0000000000..4a063d2215
--- /dev/null
+++ b/third_party/libwebrtc/build/config/android/test/resource_overlay/BUILD.gn
@@ -0,0 +1,60 @@
+# 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.
+
+import("//build/config/android/rules.gni")
+
+# Tests for 'resource_overlay' parameter in android_resources() template.
+
+template("test_resources") {
+ jinja_template_resources(target_name) {
+ forward_variables_from(invoker, "*")
+ testonly = true
+ variables = [
+ "resource_name=$resource_name",
+ "resource_value=$resource_value",
+ ]
+ res_dir = "java/res_template"
+ resources = [ "java/res_template/values/values.xml" ]
+ }
+}
+
+test_resources("dependency_tagged_dependency_resources") {
+ resource_overlay = true
+ resource_name = "resource_overlay_dependency_tagged_secret"
+ resource_value = 41
+}
+
+test_resources("dependency_tagged_root_resources") {
+ resource_name = "resource_overlay_dependency_tagged_secret"
+ resource_value = 42
+ deps = [ ":dependency_tagged_dependency_resources" ]
+}
+
+test_resources("root_tagged_dependency_resources") {
+ resource_name = "resource_overlay_root_tagged_secret"
+ resource_value = 41
+}
+
+test_resources("root_tagged_root_resources") {
+ resource_overlay = true
+ resource_name = "resource_overlay_root_tagged_secret"
+ resource_value = 42
+ deps = [ ":root_tagged_dependency_resources" ]
+}
+
+android_library("javatests") {
+ testonly = true
+ sources = [
+ "java/src/org/chromium/build/resource_overlay/ResourceOverlayTest.java",
+ ]
+ resources_package = "org.chromium.build.resource_overlay"
+ deps = [
+ ":dependency_tagged_root_resources",
+ ":root_tagged_root_resources",
+ "//base:base_java_test_support",
+ "//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/resource_overlay/java/res_template/values/values.xml b/third_party/libwebrtc/build/config/android/test/resource_overlay/java/res_template/values/values.xml
new file mode 100644
index 0000000000..973f855206
--- /dev/null
+++ b/third_party/libwebrtc/build/config/android/test/resource_overlay/java/res_template/values/values.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+ <integer name="{{resource_name}}">{{resource_value}}</integer>
+</resources> \ No newline at end of file
diff --git a/third_party/libwebrtc/build/config/android/test/resource_overlay/java/src/org/chromium/build/resource_overlay/ResourceOverlayTest.java b/third_party/libwebrtc/build/config/android/test/resource_overlay/java/src/org/chromium/build/resource_overlay/ResourceOverlayTest.java
new file mode 100644
index 0000000000..794cafac53
--- /dev/null
+++ b/third_party/libwebrtc/build/config/android/test/resource_overlay/java/src/org/chromium/build/resource_overlay/ResourceOverlayTest.java
@@ -0,0 +1,49 @@
+// 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.build.resource_overlay;
+
+import static org.junit.Assert.assertEquals;
+
+import android.content.res.Resources;
+import android.support.test.InstrumentationRegistry;
+
+import androidx.test.filters.SmallTest;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.chromium.base.test.BaseJUnit4ClassRunner;
+import org.chromium.base.test.util.Batch;
+
+/**
+ * Test for resource_overlay parameter in android_resources() build rule.
+ */
+@RunWith(BaseJUnit4ClassRunner.class)
+@Batch(Batch.UNIT_TESTS)
+public class ResourceOverlayTest {
+ /**
+ * Test that when an android_resources() target with resource_overlay=false has a resource with
+ * the same name but a different value as a dependency with resource_overlay=true that the value
+ * of the resource in the dependency is used.
+ */
+ @Test
+ @SmallTest
+ public void testDependencyTagged() {
+ Resources resources = InstrumentationRegistry.getTargetContext().getResources();
+ assertEquals(41, resources.getInteger(R.integer.resource_overlay_dependency_tagged_secret));
+ }
+
+ /**
+ * Test that when an android_resources() target with resource_overlay=true has a resource with
+ * the same name but different value as one of its dependencies that the value of resource in
+ * the target with resource_overlay=true is used.
+ */
+ @Test
+ @SmallTest
+ public void testRootTagged() {
+ Resources resources = InstrumentationRegistry.getTargetContext().getResources();
+ assertEquals(42, resources.getInteger(R.integer.resource_overlay_root_tagged_secret));
+ }
+}