@@ -17,7 +17,8 @@ import { DEFAULT_OPTIONS } from 'common/services/OptionsService';
1717import { clone } from 'common/Clone' ;
1818import { BufferService } from 'common/services/BufferService' ;
1919import { CoreService } from 'common/services/CoreService' ;
20-
20+ import * as Base64 from 'common/Base64' ;
21+ import { ClipboardEventType , ClipboardSelectionType , IClipboardEvent } from 'xterm' ;
2122
2223function getCursor ( bufferService : IBufferService ) : number [ ] {
2324 return [
@@ -245,7 +246,7 @@ describe('InputHandler', () => {
245246 assert . equal ( coreService . decPrivateModes . bracketedPasteMode , false ) ;
246247 } ) ;
247248 } ) ;
248- describe ( 'regression tests' , function ( ) : void {
249+ describe ( 'regression tests' , function ( ) : void {
249250 function termContent ( bufferService : IBufferService , trim : boolean ) : string [ ] {
250251 const result = [ ] ;
251252 for ( let i = 0 ; i < bufferService . rows ; ++ i ) result . push ( bufferService . buffer . lines . get ( i ) ! . translateToString ( trim ) ) ;
@@ -1982,6 +1983,88 @@ describe('InputHandler', () => {
19821983 assert . deepEqual ( stack , [ [ { type : ColorRequestType . SET , index : 0 , color : [ 170 , 187 , 204 ] } , { type : ColorRequestType . SET , index : 123 , color : [ 0 , 17 , 34 ] } ] ] ) ;
19831984 stack . length = 0 ;
19841985 } ) ;
1986+ describe ( '52: manipulate selection data' , async ( ) => {
1987+ const testDataRaw = 'hello world' ;
1988+ const testDataB64 = Base64 . encode ( testDataRaw ) ;
1989+ beforeEach ( ( ) => {
1990+ optionsService . options . allowClipboardAccess = true ;
1991+ } ) ;
1992+
1993+ it ( '52: set invalid base64 clipboard string' , async ( ) => {
1994+ const stack : IClipboardEvent [ ] = [ ] ;
1995+ inputHandler . onClipboard ( ev => stack . push ( ev ) ) ;
1996+ await inputHandler . parseP ( `\x1b]52;c;${ testDataB64 } =\x07` ) ;
1997+ await inputHandler . parseP ( `\x1b]52;c;?\x07` ) ;
1998+ assert . deepEqual ( stack , [
1999+ {
2000+ type : ClipboardEventType . SET ,
2001+ selection : ClipboardSelectionType . CLIPBOARD
2002+ } ,
2003+ {
2004+
2005+ type : ClipboardEventType . QUERY ,
2006+ selection : ClipboardSelectionType . CLIPBOARD
2007+ }
2008+ ] ) ;
2009+ stack . length = 0 ;
2010+ } ) ;
2011+ it ( '52: set and query clipboard data' , async ( ) => {
2012+ const stack : IClipboardEvent [ ] = [ ] ;
2013+ inputHandler . onClipboard ( ev => stack . push ( ev ) ) ;
2014+ await inputHandler . parseP ( `\x1b]52;c;${ testDataB64 } \x07` ) ;
2015+ await inputHandler . parseP ( `\x1b]52;c;?\x07` ) ;
2016+ assert . deepEqual ( stack , [
2017+ {
2018+ type : ClipboardEventType . SET ,
2019+ selection : ClipboardSelectionType . CLIPBOARD ,
2020+ payload : testDataRaw
2021+ } ,
2022+ {
2023+
2024+ type : ClipboardEventType . QUERY ,
2025+ selection : ClipboardSelectionType . CLIPBOARD
2026+ }
2027+ ] ) ;
2028+ stack . length = 0 ;
2029+ } ) ;
2030+ it ( '52: clear clipboard data' , async ( ) => {
2031+ const stack : IClipboardEvent [ ] = [ ] ;
2032+ inputHandler . onClipboard ( ev => stack . push ( ev ) ) ;
2033+ await inputHandler . parseP ( `\x1b]52;c;!\x07` ) ;
2034+ await inputHandler . parseP ( `\x1b]52;c;?\x07` ) ;
2035+ assert . deepEqual ( stack , [
2036+ {
2037+ type : ClipboardEventType . SET ,
2038+ selection : ClipboardSelectionType . CLIPBOARD
2039+ } ,
2040+ {
2041+
2042+ type : ClipboardEventType . QUERY ,
2043+ selection : ClipboardSelectionType . CLIPBOARD
2044+ }
2045+ ] ) ;
2046+ stack . length = 0 ;
2047+ } ) ;
2048+ it ( '52: set primary clipboard data' , async ( ) => {
2049+ const stack : IClipboardEvent [ ] = [ ] ;
2050+ inputHandler . onClipboard ( ev => stack . push ( ev ) ) ;
2051+ await inputHandler . parseP ( `\x1b]52;p;${ testDataB64 } \x07` ) ;
2052+ await inputHandler . parseP ( `\x1b]52;p;?\x07` ) ;
2053+ assert . deepEqual ( stack , [
2054+ {
2055+ type : ClipboardEventType . SET ,
2056+ selection : ClipboardSelectionType . PRIMARY ,
2057+ payload : testDataRaw
2058+ } ,
2059+ {
2060+
2061+ type : ClipboardEventType . QUERY ,
2062+ selection : ClipboardSelectionType . PRIMARY
2063+ }
2064+ ] ) ;
2065+ stack . length = 0 ;
2066+ } ) ;
2067+ } ) ;
19852068 it ( '104: restore events' , async ( ) => {
19862069 const stack : IColorEvent [ ] = [ ] ;
19872070 inputHandler . onColor ( ev => stack . push ( ev ) ) ;
@@ -1994,7 +2077,7 @@ describe('InputHandler', () => {
19942077 stack . length = 0 ;
19952078 // full ANSI table restore
19962079 await inputHandler . parseP ( '\x1b]104\x07' ) ;
1997- assert . deepEqual ( stack , [ [ { type : ColorRequestType . RESTORE } ] ] ) ;
2080+ assert . deepEqual ( stack , [ [ { type : ColorRequestType . RESTORE } ] ] ) ;
19982081 } ) ;
19992082
20002083 it ( '10: FG set & query events' , async ( ) => {
0 commit comments