|
| 1 | +package io.flutter.embedding.engine.mutatorsstack; |
| 2 | + |
| 3 | +import static junit.framework.TestCase.*; |
| 4 | +import static org.mockito.Mockito.*; |
| 5 | + |
| 6 | +import android.graphics.Matrix; |
| 7 | +import android.view.MotionEvent; |
| 8 | +import io.flutter.embedding.android.AndroidTouchProcessor; |
| 9 | +import org.junit.Test; |
| 10 | +import org.junit.runner.RunWith; |
| 11 | +import org.mockito.ArgumentCaptor; |
| 12 | +import org.robolectric.RobolectricTestRunner; |
| 13 | +import org.robolectric.RuntimeEnvironment; |
| 14 | +import org.robolectric.annotation.Config; |
| 15 | + |
| 16 | +@Config(manifest = Config.NONE) |
| 17 | +@RunWith(RobolectricTestRunner.class) |
| 18 | +public class FlutterMutatorViewTest { |
| 19 | + |
| 20 | + @Test |
| 21 | + public void canDragViews() { |
| 22 | + final AndroidTouchProcessor touchProcessor = mock(AndroidTouchProcessor.class); |
| 23 | + final FlutterMutatorView view = |
| 24 | + new FlutterMutatorView(RuntimeEnvironment.systemContext, 1.0f, touchProcessor); |
| 25 | + final FlutterMutatorsStack mutatorStack = mock(FlutterMutatorsStack.class); |
| 26 | + |
| 27 | + assertTrue(view.onInterceptTouchEvent(mock(MotionEvent.class))); |
| 28 | + |
| 29 | + { |
| 30 | + view.readyToDisplay(mutatorStack, /*left=*/ 1, /*top=*/ 2, /*width=*/ 0, /*height=*/ 0); |
| 31 | + view.onTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0.0f, 0.0f, 0)); |
| 32 | + final ArgumentCaptor<Matrix> matrixCaptor = ArgumentCaptor.forClass(Matrix.class); |
| 33 | + verify(touchProcessor).onTouchEvent(any(), matrixCaptor.capture()); |
| 34 | + |
| 35 | + final Matrix screenMatrix = new Matrix(); |
| 36 | + screenMatrix.postTranslate(1, 2); |
| 37 | + assertTrue(matrixCaptor.getValue().equals(screenMatrix)); |
| 38 | + } |
| 39 | + |
| 40 | + reset(touchProcessor); |
| 41 | + |
| 42 | + { |
| 43 | + view.readyToDisplay(mutatorStack, /*left=*/ 3, /*top=*/ 4, /*width=*/ 0, /*height=*/ 0); |
| 44 | + view.onTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0.0f, 0.0f, 0)); |
| 45 | + final ArgumentCaptor<Matrix> matrixCaptor = ArgumentCaptor.forClass(Matrix.class); |
| 46 | + verify(touchProcessor).onTouchEvent(any(), matrixCaptor.capture()); |
| 47 | + |
| 48 | + final Matrix screenMatrix = new Matrix(); |
| 49 | + screenMatrix.postTranslate(1, 2); |
| 50 | + assertTrue(matrixCaptor.getValue().equals(screenMatrix)); |
| 51 | + } |
| 52 | + |
| 53 | + reset(touchProcessor); |
| 54 | + |
| 55 | + { |
| 56 | + view.readyToDisplay(mutatorStack, /*left=*/ 5, /*top=*/ 6, /*width=*/ 0, /*height=*/ 0); |
| 57 | + view.onTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0.0f, 0.0f, 0)); |
| 58 | + final ArgumentCaptor<Matrix> matrixCaptor = ArgumentCaptor.forClass(Matrix.class); |
| 59 | + verify(touchProcessor).onTouchEvent(any(), matrixCaptor.capture()); |
| 60 | + |
| 61 | + final Matrix screenMatrix = new Matrix(); |
| 62 | + screenMatrix.postTranslate(3, 4); |
| 63 | + assertTrue(matrixCaptor.getValue().equals(screenMatrix)); |
| 64 | + } |
| 65 | + |
| 66 | + reset(touchProcessor); |
| 67 | + |
| 68 | + { |
| 69 | + view.readyToDisplay(mutatorStack, /*left=*/ 7, /*top=*/ 8, /*width=*/ 0, /*height=*/ 0); |
| 70 | + view.onTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0.0f, 0.0f, 0)); |
| 71 | + final ArgumentCaptor<Matrix> matrixCaptor = ArgumentCaptor.forClass(Matrix.class); |
| 72 | + verify(touchProcessor).onTouchEvent(any(), matrixCaptor.capture()); |
| 73 | + |
| 74 | + final Matrix screenMatrix = new Matrix(); |
| 75 | + screenMatrix.postTranslate(7, 8); |
| 76 | + assertTrue(matrixCaptor.getValue().equals(screenMatrix)); |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments