@@ -60,3 +60,46 @@ QUnit.test('trigger "change" event when mode changes on a TextTrack', function(a
6060 ttl . removeTrack ( tt ) ;
6161 tech . dispose ( ) ;
6262} ) ;
63+
64+ QUnit . test ( 'toJSON' , function ( assert ) {
65+ const tech = new TechFaker ( ) ;
66+ const ttl = new TextTrackList ( [ ] ) ;
67+
68+ let textTrackListJSON = ttl . toJSON ( ) ;
69+
70+ assert . ok ( textTrackListJSON . length === 0 , 'an empty array is returned when the list is empty' ) ;
71+
72+ const tt1 = new TextTrack ( { tech} ) ;
73+
74+ ttl . addTrack ( tt1 ) ;
75+ textTrackListJSON = ttl . toJSON ( ) ;
76+
77+ assert . equal ( textTrackListJSON [ 0 ] . id , tt1 . id , 'text track in array of JSON should match the original track' ) ;
78+ assert . notOk ( textTrackListJSON [ 0 ] . tech_ , 'tech_ should not exist on the text track value in the JSON list' ) ;
79+
80+ const tt2 = new TextTrack ( { tech} ) ;
81+ const tt3 = new TextTrack ( { tech} ) ;
82+
83+ ttl . addTrack ( tt2 ) ;
84+ ttl . addTrack ( tt3 ) ;
85+ textTrackListJSON = ttl . toJSON ( ) ;
86+
87+ assert . equal ( textTrackListJSON [ 1 ] . id , tt2 . id , 'text track in second spot of array should match the original track' ) ;
88+ assert . equal ( textTrackListJSON [ 2 ] . id , tt3 . id , 'text track in third spot of array should match the original track' ) ;
89+ } ) ;
90+
91+ QUnit . test ( 'serialize' , function ( assert ) {
92+ const tech = new TechFaker ( ) ;
93+ const tt1 = new TextTrack ( { tech} ) ;
94+ const tt2 = new TextTrack ( { tech} ) ;
95+ const tt3 = new TextTrack ( { tech} ) ;
96+ const ttl = new TextTrackList ( [ tt1 , tt2 , tt3 ] ) ;
97+
98+ const serializedTrackList = JSON . stringify ( ttl ) ;
99+
100+ assert . notOk ( serializedTrackList . includes ( '"tech_":' ) , 'tech_ does not exist in the serialized data' ) ;
101+
102+ assert . ok ( serializedTrackList . includes ( `"id":"${ tt1 . id } "` ) , 'serialzed track is found for text track 1' ) ;
103+ assert . ok ( serializedTrackList . includes ( `"id":"${ tt2 . id } "` ) , 'serialzed track is found for text track 2' ) ;
104+ assert . ok ( serializedTrackList . includes ( `"id":"${ tt3 . id } "` ) , 'serialzed track is found for text track 3' ) ;
105+ } ) ;
0 commit comments