Skip to content

Commit

Permalink
Implement updated TextTrackCue constructor proposal
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=262053
rdar://116002871

Reviewed by Eric Carlson.

Implements spec changes suggested at:
whatwg/html#9771

Specifically:

 * supports `b` and `i` elements, to match WebVTT
 * drops support for allowing `img` in the cue fragment
 * implements more robust error checking to prevent malformed ::cue and :cuebackground hierarchies
 * As such, ::tagPseudoObjects() can now throw
 * Switch from InvalidStateError to InvalidNodeTypeError for when required attributes are missing
 * implements cuebackground and cue global attributes

* LayoutTests/imported/w3c/web-platform-tests/custom-elements/reactions/HTMLElement-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/custom-elements/reactions/HTMLElement.html:
* LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cue-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cue.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cuebackground-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/cuebackground.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/historical-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/historical.html:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/interfaces/TextTrackCue/constructor-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/interfaces/TextTrackCue/constructor.html:
* LayoutTests/inspector/model/remote-object/dom-expected.txt:
* LayoutTests/media/track/texttrackcue/texttrackcue-constructor-expected.txt:
* LayoutTests/media/track/texttrackcue/texttrackcue-constructor.html:
* Source/WebCore/html/HTMLAttributeNames.in:
* Source/WebCore/html/HTMLElement.idl:
* Source/WebCore/html/track/TextTrackCue.cpp:
(WebCore::isLegalNode):
(WebCore::tagPseudoObjects):
(WebCore::removePseudoAttributes):
(WebCore::TextTrackCue::create):
(WebCore::TextTrackCue::setPauseOnExit):
(WebCore::cueAttributName): Deleted.
(WebCore::cueBackgroundAttributName): Deleted.

Canonical link: https://commits.webkit.org/268644@main
  • Loading branch information
marcoscaceres committed Sep 29, 2023
1 parent b5117f4 commit ed93c31
Show file tree
Hide file tree
Showing 16 changed files with 1,069 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

PASS cue on HTMLElement must enqueue an attributeChanged reaction when adding cue content attribute
PASS cue on HTMLElement must enqueue an attributeChanged reaction when replacing an existing attribute
PASS cuebackground on HTMLElement must enqueue an attributeChanged reaction when adding cuebackground content attribute
PASS cuebackground on HTMLElement must enqueue an attributeChanged reaction when replacing an existing attribute
PASS title on HTMLElement must enqueue an attributeChanged reaction when adding title content attribute
PASS title on HTMLElement must enqueue an attributeChanged reaction when replacing an existing attribute
PASS lang on HTMLElement must enqueue an attributeChanged reaction when adding lang content attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<body>
<div id="log"></div>
<script>

testReflectBooleanAttribute('cue', 'cue', 'cue on HTMLElement');
testReflectBooleanAttribute('cuebackground', 'cuebackground', 'cuebackground on HTMLElement');
testReflectAttribute('title', 'title', 'foo', 'bar', 'title on HTMLElement');
testReflectAttribute('lang', 'lang', 'en', 'zh', 'lang on HTMLElement');
testReflectAttributeWithContentValues('translate', 'translate', true, 'yes', false, 'no', 'translate on HTMLElement');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

PASS "cue" attribute in HTML defaults to false
PASS Boolean attributes should be case-insensitive
PASS Setting "cue" attribute in HTML should set the property to true
PASS Getting a present "cue" attribute should return the attribute value
PASS Setting "cue" attribute using setAttribute should set the property to true
PASS Setting the 'cue' to true should set its value to empty string
PASS Toggling "cue" attribute should result in the correct value
PASS Cloning an element should preserve the boolean attribute
PASS Boolean attribute should work correctly on dynamically created elements
PASS Removing "cue" attribute using removeAttribute should set the property to false
PASS Setting "cue" property via JavaScript should reflect the correct boolean value
PASS Setting "cue" property via JavaScript should reflect in the content attribute
PASS Setting "cue" property in JavaScript with truthy value (boolean true) should set the property to true
PASS Setting "cue" property in JavaScript with truthy value (number 1) should set the property to true
PASS Setting "cue" property in JavaScript with truthy value (string true) should set the property to true
PASS Setting "cue" property in JavaScript with truthy value (object [object Object]) should set the property to true
PASS Setting "cue" property in JavaScript with truthy value (object ) should set the property to true
PASS Setting "cue" property in JavaScript with truthy value (string any-non-empty-string) should set the property to true
PASS Setting "cue" property in JavaScript with falsy value (false) should set the property to false
PASS Setting "cue" property in JavaScript with falsy value (0) should set the property to false
PASS Setting "cue" property in JavaScript with falsy value () should set the property to false
PASS Setting "cue" property in JavaScript with falsy value (null) should set the property to false
PASS Setting "cue" property in JavaScript with falsy value (undefined) should set the property to false

Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<!DOCTYPE html>
<html>
<head>
<title>Test for cue attribute</title>
<link rel="help" href="https://github.com/whatwg/html/pull/9771" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<span id="element1"></span>
<span id="element2" cue></span>
<span id="element3" cue="custom value"></span>
</body>
<script>
const element1 = document.getElementById("element1");
const element2 = document.getElementById("element2");
const element3 = document.getElementById("element3");
test(() => {
assert_false(element1.cue);
}, '"cue" attribute in HTML defaults to false');

