1package io.flutter.embedding.engine.mutatorsstack;
3import static android.view.View.OnFocusChangeListener;
4import static junit.framework.TestCase.*;
5import static org.mockito.Mockito.*;
12import android.view.ViewTreeObserver;
13import android.view.accessibility.AccessibilityEvent;
14import android.widget.FrameLayout;
15import androidx.test.core.app.ApplicationProvider;
16import androidx.test.ext.junit.runners.AndroidJUnit4;
17import io.flutter.embedding.android.AndroidTouchProcessor;
19import org.junit.runner.RunWith;
20import org.mockito.ArgumentCaptor;
21import org.robolectric.annotation.Config;
22import org.robolectric.annotation.Implementation;
23import org.robolectric.annotation.Implements;
26@RunWith(AndroidJUnit4.class)
28 private final Context ctx = ApplicationProvider.getApplicationContext();
40 view.
onTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0.0f, 0.0f, 0));
41 final ArgumentCaptor<Matrix> matrixCaptor = ArgumentCaptor.forClass(
Matrix.class);
42 verify(touchProcessor).onTouchEvent(
any(), matrixCaptor.capture());
45 screenMatrix.postTranslate(1, 2);
46 assertTrue(matrixCaptor.getValue().equals(screenMatrix));
49 reset(touchProcessor);
53 view.
onTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0.0f, 0.0f, 0));
54 final ArgumentCaptor<Matrix> matrixCaptor = ArgumentCaptor.forClass(
Matrix.class);
55 verify(touchProcessor).onTouchEvent(
any(), matrixCaptor.capture());
58 screenMatrix.postTranslate(1, 2);
59 assertTrue(matrixCaptor.getValue().equals(screenMatrix));
62 reset(touchProcessor);
66 view.
onTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0.0f, 0.0f, 0));
67 final ArgumentCaptor<Matrix> matrixCaptor = ArgumentCaptor.forClass(
Matrix.class);
68 verify(touchProcessor).onTouchEvent(
any(), matrixCaptor.capture());
71 screenMatrix.postTranslate(3, 4);
72 assertTrue(matrixCaptor.getValue().equals(screenMatrix));
75 reset(touchProcessor);
79 view.
onTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0.0f, 0.0f, 0));
80 final ArgumentCaptor<Matrix> matrixCaptor = ArgumentCaptor.forClass(
Matrix.class);
81 verify(touchProcessor).onTouchEvent(
any(), matrixCaptor.capture());
84 screenMatrix.postTranslate(7, 8);
85 assertTrue(matrixCaptor.getValue().equals(screenMatrix));
91 final ViewTreeObserver viewTreeObserver = mock(ViewTreeObserver.class);
92 when(viewTreeObserver.isAlive()).thenReturn(
true);
97 public ViewTreeObserver getViewTreeObserver() {
98 return viewTreeObserver;
102 public boolean hasFocus() {
107 final OnFocusChangeListener focusListener = mock(OnFocusChangeListener.class);
110 final ArgumentCaptor<ViewTreeObserver.OnGlobalFocusChangeListener> focusListenerCaptor =
111 ArgumentCaptor.forClass(ViewTreeObserver.OnGlobalFocusChangeListener.class);
112 verify(viewTreeObserver).addOnGlobalFocusChangeListener(focusListenerCaptor.capture());
114 focusListenerCaptor.getValue().onGlobalFocusChanged(
null,
null);
115 verify(focusListener).onFocusChange(view,
true);
120 final ViewTreeObserver viewTreeObserver = mock(ViewTreeObserver.class);
121 when(viewTreeObserver.isAlive()).thenReturn(
true);
126 public ViewTreeObserver getViewTreeObserver() {
127 return viewTreeObserver;
131 public boolean hasFocus() {
136 final OnFocusChangeListener focusListener = mock(OnFocusChangeListener.class);
139 final ArgumentCaptor<ViewTreeObserver.OnGlobalFocusChangeListener> focusListenerCaptor =
140 ArgumentCaptor.forClass(ViewTreeObserver.OnGlobalFocusChangeListener.class);
141 verify(viewTreeObserver).addOnGlobalFocusChangeListener(focusListenerCaptor.capture());
143 focusListenerCaptor.getValue().onGlobalFocusChanged(
null,
null);
144 verify(focusListener).onFocusChange(view,
false);
152 public ViewTreeObserver getViewTreeObserver() {
153 final ViewTreeObserver viewTreeObserver = mock(ViewTreeObserver.class);
154 when(viewTreeObserver.isAlive()).thenReturn(
false);
155 return viewTreeObserver;
163 final ViewTreeObserver viewTreeObserver = mock(ViewTreeObserver.class);
164 when(viewTreeObserver.isAlive()).thenReturn(
true);
169 public ViewTreeObserver getViewTreeObserver() {
170 return viewTreeObserver;
179 final ViewTreeObserver.OnGlobalFocusChangeListener activeFocusListener =
185 verify(viewTreeObserver,
times(1)).removeOnGlobalFocusChangeListener(activeFocusListener);
190 final ViewTreeObserver viewTreeObserver = mock(ViewTreeObserver.class);
191 when(viewTreeObserver.isAlive()).thenReturn(
true);
196 public ViewTreeObserver getViewTreeObserver() {
197 return viewTreeObserver;
206 final ViewTreeObserver.OnGlobalFocusChangeListener activeFocusListener =
213 verify(viewTreeObserver,
times(1)).removeOnGlobalFocusChangeListener(activeFocusListener);
219 ShadowViewGroup.class,
224 final View embeddedView = mock(View.class);
225 wrapperView.addView(embeddedView);
227 when(embeddedView.getImportantForAccessibility())
228 .thenReturn(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
229 final boolean eventSent =
231 assertFalse(eventSent);
234 @Implements(ViewGroup.class)
242 @Implements(FrameLayout.class)
static SkISize times(const SkISize &size, float factor)
boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event)
SK_API sk_sp< PrecompileColorFilter > Matrix()
SIT bool any(const Vec< 1, T > &x)