Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for 'class' and 'for' aliases for 'className' and 'htmlFor' #48220

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion acid/acid3/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -2264,7 +2264,7 @@
assert(test.htmlFor != test.getAttribute('htmlFor'), "pots: htmlFor attribute equals htmlFor property");
assert(!('for' in test), "pots: element has for property");
test['for'] = "oil";
assert(test.htmlFor != "oil", "pots: for property affected htmlFor");
assert(test.htmlFor == "oil", "pots: for property did not affect htmlFor");
schenney-chromium marked this conversation as resolved.
Show resolved Hide resolved
// <meta http-equiv="">
test = document.createElement('meta');
test.setAttribute('http-equiv', 'boxes');
Expand Down
2 changes: 2 additions & 0 deletions dom/lists/DOMTokenList-coverage-for-attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

var pairs = [
// Defined in DOM
{attr: "class", sup: ["anyElement"]},
{attr: "classList", sup: ["anyElement"]},
// Defined in HTML except for a which is also SVG
{attr: "relList", sup: ["a", "area", "link"]},
// Defined in HTML
{attr: "for", sup: ["output"]},
{attr: "htmlFor", sup: ["output"]},
{attr: "sandbox", sup: ["iframe"]},
{attr: "sizes", sup: ["link"]}
Expand Down
32 changes: 32 additions & 0 deletions dom/nodes/Element-class-alias.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>class alias for className</title>
<link rel="author" title="Psychpsyo" href="mailto:[email protected]">
<link rel="help" href="https://dom.spec.whatwg.org/#dom-element-class">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Tests if the class and className IDL attributes do the same</h1>
<div id="testDiv"></div>

<script>
test(function() {
assert_true(testDiv.class == "", "class must reflect \"class\"");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use assert_equals

assert_true(testDiv.className == "", "className must reflect \"class\"");

testDiv.setAttribute("class", "test 1");
assert_true(testDiv.class == "test 1", "class must reflect changes made to \"class\"");
assert_true(testDiv.className == "test 1", "className must reflect changes made to \"class\"");
});
test(function() {
testDiv.className = "test 2";
assert_true(testDiv.class == "test 2", "setting className must be reflected by class");
assert_true(testDiv.className == "test 2", "setting className must be reflected by className");
assert_true(testDiv.getAttribute("class") == "test 2", "setting className must be reflected by \"class\"");
});
test(function() {
testDiv.class = "test 3";
assert_true(testDiv.class == "test 3", "setting class must be reflected by class");
assert_true(testDiv.className == "test 3", "setting class must be reflected by className");
assert_true(testDiv.getAttribute("class") == "test 3", "setting class must be reflected by \"class\"");
});
</script>
37 changes: 37 additions & 0 deletions html/the-elements-of-html/html_for_alias.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>for alias for htmlFor</title>
<link rel="author" title="Psychpsyo" href="mailto:[email protected]">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-label-for">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-output-for">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Tests if the for and htmlFor IDL attributes on &lt;label&gt; and &lt;output&gt; and do the same</h1>

<script>
const elements = [document.createElement("label"), document.createElement("output")]
test(function() {
for (const elem of elements) {
assert_true(elem.for == "", "for must reflect \"for\"");
assert_true(elem.htmlFor == "", "htmlFor must reflect \"for\"");

elem.setAttribute("for", "test1");
assert_true(elem.for == "test1", "for must reflect changes made to \"for\"");
assert_true(elem.htmlFor == "test1", "htmlFor must reflect changes made to \"for\"");
}
});
test(function() {
for (const elem of elements) {
elem.htmlFor = "test2";
assert_true(elem.for == "test2", "setting htmlFor must be reflected by for");
assert_true(elem.htmlFor == "test2", "setting htmlFor must be reflected by htmlFor");
}
});
test(function() {
for (const elem of elements) {
elem.for = "test3";
assert_true(elem.for == "test3", "setting for must be reflected by for");
assert_true(elem.htmlFor == "test3", "setting for must be reflected by htmlFor");
}
});
</script>
3 changes: 2 additions & 1 deletion interfaces/dom.idl
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ interface Element : Node {
readonly attribute DOMString tagName;

[CEReactions] attribute DOMString id;
[CEReactions] attribute DOMString className;
[CEReactions] attribute DOMString class;
[CEReactions] attribute DOMString className; // legacy alias of .class
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that a bot will make those changes as soon as the spec change lands

[SameObject, PutForwards=value] readonly attribute DOMTokenList classList;
[CEReactions, Unscopable] attribute DOMString slot;

Expand Down
6 changes: 4 additions & 2 deletions interfaces/html.idl
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,8 @@ interface HTMLLabelElement : HTMLElement {
[HTMLConstructor] constructor();

readonly attribute HTMLFormElement? form;
[CEReactions] attribute DOMString htmlFor;
[CEReactions] attribute DOMString for;
[CEReactions] attribute DOMString htmlFor; // legacy alias of .for
readonly attribute HTMLElement? control;
};

Expand Down Expand Up @@ -1084,7 +1085,8 @@ interface HTMLTextAreaElement : HTMLElement {
interface HTMLOutputElement : HTMLElement {
[HTMLConstructor] constructor();

[SameObject, PutForwards=value] readonly attribute DOMTokenList htmlFor;
[SameObject, PutForwards=value] readonly attribute DOMTokenList for;
[SameObject, PutForwards=value] readonly attribute DOMTokenList htmlFor; // legacy alias of .for
readonly attribute HTMLFormElement? form;
[CEReactions] attribute DOMString name;

Expand Down