summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_eme_autoplay.html
blob: c8947f63e057093ff6c7a4dc531002acebd93af0 (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
107
108
109
110
111
112
113
114
115
<!DOCTYPE HTML>
<html>
<head>
  <title>Test Encrypted Media Extensions</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  <script type="text/javascript" src="manifest.js"></script>
  <script type="text/javascript" src="https://example.com:443/tests/dom/media/test/eme.js"></script>
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
/* import-globals-from eme.js */
var manager = new MediaTestManager;

var EMEmanifest = [
  {
    name:"bipbop 10s",
    tracks: [
      {
          name:"video",
          type:"video/mp4; codecs=\"avc1.4d4015\"",
          fragments:[ "bipbop-cenc-video-10s.mp4",
                    ]
      }
    ],
    keys: {
      "7e571d037e571d037e571d037e571d11" : "7e5733337e5733337e5733337e573311",
    },
    sessionType:"temporary",
    sessionCount:1,
    duration:10.01
  },
];

function startTest(test, token)
{
  manager.started(token);

  let v = document.createElement("video");
  v.controls = true;
  v.autoplay = true;

  document.body.appendChild(v);

  var eventCounts = { play: 0, playing: 0};
  function ForbiddenEvents(e) {
    var video = e.target;
    ok(video.readyState >= video.HAVE_FUTURE_DATA, "Must not have received event too early");
    is(eventCounts[e.type], 0, "event should have only be fired once");
    eventCounts[e.type]++;
  }
  // Log events for debugging.
  var events = ["suspend", "play", "canplay", "canplaythrough", "loadstart", "loadedmetadata",
                "loadeddata", "playing", "ended", "error", "stalled", "emptied", "abort",
                "waiting", "pause", "durationchange", "seeking", "seeked"];
  function logEvent(e) {
    info("got " + e.type + " event");
  }
  events.forEach(function(e) {
    v.addEventListener(e, logEvent);
  });
  v.addEventListener("play", ForbiddenEvents);
  v.addEventListener("playing", ForbiddenEvents);

  var gotWaitingForKey = 0;

  let waitForKey = new EMEPromise;
  v.addEventListener("waitingforkey", function() {
    gotWaitingForKey += 1;
    waitForKey.resolve();
  });

  v.addEventListener("loadedmetadata", function() {
    ok(SpecialPowers.do_lookupGetter(v, "isEncrypted").apply(v),
       TimeStamp(token) + " isEncrypted should be true");
    is(v.isEncrypted, undefined, "isEncrypted should not be accessible from content");
  });

  let finish = new EMEPromise;
  v.addEventListener("playing", function() {
    ok(true, TimeStamp(token) + " got playing event");
    // We expect only one waitingForKey as we delay until all sessions are ready.
    // I.e. one waitingForKey should be fired, after which, we process all sessions,
    // so it should not be possible to be blocked by a key after that point.
    ok(gotWaitingForKey == 1,  "Expected number 1 wait, got: " + gotWaitingForKey);

    finish.resolve();
  });

  Promise.all([
    LoadInitData(v, test, token),
    CreateAndSetMediaKeys(v, test, token),
    LoadTest(test, v, token, false /* do not call endOfStream */),
    waitForKey.promise])
  .then(values => {
    let initData = values[0];
    return ProcessInitData(v, test, token, initData);
  })
  .then(sessions => {
    Log(token, "Updated all sessions, loading complete");
    finish.promise.then(() => CloseSessions(v, sessions));
    return finish.promise;
  })
  .catch(reason => ok(false, reason))
  .then(() => manager.finished(token));
}

SimpleTest.waitForExplicitFinish();
manager.runTests(EMEmanifest, startTest);

</script>
</pre>
</body>
</html>