Flutter Engine
The Flutter Engine
AccessibilityEventsDelegateTest.java
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package io.flutter.plugin.platform;
6
7import static junit.framework.TestCase.assertFalse;
8import static junit.framework.TestCase.assertTrue;
9import static org.mockito.ArgumentMatchers.any;
10import static org.mockito.ArgumentMatchers.anyBoolean;
11import static org.mockito.Mockito.mock;
12import static org.mockito.Mockito.times;
13import static org.mockito.Mockito.verify;
14import static org.mockito.Mockito.when;
15
16import android.view.MotionEvent;
17import android.view.View;
18import android.view.accessibility.AccessibilityEvent;
19import androidx.test.ext.junit.runners.AndroidJUnit4;
20import io.flutter.view.AccessibilityBridge;
21import org.junit.Test;
22import org.junit.runner.RunWith;
23
24@RunWith(AndroidJUnit4.class)
26 @Test
28 final AccessibilityBridge mockAccessibilityBridge = mock(AccessibilityBridge.class);
29 final View embeddedView = mock(View.class);
30 final View originView = mock(View.class);
31 final AccessibilityEvent event = mock(AccessibilityEvent.class);
32
34 delegate.setAccessibilityBridge(mockAccessibilityBridge);
35 when(mockAccessibilityBridge.externalViewRequestSendAccessibilityEvent(any(), any(), any()))
36 .thenReturn(true);
37
38 final boolean handled = delegate.requestSendAccessibilityEvent(embeddedView, originView, event);
39
40 assertTrue(handled);
41 verify(mockAccessibilityBridge, times(1))
42 .externalViewRequestSendAccessibilityEvent(embeddedView, originView, event);
43 }
44
45 @Test
47 final View embeddedView = mock(View.class);
48 final View originView = mock(View.class);
49 final AccessibilityEvent event = mock(AccessibilityEvent.class);
50
52
53 final boolean handled = delegate.requestSendAccessibilityEvent(embeddedView, originView, event);
54
55 assertFalse(handled);
56 }
57
58 @Test
60 final AccessibilityBridge mockAccessibilityBridge = mock(AccessibilityBridge.class);
61 final MotionEvent event = mock(MotionEvent.class);
62
64 delegate.setAccessibilityBridge(mockAccessibilityBridge);
65 when(mockAccessibilityBridge.onAccessibilityHoverEvent(any(), anyBoolean())).thenReturn(true);
66
67 final boolean handled = delegate.onAccessibilityHoverEvent(event, true);
68
69 assertTrue(handled);
70 verify(mockAccessibilityBridge, times(1)).onAccessibilityHoverEvent(event, true);
71 }
72
73 @Test
75 final MotionEvent event = mock(MotionEvent.class);
76
78
79 final boolean handled = delegate.onAccessibilityHoverEvent(event, true);
80
81 assertFalse(handled);
82 }
83}
static SkISize times(const SkISize &size, float factor)
boolean onAccessibilityHoverEvent(MotionEvent event, boolean ignorePlatformViews)
void setAccessibilityBridge(@Nullable AccessibilityBridge accessibilityBridge)
boolean requestSendAccessibilityEvent( @NonNull View embeddedView, @NonNull View eventOrigin, @NonNull AccessibilityEvent event)
FlKeyEvent * event
SIT bool any(const Vec< 1, T > &x)
Definition: SkVx.h:530