Commit eafc7f07 authored by Sriram's avatar Sriram Committed by Commit Bot

[WebVTT] Update dom construction logic for timestamp per spec

According to the spec [1] we need to include optional components
and add leading zeros if required for timestamp construction.
[1]: https://w3c.github.io/webvtt/#dom-construction-rules

Bug: 786382
Change-Id: I2b7320bd6b187cb3b85a5532c0a0fd398b3888cf
Reviewed-on: https://chromium-review.googlesource.com/773763
Commit-Queue: srirama chandra sekhar <srirama.m@samsung.com>
Reviewed-by: default avatarFredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#517767}
parent 965bbf35
......@@ -9,7 +9,7 @@ PASS VTTCue.getCueAsHTML(), <ruby>
PASS VTTCue.getCueAsHTML(), <rt>
PASS VTTCue.getCueAsHTML(), <v>
PASS VTTCue.getCueAsHTML(), <v a b>
FAIL VTTCue.getCueAsHTML(), <1:00:00.500> assert_equals: data expected "01:00:00.500" but got "1:00:00.500"
PASS VTTCue.getCueAsHTML(), <1:00:00.500>
FAIL VTTCue.getCueAsHTML(), x\0 assert_equals: data expected "x\0" but got "x"
Harness: the test ran to completion.
This is a testharness.js-based test.
PASS WebVTT cue data parser test timestamps - 54c245f3fbe7a3e25398b13971d44f2bb3a5f947
PASS WebVTT cue data parser test timestamps - 5e190a1b4541fcb10e403af111c14ef152fecb0d
PASS WebVTT cue data parser test timestamps - 92b97d3497836259e0b9305e27f2b91ea1dc9b31
PASS WebVTT cue data parser test timestamps - 2f0e84518d356cb1e56a366296fa491c5bed1e3a
FAIL WebVTT cue data parser test timestamps - 47fa4306a695161da88533d456ce94829e53b13d assert_equals: expected "#document-fragment\n| <?timestamp 00:00:00.500>" but got "#document-fragment\n| <?timestamp 00:00.500>"
PASS WebVTT cue data parser test timestamps - c1036a4322c1852e02e5a1843a9a81dfca6d7af3
PASS WebVTT cue data parser test timestamps - 70ec34d828ca661a583c651207becb968bb41653
PASS WebVTT cue data parser test timestamps - 66ba641ff047a226fa60fe867fd2479d40f3ff0f
PASS WebVTT cue data parser test timestamps - 398e8da1aaaf392739ca72057fef58bd5333f74d
PASS WebVTT cue data parser test timestamps - 391fce67644cf4dd9967e1436d1449ef5baf675f
Harness: the test ran to completion.
This is a testharness.js-based test.
PASS WebVTT cue data parser test timestamps - 54c245f3fbe7a3e25398b13971d44f2bb3a5f947
PASS WebVTT cue data parser test timestamps - 5e190a1b4541fcb10e403af111c14ef152fecb0d
PASS WebVTT cue data parser test timestamps - 92b97d3497836259e0b9305e27f2b91ea1dc9b31
FAIL WebVTT cue data parser test timestamps - 47fa4306a695161da88533d456ce94829e53b13d assert_equals: expected "#document-fragment\n| <?timestamp 00:00:00.500>" but got "#document-fragment\n| <?timestamp 00:00.500>"
PASS WebVTT cue data parser test timestamps - c1036a4322c1852e02e5a1843a9a81dfca6d7af3
PASS WebVTT cue data parser test timestamps - 70ec34d828ca661a583c651207becb968bb41653
PASS WebVTT cue data parser test timestamps - 66ba641ff047a226fa60fe867fd2479d40f3ff0f
PASS WebVTT cue data parser test timestamps - 398e8da1aaaf392739ca72057fef58bd5333f74d
PASS WebVTT cue data parser test timestamps - 391fce67644cf4dd9967e1436d1449ef5baf675f
Harness: the test ran to completion.
......@@ -39,6 +39,7 @@
#include "platform/loader/fetch/TextResourceDecoderOptions.h"
#include "platform/runtime_enabled_features.h"
#include "platform/text/SegmentedString.h"
#include "platform/wtf/DateMath.h"
#include "platform/wtf/text/CharacterNames.h"
#include "platform/wtf/text/WTFString.h"
......@@ -402,6 +403,18 @@ bool VTTParser::CollectTimeStamp(const String& line, double& time_stamp) {
return CollectTimeStamp(input, time_stamp);
}
static String SerializeTimeStamp(double time_stamp) {
uint64_t value = clampTo<uint64_t>(time_stamp * 1000);
unsigned milliseconds = value % 1000;
value /= 1000;
unsigned seconds = value % 60;
value /= 60;
unsigned minutes = value % 60;
unsigned hours = value / 60;
return String::Format("%02u:%02u:%02u.%03u", hours, minutes, seconds,
milliseconds);
}
bool VTTParser::CollectTimeStamp(VTTScanner& input, double& time_stamp) {
// Collect a WebVTT timestamp (5.3 WebVTT cue timings and settings parsing.)
// Steps 1 - 4 - Initial checks, let most significant units be minutes.
......@@ -442,11 +455,9 @@ bool VTTParser::CollectTimeStamp(VTTScanner& input, double& time_stamp) {
return false;
// Steps 18 - 19 - Calculate result.
const double kSecondsPerHour = 3600;
const double kSecondsPerMinute = 60;
const double kSecondsPerMillisecond = 0.001;
time_stamp = (value1 * kSecondsPerHour) + (value2 * kSecondsPerMinute) +
value3 + (value4 * kSecondsPerMillisecond);
time_stamp = (value1 * kMinutesPerHour * kSecondsPerMinute) +
(value2 * kSecondsPerMinute) + value3 +
(value4 * (1 / kMsPerSecond));
return true;
}
......@@ -550,11 +561,11 @@ void VTTTreeBuilder::ConstructTreeFromToken(Document& document) {
break;
}
case VTTTokenTypes::kTimestampTag: {
String characters_string = token_.Characters();
double parsed_time_stamp;
if (VTTParser::CollectTimeStamp(characters_string, parsed_time_stamp))
if (VTTParser::CollectTimeStamp(token_.Characters(), parsed_time_stamp)) {
current_node_->ParserAppendChild(ProcessingInstruction::Create(
document, "timestamp", characters_string));
document, "timestamp", SerializeTimeStamp(parsed_time_stamp)));
}
break;
}
default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment