1 package com.xtremelabs.robolectric.shadows; 2 3 import android.app.Activity; 4 import android.view.ViewConfiguration; 5 import com.xtremelabs.robolectric.WithTestDefaultsRunner; 6 import org.junit.Test; 7 import org.junit.runner.RunWith; 8 9 import static com.xtremelabs.robolectric.Robolectric.shadowOf; 10 import static junit.framework.Assert.assertEquals; 11 12 13 @RunWith(WithTestDefaultsRunner.class) 14 public class ViewConfigurationTest { 15 16 @Test methodsShouldReturnAndroidConstants()17 public void methodsShouldReturnAndroidConstants() { 18 Activity context = new Activity(); 19 ViewConfiguration viewConfiguration = ViewConfiguration.get(context); 20 21 assertEquals(10, ViewConfiguration.getScrollBarSize()); 22 assertEquals(250, ViewConfiguration.getScrollBarFadeDuration()); 23 assertEquals(300, ViewConfiguration.getScrollDefaultDelay()); 24 assertEquals(12, ViewConfiguration.getFadingEdgeLength()); 25 assertEquals(125, ViewConfiguration.getPressedStateDuration()); 26 assertEquals(500, ViewConfiguration.getLongPressTimeout()); 27 assertEquals(115, ViewConfiguration.getTapTimeout()); 28 assertEquals(500, ViewConfiguration.getJumpTapTimeout()); 29 assertEquals(300, ViewConfiguration.getDoubleTapTimeout()); 30 assertEquals(12, ViewConfiguration.getEdgeSlop()); 31 assertEquals(16, ViewConfiguration.getTouchSlop()); 32 assertEquals(16, ViewConfiguration.getWindowTouchSlop()); 33 assertEquals(50, ViewConfiguration.getMinimumFlingVelocity()); 34 assertEquals(4000, ViewConfiguration.getMaximumFlingVelocity()); 35 assertEquals(320 * 480 * 4, ViewConfiguration.getMaximumDrawingCacheSize()); 36 assertEquals(3000, ViewConfiguration.getZoomControlsTimeout()); 37 assertEquals(500, ViewConfiguration.getGlobalActionKeyTimeout()); 38 assertEquals(0.015f, ViewConfiguration.getScrollFriction()); 39 40 assertEquals(1f, context.getResources().getDisplayMetrics().density); 41 42 assertEquals(10, viewConfiguration.getScaledScrollBarSize()); 43 assertEquals(12, viewConfiguration.getScaledFadingEdgeLength()); 44 assertEquals(12, viewConfiguration.getScaledEdgeSlop()); 45 assertEquals(16, viewConfiguration.getScaledTouchSlop()); 46 assertEquals(32, viewConfiguration.getScaledPagingTouchSlop()); 47 assertEquals(100, viewConfiguration.getScaledDoubleTapSlop()); 48 assertEquals(16, viewConfiguration.getScaledWindowTouchSlop()); 49 assertEquals(50, viewConfiguration.getScaledMinimumFlingVelocity()); 50 assertEquals(4000, viewConfiguration.getScaledMaximumFlingVelocity()); 51 } 52 53 @Test methodsShouldReturnScaledAndroidConstantsDependingOnPixelDensity()54 public void methodsShouldReturnScaledAndroidConstantsDependingOnPixelDensity() { 55 Activity context = new Activity(); 56 shadowOf(context.getResources()).setDensity(1.5f); 57 ViewConfiguration viewConfiguration = ViewConfiguration.get(context); 58 59 assertEquals(15, viewConfiguration.getScaledScrollBarSize()); 60 assertEquals(18, viewConfiguration.getScaledFadingEdgeLength()); 61 assertEquals(18, viewConfiguration.getScaledEdgeSlop()); 62 assertEquals(24, viewConfiguration.getScaledTouchSlop()); 63 assertEquals(48, viewConfiguration.getScaledPagingTouchSlop()); 64 assertEquals(150, viewConfiguration.getScaledDoubleTapSlop()); 65 assertEquals(24, viewConfiguration.getScaledWindowTouchSlop()); 66 assertEquals(75, viewConfiguration.getScaledMinimumFlingVelocity()); 67 assertEquals(6000, viewConfiguration.getScaledMaximumFlingVelocity()); 68 } 69 70 } 71