tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

activeCues.html (4610B)


      1 <!doctype html>
      2 <title>TextTrack.activeCues</title>
      3 <script src=/resources/testharness.js></script>
      4 <script src=/resources/testharnessreport.js></script>
      5 <script src=/common/media.js></script>
      6 <div id=log></div>
      7 <script>
      8 setup(function(){
      9    window.video = document.createElement('video');
     10    window.t1 = video.addTextTrack('subtitles');
     11    window.track = document.createElement('track');
     12    track['default'] = true;
     13    video.appendChild(track);
     14    window.t2 = track.track;
     15    t2.mode = 'showing';
     16    window.t1_cues = t1.activeCues;
     17    window.t2_cues = t2.activeCues;
     18    document.body.appendChild(video);
     19    if (!t1)
     20        throw new Error('t1 was undefined')
     21 });
     22 function smoke_test() {
     23  assert_true('HTMLTrackElement' in window, 'track not supported');
     24 }
     25 
     26 test(function(){
     27    smoke_test();
     28    assert_equals(t1.activeCues, t1_cues, 't1.activeCues should return same object');
     29    assert_equals(t2.activeCues, t2_cues, 't2.activeCues should return same object');
     30    assert_not_equals(t1.activeCues, t2.activeCues, 't1.activeCues and t2.activeCues should be different objects');
     31    assert_not_equals(t1.activeCues, null, 't1.activeCues should not be null');
     32    assert_not_equals(t2.activeCues, null, 't2.activeCues should not be null');
     33    assert_equals(t1.activeCues.length, 0, 't1.activeCues should have length 0');
     34    assert_equals(t2.activeCues.length, 0, 't2.activeCues should have length 0');
     35 }, document.title+', empty list');
     36 test(function(){
     37    smoke_test();
     38    var c = new VTTCue(0, 1, "text");
     39    t1.addCue(c);
     40    assert_equals(t1.activeCues, t1_cues, "t1.activeCues should return same object");
     41    assert_equals(t1.activeCues.length, 0, "t1.activeCues.length");
     42    var c2 = new VTTCue(1, 2, "text2");
     43    t1.addCue(c2);
     44    assert_equals(t1.activeCues, t1_cues, "t1.activeCues should return the same object after adding a second cue");
     45    assert_equals(t1.activeCues.length, 0, "t1.activeCues.length after adding a second cue");
     46 }, document.title+', after addCue()');
     47 test(function(){
     48    smoke_test();
     49    t1.mode = 'showing';
     50    assert_equals(t1.activeCues, t1_cues, "t1.activeCues should return the same object after setting mode to showing");
     51    t1.mode = 'hidden';
     52    assert_equals(t1.activeCues, t1_cues, "t1.activeCues should return the same object after setting mode to hidden");
     53    t1.mode = 'disabled';
     54    assert_equals(t1.activeCues, null, "t1.activeCues should be null when mode is disabled");
     55    assert_equals(t1_cues.length, 0, "t1_cues should still be intact after setting mode to disabled");
     56 }, document.title+', different modes');
     57 
     58 // ok now let's load in a video
     59 var test1 = async_test(document.title+', video loading');
     60 var test2 = async_test(document.title+', video playing');
     61 var test3 = async_test(document.title+', adding cue during playback');
     62 test1.step(smoke_test);
     63 test2.step(smoke_test);
     64 test3.step(smoke_test);
     65 test1.step(function(){
     66    t1.mode = 'showing';
     67    video.onloadeddata = test1.step_func(function(e) {
     68        video.onplaying = test2.step_func(function(e) {
     69            try {
     70                assert_equals(t1.activeCues, t1_cues, "t1.activeCues should return the same object after playing a video");
     71                assert_equals(t1.activeCues.length, 1, "t1.activeCues.length after the video has started playing");
     72            } catch(ex) {
     73                test2.step(function() { throw ex; });
     74                test3.step(function() { assert_unreached(); });
     75                return;
     76            }
     77            test3.step(function(){
     78                var c3 = new VTTCue(0, 2, "text3");
     79                t1.addCue(c3);
     80                assert_equals(t1.activeCues.length, 2, "t1.activeCues.length should be changed immediately");
     81                test3.done();
     82            });
     83            test2.done();
     84        });
     85        try {
     86            assert_equals(t1.activeCues, t1_cues, "t1.activeCues should return the same object after loading a video");
     87            assert_equals(t2.activeCues, t2_cues, "t2.activeCues should return the same object after loading a video");
     88            assert_equals(t1.activeCues.length, 0, "t1.activeCues.length before the video has started playing");
     89            assert_equals(t2.activeCues.length, 0, "t1.activeCues.length before the video has started playing");
     90        } catch(ex) {
     91            test1.step(function() { throw ex; });
     92            test2.step(function() { assert_unreached(); });
     93            test3.step(function() { assert_unreached(); });
     94            return;
     95        }
     96        video.play();
     97        test1.done();
     98    });
     99    video.src = getVideoURI("/media/movie_5");
    100 });
    101 </script>