test(() => {
element1.setAttribute("CUE", "");
assert_true(element1.cue);
element1.removeAttribute("CUE");
assert_false(element1.cue);
}, "Boolean attributes should be case-insensitive");

test(() => {
assert_true(element2.cue);
}, 'Setting "cue" attribute in HTML should set the property to true');

test(() => {
assert_true(element3.cue);
assert_equals(element3.getAttribute("cue"), "custom value");
element3.setAttribute("cue", "new value")
assert_true(element3.cue);
assert_equals(element3.getAttribute("cue"), "new value");
element3.cue = false;
assert_equals(element3.getAttribute("cue"), null);
}, 'Getting a present "cue" attribute should return the attribute value');

test(() => {
element1.setAttribute("cue", "");
assert_true(element1.cue);
}, 'Setting "cue" attribute using setAttribute should set the property to true');

test(() => {
element1.cuebackground = true;
assert_equals(element1.getAttribute("cue"), "");
}, "Setting the 'cue' to true should set its value to empty string");

test(() => {
element1.cue = true;
assert_true(element1.cue);
element1.cue = false;
assert_false(element1.cue);
element1.cue = true;
assert_true(element1.cue);
}, 'Toggling "cue" attribute should result in the correct value');

test(() => {
element1.cue = true;
const clone = element1.cloneNode(true);
assert_true(clone.cue);
}, "Cloning an element should preserve the boolean attribute");

test(() => {
const dynamicElement = document.createElement("example-element");
assert_false(dynamicElement.cue);
dynamicElement.cue = true;
assert_true(dynamicElement.cue);
}, "Boolean attribute should work correctly on dynamically created elements");

test(() => {
element1.setAttribute("cue", "");
assert_true(element1.cue);
element1.removeAttribute("cue");
assert_false(element1.cue);
}, 'Removing "cue" attribute using removeAttribute should set the property to false');

test(() => {
element1.cue = true;
assert_true(element1.cue);
element1.cue = false;
assert_false(element1.cue);
}, 'Setting "cue" property via JavaScript should reflect the correct boolean value');

test(() => {
element1.cue = false;
assert_false(element1.hasAttribute("cue"));
element1.cue = true;
assert_true(element1.hasAttribute("cue"));
}, 'Setting "cue" property via JavaScript should reflect in the content attribute');

const truthyValues = [true, 1, "true", {}, [], "any-non-empty-string"];
truthyValues.forEach((value) => {
test(() => {
element1.cue = value;
assert_true(element1.cue);
}, `Setting "cue" property in JavaScript with truthy value (${typeof value} ${value}) should set the property to true`);
});

const falsyValues = [false, 0, "", null, undefined];
falsyValues.forEach((value, index) => {
test(() => {
element1.cue = value;
assert_false(element1.cue);
}, `Setting "cue" property in JavaScript with falsy value (${value}) should set the property to false`);
});
</script>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

PASS "cuebackground" attribute in HTML defaults to false
PASS Boolean attributes should be case-insensitive
PASS Setting "cuebackground" attribute in HTML should set the property to true
PASS Getting a present "cuebackground" attribute should return the attribute value
PASS Setting "cuebackground" attribute using setAttribute should set the property to true
PASS Setting the 'cuebackground' to true should set its value to empty string
PASS Toggling "cuebackground" attribute should result in the correct value
PASS Cloning an element should preserve the boolean attribute
PASS Boolean attribute should work correctly on dynamically created elements
PASS Removing "cuebackground" attribute using removeAttribute should set the property to false
PASS Setting "cuebackground" property via JavaScript should reflect the correct boolean value
PASS Setting "cue" property via JavaScript should reflect in the content attribute
PASS Setting "cuebackground" property in JavaScript with truthy value (boolean true) should set the property to true
PASS Setting "cuebackground" property in JavaScript with truthy value (number 1) should set the property to true
PASS Setting "cuebackground" property in JavaScript with truthy value (string true) should set the property to true
PASS Setting "cuebackground" property in JavaScript with truthy value (object [object Object]) should set the property to true
PASS Setting "cuebackground" property in JavaScript with truthy value (object ) should set the property to true
PASS Setting "cuebackground" property in JavaScript with truthy value (string any-non-empty-string) should set the property to true
PASS Setting "cuebackground" property in JavaScript with falsy value (false) should set the property to false
PASS Setting "cuebackground" property in JavaScript with falsy value (0) should set the property to false
PASS Setting "cuebackground" property in JavaScript with falsy value () should set the property to false
PASS Setting "cuebackground" property in JavaScript with falsy value (null) should set the property to false
PASS Setting "cuebackground" property in JavaScript with falsy value (undefined) should set the property to false

Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<!DOCTYPE html>
<html>
<head>
<title>Test for cuebackground attribute</title>
<link rel="help" href="https://github.com/whatwg/html/pull/9771" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<span id="element1"></span>
<span id="element2" cuebackground></span>
<span id="element3" cuebackground="custom value"></span>
</body>
<script>
const element1 = document.getElementById("element1");
const element2 = document.getElementById("element2");
const element3 = document.getElementById("element3");
test(() => {
assert_false(element1.cuebackground);
}, '"cuebackground" attribute in HTML defaults to false');

