Bug 1278164 - part2 : modify test. draft
authorAlastor Wu <alwu@mozilla.com>
Tue, 14 Jun 2016 13:04:33 +0100
changeset 377991 4173a9eff3a0ddab64779392be0b5fdb50e09100
parent 377990 fc4bc5b9d63cebe39dc97f63d538aa57f0d2afb6
child 523448 88c82b1c4a98ae3df8b18ab87b1031bd65b8b9e4
push id20915
push useralwu@mozilla.com
push dateTue, 14 Jun 2016 12:04:48 +0000
bugs1278164
milestone50.0a1
Bug 1278164 - part2 : modify test. MozReview-Commit-ID: 25vgl3t1ssj
dom/media/test/mochitest.ini
dom/media/test/test_webvtt_empty_displaystate.html
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -858,16 +858,18 @@ skip-if = toolkit == 'gonk' # bug 112884
 [test_videoDocumentTitle.html]
 [test_VideoPlaybackQuality.html]
 [test_VideoPlaybackQuality_disabled.html]
 [test_volume.html]
 [test_vttparser.html]
 tags = webvtt
 [test_webvtt_disabled.html]
 tags = webvtt
+[test_webvtt_empty_displaystate.html]
+tags = webvtt
 [test_webvtt_positionalign.html]
 tags = webvtt
 
 # The tests below contain backend-specific tests. Write backend independent
 # tests rather than adding to this list.
 [test_can_play_type_webm.html]
 [test_can_play_type_wave.html]
 [test_fragment_noplay.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_webvtt_empty_displaystate.html
@@ -0,0 +1,86 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset='utf-8'>
+  <title>WebVTT : cue's displaystate should be empty when its active flag is unset</title>
+  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<div id="content">
+</div>
+<script class="testbody" type="text/javascript">
+SimpleTest.waitForExplicitFinish();
+
+var isReceivedOnEnterEvent = false;
+var isReceivedOnExitEvent = false;
+
+function checkCueEvents() {
+  ok(isReceivedOnEnterEvent, "Already received cue's onEnter event.");
+  ok(isReceivedOnExitEvent, "Already received cue's onExit event.");
+  SimpleTest.finish();
+}
+
+function checkCueDisplayState(cue, expectedState) {
+  var cueChrome = SpecialPowers.wrap(cue);
+  if (expectedState) {
+    ok(cueChrome.displayState, "Cue's displayState shouldn't be empty.");
+  } else {
+    ok(!cueChrome.displayState, "Cue's displayState should be empty.");
+  }
+}
+
+function runTest() {
+  info("--- create video ---");
+  var video = document.createElement("video");
+  video.src = "seek.webm";
+  video.autoplay = true;
+  document.getElementById("content").appendChild(video);
+
+  video.onended = function () {
+    video.onended = null;
+    checkCueEvents();
+  };
+
+  video.onpause = function () {
+    video.onpause = null;
+    checkCueEvents();
+  }
+
+  info("--- create the type of track ---");
+  isnot(window.TextTrack, undefined, "TextTrack should be defined.");
+
+  var track = video.addTextTrack("subtitles", "A", "en");
+  track.mode = "showing";
+  ok(track instanceof TextTrack, "Track should be an instanceof TextTrack.");
+
+  info("--- check the type of cue ---");
+  isnot(window.TextTrackCue, undefined, "TextTrackCue should be defined.");
+  isnot(window.VTTCue, undefined, "VTTCue should be defined.");
+
+  var cue = new VTTCue(0, 1, "Test cue");
+  ok(cue instanceof TextTrackCue, "Cue should be an instanceof TextTrackCue.");
+  ok(cue instanceof VTTCue, "Cue should be an instanceof VTTCue.");
+
+  info("--- add cue ---");
+  track.addCue(cue);
+
+  cue.onenter = function () {
+    cue.onenter = null;
+    isReceivedOnEnterEvent = true;
+    checkCueDisplayState(cue, true /* has display-state */);
+
+    cue.onexit = function () {
+      cue.onexit = null;
+      isReceivedOnExitEvent = true;
+      checkCueDisplayState(cue, false /* no display-state */);
+      video.pause();
+    }
+  }
+}
+
+onload = runTest;
+</script>
+</body>
+</html>