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 */ 16package android.uirendering.cts.testclasses; 17 18import static org.junit.Assume.assumeNotNull; 19 20import android.content.res.TypedArray; 21import android.graphics.Bitmap; 22import android.graphics.Canvas; 23import android.graphics.Color; 24import android.graphics.drawable.Drawable; 25import android.support.test.filters.MediumTest; 26import android.support.test.runner.AndroidJUnit4; 27import android.uirendering.cts.R; 28import android.uirendering.cts.bitmapcomparers.MSSIMComparer; 29import android.uirendering.cts.bitmapverifiers.GoldenImageVerifier; 30import android.uirendering.cts.testinfrastructure.ActivityTestBase; 31 32import org.junit.Test; 33import org.junit.runner.RunWith; 34 35@MediumTest 36@RunWith(AndroidJUnit4.class) 37public class AutofillHighlightTests extends ActivityTestBase { 38 @Test 39 public void testHighlightedFrameLayout() { 40 Bitmap goldenBitmap = Bitmap.createBitmap(ActivityTestBase.TEST_WIDTH, 41 ActivityTestBase.TEST_HEIGHT, Bitmap.Config.ARGB_8888); 42 goldenBitmap.eraseColor(Color.WHITE); 43 Canvas canvas = new Canvas(goldenBitmap); 44 45 TypedArray a = getActivity().getTheme().obtainStyledAttributes( 46 new int[]{android.R.attr.autofilledHighlight}); 47 int attributeResourceId = a.getResourceId(0, 0); 48 Drawable autofilledDrawable = getActivity().getDrawable(attributeResourceId); 49 a.recycle(); 50 51 // Test does not make sense if autofill highlight is not set 52 assumeNotNull(autofilledDrawable); 53 54 autofilledDrawable.setBounds(0, 0, ActivityTestBase.TEST_WIDTH, 55 ActivityTestBase.TEST_HEIGHT); 56 autofilledDrawable.draw(canvas); 57 58 createTest().addLayout(R.layout.simple_white_layout, view -> view.setAutofilled(true)) 59 .runWithVerifier(new GoldenImageVerifier(goldenBitmap, new MSSIMComparer(0.99))); 60 } 61} 62 63