Bug 972479 - TextTracks added to a TextTrackList through an HTMLTrackElement should dispatch 'onaddtrack' event. r=rillian

The problem was that the HTMLTrackElement calls a different
AddTextTrack method then the HTMLMediaElement does when
addTextTrack is called on it. This patch has the method
that the HTMLTrackElement calls dispatch the onaddtrackevent
as well.
This commit is contained in:
Rick Eyre 2014-02-13 13:28:21 -05:00
parent 3c76661733
commit 0f68038790
3 changed files with 29 additions and 15 deletions

View File

@ -67,13 +67,19 @@ TextTrackList::AddTextTrack(TextTrackKind aKind,
const nsAString& aLanguage)
{
nsRefPtr<TextTrack> track = new TextTrack(mGlobal, this, aKind, aLabel, aLanguage);
if (mTextTracks.AppendElement(track)) {
CreateAndDispatchTrackEventRunner(track, NS_LITERAL_STRING("addtrack"));
}
AddTextTrack(track);
return track.forget();
}
void
TextTrackList::AddTextTrack(TextTrack* aTextTrack)
{
if (mTextTracks.AppendElement(aTextTrack)) {
aTextTrack->SetTextTrackList(this);
CreateAndDispatchTrackEventRunner(aTextTrack, NS_LITERAL_STRING("addtrack"));
}
}
TextTrack*
TextTrackList::GetTrackById(const nsAString& aId)
{

View File

@ -51,10 +51,7 @@ public:
const nsAString& aLanguage);
TextTrack* GetTrackById(const nsAString& aId);
void AddTextTrack(TextTrack* aTextTrack) {
mTextTracks.AppendElement(aTextTrack);
aTextTrack->SetTextTrackList(this);
}
void AddTextTrack(TextTrack* aTextTrack);
void RemoveTextTrack(TextTrack* aTrack);
void DidSeek();

View File

@ -23,7 +23,7 @@ SpecialPowers.pushPrefEnv({"set": [["media.webvtt.enabled", true]]},
var trackList = video.textTracks;
is(trackList.length, 0, "Length should be 0.");
var evtTextTrack, numOfCalls = 0;
var evtTextTrack, numOfCalls = 0, tt;
trackList.onaddtrack = function(event) {
ok(event instanceof TrackEvent, "Fired event from onaddtrack should be a TrackEvent");
is(event.type, "addtrack", "Event type should be addtrack");
@ -32,26 +32,37 @@ SpecialPowers.pushPrefEnv({"set": [["media.webvtt.enabled", true]]},
ok(!event.cancelable, "Event shouldn't be cancelable!");
evtTextTrack = event.track;
ok(textTrack[numOfCalls] === evtTextTrack, "Text tracks should be the same");
tt = textTrack[numOfCalls].track || textTrack[numOfCalls];
ok(tt === evtTextTrack, "Text tracks should be the same");
is(evtTextTrack.label, label[numOfCalls], "Label should be set to "+ label[numOfCalls]);
is(evtTextTrack.language, language[numOfCalls], "Language should be " + language[numOfCalls]);
is(evtTextTrack.kind, kind[numOfCalls], "Kind should be " + kind[numOfCalls]);
if (++numOfCalls == 3) {
if (++numOfCalls == 4) {
SimpleTest.finish();
}
};
var label = ["Oasis", "Coldplay", "t.A.T.u"];
language = ["en-CA", "en-GB", "ru" ];
kind = ["subtitles", "captions", "chapters"];
var label = ["Oasis", "Coldplay", "t.A.T.u", ""];
language = ["en-CA", "en-GB", "ru", ""];
kind = ["subtitles", "captions", "chapters", "subtitles"];
var textTrack = new Array(3);
var textTrack = new Array(4);
for (var i = 0; i < 3; ++i) {
textTrack[i] = video.addTextTrack(kind[i], label[i], language[i]);
is(trackList.length, i + 1, "Length should be " + (i+1));
}
video.src = "seek.webm";
video.preload = "auto";
var trackElement = document.createElement("track");
trackElement.src = "basic.vtt";
textTrack[3] = trackElement;
document.getElementById("content").appendChild(video);
video.appendChild(trackElement);
//TODO: Tests for removetrack event to be added along with bug 882677
}
);