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 */ 16package android.uirendering.cts.testclasses; 17 18import android.graphics.Color; 19import android.graphics.Point; 20import android.support.test.filters.MediumTest; 21import android.support.test.runner.AndroidJUnit4; 22import android.uirendering.cts.R; 23import android.uirendering.cts.bitmapverifiers.SamplePointVerifier; 24import android.uirendering.cts.testinfrastructure.ActivityTestBase; 25import android.uirendering.cts.util.CompareUtils; 26 27import org.junit.Test; 28import org.junit.runner.RunWith; 29 30@MediumTest 31@RunWith(AndroidJUnit4.class) 32public class ShadowTests extends ActivityTestBase { 33 34 private class GrayScaleVerifier extends SamplePointVerifier { 35 public GrayScaleVerifier(Point[] testPoints, int[] expectedColors, int tolerance) { 36 super(testPoints, expectedColors, tolerance) ; 37 } 38 39 @Override 40 protected boolean verifyPixel(int color, int expectedColor) { 41 return super.verifyPixel(color, expectedColor) 42 && CompareUtils.verifyPixelGrayScale(color, 1); 43 } 44 } 45 46 @Test 47 public void testShadowLayout() { 48 int shadowColorValue = 0xDB; 49 // Android TV theme overrides shadow opacity to be darker. 50 if (getActivity().getOnTv()) { 51 shadowColorValue = 0xBB; 52 } 53 54 // Use a higher threshold than default value (20), since we also double check gray scale; 55 GrayScaleVerifier verifier = new GrayScaleVerifier( 56 new Point[] { 57 // view area 58 new Point(25, 64), 59 new Point(64, 64), 60 // shadow area 61 new Point(25, 65), 62 new Point(64, 65) 63 }, 64 new int[] { 65 Color.WHITE, 66 Color.WHITE, 67 Color.rgb(shadowColorValue, shadowColorValue, shadowColorValue), 68 Color.rgb(shadowColorValue, shadowColorValue, shadowColorValue), 69 }, 70 64); 71 72 createTest() 73 .addLayout(R.layout.simple_shadow_layout, null, true/* HW only */) 74 .runWithVerifier(verifier); 75 } 76} 77