Add test case for merge tag
Bug: 38344669
Test: LayoutInflaterFactoryTestCase
Change-Id: Id1feb299ebb7d9fbe9144ecd2685c7b54aab61ac
diff --git a/appcompat/appcompat/src/androidTest/java/androidx/appcompat/app/LayoutInflaterFactoryTestCase.java b/appcompat/appcompat/src/androidTest/java/androidx/appcompat/app/LayoutInflaterFactoryTestCase.java
index 15d4194..8b17ada 100644
--- a/appcompat/appcompat/src/androidTest/java/androidx/appcompat/app/LayoutInflaterFactoryTestCase.java
+++ b/appcompat/appcompat/src/androidTest/java/androidx/appcompat/app/LayoutInflaterFactoryTestCase.java
@@ -43,7 +43,6 @@
import androidx.test.annotation.UiThreadTest;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
-import androidx.test.rule.ActivityTestRule;
import org.junit.Before;
import org.junit.Rule;
@@ -52,9 +51,11 @@
@RunWith(AndroidJUnit4.class)
public class LayoutInflaterFactoryTestCase {
+
+ @SuppressWarnings("deprecation")
@Rule
- public final ActivityTestRule<LayoutInflaterFactoryTestActivity> mActivityTestRule =
- new ActivityTestRule<>(LayoutInflaterFactoryTestActivity.class);
+ public final androidx.test.rule.ActivityTestRule<LayoutInflaterFactoryTestActivity> mTestRule =
+ new androidx.test.rule.ActivityTestRule<>(LayoutInflaterFactoryTestActivity.class);
@Before
public void setup() {
@@ -66,7 +67,7 @@
@Test
@SmallTest
public void testAndroidThemeInflation() {
- final LayoutInflater inflater = LayoutInflater.from(mActivityTestRule.getActivity());
+ final LayoutInflater inflater = LayoutInflater.from(mTestRule.getActivity());
assertThemedContext(inflater.inflate(R.layout.layout_android_theme, null));
}
@@ -74,7 +75,7 @@
@Test
@SmallTest
public void testAppThemeInflation() {
- final LayoutInflater inflater = LayoutInflater.from(mActivityTestRule.getActivity());
+ final LayoutInflater inflater = LayoutInflater.from(mTestRule.getActivity());
assertThemedContext(inflater.inflate(R.layout.layout_app_theme, null));
}
@@ -83,7 +84,7 @@
@Test
@SmallTest
public void testAndroidThemeWithChildrenInflation() {
- LayoutInflater inflater = LayoutInflater.from(mActivityTestRule.getActivity());
+ LayoutInflater inflater = LayoutInflater.from(mTestRule.getActivity());
final ViewGroup root = (ViewGroup) inflater.inflate(
R.layout.layout_android_theme_children, null);
assertThemedContext(root);
@@ -93,7 +94,7 @@
@Test
@SmallTest
public void testAndroidThemeWithIncludeInflation() {
- LayoutInflater inflater = LayoutInflater.from(mActivityTestRule.getActivity());
+ LayoutInflater inflater = LayoutInflater.from(mTestRule.getActivity());
final ViewGroup root = (ViewGroup) inflater.inflate(
R.layout.layout_android_theme_with_include, null);
assertThemedContext(root.findViewById(R.id.included_view));
@@ -102,8 +103,19 @@
@UiThreadTest
@Test
@SmallTest
+ public void testAndroidThemeWithMergeInflation() {
+ LayoutInflater inflater = LayoutInflater.from(mTestRule.getActivity());
+ final ViewGroup root = (ViewGroup) inflater.inflate(
+ R.layout.layout_android_theme_with_merge, null);
+ assertThemedContext(root.findViewById(R.id.merged_view));
+ assertThemedContext(root.findViewById(R.id.merged_view_2));
+ }
+
+ @UiThreadTest
+ @Test
+ @SmallTest
public void testThemedInflationWithUnattachedParent() {
- final Context activity = mActivityTestRule.getActivity();
+ final Context activity = mTestRule.getActivity();
// Create a parent but not attached
final LinearLayout parent = new LinearLayout(activity);
@@ -205,15 +217,15 @@
@Test
@SmallTest
public void testDeclarativeOnClickWithContextWrapper() {
- LayoutInflater inflater = LayoutInflater.from(mActivityTestRule.getActivity());
+ LayoutInflater inflater = LayoutInflater.from(mTestRule.getActivity());
View view = inflater.inflate(R.layout.layout_button_themed_onclick, null);
assertTrue(view.performClick());
- assertTrue(mActivityTestRule.getActivity().wasDeclarativeOnClickCalled());
+ assertTrue(mTestRule.getActivity().wasDeclarativeOnClickCalled());
}
private void verifyAppCompatWidgetInflation(final int layout, final Class<?> expectedClass) {
- LayoutInflater inflater = LayoutInflater.from(mActivityTestRule.getActivity());
+ LayoutInflater inflater = LayoutInflater.from(mTestRule.getActivity());
View view = inflater.inflate(layout, null);
assertSame("View is " + expectedClass.getSimpleName(), expectedClass,
view.getClass());
diff --git a/appcompat/appcompat/src/androidTest/res/layout/layout_android_theme_merged_views.xml b/appcompat/appcompat/src/androidTest/res/layout/layout_android_theme_merged_views.xml
new file mode 100644
index 0000000..37c5c1e
--- /dev/null
+++ b/appcompat/appcompat/src/androidTest/res/layout/layout_android_theme_merged_views.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2021 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<merge xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <TextView
+ android:id="@+id/merged_view"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Test" />
+
+ <TextView
+ android:id="@+id/merged_view_2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Test 2" />
+
+</merge>
\ No newline at end of file
diff --git a/appcompat/appcompat/src/androidTest/res/layout/layout_android_theme_with_merge.xml b/appcompat/appcompat/src/androidTest/res/layout/layout_android_theme_with_merge.xml
new file mode 100644
index 0000000..c9d3511
--- /dev/null
+++ b/appcompat/appcompat/src/androidTest/res/layout/layout_android_theme_with_merge.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2021 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:theme="@style/MagentaThemeOverlay">
+
+ <include layout="@layout/layout_android_theme_merged_views"
+ android:id="@+id/included_view" />
+
+</FrameLayout>
\ No newline at end of file