script: Implement the HTMLTrackElement API

Implement the basics of the HTMLTrackElement and update the wpt tests.
This commit is contained in:
Dan Robertson 2019-01-07 23:21:30 +00:00
parent 121cbd0078
commit c4802076b3
No known key found for this signature in database
GPG key ID: 45C4A652C47E42A5
24 changed files with 152 additions and 382 deletions

8
Cargo.lock generated
View file

@ -1698,7 +1698,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"mac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"markup5ever 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"markup5ever 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2305,7 +2305,7 @@ dependencies = [
[[package]]
name = "markup5ever"
version = "0.7.1"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"phf 0.7.23 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4798,7 +4798,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"mac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"markup5ever 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"markup5ever 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -5011,7 +5011,7 @@ dependencies = [
"checksum mac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
"checksum mach 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "86dd2487cdfea56def77b88438a2c915fb45113c5319bfe7e14306ca4cd0b0e1"
"checksum malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
"checksum markup5ever 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c220b3a3d75543b76e5c1fcab6635a8430ab5f9bfa011d003c3787ae0abf4ffa"
"checksum markup5ever 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "897636f9850c3eef4905a5540683ed53dc9393860f0846cab2c2ddf9939862ff"
"checksum matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efd7622e3022e1a6eaa602c4cea8912254e5582c9c692e9167714182244801b1"
"checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16"
"checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff"

View file

@ -40,6 +40,7 @@ input
invalid
keydown
keypress
kind
left
ltr
load
@ -89,6 +90,7 @@ seeked
seeking
select
serif
srclang
statechange
storage
submit

View file

@ -2,17 +2,35 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::codegen::Bindings::HTMLTrackElementBinding;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::codegen::Bindings::HTMLTrackElementBinding::{
self, HTMLTrackElementConstants, HTMLTrackElementMethods,
};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::{DOMString, USVString};
use crate::dom::document::Document;
use crate::dom::element::Element;
use crate::dom::htmlelement::HTMLElement;
use crate::dom::node::Node;
use crate::dom::texttrack::TextTrack;
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix};
#[derive(Clone, Copy, JSTraceable, MallocSizeOf, PartialEq)]
#[repr(u16)]
#[allow(unused)]
pub enum ReadyState {
None = HTMLTrackElementConstants::NONE,
Loading = HTMLTrackElementConstants::LOADING,
Loaded = HTMLTrackElementConstants::LOADED,
Error = HTMLTrackElementConstants::ERROR,
}
#[dom_struct]
pub struct HTMLTrackElement {
htmlelement: HTMLElement,
ready_state: ReadyState,
track: Dom<TextTrack>,
}
impl HTMLTrackElement {
@ -20,24 +38,98 @@ impl HTMLTrackElement {
local_name: LocalName,
prefix: Option<Prefix>,
document: &Document,
track: &TextTrack,
) -> HTMLTrackElement {
HTMLTrackElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
ready_state: ReadyState::None,
track: Dom::from_ref(&track),
}
}
#[allow(unrooted_must_root)]
pub fn new(
local_name: LocalName,
prefix: Option<Prefix>,
document: &Document,
) -> DomRoot<HTMLTrackElement> {
let track = TextTrack::new(
&document.window(),
Default::default(),
Default::default(),
Default::default(),
Default::default(),
Default::default(),
);
Node::reflect_node(
Box::new(HTMLTrackElement::new_inherited(
local_name, prefix, document,
local_name, prefix, document, &track,
)),
document,
HTMLTrackElementBinding::Wrap,
)
}
}
impl HTMLTrackElementMethods for HTMLTrackElement {
// https://html.spec.whatwg.org/multipage/#dom-track-kind
fn Kind(&self) -> DOMString {
let element = self.upcast::<Element>();
// Get the value of "kind" and transform all uppercase
// chars into lowercase.
let kind = element
.get_string_attribute(&local_name!("kind"))
.to_lowercase();
match &*kind {
"subtitles" | "captions" | "descriptions" | "chapters" | "metadata" => {
// The value of "kind" is valid. Return the lowercase version
// of it.
DOMString::from(kind)
},
_ if kind.is_empty() => {
// The default value should be "subtitles". If "kind" has not
// been set, the real value for "kind" is "subtitles"
DOMString::from("subtitles")
},
_ => {
// If "kind" has been set but it is not one of the valid
// values, return the default invalid value of "metadata"
DOMString::from("metadata")
},
}
}
// https://html.spec.whatwg.org/multipage/#dom-track-kind
// Do no transformations on the value of "kind" when setting it.
// All transformations should be done in the get method.
make_setter!(SetKind, "kind");
// https://html.spec.whatwg.org/multipage/#dom-track-src
make_url_getter!(Src, "src");
// https://html.spec.whatwg.org/multipage/#dom-track-src
make_url_setter!(SetSrc, "src");
// https://html.spec.whatwg.org/multipage/#dom-track-srclang
make_getter!(Srclang, "srclang");
// https://html.spec.whatwg.org/multipage/#dom-track-srclang
make_setter!(SetSrclang, "srclang");
// https://html.spec.whatwg.org/multipage/#dom-track-label
make_getter!(Label, "label");
// https://html.spec.whatwg.org/multipage/#dom-track-label
make_setter!(SetLabel, "label");
// https://html.spec.whatwg.org/multipage/#dom-track-default
make_bool_getter!(Default, "default");
// https://html.spec.whatwg.org/multipage/#dom-track-default
make_bool_setter!(SetDefault, "default");
// https://html.spec.whatwg.org/multipage/#dom-track-readystate
fn ReadyState(&self) -> u16 {
self.ready_state as u16
}
// https://html.spec.whatwg.org/multipage/#dom-track-track
fn Track(&self) -> DomRoot<TextTrack> {
DomRoot::from_ref(&*self.track)
}
}

