@@ -3,6 +3,7 @@ import { Breakpoint } from '../JerryBreakpoints';
33import { JerryDebugProtocolHandler } from '../JerryProtocolHandler' ;
44import * as assert from 'assert' ;
55import * as sinon from 'sinon' ;
6+ import { stringToCesu8 } from '../JerryUtils' ;
67
78// utility function
89function encodeArray ( byte : number , str : string ) {
@@ -14,14 +15,26 @@ function encodeArray(byte: number, str: string) {
1415 return array ;
1516}
1617
17- function setupHaltedProtocolHandler ( ) {
18+ function setupHaltedProtocolHandler ( isThereBreakpointHit : boolean = false ) {
1819 const debugClient = {
1920 send : sinon . spy ( ) ,
2021 } ;
2122 const handler = new JerryDebugProtocolHandler ( { } ) ;
2223 handler . debuggerClient = debugClient as any ;
2324 // For these tests mock the current breakpoint by setting the private lastBreakpointHit member:
24- ( handler as any ) . lastBreakpointHit = { } as Breakpoint ;
25+ if ( ! isThereBreakpointHit ) {
26+ ( handler as any ) . lastBreakpointHit = { } as Breakpoint ;
27+ } else {
28+ const bp : any = {
29+ activeIndex : 4 ,
30+ func : {
31+ byteCodeCP : 42 ,
32+ } ,
33+ offset : 10 ,
34+ } ;
35+
36+ ( handler as any ) . lastBreakpointHit = bp as Breakpoint ;
37+ }
2538 return { handler, debugClient } ;
2639}
2740
@@ -633,19 +646,19 @@ suite('JerryProtocolHandler', () => {
633646 const bp : any = { activeIndex : 3 } ;
634647 const handler = new JerryDebugProtocolHandler ( { } ) ;
635648 await handler . updateBreakpoint ( bp , true )
636- . catch ( error => {
637- assert . strictEqual ( ( < Error > error ) . message , 'breakpoint already enabled' ) ;
638- } ) ;
649+ . catch ( error => {
650+ assert . strictEqual ( ( < Error > error ) . message , 'breakpoint already enabled' ) ;
651+ } ) ;
639652 } ) ;
640653
641654 test ( 'throws on disabling inactive breakpoint' , async ( ) => {
642655 debugClient . send . resetHistory ( ) ;
643656 const bp : any = { activeIndex : - 1 } ;
644657 const handler = new JerryDebugProtocolHandler ( { } ) ;
645658 await handler . updateBreakpoint ( bp , false )
646- . catch ( error => {
647- assert . strictEqual ( ( < Error > error ) . message , 'breakpoint already disabled' ) ;
648- } ) ;
659+ . catch ( error => {
660+ assert . strictEqual ( ( < Error > error ) . message , 'breakpoint already disabled' ) ;
661+ } ) ;
649662 } ) ;
650663
651664 test ( 'enables inactive breakpoint successfully' , async ( ) => {
@@ -758,5 +771,106 @@ suite('JerryProtocolHandler', () => {
758771 handler . stepOver ( ) ;
759772 assert ( debugClient . send . withArgs ( Uint8Array . from ( [ SP . CLIENT . JERRY_DEBUGGER_NEXT ] ) ) ) ;
760773 } ) ;
774+
775+
776+ test ( 'sends the expected message when calling resume()' , ( ) => {
777+ const { handler, debugClient } = setupHaltedProtocolHandler ( ) ;
778+ handler . resume ( ) ;
779+ assert ( debugClient . send . withArgs ( Uint8Array . from ( [ SP . CLIENT . JERRY_DEBUGGER_CONTINUE ] ) ) ) ;
780+ } ) ;
781+
782+ test ( 'pause() throwing error when pausing at breakpoint' , async ( ) => {
783+ const { handler } = setupHaltedProtocolHandler ( true ) ;
784+ await handler . pause ( )
785+ . catch ( error => {
786+ assert . strictEqual ( ( < Error > error ) . message , 'attempted pause while at breakpoint' ) ;
787+ } ) ;
788+ } ) ;
789+
790+ test ( 'pause() sending the expected message' , ( ) => {
791+ const { handler, debugClient } = setupHaltedProtocolHandler ( ) ;
792+ handler . pause ( ) ;
793+ assert ( debugClient . send . withArgs ( Uint8Array . from ( [ SP . CLIENT . JERRY_DEBUGGER_STOP ] ) ) ) ;
794+ } ) ;
795+ } ) ;
796+
797+ suite ( 'getLastBreakpoint()' , ( ) => {
798+ test ( 'returns with the correct breakpoint' , ( ) => {
799+ const { handler } = setupHaltedProtocolHandler ( true ) ;
800+ const bp : any = {
801+ activeIndex : 4 ,
802+ func : {
803+ byteCodeCP : 42 ,
804+ } ,
805+ offset : 10 ,
806+ } ;
807+ assert . deepStrictEqual ( handler . getLastBreakpoint ( ) , bp ) ;
808+ } ) ;
809+ } ) ;
810+
811+ suite ( 'sendClientSourceControl()' , ( ) => {
812+ test ( 'throws if index is -1' , async ( ) => {
813+ const handler = new JerryDebugProtocolHandler ( { } ) ;
814+ await handler . sendClientSourceControl ( - 1 )
815+ . catch ( error => {
816+ assert . strictEqual ( ( < Error > error ) . message , 'Invalid source sending control code.' ) ;
817+ } ) ;
818+ } ) ;
819+
820+ test ( 'sends with correct args' , ( ) => {
821+ const { handler, debugClient } = setupHaltedProtocolHandler ( ) ;
822+ const defConfig = {
823+ cpointerSize : 2 ,
824+ littleEndian : true ,
825+ } ;
826+
827+ const altConfig = {
828+ cpointerSize : 4 ,
829+ littleEndian : true ,
830+ } ;
831+ handler . debuggerClient = debugClient as any ;
832+ handler . sendClientSourceControl ( 10 ) ;
833+ assert ( debugClient . send . withArgs ( defConfig , 'B' , 10 ) ) ;
834+ assert ( debugClient . send . withArgs ( altConfig , 'B' , 10 ) ) ;
835+ } ) ;
836+
837+ test ( 'sends with correct args2' , ( ) => {
838+ const { handler, debugClient } = setupHaltedProtocolHandler ( ) ;
839+ const defConfig = {
840+ cpointerSize : 2 ,
841+ littleEndian : false ,
842+ } ;
843+ const altConfig = {
844+ cpointerSize : 4 ,
845+ littleEndian : false ,
846+ } ;
847+ handler . debuggerClient = debugClient as any ;
848+ handler . sendClientSourceControl ( 10 ) ;
849+ assert ( debugClient . send . withArgs ( defConfig , 'B' , 10 ) ) ;
850+ assert ( debugClient . send . withArgs ( altConfig , 'B' , 10 ) ) ;
851+ } ) ;
852+ } ) ;
853+
854+ suite ( 'sendClientSource()' , ( ) => {
855+ test ( 'throws if waitForSource is not enabled' , async ( ) => {
856+ const handler = new JerryDebugProtocolHandler ( { } ) ;
857+ await handler . sendClientSource ( 'onelittlekitten' , 'and some more' )
858+ . catch ( error => {
859+ assert . strictEqual ( ( < Error > error ) . message , 'wait-for-source not enabled' ) ;
860+ } ) ;
861+ } ) ;
862+
863+ test ( 'if byteLength is less than maxMessageSize send the array' , ( ) => {
864+ const { handler, debugClient } = setupHaltedProtocolHandler ( ) ;
865+ const defConfig = {
866+ cpointerSize : 2 ,
867+ littleEndian : false ,
868+ } ;
869+ ( handler as any ) . maxMessageSize = 100 ;
870+ let array = stringToCesu8 ( `onelittlekitten\0and some more` , 5 , defConfig ) ;
871+ ( handler as any ) . onWaitForSource ( ) ;
872+ handler . sendClientSource ( 'onelittlekitten' , 'and some more' ) ;
873+ assert ( debugClient . send . withArgs ( array ) ) ;
874+ } ) ;
761875 } ) ;
762876} ) ;
0 commit comments