mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
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:
parent
5a217147ab
commit
f8467f7947
@ -73,15 +73,13 @@ TextTrack::SetMode(TextTrackMode aValue)
|
|||||||
void
|
void
|
||||||
TextTrack::AddCue(TextTrackCue& aCue)
|
TextTrack::AddCue(TextTrackCue& aCue)
|
||||||
{
|
{
|
||||||
//XXX: If cue exists, remove. Bug 867823.
|
|
||||||
mCueList->AddCue(aCue);
|
mCueList->AddCue(aCue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TextTrack::RemoveCue(TextTrackCue& aCue)
|
TextTrack::RemoveCue(TextTrackCue& aCue, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
//XXX: If cue does not exists throw NotFoundError. Bug 867823.
|
mCueList->RemoveCue(aCue, aRv);
|
||||||
mCueList->RemoveCue(aCue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -99,7 +99,7 @@ public:
|
|||||||
void Update(double aTime);
|
void Update(double aTime);
|
||||||
|
|
||||||
void AddCue(TextTrackCue& aCue);
|
void AddCue(TextTrackCue& aCue);
|
||||||
void RemoveCue(TextTrackCue& aCue);
|
void RemoveCue(TextTrackCue& aCue, ErrorResult& aRv);
|
||||||
void CueChanged(TextTrackCue& aCue);
|
void CueChanged(TextTrackCue& aCue);
|
||||||
|
|
||||||
IMPL_EVENT_HANDLER(cuechange)
|
IMPL_EVENT_HANDLER(cuechange)
|
||||||
|
@ -66,12 +66,19 @@ TextTrackCueList::GetCueById(const nsAString& aId)
|
|||||||
void
|
void
|
||||||
TextTrackCueList::AddCue(TextTrackCue& cue)
|
TextTrackCueList::AddCue(TextTrackCue& cue)
|
||||||
{
|
{
|
||||||
|
if (mList.Contains(&cue)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
mList.AppendElement(&cue);
|
mList.AppendElement(&cue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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);
|
mList.RemoveElement(&cue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsCycleCollectionParticipant.h"
|
#include "nsCycleCollectionParticipant.h"
|
||||||
#include "nsWrapperCache.h"
|
#include "nsWrapperCache.h"
|
||||||
|
#include "mozilla/ErrorResult.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
@ -47,7 +48,7 @@ public:
|
|||||||
TextTrackCue* GetCueById(const nsAString& aId);
|
TextTrackCue* GetCueById(const nsAString& aId);
|
||||||
|
|
||||||
void AddCue(TextTrackCue& cue);
|
void AddCue(TextTrackCue& cue);
|
||||||
void RemoveCue(TextTrackCue& cue);
|
void RemoveCue(TextTrackCue& cue, ErrorResult& aRv);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nsCOMPtr<nsISupports> mParent;
|
nsCOMPtr<nsISupports> mParent;
|
||||||
|
@ -84,40 +84,29 @@ SpecialPowers.pushPrefEnv({"set": [["media.webvtt.enabled", true]]},
|
|||||||
is(cue.text, "foo", "Cue's text should be foo.");
|
is(cue.text, "foo", "Cue's text should be foo.");
|
||||||
|
|
||||||
// Adding the same cue again should not increase the cue count.
|
// 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);
|
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.
|
// Check that we are able to remove cues.
|
||||||
trackElement.track.removeCue(cue);
|
trackElement.track.removeCue(cue);
|
||||||
// TODO: Marked as todo as incorrect addition up top increases cue count
|
is(cueList.length, 4, "Cue list length should be 4.");
|
||||||
// to 4 -- https://bugzilla.mozilla.org/show_bug.cgi?id=867823
|
|
||||||
todo_is(cueList.length, 4, "Cue list length should be 4.");
|
|
||||||
|
|
||||||
var exceptionHappened = false;
|
var exceptionHappened = false;
|
||||||
try {
|
try {
|
||||||
// We should not be able to remove a cue that is not in the list.
|
// We should not be able to remove a cue that is not in the list.
|
||||||
cue = new VTTCue(1, 2, "foo");
|
cue = new VTTCue(1, 2, "foo");
|
||||||
trackElement.removeCue(cue);
|
trackElement.track.removeCue(cue);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// "NotFoundError" should be thrown when trying to remove a cue that is
|
// "NotFoundError" should be thrown when trying to remove a cue that is
|
||||||
// not in the list.
|
// not in the list.
|
||||||
// TODO: https://bugzilla.mozilla.org/show_bug.cgi?id=867823
|
is(e.name, "NotFoundError", "Should have thrown NotFoundError.");
|
||||||
// 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.");
|
|
||||||
exceptionHappened = true;
|
exceptionHappened = true;
|
||||||
}
|
}
|
||||||
// If this is false then we did not throw an error and probably removed a cue
|
// If this is false then we did not throw an error and probably removed a cue
|
||||||
// when we shouln't have.
|
// when we shouln't have.
|
||||||
ok(exceptionHappened, "Exception should have happened.");
|
ok(exceptionHappened, "Exception should have happened.");
|
||||||
|
|
||||||
// We should not have removed a cue so the cue list length should not
|
is(cueList.length, 4, "Cue list length should be 4.");
|
||||||
// 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.");
|
|
||||||
|
|
||||||
SimpleTest.finish();
|
SimpleTest.finish();
|
||||||
});
|
});
|
||||||
|
@ -37,6 +37,7 @@ interface TextTrack : EventTarget {
|
|||||||
readonly attribute TextTrackRegionList? regions;
|
readonly attribute TextTrackRegionList? regions;
|
||||||
|
|
||||||
void addCue(VTTCue cue);
|
void addCue(VTTCue cue);
|
||||||
|
[Throws]
|
||||||
void removeCue(VTTCue cue);
|
void removeCue(VTTCue cue);
|
||||||
|
|
||||||
attribute EventHandler oncuechange;
|
attribute EventHandler oncuechange;
|
||||||
|
Loading…
Reference in New Issue
Block a user