View file

@ -5,22 +5,22 @@
// https://html.spec.whatwg.org/multipage/#htmltrackelement
[HTMLConstructor]
interface HTMLTrackElement : HTMLElement {
// [CEReactions]
// attribute DOMString kind;
// [CEReactions]
// attribute DOMString src;
// [CEReactions]
// attribute DOMString srclang;
// [CEReactions]
// attribute DOMString label;
// [CEReactions]
// attribute boolean default;
[CEReactions]
attribute DOMString kind;
[CEReactions]
attribute USVString src;
[CEReactions]
attribute DOMString srclang;
[CEReactions]
attribute DOMString label;
[CEReactions]
attribute boolean default;
// const unsigned short NONE = 0;
// const unsigned short LOADING = 1;
// const unsigned short LOADED = 2;
// const unsigned short ERROR = 3;
// readonly attribute unsigned short readyState;
const unsigned short NONE = 0;
const unsigned short LOADING = 1;
const unsigned short LOADED = 2;
const unsigned short ERROR = 3;
readonly attribute unsigned short readyState;
// readonly attribute TextTrack track;
readonly attribute TextTrack track;
};

View file

@ -6897,84 +6897,6 @@
[HTMLMediaElement interface: new Audio() must inherit property "videoTracks" with the proper type]
expected: FAIL
[HTMLTrackElement interface: attribute kind]
expected: FAIL
[HTMLTrackElement interface: attribute src]
expected: FAIL
[HTMLTrackElement interface: attribute srclang]
expected: FAIL
[HTMLTrackElement interface: attribute label]
expected: FAIL
[HTMLTrackElement interface: attribute default]
expected: FAIL
[HTMLTrackElement interface: constant NONE on interface object]
expected: FAIL
[HTMLTrackElement interface: constant NONE on interface prototype object]
expected: FAIL
[HTMLTrackElement interface: constant LOADING on interface object]
expected: FAIL
[HTMLTrackElement interface: constant LOADING on interface prototype object]
expected: FAIL
[HTMLTrackElement interface: constant LOADED on interface object]
expected: FAIL
[HTMLTrackElement interface: constant LOADED on interface prototype object]
expected: FAIL
[HTMLTrackElement interface: constant ERROR on interface object]
expected: FAIL
[HTMLTrackElement interface: constant ERROR on interface prototype object]
expected: FAIL
[HTMLTrackElement interface: attribute readyState]
expected: FAIL
[HTMLTrackElement interface: attribute track]
expected: FAIL
[HTMLTrackElement interface: document.createElement("track") must inherit property "kind" with the proper type]
expected: FAIL
[HTMLTrackElement interface: document.createElement("track") must inherit property "src" with the proper type]
expected: FAIL
[HTMLTrackElement interface: document.createElement("track") must inherit property "srclang" with the proper type]
expected: FAIL
[HTMLTrackElement interface: document.createElement("track") must inherit property "label" with the proper type]
expected: FAIL
[HTMLTrackElement interface: document.createElement("track") must inherit property "default" with the proper type]
expected: FAIL
[HTMLTrackElement interface: document.createElement("track") must inherit property "NONE" with the proper type]
expected: FAIL
[HTMLTrackElement interface: document.createElement("track") must inherit property "LOADING" with the proper type]
expected: FAIL
[HTMLTrackElement interface: document.createElement("track") must inherit property "LOADED" with the proper type]
expected: FAIL
[HTMLTrackElement interface: document.createElement("track") must inherit property "ERROR" with the proper type]
expected: FAIL
[HTMLTrackElement interface: document.createElement("track") must inherit property "readyState" with the proper type]
expected: FAIL
[HTMLTrackElement interface: document.createElement("track") must inherit property "track" with the proper type]
expected: FAIL
[HTMLMediaElement interface: attribute crossOrigin]
expected: FAIL
@ -9659,51 +9581,12 @@
[TextTrack interface: attribute activeCues]
expected: FAIL
[TextTrack must be primary interface of document.createElement("track").track]
expected: FAIL
[Stringification of document.createElement("track").track]
expected: FAIL
[TextTrack interface: document.createElement("track").track must inherit property "kind" with the proper type]
expected: FAIL
[TextTrack interface: document.createElement("track").track must inherit property "label" with the proper type]
expected: FAIL
[TextTrack interface: document.createElement("track").track must inherit property "language" with the proper type]
expected: FAIL
[TextTrack interface: document.createElement("track").track must inherit property "id" with the proper type]
expected: FAIL
[TextTrack interface: document.createElement("track").track must inherit property "inBandMetadataTrackDispatchType" with the proper type]
expected: FAIL
[TextTrack interface: document.createElement("track").track must inherit property "mode" with the proper type]
expected: FAIL
[TextTrack interface: document.createElement("track").track must inherit property "cues" with the proper type]
expected: FAIL
[TextTrack interface: document.createElement("track").track must inherit property "activeCues" with the proper type]
expected: FAIL
[TextTrack interface: document.createElement("track").track must inherit property "addCue(TextTrackCue)" with the proper type]
expected: FAIL
[TextTrack interface: calling addCue(TextTrackCue) on document.createElement("track").track with too few arguments must throw TypeError]
expected: FAIL
[TextTrack interface: document.createElement("track").track must inherit property "removeCue(TextTrackCue)" with the proper type]
expected: FAIL
[TextTrack interface: calling removeCue(TextTrackCue) on document.createElement("track").track with too few arguments must throw TypeError]
expected: FAIL
[TextTrack interface: document.createElement("track").track must inherit property "oncuechange" with the proper type]
expected: FAIL
[TimeRanges must be primary interface of document.createElement("video").buffered]
expected: FAIL

