Bug 867823 - Implement TextTrack Add/RemoveCue. r=rillian

- Updated RemoveCue to throw NotFoundError if the cue being removed is
not in the cue list.
- Updated AddCue to not add cues that are already in the list. This is
done by reference comparing.
This commit is contained in:
Rick Eyre 2013-06-28 13:31:43 -04:00
parent 5a217147ab
commit f8467f7947
6 changed files with 19 additions and 23 deletions

View File

@ -73,15 +73,13 @@ TextTrack::SetMode(TextTrackMode aValue)
void
TextTrack::AddCue(TextTrackCue& aCue)
{
//XXX: If cue exists, remove. Bug 867823.
mCueList->AddCue(aCue);
}
void
TextTrack::RemoveCue(TextTrackCue& aCue)
TextTrack::RemoveCue(TextTrackCue& aCue, ErrorResult& aRv)
{
//XXX: If cue does not exists throw NotFoundError. Bug 867823.
mCueList->RemoveCue(aCue);
mCueList->RemoveCue(aCue, aRv);
}
void

View File

@ -99,7 +99,7 @@ public:
void Update(double aTime);
void AddCue(TextTrackCue& aCue);
void RemoveCue(TextTrackCue& aCue);
void RemoveCue(TextTrackCue& aCue, ErrorResult& aRv);
void CueChanged(TextTrackCue& aCue);
IMPL_EVENT_HANDLER(cuechange)

View File

@ -66,12 +66,19 @@ TextTrackCueList::GetCueById(const nsAString& aId)
void
TextTrackCueList::AddCue(TextTrackCue& cue)
{
if (mList.Contains(&cue)) {
return;
}
mList.AppendElement(&cue);
}
void
TextTrackCueList::RemoveCue(TextTrackCue& cue)
TextTrackCueList::RemoveCue(TextTrackCue& cue, ErrorResult& aRv)
{
if (!mList.Contains(&cue)) {
aRv.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
return;
}
mList.RemoveElement(&cue);
}

View File

@ -11,6 +11,7 @@
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
#include "mozilla/ErrorResult.h"
namespace mozilla {
namespace dom {
@ -47,7 +48,7 @@ public:
TextTrackCue* GetCueById(const nsAString& aId);
void AddCue(TextTrackCue& cue);
void RemoveCue(TextTrackCue& cue);
void RemoveCue(TextTrackCue& cue, ErrorResult& aRv);
private:
nsCOMPtr<nsISupports> mParent;

View File

@ -84,40 +84,29 @@ SpecialPowers.pushPrefEnv({"set": [["media.webvtt.enabled", true]]},
is(cue.text, "foo", "Cue's text should be foo.");
// Adding the same cue again should not increase the cue count.
// TODO: https://bugzilla.mozilla.org/show_bug.cgi?id=867823
// http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrack-addcue
trackElement.track.addCue(vttCue);
todo_is(cueList.length, 5, "Cue list length should be 5.");
is(cueList.length, 5, "Cue list length should be 5.");
// Check that we are able to remove cues.
trackElement.track.removeCue(cue);
// TODO: Marked as todo as incorrect addition up top increases cue count
// to 4 -- https://bugzilla.mozilla.org/show_bug.cgi?id=867823
todo_is(cueList.length, 4, "Cue list length should be 4.");
is(cueList.length, 4, "Cue list length should be 4.");
var exceptionHappened = false;
try {
// We should not be able to remove a cue that is not in the list.
cue = new VTTCue(1, 2, "foo");
trackElement.removeCue(cue);
trackElement.track.removeCue(cue);
} catch (e) {
// "NotFoundError" should be thrown when trying to remove a cue that is
// not in the list.
// TODO: https://bugzilla.mozilla.org/show_bug.cgi?id=867823
// http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#dom-texttrack-removecue
todo_is(e.name, "NotFoundError", "We should have caught an error.");
is(e.name, "NotFoundError", "Should have thrown NotFoundError.");
exceptionHappened = true;
}
// If this is false then we did not throw an error and probably removed a cue
// when we shouln't have.
ok(exceptionHappened, "Exception should have happened.");
// We should not have removed a cue so the cue list length should not
// have changed.
// TODO: Marked as todo as incorrect addition of cue up top increases
// count erroneously.
// https://bugzilla.mozilla.org/show_bug.cgi?id=867823
todo_is(cueList.length, 4, "Cue list length should be 4.");
is(cueList.length, 4, "Cue list length should be 4.");
SimpleTest.finish();
});

View File

@ -37,6 +37,7 @@ interface TextTrack : EventTarget {
readonly attribute TextTrackRegionList? regions;
void addCue(VTTCue cue);
[Throws]
void removeCue(VTTCue cue);
attribute EventHandler oncuechange;