GlifLayoutTest.java revision fce4cf6161b2a1644ad21034f0afe4087d659ab4
1/* 2 * Copyright (C) 2015 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 android.content.Context; 20import android.test.InstrumentationTestCase; 21import android.test.suitebuilder.annotation.SmallTest; 22import android.view.ContextThemeWrapper; 23import android.view.LayoutInflater; 24import android.view.View; 25import android.widget.ScrollView; 26import android.widget.TextView; 27 28import com.android.setupwizardlib.GlifLayout; 29 30public class GlifLayoutTest extends InstrumentationTestCase { 31 32 private Context mContext; 33 34 @Override 35 protected void setUp() throws Exception { 36 super.setUp(); 37 mContext = new ContextThemeWrapper(getInstrumentation().getContext(), 38 R.style.SuwThemeGlif_Light); 39 } 40 41 @SmallTest 42 public void testDefaultTemplate() { 43 GlifLayout layout = new GlifLayout(mContext); 44 assertDefaultTemplateInflated(layout); 45 } 46 47 @SmallTest 48 public void testSetHeaderText() { 49 GlifLayout layout = new GlifLayout(mContext); 50 TextView title = (TextView) layout.findViewById(R.id.suw_layout_title); 51 layout.setHeaderText("Abracadabra"); 52 assertEquals("Header text should be \"Abracadabra\"", "Abracadabra", title.getText()); 53 } 54 55 @SmallTest 56 public void testAddView() { 57 GlifLayout layout = new GlifLayout(mContext); 58 TextView tv = new TextView(mContext); 59 tv.setId(R.id.test_view_id); 60 layout.addView(tv); 61 assertDefaultTemplateInflated(layout); 62 View view = layout.findViewById(R.id.test_view_id); 63 assertSame("The view added should be the same text view", tv, view); 64 } 65 66 @SmallTest 67 public void testInflateFromXml() { 68 LayoutInflater inflater = LayoutInflater.from(mContext); 69 GlifLayout layout = (GlifLayout) inflater.inflate(R.layout.test_glif_layout, null); 70 assertDefaultTemplateInflated(layout); 71 View content = layout.findViewById(R.id.test_content); 72 assertTrue("@id/test_content should be a TextView", content instanceof TextView); 73 } 74 75 @SmallTest 76 public void testGetScrollView() { 77 GlifLayout layout = new GlifLayout(mContext); 78 assertNotNull("Get scroll view should not be null with default template", 79 layout.getScrollView()); 80 } 81 82 private void assertDefaultTemplateInflated(GlifLayout layout) { 83 View title = layout.findViewById(R.id.suw_layout_title); 84 assertNotNull("@id/suw_layout_title should not be null", title); 85 86 View icon = layout.findViewById(R.id.suw_layout_icon); 87 assertNotNull("@id/suw_layout_icon should not be null", icon); 88 89 View scrollView = layout.findViewById(R.id.suw_scroll_view); 90 assertTrue("@id/suw_scroll_view should be a ScrollView", scrollView instanceof ScrollView); 91 } 92} 93