View file

@ -5,9 +5,6 @@
[The 'href' attribute of the 'area' element]
expected: FAIL
[The 'src' attribute of the 'track' element]
expected: FAIL
[The 'cite' attribute of the 'q' element]
expected: FAIL

View file

@ -5,9 +5,6 @@
[The 'href' attribute of the 'area' element]
expected: FAIL
[The 'src' attribute of the 'track' element]
expected: FAIL
[The 'cite' attribute of the 'q' element]
expected: FAIL

View file

@ -3,3 +3,11 @@
[<video autoplay> with <track> child]
expected: TIMEOUT
[<video autoplay> with <track src=\"invalid://url\" default=\"\"> child]
expected: TIMEOUT
[<video autoplay> with <track src=\"404\" default=\"\"> child]
expected: TIMEOUT
[<video autoplay> with <track src=\"\" default=\"\"> child]
expected: TIMEOUT

View file

@ -1,23 +0,0 @@
[default.html]
type: testharness
[HTMLTrackElement.default missing value]
expected: FAIL
[HTMLTrackElement.default empty string content attribute]
expected: FAIL
[HTMLTrackElement.default empty string IDL attribute]
expected: FAIL
[HTMLTrackElement.default foo in content attribute]
expected: FAIL
[HTMLTrackElement.default foo in IDL attribute]
expected: FAIL
[HTMLTrackElement.default true in IDL attribute]
expected: FAIL
[HTMLTrackElement.default false in IDL attribute]
expected: FAIL

View file

@ -1,62 +0,0 @@
[kind.html]
type: testharness
[HTMLTrackElement.kind missing value]
expected: FAIL
[HTMLTrackElement.kind invalid value in content attribute]
expected: FAIL
[HTMLTrackElement.kind content attribute uppercase]
expected: FAIL
[HTMLTrackElement.kind content attribute with uppercase turkish I (with dot)]
expected: FAIL
[HTMLTrackElement.kind content attribute with lowercase turkish i (dotless)]
expected: FAIL
[HTMLTrackElement.kind content attribute "subtitles"]
expected: FAIL
[HTMLTrackElement.kind content attribute "captions"]
expected: FAIL
[HTMLTrackElement.kind content attribute "descriptions"]
expected: FAIL
[HTMLTrackElement.kind content attribute "chapters"]
expected: FAIL
[HTMLTrackElement.kind content attribute "metadata"]
expected: FAIL
[HTMLTrackElement.kind content attribute "captions\\u0000"]
expected: FAIL
[HTMLTrackElement.kind setting IDL attribute to "subtitles"]
expected: FAIL
[HTMLTrackElement.kind setting IDL attribute to "captions"]
expected: FAIL
[HTMLTrackElement.kind setting IDL attribute to "descriptions"]
expected: FAIL
[HTMLTrackElement.kind setting IDL attribute to "chapters"]
expected: FAIL
[HTMLTrackElement.kind setting IDL attribute to "metadata"]
expected: FAIL
[HTMLTrackElement.kind setting IDL attribute to "CAPTIONS"]
expected: FAIL
[HTMLTrackElement.kind setting IDL attribute with uppercase turkish I (with dot)]
expected: FAIL
[HTMLTrackElement.kind setting IDL attribute with lowercase turkish I (dotless)]
expected: FAIL
[HTMLTrackElement.kind setting IDL attribute with \\u0000]
expected: FAIL

View file

@ -1,35 +0,0 @@
[label.html]
type: testharness
[HTMLTrackElement.label missing value]
expected: FAIL
[HTMLTrackElement.label empty string content attribute]
expected: FAIL
[HTMLTrackElement.label empty string IDL attribute]
expected: FAIL
[HTMLTrackElement.label lowercase content attribute]
expected: FAIL
[HTMLTrackElement.label uppercase content attribute]
expected: FAIL
[HTMLTrackElement.label\\u0000 in content attribute]
expected: FAIL
[HTMLTrackElement.label lowercase IDL attribute]
expected: FAIL
[HTMLTrackElement.label uppercase IDL attribute]
expected: FAIL
[HTMLTrackElement.label whitespace in content attribute]
expected: FAIL
[HTMLTrackElement.label whitespace in IDL attribute]
expected: FAIL
[HTMLTrackElement.label \\u0000 in IDL attribute]
expected: FAIL

View file

@ -1,8 +0,0 @@
[readyState.html]
type: testharness
[HTMLTrackElement.readyState default value]
expected: FAIL
[HTMLTrackElement.readyState values]
expected: FAIL

View file

@ -1,38 +0,0 @@
[src.html]
type: testharness
[HTMLTrackElement.src missing value]
expected: FAIL
[HTMLTrackElement.src empty string in content attribute]
expected: FAIL
[HTMLTrackElement.src empty string in IDL attribute]
expected: FAIL
[HTMLTrackElement.src unresolvable value in content attribute]
expected: FAIL
[HTMLTrackElement.src assigning unresolvable value to IDL attribute]
expected: FAIL
[HTMLTrackElement.src assigning resolvable value to IDL attribute]
expected: FAIL
[HTMLTrackElement.src assigning \\u0000 to IDL attribute]
expected: FAIL
[HTMLTrackElement.src \\u0000 in content attribute]
expected: FAIL
[HTMLTrackElement.src resolvable value in content attribute]
expected: FAIL
[HTMLTrackElement.src assigning empty string to IDL attribute]
expected: FAIL
[HTMLTrackElement.src foo\\u0000bar in content attribute]
expected: FAIL
[HTMLTrackElement.src assigning foo\\u0000bar to IDL attribute]
expected: FAIL

View file

@ -1,35 +0,0 @@
[srclang.html]
type: testharness
[HTMLTrackElement.srclang missing value]
expected: FAIL
[HTMLTrackElement.srclang empty string content attribute]
expected: FAIL
[HTMLTrackElement.srclang empty string IDL attribute]
expected: FAIL
[HTMLTrackElement.srclang lowercase content attribute]
expected: FAIL
[HTMLTrackElement.srclang uppercase content attribute]
expected: FAIL
[HTMLTrackElement.srclang \\u0000 content attribute]
expected: FAIL
[HTMLTrackElement.srclang lowercase IDL attribute]
expected: FAIL
[HTMLTrackElement.srclang uppercase IDL attribute]
expected: FAIL
[HTMLTrackElement.srclang whitespace in content attribute]
expected: FAIL
[HTMLTrackElement.srclang whitespace in IDL attribute]
expected: FAIL
[HTMLTrackElement.srclang \\u0000 in IDL attribute]
expected: FAIL

View file

@ -1,5 +0,0 @@
[track.html]
type: testharness
[HTMLTrackElement.track]
expected: FAIL

View file

@ -1,21 +1,19 @@
[activeCues.html]
type: testharness
expected: ERROR
[TextTrack.activeCues, empty list]
expected: FAIL
[TextTrack.activeCues, after addCue()]
expected: FAIL
[TextTrack.activeCues, different modes]
expected: FAIL
[TextTrack.activeCues, video loading]
expected: FAIL
[TextTrack.activeCues, video playing]
expected: FAIL
[TextTrack.activeCues, adding cue during playback]
expected: FAIL
[TextTrack.activeCues, video playing]
expected: FAIL
[TextTrack.activeCues, empty list]
expected: FAIL
[TextTrack.activeCues, different modes]
expected: FAIL
[TextTrack.activeCues, after addCue()]
expected: FAIL

View file

@ -1,5 +1,6 @@
[addCue.html]
type: testharness
expected: TIMEOUT
[TextTrack.addCue(), adding a cue to two different tracks]
expected: FAIL
@ -13,5 +14,5 @@
expected: FAIL
[TextTrack.addCue(), adding a cue associated with a track element to other track]
expected: FAIL
expected: TIMEOUT

View file

@ -1,8 +0,0 @@
[mode.html]
type: testharness
[TextTrack.mode, wrong value]
expected: FAIL
[TextTrack.mode, correct value]
expected: FAIL

View file

@ -1,8 +1,9 @@
[removeCue.html]
type: testharness
expected: TIMEOUT
[TextTrack.removeCue(), two elementless tracks]
expected: FAIL
[TextTrack.removeCue(), cue from track element]
expected: FAIL
expected: TIMEOUT

View file

@ -1,8 +1,9 @@
[endTime.html]
type: testharness
expected: TIMEOUT
[TextTrackCue.endTime, script-created cue]
expected: FAIL
[TextTrackCue.endTime, parsed cue]
expected: FAIL
expected: TIMEOUT

View file

@ -1,8 +1,9 @@
[id.html]
type: testharness
expected: TIMEOUT
[TextTrackCue.id, script-created cue]
expected: FAIL
[TextTrackCue.id, parsed cue]
expected: FAIL
expected: TIMEOUT

View file

@ -1,8 +1,9 @@
[pauseOnExit.html]
type: testharness
expected: TIMEOUT
[TextTrackCue.pauseOnExit, script-created cue]
expected: FAIL
[TextTrackCue.pauseOnExit, parsed cue]
expected: FAIL
expected: TIMEOUT

View file

@ -1,8 +1,9 @@
[startTime.html]
type: testharness
expected: TIMEOUT
[TextTrackCue.startTime, script-created cue]
expected: FAIL
[TextTrackCue.startTime, parsed cue]
expected: FAIL
expected: TIMEOUT

View file

@ -1,8 +1,9 @@
[track.html]
type: testharness
expected: TIMEOUT
[TextTrackCue.track, script-created cue]
expected: FAIL
[TextTrackCue.track, parsed cue]
expected: FAIL
expected: TIMEOUT