|
1 | 1 | package io.flutter.plugin.platform;
|
2 | 2 |
|
| 3 | +import static io.flutter.embedding.engine.systemchannels.PlatformViewsChannel.PlatformViewTouch; |
| 4 | +import static org.junit.Assert.assertEquals; |
| 5 | +import static org.junit.Assert.assertNotEquals; |
3 | 6 | import static org.mockito.Matchers.eq;
|
4 | 7 | import static org.mockito.Mockito.mock;
|
5 | 8 | import static org.mockito.Mockito.never;
|
6 | 9 | import static org.mockito.Mockito.times;
|
7 | 10 | import static org.mockito.Mockito.verify;
|
8 | 11 |
|
| 12 | +import android.view.MotionEvent; |
9 | 13 | import android.view.View;
|
| 14 | +import io.flutter.embedding.android.MotionEventTracker; |
| 15 | +import java.util.Collections; |
10 | 16 | import org.junit.Test;
|
11 | 17 | import org.junit.runner.RunWith;
|
12 | 18 | import org.robolectric.RobolectricTestRunner;
|
@@ -79,4 +85,100 @@ public void itCancelsOldPresentationOnResize() {
|
79 | 85 | assertEquals(fakeVdController1.presentation != presentation, true);
|
80 | 86 | assertEquals(presentation.isShowing(), false);
|
81 | 87 | }
|
| 88 | + |
| 89 | + @Test |
| 90 | + public void itUsesActionEventTypeFromFrameworkEventForVirtualDisplays() { |
| 91 | + MotionEventTracker motionEventTracker = MotionEventTracker.getInstance(); |
| 92 | + PlatformViewsController platformViewsController = new PlatformViewsController(); |
| 93 | + |
| 94 | + MotionEvent original = |
| 95 | + MotionEvent.obtain( |
| 96 | + 100, // downTime |
| 97 | + 100, // eventTime |
| 98 | + 1, // action |
| 99 | + 0, // x |
| 100 | + 0, // y |
| 101 | + 0 // metaState |
| 102 | + ); |
| 103 | + |
| 104 | + // track an event that will later get passed to us from framework |
| 105 | + MotionEventTracker.MotionEventId motionEventId = motionEventTracker.track(original); |
| 106 | + |
| 107 | + PlatformViewTouch frameWorkTouch = |
| 108 | + new PlatformViewTouch( |
| 109 | + 0, // viewId |
| 110 | + original.getDownTime(), |
| 111 | + original.getEventTime(), |
| 112 | + 2, // action |
| 113 | + 0, // pointerCount |
| 114 | + Collections.emptyList(), |
| 115 | + Collections.emptyList(), |
| 116 | + original.getMetaState(), |
| 117 | + original.getButtonState(), |
| 118 | + original.getXPrecision(), |
| 119 | + original.getYPrecision(), |
| 120 | + original.getDeviceId(), |
| 121 | + original.getEdgeFlags(), |
| 122 | + original.getSource(), |
| 123 | + original.getFlags(), |
| 124 | + motionEventId.getId()); |
| 125 | + |
| 126 | + MotionEvent resolvedEvent = |
| 127 | + platformViewsController.toMotionEvent( |
| 128 | + 1, // density |
| 129 | + frameWorkTouch, |
| 130 | + true // usingVirtualDisplays |
| 131 | + ); |
| 132 | + |
| 133 | + assertEquals(resolvedEvent.getAction(), frameWorkTouch.action); |
| 134 | + assertNotEquals(resolvedEvent.getAction(), original.getAction()); |
| 135 | + } |
| 136 | + |
| 137 | + @Test |
| 138 | + public void itUsesActionEventTypeFromMotionEventForHybridPlatformViews() { |
| 139 | + MotionEventTracker motionEventTracker = MotionEventTracker.getInstance(); |
| 140 | + PlatformViewsController platformViewsController = new PlatformViewsController(); |
| 141 | + |
| 142 | + MotionEvent original = |
| 143 | + MotionEvent.obtain( |
| 144 | + 100, // downTime |
| 145 | + 100, // eventTime |
| 146 | + 1, // action |
| 147 | + 0, // x |
| 148 | + 0, // y |
| 149 | + 0 // metaState |
| 150 | + ); |
| 151 | + |
| 152 | + // track an event that will later get passed to us from framework |
| 153 | + MotionEventTracker.MotionEventId motionEventId = motionEventTracker.track(original); |
| 154 | + |
| 155 | + PlatformViewTouch frameWorkTouch = |
| 156 | + new PlatformViewTouch( |
| 157 | + 0, // viewId |
| 158 | + original.getDownTime(), |
| 159 | + original.getEventTime(), |
| 160 | + 2, // action |
| 161 | + 0, // pointerCount |
| 162 | + Collections.emptyList(), |
| 163 | + Collections.emptyList(), |
| 164 | + original.getMetaState(), |
| 165 | + original.getButtonState(), |
| 166 | + original.getXPrecision(), |
| 167 | + original.getYPrecision(), |
| 168 | + original.getDeviceId(), |
| 169 | + original.getEdgeFlags(), |
| 170 | + original.getSource(), |
| 171 | + original.getFlags(), |
| 172 | + motionEventId.getId()); |
| 173 | + |
| 174 | + MotionEvent resolvedEvent = |
| 175 | + platformViewsController.toMotionEvent( |
| 176 | + 1, // density |
| 177 | + frameWorkTouch, |
| 178 | + false // usingVirtualDisplays |
| 179 | + ); |
| 180 | + |
| 181 | + assertNotEquals(resolvedEvent.getAction(), frameWorkTouch.action); |
| 182 | + assertEquals(resolvedEvent.getAction(), original.getAction()); |
| 183 | + } |
82 | 184 | }
|
0 commit comments