@@ -225,9 +225,9 @@ describe('firefox.remote', () => {
225225
226226 describe ( 'installTemporaryAddon' , ( ) => {
227227
228- it ( 'throws listTabs errors' , async ( ) => {
228+ it ( 'throws getRoot errors' , async ( ) => {
229229 const client = fakeFirefoxClient ( {
230- // listTabs response:
230+ // listTabs and getRoot response:
231231 requestError : new Error ( 'some listTabs error' ) ,
232232 } ) ;
233233 const conn = makeInstance ( client ) ;
@@ -236,24 +236,33 @@ describe('firefox.remote', () => {
236236 . catch ( onlyInstancesOf ( WebExtError , ( error ) => {
237237 assert . match ( error . message , / s o m e l i s t T a b s e r r o r / ) ;
238238 } ) ) ;
239+
240+ // When getRoot fails, a fallback to listTabs is expected.
241+ sinon . assert . calledTwice ( client . request ) ;
242+ sinon . assert . calledWith ( client . request , 'getRoot' ) ;
243+ sinon . assert . calledWith ( client . request , 'listTabs' ) ;
239244 } ) ;
240245
241246 it ( 'fails when there is no add-ons actor' , async ( ) => {
242247 const client = fakeFirefoxClient ( {
243- // A listTabs response that does not contain addonsActor.
248+ // A getRoot and listTabs response that does not contain addonsActor.
244249 requestResult : { } ,
245250 } ) ;
246251 const conn = makeInstance ( client ) ;
247252 await conn . installTemporaryAddon ( '/path/to/addon' )
248253 . then ( makeSureItFails ( ) )
249254 . catch ( onlyInstancesOf ( RemoteTempInstallNotSupported , ( error ) => {
250- assert . match ( error . message , / d o e s n o t p r o v i d e a n a d d - o n s a c t o r / ) ;
255+ assert . match (
256+ error . message ,
257+ / T h i s v e r s i o n o f F i r e f o x d o e s n o t p r o v i d e a n a d d - o n s a c t o r / ) ;
251258 } ) ) ;
259+ sinon . assert . calledOnce ( client . request ) ;
260+ sinon . assert . calledWith ( client . request , 'getRoot' ) ;
252261 } ) ;
253262
254263 it ( 'lets you install an add-on temporarily' , async ( ) => {
255264 const client = fakeFirefoxClient ( {
256- // listTabs response:
265+ // getRoot response:
257266 requestResult : {
258267 addonsActor : 'addons1.actor.conn' ,
259268 } ,
@@ -265,6 +274,58 @@ describe('firefox.remote', () => {
265274 const conn = makeInstance ( client ) ;
266275 const response = await conn . installTemporaryAddon ( '/path/to/addon' ) ;
267276 assert . equal ( response . addon . id , 'abc123@temporary-addon' ) ;
277+
278+ // When called without error, there should not be any fallback.
279+ sinon . assert . calledOnce ( client . request ) ;
280+ sinon . assert . calledWith ( client . request , 'getRoot' ) ;
281+ } ) ;
282+
283+ it ( 'falls back to listTabs when getRoot is unavailable' , async ( ) => {
284+ const client = fakeFirefoxClient ( {
285+ // installTemporaryAddon response:
286+ makeRequestResult : {
287+ addon : { id : 'abc123@temporary-addon' } ,
288+ } ,
289+ } ) ;
290+ client . request = sinon . stub ( ) ;
291+ // Sample response from Firefox 49.
292+ client . request . withArgs ( 'getRoot' ) . callsArgWith ( 1 , {
293+ error : 'unrecognizedPacketType' ,
294+ message : 'Actor root does not recognize the packet type getRoot' ,
295+ } ) ;
296+ client . request . withArgs ( 'listTabs' ) . callsArgWith ( 1 , undefined , {
297+ addonsActor : 'addons1.actor.conn' ,
298+ } ) ;
299+ const conn = makeInstance ( client ) ;
300+ const response = await conn . installTemporaryAddon ( '/path/to/addon' ) ;
301+ assert . equal ( response . addon . id , 'abc123@temporary-addon' ) ;
302+
303+ sinon . assert . calledTwice ( client . request ) ;
304+ sinon . assert . calledWith ( client . request , 'getRoot' ) ;
305+ sinon . assert . calledWith ( client . request , 'listTabs' ) ;
306+ } ) ;
307+
308+ it ( 'fails when getRoot and listTabs both fail' , async ( ) => {
309+ const client = fakeFirefoxClient ( ) ;
310+ client . request = sinon . stub ( ) ;
311+ // Sample response from Firefox 48.
312+ client . request . withArgs ( 'getRoot' ) . callsArgWith ( 1 , {
313+ error : 'unrecognizedPacketType' ,
314+ message : 'Actor root does not recognize the packet type getRoot' ,
315+ } ) ;
316+ client . request . withArgs ( 'listTabs' ) . callsArgWith ( 1 , undefined , { } ) ;
317+ const conn = makeInstance ( client ) ;
318+ await conn . installTemporaryAddon ( '/path/to/addon' )
319+ . then ( makeSureItFails ( ) )
320+ . catch ( onlyInstancesOf ( RemoteTempInstallNotSupported , ( error ) => {
321+ assert . match (
322+ error . message ,
323+ / d o e s n o t p r o v i d e a n a d d - o n s a c t o r .* T r y F i r e f o x 4 9 / ) ;
324+ } ) ) ;
325+
326+ sinon . assert . calledTwice ( client . request ) ;
327+ sinon . assert . calledWith ( client . request , 'getRoot' ) ;
328+ sinon . assert . calledWith ( client . request , 'listTabs' ) ;
268329 } ) ;
269330
270331 it ( 'throws install errors' , async ( ) => {
0 commit comments