@@ -596,20 +596,54 @@ describe('getStartAppArgs', () => {
596596 expect ( spawnSpy ) . toHaveBeenCalledTimes ( 2 ) ;
597597 } ) ;
598598
599- it ( 'grants permissions to an app' , async ( ) => {
599+ it ( 'grants requested dangerous permissions to an app' , async ( ) => {
600600 const { grantPermissions } = await import ( '../adb.js' ) ;
601- const spawnSpy = vi . spyOn ( tools , 'spawn' ) ;
602- spawnSpy . mockResolvedValue ( {
603- stdout : '' ,
604- } as Awaited < ReturnType < typeof tools . spawn > > ) ;
601+ const spawnSpy = vi
602+ . spyOn ( tools , 'spawn' )
603+ . mockResolvedValueOnce ( {
604+ stdout : 'package:com.example.app\n' ,
605+ } as Awaited < ReturnType < typeof tools . spawn > > )
606+ . mockResolvedValueOnce ( {
607+ stdout : `requested permissions:\n android.permission.CAMERA\n android.permission.INTERNET\n android.permission.ACCESS_FINE_LOCATION\ninstall permissions:\n` ,
608+ } as Awaited < ReturnType < typeof tools . spawn > > )
609+ . mockResolvedValueOnce ( {
610+ stdout : `Dangerous Permissions:\n permission:android.permission.CAMERA\n permission:android.permission.ACCESS_FINE_LOCATION\n` ,
611+ } as Awaited < ReturnType < typeof tools . spawn > > )
612+ . mockResolvedValue ( {
613+ stdout : '' ,
614+ } as Awaited < ReturnType < typeof tools . spawn > > ) ;
605615
606- await grantPermissions ( 'emulator-5554' , 'com.example.app' , [
607- 'android.permission.CAMERA' ,
608- 'android.permission.RECORD_AUDIO' ,
609- ] ) ;
616+ await grantPermissions ( 'emulator-5554' , 'com.example.app' ) ;
610617
611- expect ( spawnSpy ) . toHaveBeenCalledTimes ( 2 ) ;
618+ expect ( spawnSpy ) . toHaveBeenCalledTimes ( 5 ) ;
612619 expect ( spawnSpy ) . toHaveBeenNthCalledWith ( 1 , expect . any ( String ) , [
620+ '-s' ,
621+ 'emulator-5554' ,
622+ 'shell' ,
623+ 'pm' ,
624+ 'list' ,
625+ 'packages' ,
626+ 'com.example.app' ,
627+ ] ) ;
628+ expect ( spawnSpy ) . toHaveBeenNthCalledWith ( 2 , expect . any ( String ) , [
629+ '-s' ,
630+ 'emulator-5554' ,
631+ 'shell' ,
632+ 'dumpsys' ,
633+ 'package' ,
634+ 'com.example.app' ,
635+ ] ) ;
636+ expect ( spawnSpy ) . toHaveBeenNthCalledWith ( 3 , expect . any ( String ) , [
637+ '-s' ,
638+ 'emulator-5554' ,
639+ 'shell' ,
640+ 'pm' ,
641+ 'list' ,
642+ 'permissions' ,
643+ '-g' ,
644+ '-d' ,
645+ ] ) ;
646+ expect ( spawnSpy ) . toHaveBeenNthCalledWith ( 4 , expect . any ( String ) , [
613647 '-s' ,
614648 'emulator-5554' ,
615649 'shell' ,
@@ -618,23 +652,33 @@ describe('getStartAppArgs', () => {
618652 'com.example.app' ,
619653 'android.permission.CAMERA' ,
620654 ] ) ;
621- expect ( spawnSpy ) . toHaveBeenNthCalledWith ( 2 , expect . any ( String ) , [
655+ expect ( spawnSpy ) . toHaveBeenNthCalledWith ( 5 , expect . any ( String ) , [
622656 '-s' ,
623657 'emulator-5554' ,
624658 'shell' ,
625659 'pm' ,
626660 'grant' ,
627661 'com.example.app' ,
628- 'android.permission.RECORD_AUDIO ' ,
662+ 'android.permission.ACCESS_FINE_LOCATION ' ,
629663 ] ) ;
630664 } ) ;
631665
632- it ( 'handles empty permission list when granting permissions' , async ( ) => {
666+ it ( 'does nothing when the app has no grantable dangerous permissions' , async ( ) => {
633667 const { grantPermissions } = await import ( '../adb.js' ) ;
634- const spawnSpy = vi . spyOn ( tools , 'spawn' ) ;
668+ const spawnSpy = vi
669+ . spyOn ( tools , 'spawn' )
670+ . mockResolvedValueOnce ( {
671+ stdout : 'package:com.example.app\n' ,
672+ } as Awaited < ReturnType < typeof tools . spawn > > )
673+ . mockResolvedValueOnce ( {
674+ stdout : `requested permissions:\n android.permission.INTERNET\ninstall permissions:\n` ,
675+ } as Awaited < ReturnType < typeof tools . spawn > > )
676+ . mockResolvedValueOnce ( {
677+ stdout : `Dangerous Permissions:\n permission:android.permission.CAMERA\n` ,
678+ } as Awaited < ReturnType < typeof tools . spawn > > ) ;
635679
636- await grantPermissions ( 'emulator-5554' , 'com.example.app' , [ ] ) ;
680+ await grantPermissions ( 'emulator-5554' , 'com.example.app' ) ;
637681
638- expect ( spawnSpy ) . not . toHaveBeenCalled ( ) ;
682+ expect ( spawnSpy ) . toHaveBeenCalledTimes ( 3 ) ;
639683 } ) ;
640684} ) ;
0 commit comments