@@ -3,6 +3,7 @@ import fc from 'fast-check';
33import { buildAndroidIntentArgs } from './intent-arguments.ts' ;
44
55const ACTION_ARGS = [ '-a' , 'android.settings.SETTINGS' ] ;
6+ const PROPERTY_RUNS = 100 ;
67
78test . each ( [
89 {
@@ -15,6 +16,11 @@ test.each([
1516 args : [ '-S' , '--selector' , '-a' , 'com.example.VIEW' , '--display' , '0' , '-p' , 'com.example' ] ,
1617 intentArgs : [ '--selector' , '-a' , 'com.example.VIEW' , '-p' , 'com.example' ] ,
1718 } ,
19+ {
20+ name : 'MIME type retained by AOSP across a selector' ,
21+ args : [ '-t' , 'text/plain' , '--selector' , '-d' , 'content://example/item' , '-S' ] ,
22+ intentArgs : [ '-t' , 'text/plain' , '--selector' , '-d' , 'content://example/item' ] ,
23+ } ,
1824 {
1925 name : 'positional component and unparsed trailing tokens' ,
2026 args : [ '-S' , 'com.example/.Main' , '--display' , '0' ] ,
@@ -38,6 +44,9 @@ test.each([
3844 [ '-R' ] ,
3945 [ '--es' , 'key' ] ,
4046 [ '-Sattached' ] ,
47+ [ '--display' , 'not-a-number' ] ,
48+ [ '-R--display' ] ,
49+ [ '-d' , 'content://example/item' , '--selector' , '-t' , 'text/plain' ] ,
4150 [ 'intent:#Intent;scheme=content;end' ] ,
4251] ) ( 'unprojectable launch arguments retain unknown ownership: %j' , ( ...args ) => {
4352 expect ( buildAndroidIntentArgs ( 'android.settings.SETTINGS' , args ) ) . toEqual ( {
@@ -52,6 +61,17 @@ const flagLikeValueArb = fc.oneof(
5261 fc . string ( { maxLength : 40 } ) ,
5362 fc . constantFrom ( '-S' , '-R' , '--display' , '--user' , '--selector' , '--' , '' ) ,
5463) ;
64+ const integerLaunchFlagArb = fc . constantFrom (
65+ '--sampling' ,
66+ '--profiler-output-version' ,
67+ '-R' ,
68+ '--display' ,
69+ '--task-display-area-feature-id' ,
70+ '--windowingMode' ,
71+ '--activityType' ,
72+ '--task' ,
73+ '--allow-fgs-start-reason' ,
74+ ) ;
5575const argumentGroupArb : fc . Arbitrary < ArgumentGroup > = fc . oneof (
5676 fc
5777 . tuple ( fc . constantFrom ( '-a' , '-d' , '-t' , '-i' , '-c' , '-p' ) , flagLikeValueArb )
@@ -67,8 +87,18 @@ const argumentGroupArb: fc.Arbitrary<ArgumentGroup> = fc.oneof(
6787 . tuple ( fc . constantFrom ( '-P' , '--attach-agent' ) , flagLikeValueArb )
6888 . map < ArgumentGroup > ( ( tokens ) => ( { role : 'launch' , tokens } ) ) ,
6989 fc
70- . tuple ( fc . constantFrom ( '-R' , '--display' ) , fc . nat ( { max : 20 } ) )
71- . map < ArgumentGroup > ( ( [ flag , value ] ) => ( { role : 'launch' , tokens : [ flag , String ( value ) ] } ) ) ,
90+ . tuple (
91+ integerLaunchFlagArb ,
92+ fc . oneof (
93+ fc . integer ( { min : - 2147483648 , max : 2147483647 } ) . map ( String ) ,
94+ fc . constantFrom ( '+0' , '-0' , '0001' , '2147483647' , '-2147483648' , '٠١' , '02' ) ,
95+ ) ,
96+ fc . boolean ( ) ,
97+ )
98+ . map < ArgumentGroup > ( ( [ flag , value , attached ] ) => ( {
99+ role : 'launch' ,
100+ tokens : flag === '-R' && attached ? [ flag + value ] : [ flag , value ] ,
101+ } ) ) ,
72102) ;
73103
74104test ( 'intent projection preserves whole argument groups while launch preserves the original stream' , ( ) => {
@@ -85,5 +115,24 @@ test('intent projection preserves whole argument groups while launch preserves t
85115 resolutionArgs : [ ...ACTION_ARGS , ...intentArgs ] ,
86116 } ) ;
87117 } ) ,
118+ { numRuns : PROPERTY_RUNS } ,
119+ ) ;
120+ } ) ;
121+
122+ test ( 'invalid native integer launch controls keep ownership unknown, including in selectors' , ( ) => {
123+ fc . assert (
124+ fc . property (
125+ integerLaunchFlagArb ,
126+ fc . constantFrom ( '' , '+' , '--display' , '1.0' , '0x10' , ' 1' , '2147483648' , '-2147483649' , '𝟙' ) ,
127+ fc . array ( argumentGroupArb , { maxLength : 10 } ) ,
128+ ( flag , value , groups ) => {
129+ const args = [ ...groups . flatMap ( ( group ) => group . tokens ) , '--selector' , flag , value ] ;
130+ expect ( buildAndroidIntentArgs ( 'android.settings.SETTINGS' , args ) ) . toEqual ( {
131+ launchArgs : [ ...ACTION_ARGS , ...args ] ,
132+ resolutionArgs : undefined ,
133+ } ) ;
134+ } ,
135+ ) ,
136+ { numRuns : PROPERTY_RUNS } ,
88137 ) ;
89138} ) ;
0 commit comments