1/* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.setupwizardlib.test; 18 19import static android.support.test.InstrumentationRegistry.getTargetContext; 20 21import static org.junit.Assert.assertNotNull; 22 23import android.content.Context; 24import android.support.test.filters.SmallTest; 25import android.view.ContextThemeWrapper; 26import android.view.LayoutInflater; 27import android.widget.FrameLayout; 28 29import com.android.setupwizardlib.R; 30import com.android.setupwizardlib.items.Item; 31 32import org.junit.Test; 33import org.junit.runner.RunWith; 34import org.junit.runners.Parameterized; 35import org.junit.runners.Parameterized.Parameters; 36 37import java.util.ArrayList; 38import java.util.List; 39 40/** 41 * Sanity test for all the item layouts to make sure they won't crash when being inflated in 42 * different themes. 43 */ 44@RunWith(Parameterized.class) 45@SmallTest 46public class ItemLayoutTest { 47 48 @Parameters 49 public static Iterable<Object[]> data() { 50 int[] themes = new int[] { 51 R.style.SuwThemeMaterial_Light, 52 R.style.SuwThemeMaterial, 53 R.style.SuwThemeGlif_Light, 54 R.style.SuwThemeGlif, 55 R.style.SuwThemeGlifV2_Light, 56 R.style.SuwThemeGlifV2 57 }; 58 int[] layouts = new int[] { 59 R.layout.suw_items_default, 60 R.layout.suw_items_verbose, 61 R.layout.suw_items_description 62 }; 63 64 // Test all the possible combinations of themes and layouts. 65 List<Object[]> params = new ArrayList<>(); 66 for (int theme : themes) { 67 for (int layout : layouts) { 68 params.add(new Object[] { theme, layout }); 69 } 70 } 71 return params; 72 } 73 74 private final Context mContext; 75 private final FrameLayout mParent; 76 private final Item mItem; 77 78 public ItemLayoutTest(int theme, int layout) { 79 mContext = new ContextThemeWrapper(getTargetContext(), theme); 80 mParent = new FrameLayout(mContext); 81 mItem = new Item(); 82 mItem.setLayoutResource(layout); 83 } 84 85 @Test 86 public void testInflateLayoutHasBasicViews() { 87 LayoutInflater.from(mContext).inflate(mItem.getLayoutResource(), mParent, true); 88 mItem.onBindView(mParent); 89 90 assertNotNull("Title should exist", mParent.findViewById(R.id.suw_items_title)); 91 assertNotNull("Summary should exist", mParent.findViewById(R.id.suw_items_summary)); 92 assertNotNull("Icon should exist", mParent.findViewById(R.id.suw_items_icon)); 93 } 94} 95