summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/build/config/android/test/resource_overlay
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/libwebrtc/build/config/android/test/resource_overlay')
-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
3 files changed, 119 insertions, 0 deletions
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));
+ }
+}