@@ -363,7 +363,7 @@ describe('WebDriver', function() {
363363 return driver . getSession ( ) . then ( v => assert . strictEqual ( v , aSession ) ) ;
364364 } ) ;
365365
366- it ( 'handles desired and requried capabilities' , function ( ) {
366+ it ( 'handles desired and required capabilities' , function ( ) {
367367 let aSession = new Session ( SESSION_ID , { 'browserName' : 'firefox' } ) ;
368368 let executor = new FakeExecutor ( ) .
369369 expect ( CName . NEW_SESSION ) .
@@ -392,6 +392,23 @@ describe('WebDriver', function() {
392392 return driver . getSession ( ) . then ( fail , assertIsStubError ) ;
393393 } ) ;
394394
395+ it ( 'invokes quit callback if it fails to create a session' , function ( ) {
396+ let called = false ;
397+ let executor = new FakeExecutor ( )
398+ . expect ( CName . NEW_SESSION )
399+ . withParameters ( { 'desiredCapabilities' : { 'browserName' : 'firefox' } } )
400+ . andReturnError ( new StubError ( ) )
401+ . end ( ) ;
402+
403+ var driver =
404+ WebDriver . createSession ( executor , { 'browserName' : 'firefox' } ,
405+ null , null , ( ) => called = true ) ;
406+ return driver . getSession ( ) . then ( fail , err => {
407+ assert . ok ( called ) ;
408+ assertIsStubError ( err ) ;
409+ } ) ;
410+ } ) ;
411+
395412 it ( 'usesActiveFlowByDefault' , function ( ) {
396413 let executor = new FakeExecutor ( ) .
397414 expect ( CName . NEW_SESSION ) .
@@ -420,6 +437,37 @@ describe('WebDriver', function() {
420437
421438 return waitForIdle ( otherFlow ) ;
422439 } ) ;
440+
441+ describe ( 'creation failures bubble up in control flow' , function ( ) {
442+ function runTest ( ...args ) {
443+ let executor = new FakeExecutor ( )
444+ . expect ( CName . NEW_SESSION )
445+ . withParameters ( { 'desiredCapabilities' : { 'browserName' : 'firefox' } } )
446+ . andReturnError ( new StubError ( ) )
447+ . end ( ) ;
448+
449+ WebDriver . createSession (
450+ executor , { 'browserName' : 'firefox' } , ...args ) ;
451+ return waitForAbort ( ) . then ( assertIsStubError ) ;
452+ }
453+
454+ it ( 'no onQuit callback' , ( ) => runTest ( ) ) ;
455+ it ( 'has onQuit callback' , ( ) => runTest ( null , null , function ( ) { } ) ) ;
456+
457+ it ( 'onQuit callback failure suppress creation failure' , function ( ) {
458+ let e = new Error ( 'hi!' ) ;
459+ let executor = new FakeExecutor ( )
460+ . expect ( CName . NEW_SESSION )
461+ . withParameters ( { 'desiredCapabilities' : { 'browserName' : 'firefox' } } )
462+ . andReturnError ( new StubError ( ) )
463+ . end ( ) ;
464+
465+ WebDriver . createSession (
466+ executor , { 'browserName' : 'firefox' } , null , null ,
467+ ( ) => { throw e } ) ;
468+ return waitForAbort ( ) . then ( err => assert . strictEqual ( err , e ) ) ;
469+ } ) ;
470+ } ) ;
423471 } ) ;
424472 } ) ;
425473
0 commit comments