summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/embedded-content/media-elements/ready-states/autoplay.html
blob: b60b58a4217b04eb79aaf8b37fd6777cf9f7229c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!doctype html>
<title>autoplay</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/media.js"></script>
<div id="log"></div>
<script>
function autoplay_test(tagName, src) {
  function expect_events(t, e, expected_events) {
    var actual_events = [];
    var callback = t.step_func(function(ev) {
      actual_events.push(ev.type);
      assert_array_equals(actual_events,
                          expected_events.slice(0, actual_events.length));
      if (expected_events.length == actual_events.length) {
        t.done();
      }
    });
    ['canplay', 'canplaythrough',
     'pause', 'play', 'playing', 'error'].forEach(function(type) {
      e.addEventListener(type, callback);
    });
  }

  async_test(function(t) {
    var e = document.createElement(tagName);
    e.src = src;
    e.autoplay = true;
    expect_events(t, e, ['canplay', 'play', 'playing', 'canplaythrough']);
  }, tagName + '.autoplay');

  async_test(function(t) {
    var e = document.createElement(tagName);
    e.src = src;
    e.autoplay = true;
    e.pause(); // sets the autoplaying flag to false
    e.load(); // sets the autoplaying flag to true
    expect_events(t, e, ['canplay', 'play', 'playing', 'canplaythrough']);
  }, tagName + '.autoplay and load()');

  async_test(function(t) {
    var e = document.createElement(tagName);
    e.src = src;
    e.autoplay = true;
    e.play(); // sets the autoplaying flag to false
    // play() also sets the paused attribute to false; there is no way for the
    // autoplaying flag to be true when the paused attribute is false.
    assert_equals(e.paused, false);
    expect_events(t, e, ['play', 'canplay', 'playing', 'canplaythrough']);
  }, tagName + '.autoplay and play()');

  async_test(function(t) {
    var e = document.createElement(tagName);
    e.src = src;
    e.autoplay = true;
    e.pause(); // sets the autoplaying flag to false
    expect_events(t, e, ['canplay', 'canplaythrough']);
  }, tagName + '.autoplay and pause()');

  async_test(function(t) {
    var e = document.createElement(tagName);
    e.src = src;
    e.autoplay = true;
    document.body.appendChild(e);
    document.body.removeChild(e);
    // in stable state, internal pause steps sets the autoplaying flag to false
    expect_events(t, e, ['canplay', 'canplaythrough']);
  }, tagName + '.autoplay and internal pause steps');
}

autoplay_test('audio', getAudioURI('/media/sound_5'));
autoplay_test('video', getVideoURI('/media/movie_5'));
</script>