5package io.flutter.view;
7import static io.flutter.Build.API_LEVELS;
8import static org.junit.Assert.assertEquals;
9import static org.junit.Assert.assertFalse;
10import static org.junit.Assert.assertNotEquals;
11import static org.junit.Assert.assertNotNull;
12import static org.junit.Assert.assertTrue;
13import static org.mockito.ArgumentMatchers.eq;
14import static org.mockito.Mockito.any;
15import static org.mockito.Mockito.anyInt;
16import static org.mockito.Mockito.doAnswer;
17import static org.mockito.Mockito.mock;
18import static org.mockito.Mockito.never;
19import static org.mockito.Mockito.reset;
20import static org.mockito.Mockito.spy;
21import static org.mockito.Mockito.times;
22import static org.mockito.Mockito.verify;
23import static org.mockito.Mockito.when;
25import android.annotation.TargetApi;
27import android.content.ContentResolver;
29import android.content.res.Configuration;
30import android.content.res.Resources;
33import android.text.SpannableString;
34import android.text.SpannedString;
35import android.text.style.LocaleSpan;
36import android.text.style.TtsSpan;
41import android.view.WindowInsets;
42import android.view.WindowManager;
43import android.view.accessibility.AccessibilityEvent;
44import android.view.accessibility.AccessibilityManager;
45import android.view.accessibility.AccessibilityNodeInfo;
46import androidx.test.core.app.ApplicationProvider;
47import androidx.test.ext.junit.runners.AndroidJUnit4;
48import io.flutter.embedding.engine.FlutterJNI;
49import io.flutter.embedding.engine.dart.DartExecutor;
50import io.flutter.embedding.engine.systemchannels.AccessibilityChannel;
51import io.flutter.plugin.common.BasicMessageChannel;
52import io.flutter.plugin.platform.PlatformViewsAccessibilityDelegate;
53import io.flutter.view.AccessibilityBridge.Action;
54import io.flutter.view.AccessibilityBridge.Flag;
55import java.nio.ByteBuffer;
56import java.nio.charset.Charset;
57import java.util.ArrayList;
58import java.util.HashMap;
61import org.junit.runner.RunWith;
62import org.mockito.ArgumentCaptor;
63import org.mockito.invocation.InvocationOnMock;
64import org.robolectric.annotation.Config;
67@RunWith(AndroidJUnit4.class)
75 testSemanticsNode.label =
"Hello, World";
78 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
80 assertEquals(nodeInfo.getContentDescription().toString(),
"Hello, World");
81 assertEquals(nodeInfo.getText(),
null);
91 testSemanticsNode.value =
"Hello, World";
92 testSemanticsNode.label =
"some label";
93 testSemanticsNode.hint =
"some hint";
97 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
99 assertEquals(nodeInfo.getContentDescription(),
null);
100 assertEquals(nodeInfo.getText().toString(),
"Hello, World");
101 assertEquals(nodeInfo.getHintText().toString(),
"some label, some hint");
107 AccessibilityManager mockManager = mock(AccessibilityManager.class);
108 View mockRootView = mock(View.class);
109 Context context = mock(Context.class);
110 when(mockRootView.getContext()).thenReturn(context);
111 final int position = 88;
115 int[] outLocation = (
int[]) invocation.getArguments()[0];
116 outLocation[0] = position;
117 outLocation[1] = position;
121 .getLocationOnScreen(
any(
int[].
class));
123 when(context.getPackageName()).thenReturn(
"test");
125 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
131 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
133 Rect outBoundsInScreen =
new Rect();
134 nodeInfo.getBoundsInScreen(outBoundsInScreen);
135 assertEquals(position, outBoundsInScreen.left);
136 assertEquals(position, outBoundsInScreen.top);
143 AccessibilityManager mockManager = mock(AccessibilityManager.class);
144 View mockRootView = mock(View.class);
145 Context context = mock(Context.class);
146 when(mockRootView.getContext()).thenReturn(context);
147 when(context.getPackageName()).thenReturn(
"test");
148 when(mockManager.isTouchExplorationEnabled()).thenReturn(
false);
157 ArgumentCaptor<AccessibilityManager.TouchExplorationStateChangeListener> listenerCaptor =
158 ArgumentCaptor.forClass(AccessibilityManager.TouchExplorationStateChangeListener.class);
159 verify(mockManager).addTouchExplorationStateChangeListener(listenerCaptor.capture());
162 verify(mockChannel).setAccessibilityFeatures(0);
166 accessibilityBridge.createAccessibilityNodeInfo(0);
167 verify(mockChannel).setAccessibilityFeatures(1);
172 listenerCaptor.getValue().onTouchExplorationStateChanged(
false);
173 verify(mockChannel).setAccessibilityFeatures(0);
182 testSemanticsNode.label =
"Hello, World";
187 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
189 assertEquals(nodeInfo.getContentDescription(),
null);
190 assertEquals(nodeInfo.getText(),
null);
196 AccessibilityManager mockManager = mock(AccessibilityManager.class);
197 View mockRootView = mock(View.class);
198 Context context = mock(Context.class);
199 when(mockRootView.getContext()).thenReturn(context);
200 when(context.getPackageName()).thenReturn(
"test");
202 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
209 platformView.platformViewId = 42;
210 root.children.add(platformView);
215 View mockView = mock(View.class);
216 AccessibilityEvent focusEvent = mock(AccessibilityEvent.class);
220 when(focusEvent.getEventType()).thenReturn(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
221 accessibilityBridge.externalViewRequestSendAccessibilityEvent(mockView, mockView, focusEvent);
226 root.children.clear();
227 root.children.add(node);
228 testSemanticsUpdate =
root.toUpdate();
229 when(mockManager.isEnabled()).thenReturn(
true);
230 ViewParent mockParent = mock(ViewParent.class);
231 when(mockRootView.getParent()).thenReturn(mockParent);
235 ArgumentCaptor<AccessibilityEvent> eventCaptor =
236 ArgumentCaptor.forClass(AccessibilityEvent.class);
237 verify(mockParent,
times(2))
238 .requestSendAccessibilityEvent(
eq(mockRootView), eventCaptor.capture());
239 AccessibilityEvent
event = eventCaptor.getAllValues().get(0);
240 assertEquals(
event.getEventType(), AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED);
246 AccessibilityManager mockManager = mock(AccessibilityManager.class);
247 View mockRootView = mock(View.class);
248 Context context = mock(Context.class);
249 when(mockRootView.getContext()).thenReturn(context);
250 when(context.getPackageName()).thenReturn(
"test");
252 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
253 ViewParent mockParent = mock(ViewParent.class);
254 when(mockRootView.getParent()).thenReturn(mockParent);
255 when(mockManager.isEnabled()).thenReturn(
true);
263 node1.label =
"node1";
264 root.children.add(node1);
268 verify(mockRootView,
times(1)).setAccessibilityPaneTitle(
eq(
"node1"));
276 new_node1.label =
"new_node1";
282 new_node2.label =
"new_node2";
284 testSemanticsUpdate = new_root.
toUpdate();
287 verify(mockRootView,
times(1)).setAccessibilityPaneTitle(
eq(
"new_node2"));
293 AccessibilityManager mockManager = mock(AccessibilityManager.class);
294 View mockRootView = mock(View.class);
295 Context context = mock(Context.class);
296 when(mockRootView.getContext()).thenReturn(context);
297 when(context.getPackageName()).thenReturn(
"test");
299 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
300 ViewParent mockParent = mock(ViewParent.class);
301 when(mockRootView.getParent()).thenReturn(mockParent);
302 when(mockManager.isEnabled()).thenReturn(
true);
308 node1.label =
"node1";
309 root.children.add(node1);
312 node2.label =
"node2";
313 root.children.add(node2);
318 AccessibilityNodeInfo mockNodeInfo2 = mock(AccessibilityNodeInfo.class);
320 when(spyAccessibilityBridge.obtainAccessibilityNodeInfo(mockRootView, 2))
321 .thenReturn(mockNodeInfo2);
322 spyAccessibilityBridge.createAccessibilityNodeInfo(2);
323 verify(mockNodeInfo2,
times(1)).setTraversalAfter(
eq(mockRootView),
eq(1));
331 AccessibilityManager mockManager = mock(AccessibilityManager.class);
332 View mockRootView = mock(View.class);
333 Context context = mock(Context.class);
334 when(mockRootView.getContext()).thenReturn(context);
335 when(context.getPackageName()).thenReturn(
"test");
337 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
338 ViewParent mockParent = mock(ViewParent.class);
339 when(mockRootView.getParent()).thenReturn(mockParent);
340 when(mockManager.isEnabled()).thenReturn(
true);
348 AccessibilityNodeInfo mockNodeInfo = mock(AccessibilityNodeInfo.class);
350 when(spyAccessibilityBridge.obtainAccessibilityNodeInfo(mockRootView)).thenReturn(mockNodeInfo);
351 spyAccessibilityBridge.createAccessibilityNodeInfo(View.NO_ID);
352 verify(mockNodeInfo,
times(1)).setImportantForAccessibility(
eq(
false));
360 AccessibilityManager mockManager = mock(AccessibilityManager.class);
361 View mockRootView = mock(View.class);
362 Context context = mock(Context.class);
363 when(mockRootView.getContext()).thenReturn(context);
364 when(context.getPackageName()).thenReturn(
"test");
366 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
367 ViewParent mockParent = mock(ViewParent.class);
368 when(mockRootView.getParent()).thenReturn(mockParent);
369 when(mockManager.isEnabled()).thenReturn(
true);
373 root.label =
"some label";
378 AccessibilityNodeInfo mockNodeInfo = mock(AccessibilityNodeInfo.class);
380 when(spyAccessibilityBridge.obtainAccessibilityNodeInfo(mockRootView, 0))
381 .thenReturn(mockNodeInfo);
382 spyAccessibilityBridge.createAccessibilityNodeInfo(0);
383 verify(mockNodeInfo,
times(1)).setImportantForAccessibility(
eq(
true));
391 AccessibilityManager mockManager = mock(AccessibilityManager.class);
392 View mockRootView = mock(View.class);
393 Context context = mock(Context.class);
394 when(mockRootView.getContext()).thenReturn(context);
395 when(context.getPackageName()).thenReturn(
"test");
397 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
398 ViewParent mockParent = mock(ViewParent.class);
399 when(mockRootView.getParent()).thenReturn(mockParent);
400 when(mockManager.isEnabled()).thenReturn(
true);
409 AccessibilityNodeInfo mockNodeInfo = mock(AccessibilityNodeInfo.class);
411 when(spyAccessibilityBridge.obtainAccessibilityNodeInfo(mockRootView, 0))
412 .thenReturn(mockNodeInfo);
413 spyAccessibilityBridge.createAccessibilityNodeInfo(0);
414 verify(mockNodeInfo,
times(1)).setImportantForAccessibility(
eq(
true));
422 AccessibilityManager mockManager = mock(AccessibilityManager.class);
423 View mockRootView = mock(View.class);
424 Context context = mock(Context.class);
425 when(mockRootView.getContext()).thenReturn(context);
426 when(context.getPackageName()).thenReturn(
"test");
428 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
429 ViewParent mockParent = mock(ViewParent.class);
430 when(mockRootView.getParent()).thenReturn(mockParent);
431 when(mockManager.isEnabled()).thenReturn(
true);
437 root.children.add(node);
442 AccessibilityNodeInfo mockNodeInfo = mock(AccessibilityNodeInfo.class);
444 when(spyAccessibilityBridge.obtainAccessibilityNodeInfo(mockRootView, 0))
445 .thenReturn(mockNodeInfo);
446 spyAccessibilityBridge.createAccessibilityNodeInfo(0);
447 verify(mockNodeInfo,
times(1)).setImportantForAccessibility(
eq(
false));
449 AccessibilityNodeInfo mockNodeInfo1 = mock(AccessibilityNodeInfo.class);
451 when(spyAccessibilityBridge.obtainAccessibilityNodeInfo(mockRootView, 1))
452 .thenReturn(mockNodeInfo1);
453 spyAccessibilityBridge.createAccessibilityNodeInfo(1);
454 verify(mockNodeInfo1,
times(1)).setImportantForAccessibility(
eq(
false));
457 @SuppressWarnings(
"deprecation")
463 int expectedInsetLeft = 5;
469 AccessibilityManager mockManager = mock(AccessibilityManager.class);
470 View mockRootView = mock(View.class);
471 Activity context = mock(Activity.class);
472 Window
window = mock(Window.class);
473 WindowInsets insets = mock(WindowInsets.class);
474 WindowManager.LayoutParams layoutParams =
new WindowManager.LayoutParams();
475 layoutParams.layoutInDisplayCutoutMode =
476 WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
477 when(mockRootView.getContext()).thenReturn(context);
478 when(context.getWindow()).thenReturn(
window);
479 when(
window.getAttributes()).thenReturn(layoutParams);
480 when(mockRootView.getRootWindowInsets()).thenReturn(insets);
481 when(insets.getSystemWindowInsetLeft()).thenReturn(expectedInsetLeft);
482 when(context.getPackageName()).thenReturn(
"test");
484 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
485 ViewParent mockParent = mock(ViewParent.class);
486 when(mockRootView.getParent()).thenReturn(mockParent);
487 when(mockManager.isEnabled()).thenReturn(
true);
494 root.bottom = bottom;
499 AccessibilityNodeInfo mockNodeInfo = mock(AccessibilityNodeInfo.class);
501 when(spyAccessibilityBridge.obtainAccessibilityNodeInfo(mockRootView, 0))
502 .thenReturn(mockNodeInfo);
503 spyAccessibilityBridge.createAccessibilityNodeInfo(0);
504 verify(mockNodeInfo,
times(1))
506 new Rect(left + expectedInsetLeft, top, right + expectedInsetLeft, bottom));
509 @SuppressWarnings(
"deprecation")
515 int expectedInsetLeft = 5;
521 AccessibilityManager mockManager = mock(AccessibilityManager.class);
522 View mockRootView = mock(View.class);
523 Activity context = mock(Activity.class);
524 Window
window = mock(Window.class);
525 WindowInsets insets = mock(WindowInsets.class);
526 WindowManager.LayoutParams layoutParams =
new WindowManager.LayoutParams();
527 layoutParams.layoutInDisplayCutoutMode =
528 WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT;
529 when(mockRootView.getContext()).thenReturn(context);
530 when(context.getWindow()).thenReturn(
window);
531 when(
window.getAttributes()).thenReturn(layoutParams);
532 when(mockRootView.getRootWindowInsets()).thenReturn(insets);
533 when(insets.getSystemWindowInsetLeft()).thenReturn(expectedInsetLeft);
534 when(context.getPackageName()).thenReturn(
"test");
536 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
537 ViewParent mockParent = mock(ViewParent.class);
538 when(mockRootView.getParent()).thenReturn(mockParent);
539 when(mockManager.isEnabled()).thenReturn(
true);
546 root.bottom = bottom;
551 AccessibilityNodeInfo mockNodeInfo = mock(AccessibilityNodeInfo.class);
553 when(spyAccessibilityBridge.obtainAccessibilityNodeInfo(mockRootView, 0))
554 .thenReturn(mockNodeInfo);
555 spyAccessibilityBridge.createAccessibilityNodeInfo(0);
556 verify(mockNodeInfo,
times(1))
558 new Rect(left + expectedInsetLeft, top, right + expectedInsetLeft, bottom));
561 @SuppressWarnings(
"deprecation")
567 int expectedInsetLeft = 5;
573 AccessibilityManager mockManager = mock(AccessibilityManager.class);
574 View mockRootView = mock(View.class);
575 Activity context = mock(Activity.class);
576 Window
window = mock(Window.class);
577 WindowInsets insets = mock(WindowInsets.class);
578 WindowManager.LayoutParams layoutParams =
new WindowManager.LayoutParams();
579 layoutParams.layoutInDisplayCutoutMode =
580 WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
581 when(mockRootView.getContext()).thenReturn(context);
582 when(context.getWindow()).thenReturn(
window);
583 when(
window.getAttributes()).thenReturn(layoutParams);
584 when(mockRootView.getRootWindowInsets()).thenReturn(insets);
585 when(insets.getSystemWindowInsetLeft()).thenReturn(expectedInsetLeft);
586 when(context.getPackageName()).thenReturn(
"test");
588 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
589 ViewParent mockParent = mock(ViewParent.class);
590 when(mockRootView.getParent()).thenReturn(mockParent);
591 when(mockManager.isEnabled()).thenReturn(
true);
598 root.bottom = bottom;
603 AccessibilityNodeInfo mockNodeInfo = mock(AccessibilityNodeInfo.class);
605 when(spyAccessibilityBridge.obtainAccessibilityNodeInfo(mockRootView, 0))
606 .thenReturn(mockNodeInfo);
607 spyAccessibilityBridge.createAccessibilityNodeInfo(0);
609 verify(mockNodeInfo,
times(1)).setBoundsInScreen(
new Rect(left, top, right, bottom));
612 @SuppressWarnings(
"deprecation")
619 int expectedInsetLeft = 5;
625 AccessibilityManager mockManager = mock(AccessibilityManager.class);
626 View mockRootView = mock(View.class);
627 Activity context = mock(Activity.class);
628 Window
window = mock(Window.class);
629 WindowInsets insets = mock(WindowInsets.class);
630 WindowManager.LayoutParams layoutParams =
new WindowManager.LayoutParams();
631 layoutParams.layoutInDisplayCutoutMode =
632 WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
633 when(mockRootView.getContext()).thenReturn(context);
634 when(context.getWindow()).thenReturn(
window);
635 when(
window.getAttributes()).thenReturn(layoutParams);
636 when(mockRootView.getRootWindowInsets()).thenReturn(insets);
637 when(insets.getSystemWindowInsetLeft()).thenReturn(expectedInsetLeft);
638 when(context.getPackageName()).thenReturn(
"test");
640 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
641 ViewParent mockParent = mock(ViewParent.class);
642 when(mockRootView.getParent()).thenReturn(mockParent);
643 when(mockManager.isEnabled()).thenReturn(
true);
650 root.bottom = bottom;
655 AccessibilityNodeInfo mockNodeInfo = mock(AccessibilityNodeInfo.class);
657 when(spyAccessibilityBridge.obtainAccessibilityNodeInfo(mockRootView, 0))
658 .thenReturn(mockNodeInfo);
659 spyAccessibilityBridge.createAccessibilityNodeInfo(0);
661 verify(mockNodeInfo,
times(1)).setBoundsInScreen(
new Rect(left, top, right, bottom));
667 AccessibilityManager mockManager = mock(AccessibilityManager.class);
668 View mockRootView = mock(View.class);
669 Context context = mock(Context.class);
670 when(mockRootView.getContext()).thenReturn(context);
671 when(context.getPackageName()).thenReturn(
"test");
673 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
674 ViewParent mockParent = mock(ViewParent.class);
675 when(mockRootView.getParent()).thenReturn(mockParent);
676 when(mockManager.isEnabled()).thenReturn(
true);
677 when(mockManager.isTouchExplorationEnabled()).thenReturn(
true);
692 root.children.add(ignored);
695 child.label =
"label";
700 root.children.add(child);
704 verify(mockRootView,
times(1)).setAccessibilityPaneTitle(
eq(
" "));
707 MotionEvent mockEvent = mock(MotionEvent.class);
708 when(mockEvent.getX()).thenReturn(10.0
f);
709 when(mockEvent.getY()).thenReturn(10.0
f);
710 when(mockEvent.getAction()).thenReturn(MotionEvent.ACTION_HOVER_ENTER);
711 boolean hit = accessibilityBridge.onAccessibilityHoverEvent(mockEvent);
713 assertEquals(hit,
true);
715 ArgumentCaptor<AccessibilityEvent> eventCaptor =
716 ArgumentCaptor.forClass(AccessibilityEvent.class);
717 verify(mockParent,
times(2))
718 .requestSendAccessibilityEvent(
eq(mockRootView), eventCaptor.capture());
719 AccessibilityEvent
event = eventCaptor.getAllValues().get(1);
720 assertEquals(
event.getEventType(), AccessibilityEvent.TYPE_VIEW_HOVER_ENTER);
727 AccessibilityManager mockManager = mock(AccessibilityManager.class);
728 View mockRootView = mock(View.class);
729 Context context = mock(Context.class);
730 when(mockRootView.getContext()).thenReturn(context);
731 when(context.getPackageName()).thenReturn(
"test");
733 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
734 ViewParent mockParent = mock(ViewParent.class);
735 when(mockRootView.getParent()).thenReturn(mockParent);
736 when(mockManager.isEnabled()).thenReturn(
true);
737 when(mockManager.isTouchExplorationEnabled()).thenReturn(
true);
747 platformView.platformViewId = 1;
748 platformView.left = 0;
749 platformView.top = 0;
750 platformView.bottom = 20;
751 platformView.right = 20;
752 root.addChild(platformView);
757 MotionEvent mockEvent = mock(MotionEvent.class);
758 when(mockEvent.getX()).thenReturn(10.0
f);
759 when(mockEvent.getY()).thenReturn(10.0
f);
760 when(mockEvent.getAction()).thenReturn(MotionEvent.ACTION_HOVER_ENTER);
762 final boolean handled = accessibilityBridge.onAccessibilityHoverEvent(mockEvent);
770 AccessibilityManager mockManager = mock(AccessibilityManager.class);
771 View mockRootView = mock(View.class);
772 Context context = mock(Context.class);
773 when(mockRootView.getContext()).thenReturn(context);
774 when(context.getPackageName()).thenReturn(
"test");
776 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
777 ViewParent mockParent = mock(ViewParent.class);
778 when(mockRootView.getParent()).thenReturn(mockParent);
779 when(mockManager.isEnabled()).thenReturn(
true);
780 when(mockManager.isTouchExplorationEnabled()).thenReturn(
true);
790 platformView.platformViewId = 1;
791 platformView.left = 0;
792 platformView.top = 0;
793 platformView.bottom = 20;
794 platformView.right = 20;
795 root.addChild(platformView);
800 MotionEvent mockEvent = mock(MotionEvent.class);
801 when(mockEvent.getX()).thenReturn(10.0
f);
802 when(mockEvent.getY()).thenReturn(10.0
f);
803 when(mockEvent.getAction()).thenReturn(MotionEvent.ACTION_HOVER_ENTER);
805 final boolean handled = accessibilityBridge.onAccessibilityHoverEvent(mockEvent,
true);
807 assertFalse(handled);
813 AccessibilityManager mockManager = mock(AccessibilityManager.class);
814 View mockRootView = mock(View.class);
815 Context context = mock(Context.class);
816 when(mockRootView.getContext()).thenReturn(context);
817 when(context.getPackageName()).thenReturn(
"test");
819 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
820 ViewParent mockParent = mock(ViewParent.class);
821 when(mockRootView.getParent()).thenReturn(mockParent);
822 when(mockManager.isEnabled()).thenReturn(
true);
830 node1.label =
"node1";
831 root.children.add(node1);
836 node2.label =
"node2";
841 verify(mockRootView,
times(1)).setAccessibilityPaneTitle(
eq(
"node2"));
847 new_node1.label =
"new_node1";
853 new_node2.label =
"new_node2";
855 testSemanticsUpdate = new_root.
toUpdate();
858 verify(mockRootView,
times(1)).setAccessibilityPaneTitle(
eq(
"new_node2"));
866 AccessibilityManager mockManager = mock(AccessibilityManager.class);
867 View mockRootView = mock(View.class);
868 Context context = mock(Context.class);
869 when(mockRootView.getContext()).thenReturn(context);
870 when(context.getPackageName()).thenReturn(
"test");
880 ViewParent mockParent = mock(ViewParent.class);
881 when(mockRootView.getParent()).thenReturn(mockParent);
882 when(mockManager.isEnabled()).thenReturn(
true);
889 root.children.add(node1);
892 Bundle bundle =
new Bundle();
893 String expectedText =
"some string";
894 bundle.putString(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, expectedText);
895 accessibilityBridge.performAction(1, AccessibilityNodeInfo.ACTION_SET_TEXT, bundle);
905 AccessibilityManager mockManager = mock(AccessibilityManager.class);
906 View mockRootView = mock(View.class);
907 Context context = mock(Context.class);
908 when(mockRootView.getContext()).thenReturn(context);
909 when(context.getPackageName()).thenReturn(
"test");
919 ViewParent mockParent = mock(ViewParent.class);
920 when(mockRootView.getParent()).thenReturn(mockParent);
921 when(mockManager.isEnabled()).thenReturn(
true);
928 root.children.add(node1);
931 Bundle bundle =
new Bundle();
932 String expectedText =
"some string";
933 bundle.putString(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, expectedText);
934 accessibilityBridge.performAction(1, AccessibilityNodeInfo.ACTION_SET_TEXT, bundle);
935 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(1);
936 assertEquals(nodeInfo.getText().toString(), expectedText);
944 AccessibilityManager mockManager = mock(AccessibilityManager.class);
945 View mockRootView = mock(View.class);
946 Context context = mock(Context.class);
947 when(mockRootView.getContext()).thenReturn(context);
948 when(context.getPackageName()).thenReturn(
"test");
958 ViewParent mockParent = mock(ViewParent.class);
959 when(mockRootView.getParent()).thenReturn(mockParent);
960 when(mockManager.isEnabled()).thenReturn(
true);
964 root.label =
"label";
969 root.labelAttributes =
970 new ArrayList<TestStringAttribute>() {
975 root.value =
"value";
977 localeAttribute.start = 1;
978 localeAttribute.end = 2;
980 localeAttribute.locale =
"es-MX";
981 root.valueAttributes =
982 new ArrayList<TestStringAttribute>() {
984 add(localeAttribute);
990 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
991 SpannedString actual = (SpannedString) nodeInfo.getContentDescription();
992 assertEquals(actual.toString(),
"value, label");
993 Object[] objectSpans = actual.getSpans(0, actual.length(), Object.class);
994 assertEquals(objectSpans.length, 2);
995 LocaleSpan localeSpan = (LocaleSpan) objectSpans[0];
996 assertEquals(localeSpan.getLocale().toLanguageTag(),
"es-MX");
997 assertEquals(actual.getSpanStart(localeSpan), 1);
998 assertEquals(actual.getSpanEnd(localeSpan), 2);
999 TtsSpan spellOutSpan = (TtsSpan) objectSpans[1];
1000 assertEquals(spellOutSpan.getType(), TtsSpan.TYPE_VERBATIM);
1001 assertEquals(actual.getSpanStart(spellOutSpan), 8);
1002 assertEquals(actual.getSpanEnd(spellOutSpan), 9);
1010 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1011 View mockRootView = mock(View.class);
1012 Context context = mock(Context.class);
1013 when(mockRootView.getContext()).thenReturn(context);
1014 when(context.getPackageName()).thenReturn(
"test");
1024 ViewParent mockParent = mock(ViewParent.class);
1025 when(mockRootView.getParent()).thenReturn(mockParent);
1026 when(mockManager.isEnabled()).thenReturn(
true);
1030 root.value =
"value";
1032 attribute.start = 1;
1035 root.valueAttributes =
new ArrayList<>();
1036 root.valueAttributes.add(attribute);
1040 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
1041 SpannableString actual = (SpannableString) nodeInfo.getContentDescription();
1042 assertEquals(actual.toString(),
"value");
1043 Object[] objectSpans = actual.getSpans(0, actual.length(), Object.class);
1044 assertEquals(objectSpans.length, 1);
1045 TtsSpan spellOutSpan = (TtsSpan) objectSpans[0];
1046 assertEquals(spellOutSpan.getType(), TtsSpan.TYPE_VERBATIM);
1047 assertEquals(actual.getSpanStart(spellOutSpan), 1);
1048 assertEquals(actual.getSpanEnd(spellOutSpan), 2);
1051 Bundle bundle =
new Bundle();
1052 String expectedText =
"a";
1053 bundle.putString(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, expectedText);
1054 accessibilityBridge.performAction(0, AccessibilityNodeInfo.ACTION_SET_TEXT, bundle);
1057 nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
1058 actual = (SpannableString) nodeInfo.getContentDescription();
1059 assertEquals(actual.toString(), expectedText);
1060 objectSpans = actual.getSpans(0, actual.length(), Object.class);
1061 assertEquals(objectSpans.length, 0);
1070 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1071 View mockRootView = mock(View.class);
1072 Context context = mock(Context.class);
1073 when(mockRootView.getContext()).thenReturn(context);
1074 when(context.getPackageName()).thenReturn(
"test");
1084 ViewParent mockParent = mock(ViewParent.class);
1085 when(mockRootView.getParent()).thenReturn(mockParent);
1086 when(mockManager.isEnabled()).thenReturn(
true);
1090 root.tooltip =
"tooltip";
1097 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
1098 CharSequence actual = nodeInfo.getTooltipText();
1099 assertEquals(actual.toString(),
root.tooltip);
1107 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1108 View mockRootView = mock(View.class);
1109 Context context = mock(Context.class);
1110 when(mockRootView.getContext()).thenReturn(context);
1111 when(context.getPackageName()).thenReturn(
"test");
1121 ViewParent mockParent = mock(ViewParent.class);
1122 when(mockRootView.getParent()).thenReturn(mockParent);
1123 when(mockManager.isEnabled()).thenReturn(
true);
1127 root.identifier =
"identifier";
1135 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
1136 CharSequence actual = nodeInfo.getViewIdResourceName();
1137 assertEquals(actual.toString(),
root.identifier);
1145 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1146 View mockRootView = mock(View.class);
1147 Context context = mock(Context.class);
1148 when(mockRootView.getContext()).thenReturn(context);
1149 when(context.getPackageName()).thenReturn(
"test");
1159 ViewParent mockParent = mock(ViewParent.class);
1160 when(mockRootView.getParent()).thenReturn(mockParent);
1161 when(mockManager.isEnabled()).thenReturn(
true);
1169 root.children.add(node1);
1172 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(1);
1173 List<AccessibilityNodeInfo.AccessibilityAction> actions = nodeInfo.getActionList();
1174 assertTrue(actions.contains(AccessibilityNodeInfo.AccessibilityAction.ACTION_SET_TEXT));
1181 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1182 View mockRootView = mock(View.class);
1183 Context context = mock(Context.class);
1184 when(mockRootView.getContext()).thenReturn(context);
1185 when(context.getPackageName()).thenReturn(
"test");
1195 ViewParent mockParent = mock(ViewParent.class);
1196 when(mockRootView.getParent()).thenReturn(mockParent);
1197 when(mockManager.isEnabled()).thenReturn(
true);
1203 node1.value =
"some text";
1204 node1.textSelectionBase = -1;
1205 node1.textSelectionExtent = -1;
1207 root.children.add(node1);
1210 Bundle bundle =
new Bundle();
1211 int expectedStart = 1;
1212 int expectedEnd = 3;
1213 bundle.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_START_INT, expectedStart);
1214 bundle.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_END_INT, expectedEnd);
1215 accessibilityBridge.performAction(1, AccessibilityNodeInfo.ACTION_SET_SELECTION, bundle);
1216 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(1);
1217 assertEquals(nodeInfo.getTextSelectionStart(), expectedStart);
1218 assertEquals(nodeInfo.getTextSelectionEnd(), expectedEnd);
1227 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1228 View mockRootView = mock(View.class);
1229 Context context = mock(Context.class);
1230 when(mockRootView.getContext()).thenReturn(context);
1231 when(context.getPackageName()).thenReturn(
"test");
1235 accessibilityChannel,
1241 ViewParent mockParent = mock(ViewParent.class);
1242 when(mockRootView.getParent()).thenReturn(mockParent);
1243 when(mockManager.isEnabled()).thenReturn(
true);
1247 root.label =
"root";
1250 node1.value =
"some text";
1251 root.children.add(node1);
1255 accessibilityBridge.performAction(0, AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS,
null);
1256 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
1257 assertTrue(nodeInfo.isAccessibilityFocused());
1259 HashMap<String, Object>
message =
new HashMap<>();
1260 message.put(
"type",
"didGainFocus");
1262 verify(mockChannel).send(
message);
1264 accessibilityBridge.performAction(
1265 1, AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS,
null);
1266 nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
1267 assertTrue(nodeInfo.isAccessibilityFocused());
1270 accessibilityBridge.performAction(
1271 0, AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS,
null);
1272 nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
1273 assertFalse(nodeInfo.isAccessibilityFocused());
1280 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1281 View mockRootView = mock(View.class);
1282 Context context = mock(Context.class);
1283 when(mockRootView.getContext()).thenReturn(context);
1284 when(context.getPackageName()).thenReturn(
"test");
1294 ViewParent mockParent = mock(ViewParent.class);
1295 when(mockRootView.getParent()).thenReturn(mockParent);
1296 when(mockManager.isEnabled()).thenReturn(
true);
1300 root.addFlag(Flag.HAS_IMPLICIT_SCROLLING);
1303 node1.
addFlag(Flag.IS_READ_ONLY);
1304 root.children.add(node1);
1307 node2.
addFlag(Flag.HAS_CHECKED_STATE);
1308 root.children.add(node2);
1314 AccessibilityNodeInfo rootInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
1315 assertFalse(rootInfo.isFocusable());
1316 AccessibilityNodeInfo node1Info = accessibilityBridge.createAccessibilityNodeInfo(1);
1317 assertFalse(node1Info.isFocusable());
1318 AccessibilityNodeInfo node2Info = accessibilityBridge.createAccessibilityNodeInfo(2);
1319 assertTrue(node2Info.isFocusable());
1328 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1329 View mockRootView = mock(View.class);
1330 Context context = mock(Context.class);
1331 Resources
resource = mock(Resources.class);
1332 Configuration config =
new Configuration();
1333 config.fontWeightAdjustment = 300;
1335 when(mockRootView.getContext()).thenReturn(context);
1336 when(mockRootView.getResources()).thenReturn(
resource);
1337 when(
resource.getConfiguration()).thenReturn(config);
1348 verify(mockChannel).setAccessibilityFeatures(1 << 3);
1358 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1359 View mockRootView = mock(View.class);
1360 Context context = mock(Context.class);
1361 when(mockRootView.getContext()).thenReturn(context);
1362 when(context.getPackageName()).thenReturn(
"test");
1366 accessibilityChannel,
1372 ViewParent mockParent = mock(ViewParent.class);
1373 when(mockRootView.getParent()).thenReturn(mockParent);
1374 when(mockManager.isEnabled()).thenReturn(
true);
1378 root.label =
"root";
1385 this.accessibilityBridge = accessibilityBridge;
1389 public boolean verified =
false;
1391 public boolean verify(InvocationOnMock invocation) {
1392 AccessibilityEvent
event = (AccessibilityEvent) invocation.getArguments()[1];
1393 assertEquals(
event.getEventType(), AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
1396 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
1397 assertTrue(nodeInfo.isAccessibilityFocused());
1402 Verifier verifier =
new Verifier(accessibilityBridge);
1403 when(mockParent.requestSendAccessibilityEvent(
eq(mockRootView),
any(AccessibilityEvent.class)))
1404 .thenAnswer(invocation -> verifier.verify(invocation));
1405 accessibilityBridge.performAction(0, AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS,
null);
1406 assertTrue(verifier.verified);
1408 HashMap<String, Object>
message =
new HashMap<>();
1409 message.put(
"type",
"didGainFocus");
1411 verify(mockChannel).send(
message);
1420 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1421 View mockRootView = mock(View.class);
1422 Context context = mock(Context.class);
1423 when(mockRootView.getContext()).thenReturn(context);
1424 when(context.getPackageName()).thenReturn(
"test");
1428 accessibilityChannel,
1434 ViewParent mockParent = mock(ViewParent.class);
1435 when(mockRootView.getParent()).thenReturn(mockParent);
1436 when(mockManager.isEnabled()).thenReturn(
true);
1440 root.label =
"root";
1445 accessibilityBridge.performAction(0, AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS,
null);
1446 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
1447 assertTrue(nodeInfo.isAccessibilityFocused());
1448 HashMap<String, Object>
message =
new HashMap<>();
1449 message.put(
"type",
"didGainFocus");
1451 verify(mockChannel).send(
message);
1455 this.accessibilityBridge = accessibilityBridge;
1459 public boolean verified =
false;
1461 public boolean verify(InvocationOnMock invocation) {
1462 AccessibilityEvent
event = (AccessibilityEvent) invocation.getArguments()[1];
1464 event.getEventType(), AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED);
1467 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
1468 assertFalse(nodeInfo.isAccessibilityFocused());
1473 Verifier verifier =
new Verifier(accessibilityBridge);
1474 when(mockParent.requestSendAccessibilityEvent(
eq(mockRootView),
any(AccessibilityEvent.class)))
1475 .thenAnswer(invocation -> verifier.verify(invocation));
1476 accessibilityBridge.performAction(
1477 0, AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS,
null);
1478 assertTrue(verifier.verified);
1485 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1486 View mockRootView = mock(View.class);
1487 Context context = mock(Context.class);
1488 when(mockRootView.getContext()).thenReturn(context);
1489 when(context.getPackageName()).thenReturn(
"test");
1499 ViewParent mockParent = mock(ViewParent.class);
1500 when(mockRootView.getParent()).thenReturn(mockParent);
1501 when(mockManager.isEnabled()).thenReturn(
true);
1507 node1.value =
"some text";
1508 node1.textSelectionBase = 0;
1509 node1.textSelectionExtent = 0;
1511 root.children.add(node1);
1514 Bundle bundle =
new Bundle();
1516 AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
1517 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD);
1518 bundle.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN,
false);
1519 accessibilityBridge.performAction(
1520 1, AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY, bundle);
1521 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(1);
1523 assertEquals(nodeInfo.getTextSelectionStart(), 9);
1524 assertEquals(nodeInfo.getTextSelectionEnd(), 9);
1526 bundle =
new Bundle();
1528 AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
1529 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD);
1530 bundle.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN,
false);
1531 accessibilityBridge.performAction(
1532 1, AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, bundle);
1533 nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(1);
1535 assertEquals(nodeInfo.getTextSelectionStart(), 5);
1536 assertEquals(nodeInfo.getTextSelectionEnd(), 5);
1543 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1544 View mockRootView = mock(View.class);
1545 Context context = mock(Context.class);
1546 when(mockRootView.getContext()).thenReturn(context);
1547 when(context.getPackageName()).thenReturn(
"test");
1557 ViewParent mockParent = mock(ViewParent.class);
1558 when(mockRootView.getParent()).thenReturn(mockParent);
1559 when(mockManager.isEnabled()).thenReturn(
true);
1565 node1.value =
"some text";
1566 node1.textSelectionBase = 0;
1567 node1.textSelectionExtent = 0;
1569 root.children.add(node1);
1572 Bundle bundle =
new Bundle();
1574 AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
1575 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER);
1576 bundle.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN,
false);
1577 accessibilityBridge.performAction(
1578 1, AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY, bundle);
1579 ArgumentCaptor<AccessibilityEvent> eventCaptor =
1580 ArgumentCaptor.forClass(AccessibilityEvent.class);
1581 verify(mockParent,
times(2))
1582 .requestSendAccessibilityEvent(
eq(mockRootView), eventCaptor.capture());
1583 AccessibilityEvent
event = eventCaptor.getAllValues().get(1);
1584 assertEquals(
event.getEventType(), AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED);
1585 assertEquals(
event.getText().toString(),
"[" + node1.
value +
"]");
1586 assertEquals(
event.getFromIndex(), 1);
1587 assertEquals(
event.getToIndex(), 1);
1588 assertEquals(
event.getItemCount(), node1.
value.length());
1595 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1596 View mockRootView = mock(View.class);
1597 Context context = mock(Context.class);
1598 when(mockRootView.getContext()).thenReturn(context);
1599 when(context.getPackageName()).thenReturn(
"test");
1609 ViewParent mockParent = mock(ViewParent.class);
1610 when(mockRootView.getParent()).thenReturn(mockParent);
1611 when(mockManager.isEnabled()).thenReturn(
true);
1617 node1.value =
"some text";
1618 node1.textSelectionBase = 0;
1619 node1.textSelectionExtent = 0;
1621 root.children.add(node1);
1624 Bundle bundle =
new Bundle();
1626 AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
1627 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER);
1628 bundle.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN,
false);
1629 accessibilityBridge.performAction(
1630 1, AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, bundle);
1631 ArgumentCaptor<AccessibilityEvent> eventCaptor =
1632 ArgumentCaptor.forClass(AccessibilityEvent.class);
1633 verify(mockParent,
times(1))
1634 .requestSendAccessibilityEvent(
eq(mockRootView), eventCaptor.capture());
1635 assertEquals(eventCaptor.getAllValues().size(), 1);
1636 AccessibilityEvent
event = eventCaptor.getAllValues().get(0);
1637 assertNotEquals(
event.getEventType(), AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED);
1644 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1645 View mockRootView = mock(View.class);
1646 Context context = mock(Context.class);
1647 when(mockRootView.getContext()).thenReturn(context);
1648 when(context.getPackageName()).thenReturn(
"test");
1658 ViewParent mockParent = mock(ViewParent.class);
1659 when(mockRootView.getParent()).thenReturn(mockParent);
1660 when(mockManager.isEnabled()).thenReturn(
true);
1666 node1.value =
"ä½ å¥½ å—Ž";
1667 node1.textSelectionBase = 0;
1668 node1.textSelectionExtent = 0;
1670 root.children.add(node1);
1673 Bundle bundle =
new Bundle();
1675 AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
1676 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD);
1677 bundle.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN,
false);
1678 accessibilityBridge.performAction(
1679 1, AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY, bundle);
1680 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(1);
1682 assertEquals(nodeInfo.getTextSelectionStart(), 3);
1683 assertEquals(nodeInfo.getTextSelectionEnd(), 3);
1685 bundle =
new Bundle();
1687 AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
1688 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD);
1689 bundle.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN,
false);
1690 accessibilityBridge.performAction(
1691 1, AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, bundle);
1692 nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(1);
1694 assertEquals(nodeInfo.getTextSelectionStart(), 2);
1695 assertEquals(nodeInfo.getTextSelectionEnd(), 2);
1702 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1703 View mockRootView = mock(View.class);
1704 Context context = mock(Context.class);
1705 when(mockRootView.getContext()).thenReturn(context);
1706 when(context.getPackageName()).thenReturn(
"test");
1716 ViewParent mockParent = mock(ViewParent.class);
1717 when(mockRootView.getParent()).thenReturn(mockParent);
1718 when(mockManager.isEnabled()).thenReturn(
true);
1724 node1.value =
"How are you\nI am fine\nThank you";
1726 node1.textSelectionBase = 14;
1727 node1.textSelectionExtent = 14;
1729 root.children.add(node1);
1732 Bundle bundle =
new Bundle();
1734 AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
1735 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
1736 bundle.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN,
false);
1737 accessibilityBridge.performAction(
1738 1, AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY, bundle);
1739 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(1);
1741 assertEquals(nodeInfo.getTextSelectionStart(), 21);
1742 assertEquals(nodeInfo.getTextSelectionEnd(), 21);
1744 bundle =
new Bundle();
1746 AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
1747 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
1748 bundle.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN,
false);
1749 accessibilityBridge.performAction(
1750 1, AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, bundle);
1751 nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(1);
1753 assertEquals(nodeInfo.getTextSelectionStart(), 11);
1754 assertEquals(nodeInfo.getTextSelectionEnd(), 11);
1761 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1762 View mockRootView = mock(View.class);
1763 Context context = mock(Context.class);
1764 when(mockRootView.getContext()).thenReturn(context);
1765 when(context.getPackageName()).thenReturn(
"test");
1775 ViewParent mockParent = mock(ViewParent.class);
1776 when(mockRootView.getParent()).thenReturn(mockParent);
1777 when(mockManager.isEnabled()).thenReturn(
true);
1783 node1.value =
"some text";
1784 node1.textSelectionBase = 0;
1785 node1.textSelectionExtent = 0;
1787 root.children.add(node1);
1790 Bundle bundle =
new Bundle();
1792 AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
1793 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER);
1794 bundle.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN,
false);
1795 accessibilityBridge.performAction(
1796 1, AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY, bundle);
1797 AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(1);
1798 assertEquals(nodeInfo.getTextSelectionStart(), 1);
1799 assertEquals(nodeInfo.getTextSelectionEnd(), 1);
1801 bundle =
new Bundle();
1803 AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
1804 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER);
1805 bundle.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN,
false);
1806 accessibilityBridge.performAction(
1807 1, AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, bundle);
1808 nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(1);
1809 assertEquals(nodeInfo.getTextSelectionStart(), 0);
1810 assertEquals(nodeInfo.getTextSelectionEnd(), 0);
1816 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1817 View mockRootView = mock(View.class);
1818 Context context = mock(Context.class);
1819 when(mockRootView.getContext()).thenReturn(context);
1820 when(context.getPackageName()).thenReturn(
"test");
1822 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
1823 ViewParent mockParent = mock(ViewParent.class);
1824 when(mockRootView.getParent()).thenReturn(mockParent);
1825 when(mockManager.isEnabled()).thenReturn(
true);
1833 root.children.add(scopeRoute);
1837 verify(mockRootView,
times(1)).setAccessibilityPaneTitle(
eq(
" "));
1844 AccessibilityManager mockManager = mock(AccessibilityManager.class);
1845 View mockRootView = mock(View.class);
1846 Context context = mock(Context.class);
1847 when(mockRootView.getContext()).thenReturn(context);
1848 when(context.getPackageName()).thenReturn(
"test");
1850 setUpBridge(mockRootView, mockManager, mockViewEmbedder);
1856 platformView.id = 1;
1857 platformView.platformViewId = 42;
1858 root.children.add(platformView);
1863 accessibilityBridge.onAccessibilityHoverEvent(MotionEvent.obtain(1, 1, 1, -10, -10, 0));
1871 Context context = ApplicationProvider.getApplicationContext();
1872 View rootAccessibilityView =
new View(context);
1876 rootAccessibilityView,
1880 accessibilityViewEmbedder,
1881 accessibilityDelegate);
1887 platformView.id = 1;
1888 platformView.platformViewId = 1;
1889 root.addChild(platformView);
1897 View embeddedView = mock(View.class);
1901 AccessibilityNodeInfo nodeInfo = mock(AccessibilityNodeInfo.class);
1902 when(embeddedView.createAccessibilityNodeInfo()).thenReturn(nodeInfo);
1904 AccessibilityNodeInfo
result = accessibilityBridge.createAccessibilityNodeInfo(0);
1906 assertEquals(
result.getChildCount(), 1);
1907 assertEquals(
result.getClassName(),
"android.view.View");
1915 Context context = ApplicationProvider.getApplicationContext();
1916 View rootAccessibilityView =
new View(context);
1920 rootAccessibilityView,
1924 accessibilityViewEmbedder,
1925 accessibilityDelegate);
1931 platformView.id = 1;
1932 platformView.platformViewId = 1;
1933 root.addChild(platformView);
1935 View embeddedView = mock(View.class);
1942 verify(embeddedView).setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
1950 Context context = ApplicationProvider.getApplicationContext();
1951 View rootAccessibilityView =
new View(context);
1955 rootAccessibilityView,
1959 accessibilityViewEmbedder,
1960 accessibilityDelegate);
1963 rootWithPlatformView.id = 0;
1966 platformView.id = 1;
1967 platformView.platformViewId = 1;
1968 rootWithPlatformView.
addChild(platformView);
1970 View embeddedView = mock(View.class);
1978 rootWithoutPlatformView.id = 0;
1980 rootWithoutPlatformView.
toUpdate();
1983 verify(embeddedView)
1984 .setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
1998 accessibilityViewEmbedder,
1999 accessibilityDelegate);
2002 platformView.platformViewId = 1;
2007 View embeddedView = mock(View.class);
2011 accessibilityBridge.createAccessibilityNodeInfo(0);
2012 verify(accessibilityViewEmbedder).getRootNode(
eq(embeddedView),
eq(0),
any(
Rect.class));
2018 AccessibilityManager mockManager = mock(AccessibilityManager.class);
2019 ContentResolver mockContentResolver = mock(ContentResolver.class);
2020 when(mockManager.isEnabled()).thenReturn(
true);
2022 setUpBridge(
null, mockChannel, mockManager, mockContentResolver,
null,
null);
2024 .setAccessibilityMessageHandler(
2026 ArgumentCaptor<AccessibilityManager.AccessibilityStateChangeListener> stateListenerCaptor =
2027 ArgumentCaptor.forClass(AccessibilityManager.AccessibilityStateChangeListener.class);
2028 ArgumentCaptor<AccessibilityManager.TouchExplorationStateChangeListener> touchListenerCaptor =
2029 ArgumentCaptor.forClass(AccessibilityManager.TouchExplorationStateChangeListener.class);
2030 verify(mockManager).addAccessibilityStateChangeListener(stateListenerCaptor.capture());
2031 verify(mockManager).addTouchExplorationStateChangeListener(touchListenerCaptor.capture());
2032 accessibilityBridge.release();
2033 verify(mockChannel).setAccessibilityMessageHandler(
null);
2035 stateListenerCaptor.getValue().onAccessibilityStateChanged(
true);
2036 verify(mockChannel, never()).onAndroidAccessibilityEnabled();
2037 touchListenerCaptor.getValue().onTouchExplorationStateChanged(
true);
2038 verify(mockChannel, never()).setAccessibilityFeatures(anyInt());
2043 AccessibilityManager mockManager = mock(AccessibilityManager.class);
2047 ContentResolver mockContentResolver = mock(ContentResolver.class);
2048 View mockRootView = mock(View.class);
2049 Context context = mock(Context.class);
2050 when(mockRootView.getContext()).thenReturn(context);
2051 when(context.getPackageName()).thenReturn(
"test");
2052 ViewParent mockParent = mock(ViewParent.class);
2053 when(mockRootView.getParent()).thenReturn(mockParent);
2054 when(mockManager.isEnabled()).thenReturn(
true);
2057 setUpBridge(mockRootView, accessibilityChannel, mockManager,
null,
null,
null);
2059 HashMap<String, Object> arguments =
new HashMap<>();
2060 arguments.put(
"type",
"focus");
2061 arguments.put(
"nodeId", 123);
2066 ArgumentCaptor<AccessibilityEvent> eventCaptor =
2067 ArgumentCaptor.forClass(AccessibilityEvent.class);
2068 verify(mockParent).requestSendAccessibilityEvent(
eq(mockRootView), eventCaptor.capture());
2069 AccessibilityEvent
event = eventCaptor.getAllValues().get(0);
2070 assertEquals(
event.getEventType(), AccessibilityEvent.TYPE_VIEW_FOCUSED);
2071 assertEquals(
event.getSource(),
null);
2076 AccessibilityManager mockManager = mock(AccessibilityManager.class);
2077 ContentResolver mockContentResolver = mock(ContentResolver.class);
2078 View mockRootView = mock(View.class);
2079 Context context = mock(Context.class);
2080 when(mockRootView.getContext()).thenReturn(context);
2081 when(context.getPackageName()).thenReturn(
"test");
2082 when(mockManager.isEnabled()).thenReturn(
true);
2083 ViewParent mockParent = mock(ViewParent.class);
2084 when(mockRootView.getParent()).thenReturn(mockParent);
2085 AccessibilityEvent mockEvent = mock(AccessibilityEvent.class);
2088 setUpBridge(mockRootView,
null, mockManager,
null,
null,
null);
2092 when(spyAccessibilityBridge.obtainAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED))
2093 .thenReturn(mockEvent);
2095 spyAccessibilityBridge.sendAccessibilityEvent(123, AccessibilityEvent.TYPE_VIEW_FOCUSED);
2097 verify(mockEvent).setPackageName(
"test");
2098 verify(mockEvent).setSource(
eq(mockRootView),
eq(123));
2102 return setUpBridge(
null,
null,
null,
null,
null,
null);
2106 View rootAccessibilityView,
2107 AccessibilityManager accessibilityManager,
2110 rootAccessibilityView,
null, accessibilityManager,
null, accessibilityViewEmbedder,
null);
2114 View rootAccessibilityView,
2116 AccessibilityManager accessibilityManager,
2117 ContentResolver contentResolver,
2120 if (rootAccessibilityView ==
null) {
2121 rootAccessibilityView = mock(View.class);
2122 Context context = mock(Context.class);
2123 when(rootAccessibilityView.getContext()).thenReturn(context);
2124 when(context.getPackageName()).thenReturn(
"test");
2126 if (accessibilityChannel ==
null) {
2129 if (accessibilityManager ==
null) {
2130 accessibilityManager = mock(AccessibilityManager.class);
2132 if (contentResolver ==
null) {
2133 contentResolver = mock(ContentResolver.class);
2135 if (accessibilityViewEmbedder ==
null) {
2138 if (platformViewsAccessibilityDelegate ==
null) {
2142 rootAccessibilityView,
2143 accessibilityChannel,
2144 accessibilityManager,
2146 accessibilityViewEmbedder,
2147 platformViewsAccessibilityDelegate);
2154 this.strings = strings;
2155 this.stringAttributeArgs = stringAttributeArgs;
2159 bridge.updateSemantics(
buffer, strings, stringAttributeArgs);
2171 private final int value;
2210 int maxValueLength = 0;
2211 int currentValueLength = 0;
2212 int textSelectionBase = 0;
2213 int textSelectionExtent = 0;
2214 int platformViewId = -1;
2215 int scrollChildren = 0;
2216 int scrollIndex = 0;
2217 float scrollPosition = 0.0f;
2218 float scrollExtentMax = 0.0f;
2219 float scrollExtentMin = 0.0f;
2221 String label =
null;
2225 String increasedValue =
null;
2227 String decreasedValue =
null;
2231 String tooltip =
null;
2232 int textDirection = 0;
2236 float bottom = 0.0f;
2239 1.0f, 0.0f, 0.0f, 0.0f,
2240 0.0f, 1.0f, 0.0f, 0.0f,
2241 0.0f, 0.0f, 1.0f, 0.0f,
2242 0.0f, 0.0f, 0.0f, 1.0f
2247 children.add(child);
2252 ArrayList<String> strings =
new ArrayList<String>();
2253 ByteBuffer bytes = ByteBuffer.allocate(1000);
2254 ArrayList<ByteBuffer> stringAttributeArgs =
new ArrayList<ByteBuffer>();
2255 addToBuffer(bytes, strings, stringAttributeArgs);
2259 strings.toArray(
new String[strings.size()]),
2260 stringAttributeArgs.toArray(
new ByteBuffer[stringAttributeArgs.size()]));
2264 ByteBuffer bytes, ArrayList<String> strings, ArrayList<ByteBuffer> stringAttributeArgs) {
2266 bytes.putInt(
flags);
2267 bytes.putInt(actions);
2268 bytes.putInt(maxValueLength);
2269 bytes.putInt(currentValueLength);
2270 bytes.putInt(textSelectionBase);
2271 bytes.putInt(textSelectionExtent);
2272 bytes.putInt(platformViewId);
2273 bytes.putInt(scrollChildren);
2274 bytes.putInt(scrollIndex);
2275 bytes.putFloat(scrollPosition);
2276 bytes.putFloat(scrollExtentMax);
2277 bytes.putFloat(scrollExtentMin);
2282 bytes.putInt(strings.size() - 1);
2284 updateString(label, labelAttributes, bytes, strings, stringAttributeArgs);
2285 updateString(
value, valueAttributes, bytes, strings, stringAttributeArgs);
2286 updateString(increasedValue, increasedValueAttributes, bytes, strings, stringAttributeArgs);
2287 updateString(decreasedValue, decreasedValueAttributes, bytes, strings, stringAttributeArgs);
2288 updateString(hint, hintAttributes, bytes, strings, stringAttributeArgs);
2289 if (tooltip ==
null) {
2292 strings.add(tooltip);
2293 bytes.putInt(strings.size() - 1);
2295 bytes.putInt(textDirection);
2296 bytes.putFloat(left);
2297 bytes.putFloat(top);
2298 bytes.putFloat(right);
2299 bytes.putFloat(bottom);
2301 for (
int i = 0;
i < 16;
i++) {
2305 bytes.putInt(children.size());
2307 bytes.putInt(node.id);
2311 bytes.putInt(node.id);
2317 node.addToBuffer(bytes, strings, stringAttributeArgs);
2326 ArrayList<String> strings,
2327 ArrayList<ByteBuffer> stringAttributeArgs) {
2328 if (
value ==
null) {
2332 bytes.putInt(strings.size() - 1);
2335 if (attributes ==
null || attributes.isEmpty()) {
2339 bytes.putInt(attributes.size());
2341 bytes.putInt(attribute.start);
2342 bytes.putInt(attribute.end);
2343 bytes.putInt(attribute.type.getValue());
2344 switch (attribute.type) {
2349 bytes.putInt(stringAttributeArgs.size());
2351 stringAttributeArgs.add(Charset.forName(
"UTF-8").encode(localeAttribute.
locale));
static SkISize times(const SkISize &size, float factor)
static bool eq(const SkM44 &a, const SkM44 &b, float tol)
static SkString resource(SkPDFResourceType type, int index)
final BasicMessageChannel.MessageHandler< Object > parsingMessageHandler
void addFlag(AccessibilityBridge.Flag flag)
List< TestStringAttribute > increasedValueAttributes
void addChild(TestSemanticsNode child)
final List< TestSemanticsNode > children
List< TestStringAttribute > valueAttributes
void addToBuffer(ByteBuffer bytes, ArrayList< String > strings, ArrayList< ByteBuffer > stringAttributeArgs)
List< TestStringAttribute > labelAttributes
void addAction(AccessibilityBridge.Action action)
List< TestStringAttribute > hintAttributes
TestSemanticsUpdate toUpdate()
List< TestStringAttribute > decreasedValueAttributes
The encoding for semantics is described in platform_view_android.cc.
TestSemanticsUpdate(ByteBuffer buffer, String[] strings, ByteBuffer[] stringAttributeArgs)
final ByteBuffer[] stringAttributeArgs
void sendUpdateToBridge(AccessibilityBridge bridge)
TestStringAttributeType type
void itPerformsClearAccessibilityFocusCorrectly()
void itSetsNodeImportantForAccessibilityIfItHasActions()
void itSetsNodeImportantForAccessibilityIfItHasContent()
void itCanPerformSetText()
void itSetsNodeUnImportantForAccessibilityIfItIsEmpty()
void itProducesPlatformViewNodeForVirtualDisplay()
void itDescribesTextFieldsWithTextAndHint()
void itSetsFocusabilityBasedOnFlagsCorrectly()
void itDescribesNonTextFieldsWithAContentDescription()
void itMakesPlatformViewImportantForAccessibility()
void itDoesNotContainADescriptionIfScopesRoute()
void itAnnouncesWhiteSpaceWhenNoNamesRoute()
void itSetsAccessibleNavigation()
void itSetsTraversalAfter()
void itCanCreateAccessibilityNodeInfoWithSetText()
void itSetCutoutInsetBasedonLayoutModeAlways()
void itSetsTooltipCorrectly()
void itClearsFocusedNodeBeforeSendingEvent()
void itSetsFocusedNodeBeforeSendingEvent()
void itAnnouncesRouteNameWhenRemoveARoute()
AccessibilityBridge setUpBridge(View rootAccessibilityView, AccessibilityManager accessibilityManager, AccessibilityViewEmbedder accessibilityViewEmbedder)
void itCanPredictCursorMovementsWithGranularityWordUnicode()
void itUnfocusesPlatformViewWhenPlatformViewGoesAway()
AccessibilityBridge setUpBridge()
void itHoverOverOutOfBoundsDoesNotCrash()
void itDoesNotFireSelectionEventWhenPredictCursorMovementsDoesNotChangeSelection()
void itSetCutoutInsetBasedonLayoutModeNever()
void itSetsRootViewNotImportantForAccessibility()
static void updateString(String value, List< TestStringAttribute > attributes, ByteBuffer bytes, ArrayList< String > strings, ArrayList< ByteBuffer > stringAttributeArgs)
void itProducesPlatformViewNodeForHybridComposition()
void itBuildsAttributedString()
void itSetCutoutInsetBasedonLayoutModeShortEdges()
void itCanPredictCursorMovementsWithGranularityWord()
AccessibilityBridge setUpBridge(View rootAccessibilityView, AccessibilityChannel accessibilityChannel, AccessibilityManager accessibilityManager, ContentResolver contentResolver, AccessibilityViewEmbedder accessibilityViewEmbedder, PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate)
void itCanPredictCursorMovementsWithGranularityCharacter()
void itIgnoresUnfocusableNodeDuringHitTest()
void itSetsBoldTextFlagCorrectly()
void itTakesGlobalCoordinatesOfFlutterViewIntoAccount()
void itIgnoresPlatformViewsDuringHoverIfRequested()
void itAlsoFireSelectionEventWhenPredictCursorMovements()
void itMakesPlatformViewNoImportantForAccessibility()
void itSetCutoutInsetBasedonLayoutModeDefault()
void sendFocusAccessibilityEvent()
void SetSourceAndPackageNameForAccessibilityEvent()
void itSetsIdentifierCorrectly()
void itCanPredictSetText()
void itFindsPlatformViewsDuringHoverByDefault()
void itCanPredictCursorMovementsWithGranularityLine()
void itAnnouncesRouteNameWhenAddingNewRoute()
void itCanPredictSetSelection()
void itSetsTextCorrectly()
void releaseDropsChannelMessageHandler()
boolean getAccessibleNavigation()
Integer getRecordFlutterId( @NonNull View embeddedView, @NonNull AccessibilityRecord record)
boolean requestSendAccessibilityEvent( @NonNull View embeddedView, @NonNull View eventOrigin, @NonNull AccessibilityEvent event)
static SkString identifier(const FontFamilyDesc &family, const FontDesc &font)
FlutterSemanticsFlag flag
FlutterSemanticsFlag flags
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
SIT bool any(const Vec< 1, T > &x)
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)