@@ -13,6 +13,7 @@ import {
1313 createFakeStdin ,
1414 getFakeFirefox ,
1515 getFakeRemoteFirefox ,
16+ ZipFile ,
1617} from '../helpers.js' ;
1718
1819// Fake result for client.installTemporaryAddon().then(installResult => ...)
@@ -35,6 +36,9 @@ const fakeRDPUnixSocketFile =
3536const fakeRDPUnixAbstractSocketFile =
3637 '@org.mozilla.firefox/firefox-debugger-socket' ;
3738
39+ // The actual XPI, xpiFileName in src/extension-runners/firefox-android.js
40+ const helperXpiName = 'web-ext-internal-helper-to-open-start-urls.xpi' ;
41+
3842// Reduce the waiting time during tests.
3943FirefoxAndroidExtensionRunner . unixSocketDiscoveryRetryInterval = 0 ;
4044
@@ -833,6 +837,84 @@ describe('util/extension-runners/firefox-android', () => {
833837 sinon . assert . calledOnce ( anotherCallback ) ;
834838 } ) ;
835839
840+ it ( 'opens a single URL when specified via --start-url' , async ( ) => {
841+ const { params, fakeADBUtils } = prepareSelectedDeviceAndAPKParams ( ) ;
842+ params . startUrl = 'https://example.com/' ;
843+
844+ let pushedBackgroundJs ;
845+ fakeADBUtils . pushFile = sinon . spy ( async ( _ , localZipPath ) => {
846+ if ( localZipPath . includes ( helperXpiName ) ) {
847+ const zipFile = new ZipFile ( ) ;
848+ await zipFile . open ( localZipPath ) ;
849+ pushedBackgroundJs = await zipFile . getAsText ( 'background.js' ) ;
850+ await zipFile . close ( ) ;
851+ }
852+ } ) ;
853+
854+ const runnerInstance = new FirefoxAndroidExtensionRunner ( params ) ;
855+ await runnerInstance . run ( ) ;
856+
857+ const { installTemporaryAddon } = runnerInstance . remoteFirefox ;
858+
859+ sinon . assert . calledTwice ( installTemporaryAddon ) ;
860+
861+ sinon . assert . calledWithMatch (
862+ installTemporaryAddon ,
863+ `${ runnerInstance . selectedArtifactsDir } /${ builtFileName } .xpi` ,
864+ ) ;
865+
866+ sinon . assert . calledWithMatch (
867+ installTemporaryAddon ,
868+ `${ runnerInstance . selectedArtifactsDir } /${ helperXpiName } ` ,
869+ ) ;
870+ sinon . assert . calledWithMatch (
871+ fakeADBUtils . pushFile ,
872+ 'emulator-1' ,
873+ sinon . match ( / \b w e b - e x t - i n t e r n a l - h e l p e r - t o - o p e n - s t a r t - u r l s \. x p i $ / ) ,
874+ `${ runnerInstance . selectedArtifactsDir } /${ helperXpiName } ` ,
875+ ) ;
876+ assert . include ( pushedBackgroundJs , '["https://example.com/"]' ) ;
877+ } ) ;
878+
879+ it ( 'opens a multiple URL when specified via --start-url' , async ( ) => {
880+ const { params, fakeADBUtils } = prepareSelectedDeviceAndAPKParams ( ) ;
881+ params . startUrl = [ 'about:blank' , 'http://localhost' ] ;
882+
883+ let pushedBackgroundJs ;
884+ fakeADBUtils . pushFile = sinon . spy ( async ( _ , localZipPath ) => {
885+ if ( localZipPath . includes ( helperXpiName ) ) {
886+ const zipFile = new ZipFile ( ) ;
887+ await zipFile . open ( localZipPath ) ;
888+ pushedBackgroundJs = await zipFile . getAsText ( 'background.js' ) ;
889+ await zipFile . close ( ) ;
890+ }
891+ } ) ;
892+
893+ const runnerInstance = new FirefoxAndroidExtensionRunner ( params ) ;
894+ await runnerInstance . run ( ) ;
895+
896+ sinon . assert . calledWithMatch (
897+ fakeADBUtils . pushFile ,
898+ 'emulator-1' ,
899+ sinon . match ( / \b w e b - e x t - i n t e r n a l - h e l p e r - t o - o p e n - s t a r t - u r l s \. x p i $ / ) ,
900+ `${ runnerInstance . selectedArtifactsDir } /${ helperXpiName } ` ,
901+ ) ;
902+ assert . include ( pushedBackgroundJs , '["about:blank","http://localhost"]' ) ;
903+ } ) ;
904+
905+ it ( 'does not install helper extension without --start-url' , async ( ) => {
906+ const { params } = prepareSelectedDeviceAndAPKParams ( ) ;
907+
908+ const runnerInstance = new FirefoxAndroidExtensionRunner ( params ) ;
909+ await runnerInstance . run ( ) ;
910+
911+ const { installTemporaryAddon } = runnerInstance . remoteFirefox ;
912+ sinon . assert . calledOnce ( installTemporaryAddon ) ;
913+ const seenPath = installTemporaryAddon . firstCall . args [ 0 ] ;
914+ assert . include ( seenPath , '.xpi' ) ;
915+ assert . notInclude ( seenPath , helperXpiName ) ;
916+ } ) ;
917+
836918 it ( 'logs warnings on the unsupported CLI options' , async ( ) => {
837919 const params = prepareSelectedDeviceAndAPKParams ( ) ;
838920
@@ -856,10 +938,6 @@ describe('util/extension-runners/firefox-android', () => {
856938 params : { preInstall : true } ,
857939 expectedMessage : / A n d r o i d t a r g e t d o e s n o t s u p p o r t - - p r e - i n s t a l l / ,
858940 } ,
859- {
860- params : { startUrl : 'http://fake-start-url.org' } ,
861- expectedMessage : / A n d r o i d t a r g e t d o e s n o t s u p p o r t - - s t a r t - u r l / ,
862- } ,
863941 {
864942 params : { args : [ '-headless=false' ] } ,
865943 expectedMessage : / A n d r o i d t a r g e t d o e s n o t s u p p o r t - - a r g s / ,
0 commit comments