@@ -7,6 +7,46 @@ import 'package:flutter_test/flutter_test.dart';
77import '../testing.dart' ;
88
99void main () {
10+ group ('onFocusReceived' , () {
11+ testWidgets ('requests focus when the editor can receive focus' ,
12+ (tester) async {
13+ final editor = EditorSandBox (tester: tester);
14+ await editor.pump ();
15+
16+ final inputClient = getInputClient ();
17+ expect (editor.focusNode.hasFocus, isFalse);
18+
19+ expect (inputClient.onFocusReceived (), isTrue);
20+ await tester.pump ();
21+
22+ expect (editor.focusNode.hasFocus, isTrue);
23+ });
24+
25+ testWidgets ('returns false when the editor already has focus' ,
26+ (tester) async {
27+ final editor = EditorSandBox (tester: tester);
28+ await editor.pumpAndTap ();
29+
30+ final inputClient = getInputClient ();
31+
32+ expect (inputClient.onFocusReceived (), isFalse);
33+ expect (editor.focusNode.hasFocus, isTrue);
34+ });
35+
36+ testWidgets ('returns false when focus cannot be requested' , (tester) async {
37+ final focusNode = FocusNode (canRequestFocus: false );
38+ final editor = EditorSandBox (tester: tester, focusNode: focusNode);
39+ await editor.pump ();
40+
41+ final inputClient = getInputClient ();
42+
43+ expect (inputClient.onFocusReceived (), isFalse);
44+ await tester.pump ();
45+
46+ expect (focusNode.hasFocus, isFalse);
47+ });
48+ });
49+
1050 group ('send text editing state to TextInputConnection' , () {
1151 final composingRanges = < TextRange > [];
1252
0 commit comments