5package io.flutter.plugin.platform;
7import static android.view.View.OnFocusChangeListener;
8import static io.flutter.Build.API_LEVELS;
9import static org.junit.Assert.*;
10import static org.mockito.ArgumentMatchers.*;
11import static org.mockito.Mockito.*;
12import static org.mockito.Mockito.spy;
14import android.annotation.TargetApi;
19import android.view.View.OnFocusChangeListener;
21import android.view.ViewTreeObserver;
22import android.view.accessibility.AccessibilityEvent;
23import android.widget.FrameLayout;
24import androidx.test.core.app.ApplicationProvider;
25import androidx.test.ext.junit.runners.AndroidJUnit4;
27import org.junit.runner.RunWith;
28import org.mockito.ArgumentCaptor;
29import org.robolectric.annotation.Config;
30import org.robolectric.annotation.Implementation;
31import org.robolectric.annotation.Implements;
33@TargetApi(API_LEVELS.API_31)
34@RunWith(AndroidJUnit4.class)
36 private final Context ctx = ApplicationProvider.getApplicationContext();
46 verify(wrapper,
times(1)).invalidate();
54 public void onDraw(Canvas canvas) {
55 canvas.drawColor(
Color.RED);
59 final Canvas canvas = mock(Canvas.class);
68 final ViewTreeObserver viewTreeObserver = mock(ViewTreeObserver.class);
69 when(viewTreeObserver.isAlive()).thenReturn(
true);
74 public ViewTreeObserver getViewTreeObserver() {
75 return viewTreeObserver;
79 public boolean hasFocus() {
84 final OnFocusChangeListener focusListener = mock(OnFocusChangeListener.class);
87 final ArgumentCaptor<ViewTreeObserver.OnGlobalFocusChangeListener> focusListenerCaptor =
88 ArgumentCaptor.forClass(ViewTreeObserver.OnGlobalFocusChangeListener.class);
89 verify(viewTreeObserver).addOnGlobalFocusChangeListener(focusListenerCaptor.capture());
91 focusListenerCaptor.getValue().onGlobalFocusChanged(
null,
null);
92 verify(focusListener).onFocusChange(view,
true);
97 final ViewTreeObserver viewTreeObserver = mock(ViewTreeObserver.class);
98 when(viewTreeObserver.isAlive()).thenReturn(
true);
103 public ViewTreeObserver getViewTreeObserver() {
104 return viewTreeObserver;
108 public boolean hasFocus() {
113 final OnFocusChangeListener focusListener = mock(OnFocusChangeListener.class);
116 final ArgumentCaptor<ViewTreeObserver.OnGlobalFocusChangeListener> focusListenerCaptor =
117 ArgumentCaptor.forClass(ViewTreeObserver.OnGlobalFocusChangeListener.class);
118 verify(viewTreeObserver).addOnGlobalFocusChangeListener(focusListenerCaptor.capture());
120 focusListenerCaptor.getValue().onGlobalFocusChanged(
null,
null);
121 verify(focusListener).onFocusChange(view,
false);
129 public ViewTreeObserver getViewTreeObserver() {
130 final ViewTreeObserver viewTreeObserver = mock(ViewTreeObserver.class);
131 when(viewTreeObserver.isAlive()).thenReturn(
false);
132 return viewTreeObserver;
140 final ViewTreeObserver viewTreeObserver = mock(ViewTreeObserver.class);
141 when(viewTreeObserver.isAlive()).thenReturn(
true);
146 public ViewTreeObserver getViewTreeObserver() {
147 return viewTreeObserver;
156 final ViewTreeObserver.OnGlobalFocusChangeListener activeFocusListener =
162 verify(viewTreeObserver,
times(1)).removeOnGlobalFocusChangeListener(activeFocusListener);
167 final ViewTreeObserver viewTreeObserver = mock(ViewTreeObserver.class);
168 when(viewTreeObserver.isAlive()).thenReturn(
true);
173 public ViewTreeObserver getViewTreeObserver() {
174 return viewTreeObserver;
183 final ViewTreeObserver.OnGlobalFocusChangeListener activeFocusListener =
190 verify(viewTreeObserver,
times(1)).removeOnGlobalFocusChangeListener(activeFocusListener);
196 ShadowFrameLayout.class,
197 ShadowViewGroup.class,
202 final View embeddedView = mock(View.class);
203 wrapperView.addView(embeddedView);
205 when(embeddedView.getImportantForAccessibility())
206 .thenReturn(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
207 final boolean eventSent =
209 assertFalse(eventSent);
215 ShadowFrameLayout.class,
216 ShadowViewGroup.class,
221 final View embeddedView = mock(View.class);
222 wrapperView.addView(embeddedView);
224 when(embeddedView.getImportantForAccessibility())
225 .thenReturn(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
228 assertTrue(eventSent);
230 when(embeddedView.getImportantForAccessibility())
231 .thenReturn(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
234 assertTrue(eventSent);
237 @Implements(ViewGroup.class)
245 @Implements(FrameLayout.class)
static SkISize times(const SkISize &size, float factor)
SK_API sk_sp< SkShader > Color(SkColor)