1 /*
2  * Copyright (C) 2016 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.support.design.widget;
18 
19 import static android.support.design.testutils.FloatingActionButtonActions.setBackgroundTintColor;
20 import static android.support.design.testutils.FloatingActionButtonActions.setImageResource;
21 import static android.support.design.testutils.FloatingActionButtonActions.setSize;
22 import static android.support.design.testutils.TestUtilsMatchers.withFabBackgroundFill;
23 import static android.support.design.testutils.TestUtilsMatchers.withFabContentHeight;
24 import static android.support.test.espresso.Espresso.onView;
25 import static android.support.test.espresso.assertion.ViewAssertions.matches;
26 import static android.support.test.espresso.matcher.ViewMatchers.withId;
27 
28 import android.graphics.Color;
29 import android.support.design.test.R;
30 import android.support.design.testutils.TestUtils;
31 import android.test.suitebuilder.annotation.SmallTest;
32 
33 import org.junit.Test;
34 
35 @SmallTest
36 public class FloatingActionButtonTest
37         extends BaseInstrumentationTestCase<FloatingActionButtonActivity> {
38 
FloatingActionButtonTest()39     public FloatingActionButtonTest() {
40         super(FloatingActionButtonActivity.class);
41     }
42 
43     @Test
testDefaultBackgroundTint()44     public void testDefaultBackgroundTint() {
45         final int colorAccent = TestUtils.getThemeAttrColor(
46                 mActivityTestRule.getActivity(), R.attr.colorAccent);
47         onView(withId(R.id.fab_standard))
48                 .check(matches(withFabBackgroundFill(colorAccent)));
49     }
50 
51     @Test
testSetTintOnDefaultBackgroundTint()52     public void testSetTintOnDefaultBackgroundTint() {
53         onView(withId(R.id.fab_standard))
54                 .perform(setBackgroundTintColor(Color.GREEN))
55                 .check(matches(withFabBackgroundFill(Color.GREEN)));
56     }
57 
58     @Test
testDeclaredBackgroundTint()59     public void testDeclaredBackgroundTint() {
60         onView(withId(R.id.fab_tint))
61                 .check(matches(withFabBackgroundFill(Color.MAGENTA)));
62     }
63 
64     @Test
testSetTintOnDeclaredBackgroundTint()65     public void testSetTintOnDeclaredBackgroundTint() {
66         onView(withId(R.id.fab_tint))
67                 .perform(setBackgroundTintColor(Color.GREEN))
68                 .check(matches(withFabBackgroundFill(Color.GREEN)));
69     }
70 
71     @Test
setVectorDrawableSrc()72     public void setVectorDrawableSrc() {
73         onView(withId(R.id.fab_standard))
74                 .perform(setImageResource(R.drawable.vector_icon));
75     }
76 
77     @Test
testSetMiniSize()78     public void testSetMiniSize() {
79         final int miniSize = mActivityTestRule.getActivity().getResources()
80                 .getDimensionPixelSize(R.dimen.fab_mini_height);
81 
82         onView(withId(R.id.fab_standard))
83                 .perform(setSize(FloatingActionButton.SIZE_MINI))
84                 .check(matches(withFabContentHeight(miniSize)));
85     }
86 
87     @Test
testSetSizeToggle()88     public void testSetSizeToggle() {
89         final int miniSize = mActivityTestRule.getActivity().getResources()
90                 .getDimensionPixelSize(R.dimen.fab_mini_height);
91         final int normalSize = mActivityTestRule.getActivity().getResources()
92                 .getDimensionPixelSize(R.dimen.fab_normal_height);
93 
94         onView(withId(R.id.fab_standard))
95                 .perform(setSize(FloatingActionButton.SIZE_MINI))
96                 .check(matches(withFabContentHeight(miniSize)));
97 
98         onView(withId(R.id.fab_standard))
99                 .perform(setSize(FloatingActionButton.SIZE_NORMAL))
100                 .check(matches(withFabContentHeight(normalSize)));
101     }
102 
103 }
104