Bug 1276129 - part3 : add & modify test. draft
authorAlastor Wu <alwu@mozilla.com>
Thu, 02 Jun 2016 11:08:24 +0800
changeset 374258 51fd0161d2041b0cd3807268cf62f39603987b30
parent 374257 4be3e41f61b7d38c3954d90a9f7a8e39cf67e978
child 374259 880cb9e9dd05634965a58743df26bf313a0efa7c
push id19965
push useralwu@mozilla.com
push dateThu, 02 Jun 2016 03:12:21 +0000
bugs1276129
milestone49.0a1
Bug 1276129 - part3 : add & modify test. MozReview-Commit-ID: KeMFrMXOoTi
dom/media/test/mochitest.ini
dom/media/test/test_texttrackcue.html
dom/media/test/test_webvtt_positionalign.html
dom/media/test/vttPositionAlign.vtt
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -546,16 +546,17 @@ support-files =
   vbr.mp3
   vbr.mp3^headers^
   video-overhang.ogg
   video-overhang.ogg^headers^
   vp9.webm
   vp9.webm^headers^
   vp9cake.webm
   vp9cake.webm^headers^
+  vttPositionAlign.vtt
   wave_metadata.wav
   wave_metadata.wav^headers^
   wave_metadata_bad_len.wav
   wave_metadata_bad_len.wav^headers^
   wave_metadata_bad_no_null.wav
   wave_metadata_bad_no_null.wav^headers^
   wave_metadata_bad_utf8.wav
   wave_metadata_bad_utf8.wav^headers^
@@ -845,15 +846,16 @@ skip-if = toolkit == 'gonk' # bug 112884
 [test_video_to_canvas.html]
 [test_video_in_audio_element.html]
 [test_videoDocumentTitle.html]
 [test_VideoPlaybackQuality.html]
 [test_VideoPlaybackQuality_disabled.html]
 [test_volume.html]
 [test_vttparser.html]
 [test_webvtt_disabled.html]
+[test_webvtt_positionalign.html]
 
 # 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]
 [test_fragment_play.html]
