• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 
17 package android.view.cts;
18 
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertSame;
21 import static org.junit.Assert.assertTrue;
22 
23 import android.graphics.Canvas;
24 import android.graphics.Point;
25 import android.view.View.DragShadowBuilder;
26 
27 import androidx.test.ext.junit.runners.AndroidJUnit4;
28 import androidx.test.filters.MediumTest;
29 import androidx.test.rule.ActivityTestRule;
30 
31 import org.junit.Before;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 
36 /**
37  * Test {@link DragShadowBuilder}.
38  */
39 @MediumTest
40 @RunWith(AndroidJUnit4.class)
41 public class View_DragShadowBuilderTest {
42     private DragShadowBuilder mBuilder;
43     private MockView mView;
44 
45     @Rule
46     public ActivityTestRule<CtsActivity> mActivityRule =
47             new ActivityTestRule<>(CtsActivity.class);
48 
49     @Before
setup()50     public void setup() {
51         mView = new MockView(mActivityRule.getActivity());
52         mBuilder = new DragShadowBuilder(mView);
53     }
54 
55     @Test
testConstructor()56     public void testConstructor() {
57         new DragShadowBuilder(mView);
58 
59         new DragShadowBuilder();
60     }
61 
62     @Test
testGetView()63     public void testGetView() {
64         assertSame(mView, mBuilder.getView());
65     }
66 
67     @Test
testOnProvideShadowMetrics()68     public void testOnProvideShadowMetrics() {
69         Point outShadowSize = new Point();
70         Point outShadowTouchPoint = new Point();
71 
72         mView.setLeftTopRightBottom(0, 0, 50, 50);
73         mBuilder.onProvideShadowMetrics(outShadowSize, outShadowTouchPoint);
74 
75         assertEquals(mView.getWidth(), outShadowSize.x);
76         assertEquals(mView.getHeight(), outShadowSize.y);
77 
78         assertEquals(outShadowSize.x / 2, outShadowTouchPoint.x);
79         assertEquals(outShadowSize.y / 2, outShadowTouchPoint.y);
80     }
81 
82     @Test
testOnDrawShadow()83     public void testOnDrawShadow() {
84         Canvas canvas = new Canvas();
85         mBuilder.onDrawShadow(canvas);
86 
87         assertTrue(mView.hasCalledOnDraw());
88     }
89 }
90