1 package org.robolectric.shadows; 2 3 import static com.google.common.truth.Truth.assertThat; 4 import static org.junit.Assert.assertEquals; 5 import static org.robolectric.Shadows.shadowOf; 6 7 import android.app.Application; 8 import android.view.ViewConfiguration; 9 import androidx.test.core.app.ApplicationProvider; 10 import androidx.test.ext.junit.runners.AndroidJUnit4; 11 import org.junit.Before; 12 import org.junit.Test; 13 import org.junit.runner.RunWith; 14 15 @RunWith(AndroidJUnit4.class) 16 public class ShadowViewConfigurationTest { 17 18 private Application context; 19 20 @Before setUp()21 public void setUp() throws Exception { 22 context = ApplicationProvider.getApplicationContext(); 23 } 24 25 @Test methodsShouldReturnAndroidConstants()26 public void methodsShouldReturnAndroidConstants() { 27 ViewConfiguration viewConfiguration = ViewConfiguration.get(context); 28 29 assertEquals(10, ViewConfiguration.getScrollBarSize()); 30 assertEquals(250, ViewConfiguration.getScrollBarFadeDuration()); 31 assertEquals(300, ViewConfiguration.getScrollDefaultDelay()); 32 assertEquals(12, ViewConfiguration.getFadingEdgeLength()); 33 assertEquals(125, ViewConfiguration.getPressedStateDuration()); 34 assertEquals(500, ViewConfiguration.getLongPressTimeout()); 35 assertEquals(115, ViewConfiguration.getTapTimeout()); 36 assertEquals(500, ViewConfiguration.getJumpTapTimeout()); 37 assertEquals(300, ViewConfiguration.getDoubleTapTimeout()); 38 assertEquals(12, ViewConfiguration.getEdgeSlop()); 39 assertEquals(16, ViewConfiguration.getTouchSlop()); 40 assertEquals(16, ViewConfiguration.getWindowTouchSlop()); 41 assertEquals(50, ViewConfiguration.getMinimumFlingVelocity()); 42 assertEquals(4000, ViewConfiguration.getMaximumFlingVelocity()); 43 assertEquals(320 * 480 * 4, ViewConfiguration.getMaximumDrawingCacheSize()); 44 assertEquals(3000, ViewConfiguration.getZoomControlsTimeout()); 45 assertEquals(500, ViewConfiguration.getGlobalActionKeyTimeout()); 46 assertThat(ViewConfiguration.getScrollFriction()).isEqualTo(0.015f); 47 48 assertThat(context.getResources().getDisplayMetrics().density).isEqualTo(1f); 49 50 assertEquals(10, viewConfiguration.getScaledScrollBarSize()); 51 assertEquals(12, viewConfiguration.getScaledFadingEdgeLength()); 52 assertEquals(12, viewConfiguration.getScaledEdgeSlop()); 53 assertEquals(16, viewConfiguration.getScaledTouchSlop()); 54 assertEquals(32, viewConfiguration.getScaledPagingTouchSlop()); 55 assertEquals(100, viewConfiguration.getScaledDoubleTapSlop()); 56 assertEquals(16, viewConfiguration.getScaledWindowTouchSlop()); 57 assertEquals(50, viewConfiguration.getScaledMinimumFlingVelocity()); 58 assertEquals(4000, viewConfiguration.getScaledMaximumFlingVelocity()); 59 } 60 61 @Test methodsShouldReturnScaledAndroidConstantsDependingOnPixelDensity()62 public void methodsShouldReturnScaledAndroidConstantsDependingOnPixelDensity() { 63 context.getResources().getDisplayMetrics().density = 1.5f; 64 ViewConfiguration viewConfiguration = ViewConfiguration.get(context); 65 66 assertEquals(15, viewConfiguration.getScaledScrollBarSize()); 67 assertEquals(18, viewConfiguration.getScaledFadingEdgeLength()); 68 assertEquals(18, viewConfiguration.getScaledEdgeSlop()); 69 assertEquals(24, viewConfiguration.getScaledTouchSlop()); 70 assertEquals(48, viewConfiguration.getScaledPagingTouchSlop()); 71 assertEquals(150, viewConfiguration.getScaledDoubleTapSlop()); 72 assertEquals(24, viewConfiguration.getScaledWindowTouchSlop()); 73 assertEquals(75, viewConfiguration.getScaledMinimumFlingVelocity()); 74 assertEquals(6000, viewConfiguration.getScaledMaximumFlingVelocity()); 75 } 76 77 @Test testHasPermanentMenuKey()78 public void testHasPermanentMenuKey() throws Exception { 79 ViewConfiguration viewConfiguration = ViewConfiguration.get(context); 80 assertThat(viewConfiguration.hasPermanentMenuKey()).isFalse(); 81 82 ShadowViewConfiguration shadowViewConfiguration = shadowOf(viewConfiguration); 83 shadowViewConfiguration.setHasPermanentMenuKey(true); 84 assertThat(viewConfiguration.hasPermanentMenuKey()).isTrue(); 85 } 86 } 87