Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: third_party/WebKit/LayoutTests/external/wpt/html/semantics/forms/the-option-element/option-element-constructor.html

Issue 2891723002: Do not create child node for Option constructor with no arguments/undefined text (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/external/wpt/html/semantics/forms/the-option-element/option-element-constructor.html
diff --git a/third_party/WebKit/LayoutTests/external/wpt/html/semantics/forms/the-option-element/option-element-constructor.html b/third_party/WebKit/LayoutTests/external/wpt/html/semantics/forms/the-option-element/option-element-constructor.html
new file mode 100644
index 0000000000000000000000000000000000000000..ad3104b6590afa3d56dc1669c99ba9b7b6d3d23e
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/html/semantics/forms/the-option-element/option-element-constructor.html
@@ -0,0 +1,120 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Option element constructor</title>
+<link rel="author" title="Alex Pearson" href="mailto:alex@alexpear.com">
+<link rel="help" href="https://html.spec.whatwg.org/#the-option-element">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<div id="parent">
+ <div id="child" tabindex="0"></div>
+</div>
+
+<body>
+<script>
+ "use strict";
+
+ test(() => {
+ const option = new Option();
+
+ assert_true(option instanceof HTMLOptionElement);
+
+ assert_false(option.hasChildNodes());
+ assert_false(option.hasAttribute("value"));
+ assert_false(option.hasAttribute("selected"));
+ assert_false(option.selected);
+
+ assert_equals(option.textContent, "");
+ assert_equals(option.value, "");
+ }, "Option constructor with no arguments");
+
+ test(() => {
+ const option = new Option(false, false);
+
+ assert_true(option instanceof HTMLOptionElement);
+
+ assert_true(option.hasChildNodes());
+ assert_equals(option.childNodes.length, 1);
+ assert_equals(option.childNodes[0].nodeType, Node.TEXT_NODE);
+ assert_equals(option.childNodes[0].data, "false");
+ assert_equals(option.getAttribute("value"), "false");
+ assert_false(option.hasAttribute("selected"));
+ assert_false(option.selected);
+
+ assert_equals(option.textContent, "false");
+ assert_equals(option.value, "false");
+ }, "Option constructor with falsy arguments");
+
+ test(() => {
+ const option = new Option("text", "value");
+
+ assert_true(option.hasChildNodes());
+ assert_equals(option.childNodes.length, 1);
+ assert_equals(option.childNodes[0].nodeType, Node.TEXT_NODE);
+ assert_equals(option.childNodes[0].data, "text");
+ assert_equals(option.getAttribute("value"), "value");
+ assert_false(option.hasAttribute("selected"));
+ assert_false(option.selected);
+
+ assert_equals(option.textContent, "text");
+ assert_equals(option.value, "value");
+ }, "Option constructor creates HTMLOptionElement with specified text and value");
+
+ test(() => {
+ const notSelected = new Option("text", "value", false);
+ const selected = new Option("text", "value", true);
+
+ assert_false(notSelected.hasAttribute("selected"));
+ assert_equals(notSelected.getAttribute("selected"), null);
+ assert_false(notSelected.selected);
+
+ assert_equals(selected.getAttribute("selected"), "");
+ assert_false(selected.selected);
+ }, "Option constructor handles selectedness correctly when specified with defaultSelected only");
+
+ test(() => {
+ const notSelected = new Option("text", "value", true, false);
+ const selected = new Option("text", "value", false, true);
+
+ assert_equals(notSelected.selected, false);
+ assert_equals(selected.selected, true);
+ }, "Option constructor handles selectedness correctly, even when incongruous with defaultSelected");
+
+ test(() => {
+ const option = new Option(undefined, undefined);
+
+ assert_false(option.hasChildNodes());
+ assert_false(option.hasAttribute("value"));
+
+ assert_equals(option.textContent, "");
+ assert_equals(option.value, "");
+ }, "Option constructor treats undefined text and value correctly");
+
+ test(() => {
+ const option = new Option("text", "value", 0, "");
+
+ assert_false(option.hasAttribute("selected"));
+ assert_false(option.selected);
+ }, "Option constructor treats falsy selected and defaultSelected correctly");
+
+ test(() => {
+ const option = new Option("text", "value", {}, 1);
+
+ assert_true(option.hasAttribute("selected"));
+ assert_true(option.selected);
+ }, "Option constructor treats truthy selected and defaultSelected correctly");
+
+ test(() => {
+ const option = new Option("text", "value", false, true);
+
+ assert_false(option.hasAttribute("selected"));
+ assert_true(option.selected);
+
+ option.setAttribute("selected", "");
+ assert_true(option.selected);
+
+ option.removeAttribute("selected");
+ assert_false(option.selected);
+ }, "Option constructor does not set dirtiness (so, manipulating the selected content attribute still updates the " +
+ "selected IDL attribute)");
+</script>

Powered by Google App Engine
This is Rietveld 408576698