13f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov/* 23f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov * Copyright (C) 2017 The Android Open Source Project 33f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov * 43f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov * Licensed under the Apache License, Version 2.0 (the "License"); 53f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov * you may not use this file except in compliance with the License. 63f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov * You may obtain a copy of the License at 73f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov * 83f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov * http://www.apache.org/licenses/LICENSE-2.0 93f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov * 103f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov * Unless required by applicable law or agreed to in writing, software 113f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov * distributed under the License is distributed on an "AS IS" BASIS, 123f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 133f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov * See the License for the specific language governing permissions and 143f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov * limitations under the License. 153f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov */ 16ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikaspackage androidx.appcompat.app; 173f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 183f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikovimport static org.junit.Assert.assertEquals; 193f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 203f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikovimport android.support.test.filters.SmallTest; 213f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikovimport android.support.test.rule.ActivityTestRule; 223f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikovimport android.support.test.runner.AndroidJUnit4; 233de8a4e8305507475d7890205184946a25cf45e7Aurimas Liutikasimport android.view.ViewGroup; 243de8a4e8305507475d7890205184946a25cf45e7Aurimas Liutikasimport android.widget.ScrollView; 253de8a4e8305507475d7890205184946a25cf45e7Aurimas Liutikasimport android.widget.ToggleButton; 263de8a4e8305507475d7890205184946a25cf45e7Aurimas Liutikas 27ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.appcompat.test.R; 28ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.appcompat.testutils.BaseTestActivity; 29ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.appcompat.widget.AppCompatButton; 30ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.appcompat.widget.AppCompatImageButton; 31ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.appcompat.widget.AppCompatRadioButton; 32ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.appcompat.widget.AppCompatSpinner; 33ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.appcompat.widget.AppCompatTextView; 343f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 353f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikovimport org.junit.Before; 363f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikovimport org.junit.Rule; 373f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikovimport org.junit.Test; 383f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikovimport org.junit.runner.RunWith; 393f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 403f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov/** 413f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov * Testing the default view inflation where appcompat views are used for specific 423f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov * views in layouts specified in XML. 433f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov */ 443f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov@SmallTest 453f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov@RunWith(AndroidJUnit4.class) 463f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikovpublic abstract class AppCompatInflaterPassTest<A extends BaseTestActivity> { 473f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov private ViewGroup mContainer; 483f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov private A mActivity; 493f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 503f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov @Rule 513f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov public final ActivityTestRule<A> mActivityTestRule; 523f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 533f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov public AppCompatInflaterPassTest(Class clazz) { 543f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov mActivityTestRule = new ActivityTestRule<A>(clazz); 553f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov } 563f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 573f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov @Before 583f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov public void setUp() { 593f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov mActivity = mActivityTestRule.getActivity(); 603f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov mContainer = mActivity.findViewById(R.id.container); 613f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov } 623f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 633f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov @Test 643f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov public void testViewClasses() { 653f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov // View defined as <Button> should be inflated as AppCompatButton 663f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov assertEquals(AppCompatButton.class, mContainer.findViewById(R.id.button).getClass()); 673f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 683f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov // View defined as <AppCompatButton> should be inflated as AppCompatButton 693f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov assertEquals(AppCompatButton.class, mContainer.findViewById(R.id.ac_button).getClass()); 703f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 713f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov // View defined as <TextView> should be inflated as AppCompatTextView 723f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov assertEquals(AppCompatTextView.class, mContainer.findViewById(R.id.textview).getClass()); 733f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 743f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov // View defined as <AppCompatTextView> should be inflated as AppCompatTextView 753f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov assertEquals(AppCompatTextView.class, mContainer.findViewById(R.id.ac_textview).getClass()); 763f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 773f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov // View defined as <RadioButton> should be inflated as AppCompatRadioButton 783f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov assertEquals(AppCompatRadioButton.class, 793f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov mContainer.findViewById(R.id.radiobutton).getClass()); 803f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 813f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov // View defined as <ImageButton> should be inflated as AppCompatImageButton 823f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov assertEquals(AppCompatImageButton.class, 833f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov mContainer.findViewById(R.id.imagebutton).getClass()); 843f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 853f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov // View defined as <Spinner> should be inflated as AppCompatSpinner 863f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov assertEquals(AppCompatSpinner.class, mContainer.findViewById(R.id.spinner).getClass()); 873f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 883f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov // View defined as <ToggleButton> should be inflated as ToggleButton 893f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov assertEquals(ToggleButton.class, 903f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov mContainer.findViewById(R.id.togglebutton).getClass()); 913f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 923f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov // View defined as <ScrollView> should be inflated as ScrollView 933f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov assertEquals(ScrollView.class, 943f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov mContainer.findViewById(R.id.scrollview).getClass()); 953f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov } 963f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov 973f27daae519adbed30f080624f3ff0f2b68e5b27Kirill Grouchnikov} 98