Bug 1307710 - part3: fix ProcessingInstruction node for testcase. r=rillian
authorbechen <bechen@mozilla.com>
Fri, 03 Mar 2017 11:34:33 +0800
changeset 345851 73b6ba6b82a0c0427c670ad5b278397d6b630400
parent 345850 e99bfc26ca21060d520dc1e9e94ce017850c1278
child 345852 a4f7f1dd00bdb69fef9f78100ed48576be85fd5e
push id31451
push usercbook@mozilla.com
push dateMon, 06 Mar 2017 09:52:09 +0000
treeherdermozilla-central@7099e03837e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs1307710
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1307710 - part3: fix ProcessingInstruction node for testcase. r=rillian MozReview-Commit-ID: 9Wc98cOVjHD
dom/media/webvtt/vtt.jsm
--- a/dom/media/webvtt/vtt.jsm
+++ b/dom/media/webvtt/vtt.jsm
@@ -348,16 +348,41 @@ Cu.import('resource://gre/modules/Servic
       element.localName = tagName;
       var name = TAG_ANNOTATION[type];
       if (name) {
         element[name] = annotation ? annotation.trim() : "";
       }
       return element;
     }
 
+    // https://w3c.github.io/webvtt/#webvtt-timestamp-object
+    // Return hhhhh:mm:ss.fff
+    function normalizedTimeStamp(secondsWithFrag) {
+      var totalsec = parseInt(secondsWithFrag, 10);
+      var hours = Math.floor(totalsec / 3600);
+      var minutes = Math.floor(totalsec % 3600 / 60);
+      var seconds = Math.floor(totalsec % 60);
+      if (hours < 10) {
+        hours = "0" + hours;
+      }
+      if (minutes < 10) {
+        minutes = "0" + minutes;
+      }
+      if (seconds < 10) {
+        seconds = "0" + seconds;
+      }
+      var f = secondsWithFrag.toString().split(".");
+      if (f[1]) {
+        f = f[1].slice(0, 3).padEnd(3, "0");
+      } else {
+        f = "000";
+      }
+      return hours + ':' + minutes + ':' + seconds + '.' + f;
+    }
+
     var root;
     if (bReturnFrag) {
       root = window.document.createDocumentFragment();
     } else {
       root = window.document.createElement("div");
     }
     var current = root,
         t,
@@ -374,17 +399,17 @@ Cu.import('resource://gre/modules/Servic
           }
           // Otherwise just ignore the end tag.
           continue;
         }
         var ts = collectTimeStamp(t.substr(1, t.length - 2));
         var node;
         if (ts) {
           // Timestamps are lead nodes as well.
-          node = window.document.createProcessingInstruction("timestamp", ts);
+          node = window.document.createProcessingInstruction("timestamp", normalizedTimeStamp(ts));
           current.appendChild(node);
           continue;
         }
         var m = t.match(/^<([^.\s/0-9>]+)(\.[^\s\\>]+)?([^>\\]+)?(\\?)>?$/);
         // If we can't parse the tag, skip to the next tag.
         if (!m) {
           continue;
         }