@@ -657,6 +657,137 @@ public void showTextInput_textInputTypeNone() {
657
657
}
658
658
659
659
// -------- Start: Autofill Tests -------
660
+ @ Test
661
+ public void autofill_enabledByDefault () {
662
+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .O ) {
663
+ return ;
664
+ }
665
+ FlutterView testView = new FlutterView (RuntimeEnvironment .application );
666
+ TextInputChannel textInputChannel = new TextInputChannel (mock (DartExecutor .class ));
667
+ TextInputPlugin textInputPlugin =
668
+ new TextInputPlugin (testView , textInputChannel , mock (PlatformViewsController .class ));
669
+ final TextInputChannel .Configuration .Autofill autofill =
670
+ new TextInputChannel .Configuration .Autofill (
671
+ "1" , new String [] {}, null , new TextInputChannel .TextEditState ("" , 0 , 0 , -1 , -1 ));
672
+
673
+ final TextInputChannel .Configuration config =
674
+ new TextInputChannel .Configuration (
675
+ false ,
676
+ false ,
677
+ true ,
678
+ true ,
679
+ TextInputChannel .TextCapitalization .NONE ,
680
+ null ,
681
+ null ,
682
+ null ,
683
+ autofill ,
684
+ null );
685
+
686
+ textInputPlugin .setTextInputClient (
687
+ 0 ,
688
+ new TextInputChannel .Configuration (
689
+ false ,
690
+ false ,
691
+ true ,
692
+ true ,
693
+ TextInputChannel .TextCapitalization .NONE ,
694
+ null ,
695
+ null ,
696
+ null ,
697
+ autofill ,
698
+ new TextInputChannel .Configuration [] {config }));
699
+
700
+ final ViewStructure viewStructure = mock (ViewStructure .class );
701
+ final ViewStructure [] children = {mock (ViewStructure .class ), mock (ViewStructure .class )};
702
+
703
+ when (viewStructure .newChild (anyInt ()))
704
+ .thenAnswer (invocation -> children [(int ) invocation .getArgument (0 )]);
705
+
706
+ textInputPlugin .onProvideAutofillVirtualStructure (viewStructure , 0 );
707
+
708
+ verify (viewStructure ).newChild (0 );
709
+
710
+ verify (children [0 ]).setAutofillId (any (), eq ("1" .hashCode ()));
711
+ verify (children [0 ]).setAutofillHints (aryEq (new String [] {}));
712
+ verify (children [0 ]).setDimens (anyInt (), anyInt (), anyInt (), anyInt (), gt (0 ), gt (0 ));
713
+ }
714
+
715
+ @ Test
716
+ public void autofill_canBeDisabled () {
717
+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .O ) {
718
+ return ;
719
+ }
720
+ FlutterView testView = new FlutterView (RuntimeEnvironment .application );
721
+ TextInputChannel textInputChannel = new TextInputChannel (mock (DartExecutor .class ));
722
+ TextInputPlugin textInputPlugin =
723
+ new TextInputPlugin (testView , textInputChannel , mock (PlatformViewsController .class ));
724
+ final TextInputChannel .Configuration .Autofill autofill =
725
+ new TextInputChannel .Configuration .Autofill (
726
+ "1" , new String [] {}, null , new TextInputChannel .TextEditState ("" , 0 , 0 , -1 , -1 ));
727
+
728
+ final TextInputChannel .Configuration config =
729
+ new TextInputChannel .Configuration (
730
+ false ,
731
+ false ,
732
+ true ,
733
+ true ,
734
+ TextInputChannel .TextCapitalization .NONE ,
735
+ null ,
736
+ null ,
737
+ null ,
738
+ null ,
739
+ null );
740
+
741
+ textInputPlugin .setTextInputClient (0 , config );
742
+
743
+ final ViewStructure viewStructure = mock (ViewStructure .class );
744
+
745
+ textInputPlugin .onProvideAutofillVirtualStructure (viewStructure , 0 );
746
+
747
+ verify (viewStructure , times (0 )).newChild (anyInt ());
748
+ }
749
+
750
+ @ Test
751
+ public void autofill_hintText () {
752
+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .O ) {
753
+ return ;
754
+ }
755
+ FlutterView testView = new FlutterView (RuntimeEnvironment .application );
756
+ TextInputChannel textInputChannel = new TextInputChannel (mock (DartExecutor .class ));
757
+ TextInputPlugin textInputPlugin =
758
+ new TextInputPlugin (testView , textInputChannel , mock (PlatformViewsController .class ));
759
+ final TextInputChannel .Configuration .Autofill autofill =
760
+ new TextInputChannel .Configuration .Autofill (
761
+ "1" ,
762
+ new String [] {},
763
+ "placeholder" ,
764
+ new TextInputChannel .TextEditState ("" , 0 , 0 , -1 , -1 ));
765
+
766
+ final TextInputChannel .Configuration config =
767
+ new TextInputChannel .Configuration (
768
+ false ,
769
+ false ,
770
+ true ,
771
+ true ,
772
+ TextInputChannel .TextCapitalization .NONE ,
773
+ null ,
774
+ null ,
775
+ null ,
776
+ autofill ,
777
+ null );
778
+
779
+ textInputPlugin .setTextInputClient (0 , config );
780
+
781
+ final ViewStructure viewStructure = mock (ViewStructure .class );
782
+ final ViewStructure [] children = {mock (ViewStructure .class ), mock (ViewStructure .class )};
783
+
784
+ when (viewStructure .newChild (anyInt ()))
785
+ .thenAnswer (invocation -> children [(int ) invocation .getArgument (0 )]);
786
+
787
+ textInputPlugin .onProvideAutofillVirtualStructure (viewStructure , 0 );
788
+ verify (children [0 ]).setHint ("placeholder" );
789
+ }
790
+
660
791
@ Test
661
792
public void autofill_onProvideVirtualViewStructure () {
662
793
if (Build .VERSION .SDK_INT < Build .VERSION_CODES .O ) {
@@ -669,11 +800,15 @@ public void autofill_onProvideVirtualViewStructure() {
669
800
new TextInputPlugin (testView , textInputChannel , mock (PlatformViewsController .class ));
670
801
final TextInputChannel .Configuration .Autofill autofill1 =
671
802
new TextInputChannel .Configuration .Autofill (
672
- "1" , new String [] {"HINT1" }, new TextInputChannel .TextEditState ("" , 0 , 0 , -1 , -1 ));
803
+ "1" ,
804
+ new String [] {"HINT1" },
805
+ "placeholder1" ,
806
+ new TextInputChannel .TextEditState ("" , 0 , 0 , -1 , -1 ));
673
807
final TextInputChannel .Configuration .Autofill autofill2 =
674
808
new TextInputChannel .Configuration .Autofill (
675
809
"2" ,
676
810
new String [] {"HINT2" , "EXTRA" },
811
+ null ,
677
812
new TextInputChannel .TextEditState ("" , 0 , 0 , -1 , -1 ));
678
813
679
814
final TextInputChannel .Configuration config1 =
@@ -729,10 +864,12 @@ public void autofill_onProvideVirtualViewStructure() {
729
864
verify (children [0 ]).setAutofillId (any (), eq ("1" .hashCode ()));
730
865
verify (children [0 ]).setAutofillHints (aryEq (new String [] {"HINT1" }));
731
866
verify (children [0 ]).setDimens (anyInt (), anyInt (), anyInt (), anyInt (), gt (0 ), gt (0 ));
867
+ verify (children [0 ]).setHint ("placeholder1" );
732
868
733
869
verify (children [1 ]).setAutofillId (any (), eq ("2" .hashCode ()));
734
870
verify (children [1 ]).setAutofillHints (aryEq (new String [] {"HINT2" , "EXTRA" }));
735
871
verify (children [1 ]).setDimens (anyInt (), anyInt (), anyInt (), anyInt (), gt (0 ), gt (0 ));
872
+ verify (children [1 ], times (0 )).setHint (any ());
736
873
}
737
874
738
875
@ Test
@@ -747,7 +884,10 @@ public void autofill_onProvideVirtualViewStructure_single() {
747
884
new TextInputPlugin (testView , textInputChannel , mock (PlatformViewsController .class ));
748
885
final TextInputChannel .Configuration .Autofill autofill =
749
886
new TextInputChannel .Configuration .Autofill (
750
- "1" , new String [] {"HINT1" }, new TextInputChannel .TextEditState ("" , 0 , 0 , -1 , -1 ));
887
+ "1" ,
888
+ new String [] {"HINT1" },
889
+ "placeholder" ,
890
+ new TextInputChannel .TextEditState ("" , 0 , 0 , -1 , -1 ));
751
891
752
892
// Autofill should still work without AutofillGroup.
753
893
textInputPlugin .setTextInputClient (
@@ -776,6 +916,7 @@ public void autofill_onProvideVirtualViewStructure_single() {
776
916
777
917
verify (children [0 ]).setAutofillId (any (), eq ("1" .hashCode ()));
778
918
verify (children [0 ]).setAutofillHints (aryEq (new String [] {"HINT1" }));
919
+ verify (children [0 ]).setHint ("placeholder" );
779
920
// Verifies that the child has a non-zero size.
780
921
verify (children [0 ]).setDimens (anyInt (), anyInt (), anyInt (), anyInt (), gt (0 ), gt (0 ));
781
922
}
@@ -796,11 +937,15 @@ public void autofill_testLifeCycle() {
796
937
// Set up an autofill scenario with 2 fields.
797
938
final TextInputChannel .Configuration .Autofill autofill1 =
798
939
new TextInputChannel .Configuration .Autofill (
799
- "1" , new String [] {"HINT1" }, new TextInputChannel .TextEditState ("" , 0 , 0 , -1 , -1 ));
940
+ "1" ,
941
+ new String [] {"HINT1" },
942
+ "placeholder1" ,
943
+ new TextInputChannel .TextEditState ("" , 0 , 0 , -1 , -1 ));
800
944
final TextInputChannel .Configuration .Autofill autofill2 =
801
945
new TextInputChannel .Configuration .Autofill (
802
946
"2" ,
803
947
new String [] {"HINT2" , "EXTRA" },
948
+ null ,
804
949
new TextInputChannel .TextEditState ("" , 0 , 0 , -1 , -1 ));
805
950
806
951
final TextInputChannel .Configuration config1 =
@@ -921,11 +1066,13 @@ public void autofill_testAutofillUpdatesTheFramework() {
921
1066
new TextInputChannel .Configuration .Autofill (
922
1067
"1" ,
923
1068
new String [] {"HINT1" },
1069
+ null ,
924
1070
new TextInputChannel .TextEditState ("field 1" , 0 , 0 , -1 , -1 ));
925
1071
final TextInputChannel .Configuration .Autofill autofill2 =
926
1072
new TextInputChannel .Configuration .Autofill (
927
1073
"2" ,
928
1074
new String [] {"HINT2" , "EXTRA" },
1075
+ null ,
929
1076
new TextInputChannel .TextEditState ("field 2" , 0 , 0 , -1 , -1 ));
930
1077
931
1078
final TextInputChannel .Configuration config1 =
@@ -1008,11 +1155,15 @@ public void autofill_testSetTextIpnutClientUpdatesSideFields() {
1008
1155
// Set up an autofill scenario with 2 fields.
1009
1156
final TextInputChannel .Configuration .Autofill autofill1 =
1010
1157
new TextInputChannel .Configuration .Autofill (
1011
- "1" , new String [] {"HINT1" }, new TextInputChannel .TextEditState ("" , 0 , 0 , -1 , -1 ));
1158
+ "1" ,
1159
+ new String [] {"HINT1" },
1160
+ "null" ,
1161
+ new TextInputChannel .TextEditState ("" , 0 , 0 , -1 , -1 ));
1012
1162
final TextInputChannel .Configuration .Autofill autofill2 =
1013
1163
new TextInputChannel .Configuration .Autofill (
1014
1164
"2" ,
1015
1165
new String [] {"HINT2" , "EXTRA" },
1166
+ "null" ,
1016
1167
new TextInputChannel .TextEditState (
1017
1168
"Unfocused fields need love like everything does" , 0 , 0 , -1 , -1 ));
1018
1169
0 commit comments