test(() => {
element1.setAttribute("CUEBACKGROUND", "");
assert_true(element1.cuebackground);
}, "Boolean attributes should be case-insensitive");

test(() => {
assert_true(element2.cuebackground);
}, 'Setting "cuebackground" attribute in HTML should set the property to true');

test(() => {
assert_true(element3.cuebackground);
assert_equals(element3.getAttribute("cuebackground"), "custom value");
element3.setAttribute("cuebackground", "new value")
assert_true(element3.cuebackground);
assert_equals(element3.getAttribute("cuebackground"), "new value");
element3.cuebackground = false;
assert_equals(element3.getAttribute("cuebackground"), null);
}, 'Getting a present "cuebackground" attribute should return the attribute value');

test(() => {
element1.setAttribute("cuebackground", "");
assert_true(element1.cuebackground);
}, 'Setting "cuebackground" attribute using setAttribute should set the property to true');

test(() => {
element1.cuebackground = true;
assert_equals(element1.getAttribute("cuebackground"), "");
}, "Setting the 'cuebackground' to true should set its value to empty string");

test(() => {
element1.cuebackground = true;
assert_true(element1.cuebackground);
element1.cuebackground = false;
assert_false(element1.cuebackground);
element1.cuebackground = true;
assert_true(element1.cuebackground);
}, 'Toggling "cuebackground" attribute should result in the correct value');

test(() => {
element1.cuebackground = true;
const clone = element1.cloneNode(true);
assert_true(clone.cuebackground);
}, "Cloning an element should preserve the boolean attribute");

test(() => {
const dynamicElement = document.createElement("example-element");
assert_false(dynamicElement.cuebackground);
dynamicElement.cuebackground = true;
assert_true(dynamicElement.cuebackground);
}, "Boolean attribute should work correctly on dynamically created elements");

test(() => {
element1.setAttribute("cuebackground", "");
assert_true(element1.cuebackground);
element1.removeAttribute("cuebackground");
assert_false(element1.cuebackground);
}, 'Removing "cuebackground" attribute using removeAttribute should set the property to false');

test(() => {
element1.cuebackground = true;
assert_true(element1.cuebackground);
element1.cuebackground = false;
assert_false(element1.cuebackground);
}, 'Setting "cuebackground" property via JavaScript should reflect the correct boolean value');

test(() => {
element1.cue = false;
assert_false(element1.hasAttribute("cue"));
element1.cue = true;
assert_true(element1.hasAttribute("cue"));
}, 'Setting "cue" property via JavaScript should reflect in the content attribute');

const truthyValues = [true, 1, "true", {}, [], "any-non-empty-string"];
truthyValues.forEach((value) => {
test(() => {
element1.cuebackground = value;
assert_true(element1.cuebackground);
}, `Setting "cuebackground" property in JavaScript with truthy value (${typeof value} ${value}) should set the property to true`);
});

const falsyValues = [false, 0, "", null, undefined];
falsyValues.forEach((value, index) => {
test(() => {
element1.cuebackground = value;
assert_false(element1.cuebackground);
}, `Setting "cuebackground" property in JavaScript with falsy value (${value}) should set the property to false`);
});
</script>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ PASS audio.mozPreservesPitch should not be supported
PASS video.mozPreservesPitch should not be supported
FAIL audio.webkitPreservesPitch should not be supported assert_false: expected false got true
FAIL video.webkitPreservesPitch should not be supported assert_false: expected false got true
PASS TextTrackCue constructor should not be supported
FAIL audio.mediaGroup should not be supported assert_false: expected false got true
FAIL video.mediaGroup should not be supported assert_false: expected false got true
FAIL audio.controller should not be supported assert_false: expected false got true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@
t('mozPreservesPitch'); // prefixed version should be removed.
t('webkitPreservesPitch'); // prefixed version should be removed.

// TextTrackCue constructor: added in r5723, removed in r7742.
test(function() {
assert_throws_js(TypeError, function() {
new TextTrackCue(0, 0, '');
});
}, 'TextTrackCue constructor should not be supported');

// added in https://github.com/whatwg/html/commit/66c5b32240c202c74f475872e7ea2cd163777b4a
// removed in https://github.com/whatwg/html/commit/634698e70ea4586d58c989fa7d2cbfcad20d33e6
t('mediaGroup');
Expand Down
Loading

0 comments on commit ed93c31

Please sign in to comment.