1 /* 2 * Copyright 2014 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 package com.example.android.clippingbasic.tests; 17 18 import com.example.android.clippingbasic.*; 19 20 import android.test.ActivityInstrumentationTestCase2; 21 import android.test.TouchUtils; 22 import android.view.View; 23 24 /** 25 * Tests for ClippingBasic sample. 26 */ 27 public class SampleTests extends ActivityInstrumentationTestCase2<MainActivity> { 28 29 private MainActivity mTestActivity; 30 private ClippingBasicFragment mTestFragment; 31 32 public SampleTests() { 33 super(MainActivity.class); 34 } 35 36 @Override 37 protected void setUp() throws Exception { 38 super.setUp(); 39 40 // Starts the activity under test using the default Intent with: 41 // action = {@link Intent#ACTION_MAIN} 42 // flags = {@link Intent#FLAG_ACTIVITY_NEW_TASK} 43 // All other fields are null or empty. 44 mTestActivity = getActivity(); 45 mTestFragment = (ClippingBasicFragment) 46 mTestActivity.getSupportFragmentManager().getFragments().get(1); 47 } 48 49 /** 50 * Test if the test fixture has been set up correctly. 51 */ 52 public void testPreconditions() { 53 assertNotNull("mTestActivity is null", mTestActivity); 54 assertNotNull("mTestFragment is null", mTestFragment); 55 assertNotNull("Clipped frame is null", mTestActivity.findViewById(R.id.frame)); 56 assertNotNull("Text view is null", mTestActivity.findViewById(R.id.text_view)); 57 } 58 59 /** 60 * Triggers a click on the button and tests if the view is clipped afterwards. 61 */ 62 public void testClipping() { 63 View clippedView = mTestActivity.findViewById(R.id.frame); 64 65 // Initially, the view is not clipped. 66 assertFalse(clippedView.getClipToOutline()); 67 68 // Trigger a click on the button to activate clipping. 69 TouchUtils.clickView(this, mTestActivity.findViewById(R.id.button)); 70 71 // Check that the view has been clipped. 72 assertTrue(clippedView.getClipToOutline()); 73 } 74 }