summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mediasession/positionstate.html
blob: 9141091a90655fb9009ef5ad131f0824376827b5 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<title>MediaSession.setPositionState</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
test(() => {
  window.navigator.mediaSession.setPositionState(null);
}, 'Test setPositionState with a null value');

test(() => {
  window.navigator.mediaSession.setPositionState({
    duration: 60.9,
    position: 10.1,
    playbackRate: 1.5
  });
}, 'Test setPositionState with a valid value for forward playback');

test(() => {
  window.navigator.mediaSession.setPositionState({
    duration: 60.9,
    playbackRate: 1.0
  });
}, 'Test setPositionState with optional position');

test(() => {
  window.navigator.mediaSession.setPositionState({
    duration: 60.9,
    position: 10.1
  });
}, 'Test setPositionState with optional playback rate');

test(() => {
  window.navigator.mediaSession.setPositionState({
    duration: 60.9
  });
}, 'Test setPositionState with only duration');

test(() => {
  window.navigator.mediaSession.setPositionState({
    duration: 0
  });
}, 'Test setPositionState with zero duration');

test(() => {
  window.navigator.mediaSession.setPositionState({
    duration: 60.9,
    position: 10.1,
    playbackRate: -2.0
  });
}, 'Test setPositionState with negative playback rate');

test(() => {
  assert_throws_js(
      TypeError,
      _ => {
        window.navigator.mediaSession.setPositionState({
          duration: -1
        });
      });
}, 'Test setPositionState throws a TypeError if duration is negative');

test(() => {
  assert_throws_js(
      TypeError,
      _ => {
        window.navigator.mediaSession.setPositionState({
          duration: 10,
          position: -1
        });
      });
}, 'Test setPositionState throws a TypeError if position is negative');

test(() => {
  assert_throws_js(
      TypeError,
      _ => {
        window.navigator.mediaSession.setPositionState({
          duration: 10,
          position: 20
        });
      });
}, 'Test setPositionState throws a TypeError if duration is less than position');

test(() => {
  assert_throws_js(
      TypeError,
      _ => {
        window.navigator.mediaSession.setPositionState({
          duration: 60.9,
          position: 10.1,
          playbackRate: 0.0
        });
      });
}, 'Test setPositionState throws a TypeError if playback rate is zero');

test(() => {
  assert_throws_js(
      TypeError,
      _ => {
        window.navigator.mediaSession.setPositionState({
          position: 10.1,
          playbackRate: 1.0
        });
      });
}, 'Test setPositionState throws a TypeError if duration is not specified');
</script>