@@ -225,9 +225,9 @@ describe('firefox.remote', () => {
225
225
226
226
describe ( 'installTemporaryAddon' , ( ) => {
227
227
228
- it ( 'throws listTabs errors' , async ( ) => {
228
+ it ( 'throws getRoot errors' , async ( ) => {
229
229
const client = fakeFirefoxClient ( {
230
- // listTabs response:
230
+ // listTabs and getRoot response:
231
231
requestError : new Error ( 'some listTabs error' ) ,
232
232
} ) ;
233
233
const conn = makeInstance ( client ) ;
@@ -236,24 +236,33 @@ describe('firefox.remote', () => {
236
236
. catch ( onlyInstancesOf ( WebExtError , ( error ) => {
237
237
assert . match ( error . message , / s o m e l i s t T a b s e r r o r / ) ;
238
238
} ) ) ;
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' ) ;
239
244
} ) ;
240
245
241
246
it ( 'fails when there is no add-ons actor' , async ( ) => {
242
247
const client = fakeFirefoxClient ( {
243
- // A listTabs response that does not contain addonsActor.
248
+ // A getRoot and listTabs response that does not contain addonsActor.
244
249
requestResult : { } ,
245
250
} ) ;
246
251
const conn = makeInstance ( client ) ;
247
252
await conn . installTemporaryAddon ( '/path/to/addon' )
248
253
. then ( makeSureItFails ( ) )
249
254
. 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 / ) ;
251
258
} ) ) ;
259
+ sinon . assert . calledOnce ( client . request ) ;
260
+ sinon . assert . calledWith ( client . request , 'getRoot' ) ;
252
261
} ) ;
253
262
254
263
it ( 'lets you install an add-on temporarily' , async ( ) => {
255
264
const client = fakeFirefoxClient ( {
256
- // listTabs response:
265
+ // getRoot response:
257
266
requestResult : {
258
267
addonsActor : 'addons1.actor.conn' ,
259
268
} ,
@@ -265,6 +274,58 @@ describe('firefox.remote', () => {
265
274
const conn = makeInstance ( client ) ;
266
275
const response = await conn . installTemporaryAddon ( '/path/to/addon' ) ;
267
276
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' ) ;
268
329
} ) ;
269
330
270
331
it ( 'throws install errors' , async ( ) => {
0 commit comments