@@ -1537,7 +1537,7 @@ void _testIncrementables() {
1537
1537
};
1538
1538
1539
1539
pumpSemantics (isFocused: false );
1540
- final DomElement element = semantics ().debugSemanticsTree! [0 ]! .element.querySelector ('input' )! ;
1540
+ final DomElement element = owner ().debugSemanticsTree! [0 ]! .element.querySelector ('input' )! ;
1541
1541
expect (capturedActions, isEmpty);
1542
1542
1543
1543
pumpSemantics (isFocused: true );
@@ -1905,7 +1905,7 @@ void _testCheckables() {
1905
1905
};
1906
1906
1907
1907
pumpSemantics (isFocused: false );
1908
- final DomElement element = semantics ().debugSemanticsTree! [0 ]! .element;
1908
+ final DomElement element = owner ().debugSemanticsTree! [0 ]! .element;
1909
1909
expect (capturedActions, isEmpty);
1910
1910
1911
1911
pumpSemantics (isFocused: true );
@@ -1914,9 +1914,17 @@ void _testCheckables() {
1914
1914
]);
1915
1915
capturedActions.clear ();
1916
1916
1917
+ // The framework removes focus from the widget (i.e. "blurs" it). Since the
1918
+ // blurring is initiated by the framework, there's no need to send any
1919
+ // notifications back to the framework about it.
1917
1920
pumpSemantics (isFocused: false );
1918
1921
expect (capturedActions, isEmpty);
1919
1922
1923
+ // If the element is blurred by the browser, then we do want to notify the
1924
+ // framework. This is because screen reader can be focused on something
1925
+ // other than what the framework is focused on, and notifying the framework
1926
+ // about the loss of focus on a node is information that the framework did
1927
+ // not have before.
1920
1928
element.blur ();
1921
1929
expect (capturedActions, < CapturedAction > [
1922
1930
(0 , ui.SemanticsAction .didLoseAccessibilityFocus, null ),
@@ -2081,7 +2089,7 @@ void _testTappable() {
2081
2089
};
2082
2090
2083
2091
pumpSemantics (isFocused: false );
2084
- final DomElement element = semantics ().debugSemanticsTree! [0 ]! .element;
2092
+ final DomElement element = owner ().debugSemanticsTree! [0 ]! .element;
2085
2093
expect (capturedActions, isEmpty);
2086
2094
2087
2095
pumpSemantics (isFocused: true );
@@ -2874,7 +2882,7 @@ void _testDialog() {
2874
2882
});
2875
2883
2876
2884
// Test the simple scenario of a dialog coming up and containing focusable
2877
- // descentants that are not initially focused. The expectation is that the
2885
+ // descendants that are not initially focused. The expectation is that the
2878
2886
// first descendant will be auto-focused.
2879
2887
test ('focuses on the first unfocused Focusable' , () async {
2880
2888
semantics ()
@@ -2886,14 +2894,16 @@ void _testDialog() {
2886
2894
capturedActions.add ((event.nodeId, event.type, event.arguments));
2887
2895
};
2888
2896
2889
- final SemanticsTester tester = SemanticsTester (semantics ());
2897
+ final SemanticsTester tester = SemanticsTester (owner ());
2890
2898
tester.updateNode (
2891
2899
id: 0 ,
2892
2900
scopesRoute: true ,
2893
2901
transform: Matrix4 .identity ().toFloat64 (),
2894
2902
children: < SemanticsNodeUpdate > [
2895
2903
tester.updateNode (
2896
2904
id: 1 ,
2905
+ // None of the children should have isFocused set to `true` to make
2906
+ // sure that the auto-focus logic kicks in.
2897
2907
children: < SemanticsNodeUpdate > [
2898
2908
tester.updateNode (
2899
2909
id: 2 ,
@@ -2934,7 +2944,7 @@ void _testDialog() {
2934
2944
});
2935
2945
2936
2946
// Test the scenario of a dialog coming up and containing focusable
2937
- // descentants with one of them explicitly requesting focus. The expectation
2947
+ // descendants with one of them explicitly requesting focus. The expectation
2938
2948
// is that the dialog will not attempt to auto-focus on anything and let the
2939
2949
// respective descendant take focus.
2940
2950
test ('does nothing if a descendant asks for focus explicitly' , () async {
@@ -2947,7 +2957,7 @@ void _testDialog() {
2947
2957
capturedActions.add ((event.nodeId, event.type, event.arguments));
2948
2958
};
2949
2959
2950
- final SemanticsTester tester = SemanticsTester (semantics ());
2960
+ final SemanticsTester tester = SemanticsTester (owner ());
2951
2961
tester.updateNode (
2952
2962
id: 0 ,
2953
2963
scopesRoute: true ,
@@ -2975,6 +2985,7 @@ void _testDialog() {
2975
2985
isEnabled: true ,
2976
2986
isButton: true ,
2977
2987
isFocusable: true ,
2988
+ // Asked for focus explicitly.
2978
2989
isFocused: true ,
2979
2990
rect: const ui.Rect .fromLTRB (0 , 0 , 100 , 50 ),
2980
2991
),
@@ -2995,8 +3006,8 @@ void _testDialog() {
2995
3006
});
2996
3007
2997
3008
// Test the scenario of a dialog coming up and containing non-focusable
2998
- // descentants that can have a11y focus. The expectation is that the first
2999
- // descendant will be auto-focused.
3009
+ // descendants that can have a11y focus. The expectation is that the first
3010
+ // descendant will be auto-focused, even if it's not input-focusable .
3000
3011
test ('focuses on the first non-focusable descedant' , () async {
3001
3012
semantics ()
3002
3013
..debugOverrideTimestampFunction (() => _testTime)
@@ -3007,7 +3018,7 @@ void _testDialog() {
3007
3018
capturedActions.add ((event.nodeId, event.type, event.arguments));
3008
3019
};
3009
3020
3010
- final SemanticsTester tester = SemanticsTester (semantics ());
3021
+ final SemanticsTester tester = SemanticsTester (owner ());
3011
3022
tester.updateNode (
3012
3023
id: 0 ,
3013
3024
scopesRoute: true ,
@@ -3043,7 +3054,7 @@ void _testDialog() {
3043
3054
expect (capturedActions, isEmpty);
3044
3055
3045
3056
// However, the element should have gotten the focus.
3046
- final DomElement element = semantics ().debugSemanticsTree! [2 ]! .element;
3057
+ final DomElement element = owner ().debugSemanticsTree! [2 ]! .element;
3047
3058
expect (element.tabIndex, - 1 );
3048
3059
expect (domDocument.activeElement, element);
3049
3060
@@ -3062,17 +3073,16 @@ void _testDialog() {
3062
3073
capturedActions.add ((event.nodeId, event.type, event.arguments));
3063
3074
};
3064
3075
3065
- final SemanticsTester tester = SemanticsTester (semantics ());
3076
+ final SemanticsTester tester = SemanticsTester (owner ());
3066
3077
tester.updateNode (
3067
3078
id: 0 ,
3068
3079
scopesRoute: true ,
3069
3080
transform: Matrix4 .identity ().toFloat64 (),
3070
3081
);
3071
3082
tester.apply ();
3072
3083
3073
- // The focused node is not focusable, so no notification is sent to the
3074
- // framework.
3075
3084
expect (capturedActions, isEmpty);
3085
+ expect (domDocument.activeElement, domDocument.body);
3076
3086
3077
3087
semantics ().semanticsEnabled = false ;
3078
3088
});
0 commit comments