track-element-src-change.html (3288B)
1 <!DOCTYPE html> 2 <title>HTMLTrackElement 'src' attribute mutations</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <video> 6 <track src="resources/settings.vtt" default> 7 <script> 8 async_test(function(t) { 9 var cues = null; 10 var testTrack = document.querySelector("track"); 11 var stage = 0; 12 function step_onLoad() { 13 switch (stage) { 14 case 0: 15 cues = testTrack.track.cues; 16 assert_equals(testTrack.readyState, HTMLTrackElement.LOADED, "readyState after first loading of the track"); 17 assert_equals(cues.length, 4, "Number of cues after first loading of the track"); 18 assert_equals(cues[cues.length-1].text, 'I said Bear is coming now!!!! Tab separators.', "Last cue content check"); 19 ++stage; 20 testTrack.src = "resources/entities.vtt"; 21 assert_equals(cues.length, 0, "cues list is reset immediately after 'src' mutation with the new URL"); 22 break; 23 case 1: 24 assert_equals(testTrack.readyState, HTMLTrackElement.LOADED), "readyState after loading of the second track"; 25 assert_equals(cues, testTrack.track.cues, ".cues object are the same after 'src' attr mutation"); 26 assert_equals(cues.length, 7, "Number of cues after loading of the second track"); 27 assert_equals(cues[cues.length-1].text, 'This & is parsed to the same as &.', "Last cue content check"); 28 ++stage; 29 testTrack.src = "resources/settings.vtt"; 30 break; 31 case 2: 32 assert_equals(testTrack.readyState, HTMLTrackElement.LOADED, "readyState after after loading of the first track again"); 33 assert_equals(cues[cues.length-1].text, 'I said Bear is coming now!!!! Tab separators.', "Last cue content check"); 34 assert_equals(cues, testTrack.track.cues, ".cues object are the same after 'src' attr mutation"); 35 assert_equals(cues.length, 4, "Number of cues after loading of the first track"); 36 ++stage; 37 testTrack.src = "resources/settings.vtt"; 38 // This should not raise onLoad or onError event, so we'll wait for it for some time 39 t.step_timeout(t.step_func_done(function() { 40 assert_equals(testTrack.readyState, HTMLTrackElement.LOADED, "readyState after changing 'src' to the same value"); 41 assert_equals(cues, testTrack.track.cues, ".cues object are the same after 'src' attr mutation"); 42 assert_equals(cues.length, 4, "Number of cues after changing 'src' to the same value"); 43 }, 100)); 44 break; 45 case 3: 46 assert_unreached("'load' event should not fire, stage = " + stage); 47 break; 48 } 49 } 50 51 testTrack.onload = t.step_func(step_onLoad); 52 testTrack.onerror = t.unreached_func("'error' event should not fire"); 53 }); 54 </script> 55 </video>