Commit f372d8de authored by fs@opera.com's avatar fs@opera.com

Update a cue's insertion order when reinserting it with addCue()

TextTrack.addCue is specified to always remove the cue from any list it
currently resides in, but the implementation would only do that if it
was currently in a different track's list.
Also update spec. prose snippets and merge the two exception-conditions
in the removeCue-implementation. The "!m_cues || !m_cues->remove(cue)"
part should never be true unless state has been corrupted, and the spec.
only says to throw NotFoundError in any case.

BUG=460476

Review URL: https://codereview.chromium.org/944823003

git-svn-id: svn://svn.chromium.org/blink/trunk@190655 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4b796ef8
......@@ -24,6 +24,21 @@ test(function() {
t1.addCue(c1);
assert_equals(c1.track, t1);
}, document.title+', adding a cue to a track twice');
test(function() {
var t1 = video.addTextTrack('subtitles');
var c1 = new VTTCue(0, 1, 'text1');
t1.addCue(c1);
assert_equals(t1.cues.length, 1, 't1.cues.length after first addition');
assert_equals(t1.cues[0], c1, 'position of c1 in the list');
var c2 = new VTTCue(0, 1, 'text2');
t1.addCue(c2);
assert_equals(t1.cues.length, 2, 't1.cues.length after second addition');
assert_equals(t1.cues[1], c2, 'position of c2 in the list');
t1.addCue(c1);
assert_equals(t1.cues.length, 2, 't1.cues.length after reinserting c1');
assert_equals(t1.cues[1], c1, 'position of c1 in the list');
assert_equals(t1.cues[0], c2, 'position of c2 in the list');
}, document.title+', adding a cue to a track twice when another cue has same timestamps');
test(function() {
var t1 = video.addTextTrack('subtitles');
var t2 = video.addTextTrack('subtitles');
......
......@@ -232,17 +232,18 @@ void TextTrack::addCue(PassRefPtrWillBeRawPtr<TextTrackCue> prpCue)
if (std::isnan(cue->startTime()) || std::isnan(cue->endTime()) || cue->startTime() < 0 || cue->endTime() < 0)
return;
// 4.8.10.12.5 Text track API
// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-texttrack-addcue
// The addCue(cue) method of TextTrack objects, when invoked, must run the following steps:
// 1. If the given cue is in a text track list of cues, then remove cue from that text track
// list of cues.
TextTrack* cueTrack = cue->track();
if (cueTrack && cueTrack != this)
// (Steps 1 and 2 - pertaining to association of rendering rules - are not implemented.)
// 3. If the given cue is in a text track list of cues, then remove cue
// from that text track list of cues.
if (TextTrack* cueTrack = cue->track())
cueTrack->removeCue(cue.get(), ASSERT_NO_EXCEPTION);
// 2. Add cue to the method's TextTrack object's text track's text track list of cues.
// 4. Add cue to the method's TextTrack object's text track's text track list of cues.
cue->setTrack(this);
ensureTextTrackCueList()->add(cue);
......@@ -254,20 +255,15 @@ void TextTrack::removeCue(TextTrackCue* cue, ExceptionState& exceptionState)
{
ASSERT(cue);
// 4.8.10.12.5 Text track API
// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-texttrack-removecue
// The removeCue(cue) method of TextTrack objects, when invoked, must run the following steps:
// 1. If the given cue is not currently listed in the method's TextTrack
// object's text track's text track list of cues, then throw a NotFoundError exception.
if (cue->track() != this) {
exceptionState.throwDOMException(NotFoundError, "The specified cue is not listed in the TextTrack's list of cues.");
return;
}
// 2. Remove cue from the method's TextTrack object's text track's text track list of cues.
if (!m_cues || !m_cues->remove(cue)) {
exceptionState.throwDOMException(InvalidStateError, "Failed to remove the specified cue.");
if (cue->track() != this || !m_cues || !m_cues->remove(cue)) {
exceptionState.throwDOMException(NotFoundError, "The specified cue is not listed in the TextTrack's list of cues.");
return;
}
......
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