--- a/dom/media/test/test_texttrackcue.html
+++ b/dom/media/test/test_texttrackcue.html
@@ -150,40 +150,24 @@ SpecialPowers.pushPrefEnv({"set": [["med
       cue.lineAlign = "middle";
       is(cue.lineAlign, "middle", "Cue's line align should be middle.");
       cue.lineAlign = "START";
       is(cue.lineAlign, "middle", "Cue's line align should be middle.");
       cue.lineAlign = "end";
       is(cue.lineAlign, "end", "Cue's line align should be end.");
 
       // Check that cue position align works properly
-      is(cue.positionAlign, "middle", "Cue's default position alignment should be middle.");
-
-      var exceptionHappened = false;
-      try {
-        cue.positionAlign = "left";
-      } catch(e) {
-        exceptionHappened = true;
-        is(e.name, "SyntaxError", "Should have thrown SyntaxError.");
-      }
-      ok(exceptionHappened, "Exception should have happened.");
+      is(cue.positionAlign, "center", "Cue's default position alignment should be center.");
 
-      exceptionHappened = false;
-      try {
-        cue.positionAlign = "right";
-      } catch(e) {
-        exceptionHappened = true;
-        is(e.name, "SyntaxError", "Should have thrown SyntaxError.");
-      }
-      ok(exceptionHappened, "Exception should have happened.");
-
-      cue.positionAlign = "start";
-      is(cue.positionAlign, "start", "Cue's position align should be start.");
-      cue.positionAlign = "end";
-      is(cue.positionAlign, "end", "Cue's position align should be end.");
+      cue.positionAlign = "line-left";
+      is(cue.positionAlign, "line-left", "Cue's position align should be line-left.");
+      cue.positionAlign = "auto";
+      is(cue.positionAlign, "auto", "Cue's position align should be auto.");
+      cue.positionAlign = "line-right";
+      is(cue.positionAlign, "line-right", "Cue's position align should be line-right.");
 
       // Check cue.line
       is(cue.line, "auto", "Cue's line value should initially be auto.");
       cue.line = 12410
       is(cue.line, 12410, "Cue's line value should now be 12410.");
       cue.line = "auto";
       is(cue.line, "auto", "Cue's line value should now be auto.");
 
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_webvtt_positionalign.html
@@ -0,0 +1,95 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset='utf-8'>
+  <title>WebVTT : position align test</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 video = document.createElement("video");
+var trackElement = document.createElement("track");
+var cuesNumber = 8;
+
+function isTrackElemenLoaded() {
+  // Re-que isTrackElemenLoaded() at the end of the event loop until the track
+  // element has loaded its data.
+  if (trackElement.readyState == 1) {
+    setTimeout(isTrackElemenLoaded, 0);
+    return;
+  }
+
+  is(trackElement.readyState, 2, "Track::ReadyState should be set to LOADED.");
+  runTest();
+}
+
+function runTest() {
+  info("--- check cues number ---");
+  var cues = trackElement.track.cues;
+  is(cues.length, cuesNumber, "Cues number is correct.");
+
+  info("--- check the typedef of TextTrackCue and VTTCue ---");
+  isnot(window.TextTrackCue, undefined, "TextTrackCue should be defined.");
+  isnot(window.VTTCue, undefined, "VTTCue should be defined.");
+
+  info("--- check the type of first parsed cue ---");
+  ok(cues[0] instanceof TextTrackCue, "Cue should be an instanceof TextTrackCue.");
+  ok(cues[0] instanceof VTTCue, "Cue should be an instanceof VTTCue.");
+
+  info("--- check the cue's position alignment ---");
+  is(cues[0].positionAlign, "center",     cues[0].text);
+  is(cues[1].positionAlign, "line-left",  cues[1].text);
+  is(cues[2].positionAlign, "center",     cues[2].text);
+  is(cues[3].positionAlign, "line-right", cues[3].text);
+  is(cues[4].positionAlign, "auto",       cues[4].text);
+
+  info("--- check the cue's computed position alignment ---");
+  // The "computedPositionAlign" is the chrome-only attributes, we need to get
+  // the chrome privilege for cues.
+  cuesChrome = SpecialPowers.wrap(cues);
+  is(cuesChrome[5].computedPositionAlign, "line-left",  cuesChrome[5].text);
+  is(cuesChrome[6].computedPositionAlign, "line-right", cuesChrome[6].text);
+  is(cuesChrome[7].computedPositionAlign, "center",     cuesChrome[7].text);
+
+  info("--- check the cue's computed position alignment from DOM API ---");
+  is(cuesChrome[0].computedPositionAlign, "center", "Cue's computedPositionAlign align is center.");
+
+  cuesChrome[0].positionAlign = "auto";
+  is(cuesChrome[0].positionAlign, "auto", "Change cue's position align to \"auto\"");
+
+  cuesChrome[0].align = "left";
+  is(cuesChrome[0].align, "left", "Change cue's align to \"left\".");
+
+  is(cuesChrome[0].computedPositionAlign, "line-left",  "Cue's computedPositionAlign becomes to \"line-left\"");
+
+  info("--- finish test ---");
+  SimpleTest.finish();
+}
+
+function setupTest() {
+  info("--- setup test ---");
+  video.src = "seek.webm";
+  video.preload = "auto";
+
+  trackElement.src = "vttPositionAlign.vtt";
+  trackElement.kind = "subtitles";
+  trackElement.default = true;
+
+  document.getElementById("content").appendChild(video);
+  video.appendChild(trackElement);
+  video.addEventListener("loadedmetadata", function() {
+    video.removeEventListener("loadedmetadata", runTest);
+    isTrackElemenLoaded();
+  });
+}
+
+onload = setupTest;
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/media/test/vttPositionAlign.vtt
@@ -0,0 +1,25 @@
+WEBVTT
+
+00:00.000 --> 00:00.500
+Cue 0 : PositionAlign should be "center".
+
+00:00.700 --> 00:00.800 position:50%,line-left
+Cue 1 : PositionAlign should be "line-left".
+
+00:00.700 --> 00:00.800 position:50%,center
+Cue 2 : PositionAlign should be "center".
+
+00:00.700 --> 00:00.800 position:50%,line-right
+Cue 3 : PositionAlign should be "line-right".
+
+00:00.700 --> 00:00.800 position:50%,auto
+Cue 4 : PositionAlign should be "auto"
+
+00:00.700 --> 00:00.800 position:50%,auto align:left
+Cue 5 : PositionAlign should be "auto", but computedPositionAlign should be "line-left".
+
+00:00.700 --> 00:00.800 position:50%,auto align:right
+Cue 6 : PositionAlign should be "auto", but computedPositionAlign should be "line-right".
+
+00:00.700 --> 00:00.800 position:50%,auto align:middle
+Cue 7 : PositionAlign should be "auto", but computedPositionAlign should be "center".
\ No newline at end of file