@@ -43,21 +43,36 @@ describe('TtmlTextParser', () => {
4343 // When xml:space="default", ignore whitespace outside tags.
4444 verifyHelper (
4545 [
46- { start : 62.03 , end : 62.05 , payload : 'A B C' } ,
46+ {
47+ start : 62.03 ,
48+ end : 62.05 ,
49+ nestedCues : [ { payload : 'A B C' } ] ,
50+ payload : '' ,
51+ } ,
4752 ] ,
4853 '<tt xml:space="default">' + ttBody + '</tt>' ,
4954 { periodStart : 0 , segmentStart : 0 , segmentEnd : 0 } ) ;
5055 // When xml:space="preserve", take them into account.
5156 verifyHelper (
5257 [
53- { start : 62.03 , end : 62.05 , payload : '\n A B C \n ' } ,
58+ {
59+ start : 62.03 ,
60+ end : 62.05 ,
61+ nestedCues : [ { payload : '\n A B C \n ' } ] ,
62+ payload : '' ,
63+ } ,
5464 ] ,
5565 '<tt xml:space="preserve">' + ttBody + '</tt>' ,
5666 { periodStart : 0 , segmentStart : 0 , segmentEnd : 0 } ) ;
5767 // The default value for xml:space is "default".
5868 verifyHelper (
5969 [
60- { start : 62.03 , end : 62.05 , payload : 'A B C' } ,
70+ {
71+ start : 62.03 ,
72+ end : 62.05 ,
73+ nestedCues : [ { payload : 'A B C' } ] ,
74+ payload : '' ,
75+ } ,
6176 ] ,
6277 '<tt>' + ttBody + '</tt>' ,
6378 { periodStart : 0 , segmentStart : 0 , segmentEnd : 0 } ) ;
@@ -78,6 +93,25 @@ describe('TtmlTextParser', () => {
7893 '<tt><body><p begin="3.45" end="1a"></p></body></tt>' ) ;
7994 } ) ;
8095
96+ it ( 'supports spans as nestedCues of paragraphs' , ( ) => {
97+ verifyHelper (
98+ [
99+ {
100+ start : 62.05 ,
101+ end : 3723.2 ,
102+ payload : '' ,
103+ nestedCues : [
104+ { payload : 'First cue' } ,
105+ { payload : '' , spacer : true } ,
106+ { payload : 'Second cuee' } ,
107+ ] ,
108+ } ,
109+ ] ,
110+ '<tt><body><p begin="01:02.05" end="01:02:03.200">' +
111+ '<span>First cue</span><br /><span>Second cue</span></p></body></tt>' ,
112+ { periodStart : 0 , segmentStart : 0 , segmentEnd : 0 } ) ;
113+ } ) ;
114+
81115 it ( 'supports colon formatted time' , ( ) => {
82116 verifyHelper (
83117 [
@@ -645,7 +679,12 @@ describe('TtmlTextParser', () => {
645679 { periodStart : 0 , segmentStart : 0 , segmentEnd : 0 } ) ;
646680 verifyHelper (
647681 [
648- { start : 62.05 , end : 3723.2 , payload : 'Line1\nLine2' } ,
682+ {
683+ start : 62.05 ,
684+ end : 3723.2 ,
685+ nestedCues : [ { payload : 'Line1\nLine2' } ] ,
686+ payload : '' ,
687+ } ,
649688 ] ,
650689 '<tt><body><p begin="01:02.05" ' +
651690 'end="01:02:03.200"><span>Line1<br/>Line2</span></p></body></tt>' ,
@@ -801,32 +840,48 @@ describe('TtmlTextParser', () => {
801840 const result = new shaka . text . TtmlTextParser ( ) . parseMedia ( data , time ) ;
802841 const properties = [ 'textAlign' , 'lineAlign' , 'positionAlign' , 'size' ,
803842 'line' , 'position' , 'direction' , 'color' , 'writingMode' ,
804- 'backgroundColor' , 'fontWeight' , 'fontFamily' ,
843+ 'backgroundColor' , 'fontWeight' , 'fontFamily' , 'spacer' ,
805844 'wrapLine' , 'lineHeight' , 'fontStyle' , 'fontSize' ] ;
806845 expect ( result ) . toBeTruthy ( ) ;
807846 expect ( result . length ) . toBe ( cues . length ) ;
847+
808848 for ( let i = 0 ; i < cues . length ; i ++ ) {
809- expect ( result [ i ] . startTime ) . toBeCloseTo ( cues [ i ] . start , 3 ) ;
810- expect ( result [ i ] . endTime ) . toBeCloseTo ( cues [ i ] . end , 3 ) ;
811- expect ( result [ i ] . payload ) . toBe ( cues [ i ] . payload ) ;
849+ const cue = cues [ i ] ;
850+ const resultCue = result [ i ] ;
851+
852+ expect ( resultCue . startTime ) . toBeCloseTo ( cue . start , 3 ) ;
853+ expect ( resultCue . endTime ) . toBeCloseTo ( cue . end , 3 ) ;
854+ expect ( resultCue . payload ) . toBe ( cue . payload ) ;
812855
813- if ( cues [ i ] . region ) {
814- verifyRegion ( cues [ i ] . region , result [ i ] . region ) ;
856+ if ( cue . region ) {
857+ verifyRegion ( cue . region , resultCue . region ) ;
815858 }
816859
817- const asObj = /** @type {!Object } */ ( result [ i ] ) ;
860+ const asObj = /** @type {!Object } */ ( resultCue ) ;
818861 for ( const property of properties ) {
819- if ( property in cues [ i ] ) {
820- expect ( asObj [ property ] ) . toEqual ( cues [ i ] [ property ] ) ;
862+ if ( property in cue ) {
863+ expect ( asObj [ property ] ) . toEqual ( cue [ property ] ) ;
821864 }
822865 }
823866
824- if ( cues [ i ] . textDecoration ) {
825- for ( let j = 0 ; j < cues [ i ] . textDecoration . length ; j ++ ) {
826- expect ( /** @type {? } */ ( result [ i ] ) . textDecoration [ j ] )
827- . toBe ( cues [ i ] . textDecoration [ j ] ) ;
867+ if ( cue . textDecoration ) {
868+ for ( let j = 0 ; j < cue . textDecoration . length ; j ++ ) {
869+ expect ( /** @type {? } */ ( resultCue ) . textDecoration [ j ] )
870+ . toBe ( cue . textDecoration [ j ] ) ;
828871 }
829872 }
873+
874+ const resultCueChildren = resultCue . nestedCues ;
875+ const expectedCueChildren = cue . nestedCues ;
876+
877+ expect ( resultCueChildren . length ) . toBe ( expectedCueChildren ) ;
878+ for ( let k = 0 ; k < expectedCueChildren . length ; k ++ ) {
879+ const expectedCueChild = expectedCueChildren [ k ] ;
880+ const resultCueChild = resultCueChildren [ k ] ;
881+
882+ expect ( resultCueChild . payload ) . toBe ( expectedCueChild . payload ) ;
883+ expect ( resultCueChild . spacer ) . toBe ( expectedCueChild . spacer ) ;
884+ }
830885 }
831886 }
832887
0 commit comments