⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 159711 in webkit


Ignore:
Timestamp:
Nov 22, 2013, 1:44:22 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

Add TextTrackList::getTrackById().
https://bugs.webkit.org/show_bug.cgi?id=124785

Patch by Brendan Long <b.long@cablelabs.com> on 2013-11-22
Reviewed by Eric Carlson.

Source/WebCore:

Test: media/track/track-id.html

  • html/track/TextTrackList.cpp: Add getTrackById()

(TextTrackList::getTrackById):

  • html/track/TextTrackList.h: Same.
  • html/track/TextTrackList.idl: Same.

LayoutTests:

Update this test to make it more interesting. It now checks that the "id"
changes when the <track> id changes, makes sure TextTrack::id is readonly,
and looks the track up by id with getTrackById().

  • media/track/track-id-expected.txt:
  • media/track/track-id.html:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r159705 r159711  
     12013-11-22  Brendan Long  <b.long@cablelabs.com>
     2
     3        Add TextTrackList::getTrackById().
     4        https://bugs.webkit.org/show_bug.cgi?id=124785
     5
     6        Reviewed by Eric Carlson.
     7
     8        Update this test to make it more interesting. It now checks that the "id"
     9        changes when the <track> id changes, makes sure TextTrack::id is readonly,
     10        and looks the track up by id with getTrackById().
     11
     12        * media/track/track-id-expected.txt:
     13        * media/track/track-id.html:
     14
    1152013-11-22  Filip Pizlo  <fpizlo@apple.com>
    216
  • trunk/LayoutTests/media/track/track-id-expected.txt

    r158760 r159711  
    1 Tests that the 'id' attribute on a TextTrack matches the track element.
     1Tests that the TextTrack "id" attribute is appropriately set.
    22
    33
    4 EXPECTED (video.textTracks[0].id == 'Test-ID-123') OK
    54
     5++ Test default attribute value
     6EXPECTED (textTrack.id == 'LoremIpsum') OK
     7EXPECTED (video.textTracks[0].id == 'LoremIpsum') OK
     8
     9++ Make sure we can look tracks up by id
     10EXPECTED (video.textTracks.getTrackById('LoremIpsum') == '[object TextTrack]') OK
     11
     12++ Test that it's readonly
     13RUN(textTrack.id = 'newvalue';)
     14EXPECTED (textTrack.id == 'LoremIpsum') OK
    615END OF TEST
    716
  • trunk/LayoutTests/media/track/track-id.html

    r158760 r159711  
    22<html>
    33    <head>
     4
    45        <script src=../media-file.js></script>
    56        <script src=../video-test.js></script>
    67        <script>
    78
    8             function loaded()
     9            var textTrack;
     10
     11            function start()
    912            {
    1013                findMediaElement();
    11                 var trackElement = video.firstElementChild;
     14                consoleWrite("");
    1215
    13                 testExpected("video.textTracks[0].id", trackElement.id);
     16                textTrack = document.getElementById("LoremIpsum").track;
    1417
     18                consoleWrite("<b>++ Test default attribute value</b>");
     19                testExpected("textTrack.id", "LoremIpsum");
     20                testExpected("video.textTracks[0].id", "LoremIpsum");
    1521                consoleWrite("");
     22
     23                consoleWrite("<b>++ Make sure we can look tracks up by id</b>");
     24                testExpected("video.textTracks.getTrackById('LoremIpsum')", textTrack);
     25                consoleWrite("");
     26
     27                consoleWrite("<b>++ Test that it's readonly</b>");
     28                run("textTrack.id = 'newvalue';");
     29                testExpected("textTrack.id", "LoremIpsum");
     30
    1631                endTest();
    1732            }
    1833
    19             setCaptionDisplayMode('Automatic');
    20 
    2134        </script>
    2235    </head>
    23     <body onload="loaded()">
    24         <p>Tests that the 'id' attribute on a TextTrack matches the track element.</p>
     36    <body onload="start()">
     37        <p>Tests that the TextTrack "id" attribute is appropriately set.</p>
    2538        <video>
    26             <track id="Test-ID-123" src="captions-webvtt/captions-fast.vtt">
     39            <track id="LoremIpsum" src="captions-webvtt/captions-fast.vtt">
    2740        </video>
    2841    </body>
  • trunk/Source/WebCore/ChangeLog

    r159702 r159711  
     12013-11-22  Brendan Long  <b.long@cablelabs.com>
     2
     3        Add TextTrackList::getTrackById().
     4        https://bugs.webkit.org/show_bug.cgi?id=124785
     5
     6        Reviewed by Eric Carlson.
     7
     8        Test: media/track/track-id.html
     9
     10        * html/track/TextTrackList.cpp: Add getTrackById()
     11        (TextTrackList::getTrackById):
     12        * html/track/TextTrackList.h: Same.
     13        * html/track/TextTrackList.idl: Same.
     14
    1152013-11-22  Hans Muller  <hmuller@adobe.com>
    216
  • trunk/Source/WebCore/html/track/TextTrackList.cpp

    r158821 r159711  
    128128}
    129129
     130TextTrack* TextTrackList::getTrackById(const AtomicString& id)
     131{
     132    // 4.8.10.12.5 Text track API
     133    // The getTrackById(id) method must return the first TextTrack in the
     134    // TextTrackList object whose id IDL attribute would return a value equal
     135    // to the value of the id argument.
     136    for (unsigned i = 0; i < length(); ++i) {
     137        TextTrack* track = item(i);
     138        if (track->id() == id)
     139            return track;
     140    }
     141
     142    // When no tracks match the given argument, the method must return null.
     143    return nullptr;
     144}
     145
    130146void TextTrackList::invalidateTrackIndexesAfterTrack(TextTrack* track)
    131147{
  • trunk/Source/WebCore/html/track/TextTrackList.h

    r158821 r159711  
    4949
    5050    TextTrack* item(unsigned index) const;
     51    TextTrack* getTrackById(const AtomicString&);
    5152    TextTrack* lastItem() const { return item(length() - 1); }
    5253
  • trunk/Source/WebCore/html/track/TextTrackList.idl

    r159061 r159711  
    3232    readonly attribute unsigned long length;
    3333    getter TextTrack item(unsigned long index);
     34    TextTrack getTrackById(DOMString id);
    3435
    3536    attribute EventListener onaddtrack;
Note: See TracChangeset for help on using the changeset viewer.