Bug 1513857 [wpt PR 14491] - Add CEReactions tests for HTMLBaseElement, a=testonly
authorkaixinjxq <xiuqix.jiang@intel.com>
Tue, 05 Mar 2019 12:15:07 +0000
changeset 522446 2f840f6a520912ad49da1fc461244b4edf3dfadd
parent 522445 51e1957476b218de66b0d3587106a8fb7589e244
child 522447 ad337b335d8d92df29535f4ff7b30896937a4e0b
push id10871
push usercbrindusan@mozilla.com
push dateMon, 18 Mar 2019 15:49:32 +0000
treeherdermozilla-beta@018abdd16060 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1513857, 14491
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1513857 [wpt PR 14491] - Add CEReactions tests for HTMLBaseElement, a=testonly Automatic update from web-platform-tests Add CEReactions tests for HTMLBaseElement -- wpt-commits: ce667da7c2cf7485f9d818deb67641613b0c5ef3 wpt-pr: 14491
testing/web-platform/tests/custom-elements/reactions/HTMLBaseElement.html
testing/web-platform/tests/custom-elements/reactions/HTMLButtonElement.html
testing/web-platform/tests/custom-elements/reactions/resources/reactions.js
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/custom-elements/reactions/HTMLBaseElement.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<head>
+<title>Custom Elements: CEReactions on HTMLBaseElement interface</title>
+<link rel="author" title="Intel" href="http://www.intel.com">
+<meta name="assert" content="href, target of HTMLBaseElement interface must have CEReactions">
+<meta name="help" content="https://html.spec.whatwg.org/#the-base-element">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../resources/custom-elements-helpers.js"></script>
+<script src="./resources/reactions.js"></script>
+</head>
+<script>
+
+function getParentElement() {
+  return document.head;
+}
+
+testReflectAttributeWithParentNode('href', 'href', '/', 'http://example.com/', 'href on HTMLBaseElement', 'base', getParentElement, HTMLBaseElement);
+testReflectAttributeWithParentNode('target', 'target', '_blank', '_self', 'target on HTMLBaseElement', 'base', getParentElement, HTMLBaseElement);
+
+</script>
--- a/testing/web-platform/tests/custom-elements/reactions/HTMLButtonElement.html
+++ b/testing/web-platform/tests/custom-elements/reactions/HTMLButtonElement.html
@@ -5,65 +5,33 @@
 <meta name="help" content="https://html.spec.whatwg.org/#htmlbuttonelement">
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="../resources/custom-elements-helpers.js"></script>
 <script src="./resources/reactions.js"></script>
 <body>
 <script>
 
+function getParentElement(parentElementName) {
+  let parentElement = document.createElement(parentElementName);
+  document.body.appendChild(parentElement);
+  return parentElement;
+}
+
 testReflectAttributeWithContentValues('autofocus', 'autofocus', true, 'true', false, 'false', 'autofocus on HTMLButtonElement', 'button', HTMLButtonElement);
 testReflectAttributeWithContentValues('disabled', 'disabled', true, 'true', false, 'false', 'disabled on HTMLButtonElement', 'button', HTMLButtonElement);
 testReflectAttribute('name', 'name', 'intel', 'intel1', 'name on HTMLButtonElement', 'button', HTMLButtonElement);
 testReflectAttribute('value', 'value', 'HTML', 'CSS', 'value on HTMLButtonElement', 'button', HTMLButtonElement);
-testReflectAttrWithParentNode('type', 'type', 'submit', 'submit', 'reset', 'reset', 'type on HTMLButtonElement', 'button', 'form', HTMLButtonElement);
+testReflectAttributeWithParentNode('type', 'type', 'submit', 'reset', 'type on HTMLButtonElement', 'button', () => getParentElement('form'), HTMLButtonElement);
 testReflectAttrWithDepAttr('formAction', 'formaction', 'type', 'intel.asp', 'intel1.asp', 'submit', 'formAction on HTMLButtonElement', 'button', 'form', HTMLButtonElement);
 testReflectAttrWithDepAttr('formEnctype', 'formenctype', 'type', 'text/plain', 'multipart/form-data', 'submit', 'formEnctype on HTMLButtonElement', 'button', 'form', HTMLButtonElement);
 testReflectAttrWithDepAttr('formMethod', 'formmethod', 'type', 'get', 'post', 'submit', 'formMethod on HTMLButtonElement', 'button', 'form', HTMLButtonElement);
 testReflectAttrWithContentValuesAndDepAttr('formNoValidate', 'formnovalidate', 'type', true, 'true', false, 'false', 'submit', 'formNoValidate on HTMLButtonElement', 'button', 'form', HTMLButtonElement);
 testReflectAttrWithDepAttr('formTarget', 'formtarget', 'type', '_blank', '_self', 'submit', 'formTarget on HTMLButtonElement', 'button', 'form', HTMLButtonElement);
 
-//In parent node, sub node's observeAttribute can enqueue by changing attribute value 
-//Test reflect attribute with content values and parent node
-function testReflectAttrWithParentNode(jsAtName, coAtName, jsAtValue1, coAtValue1, jsAtValue2, coAtValue2, name, elementName, pElementName, interfaceName) {
-    var parentElement = document.createElement(pElementName);
-    document.body.appendChild(parentElement);
-
-    test(() => {
-        var element = define_build_in_custom_element([coAtName], interfaceName, elementName);
-        var instance = document.createElement(elementName, { is: element.name });
-
-        assert_array_equals(element.takeLog().types(), ['constructed']);
-        parentElement.appendChild(instance);
-        assert_array_equals(element.takeLog().types(), ['connected']);
-        instance[jsAtName] = jsAtValue1;
-        var logEntries = element.takeLog();
-        assert_array_equals(logEntries.types(), ['attributeChanged']);
-        assert_attribute_log_entry(logEntries.last(), { name: coAtName, oldValue: null, newValue: coAtValue1, namespace: null });
-
-    }, name + ' must enqueue an attributeChanged reaction when adding a new attribute');
-
-    test(() => {
-        var element = define_build_in_custom_element([coAtName], interfaceName, elementName);
-        var instance = document.createElement(elementName, { is: element.name });
-        parentElement.appendChild(instance);
-
-        assert_array_equals(element.takeLog().types(), ['constructed', 'connected']);
-        instance[jsAtName] = jsAtValue1;
-        assert_array_equals(element.takeLog().types(), ['attributeChanged']);
-        instance[jsAtName] = jsAtValue2;
-        var logEntries = element.takeLog();
-        assert_array_equals(logEntries.types(), ['attributeChanged']);
-        assert_attribute_log_entry(logEntries.last(), { name: coAtName, oldValue: coAtValue1, newValue: coAtValue2, namespace: null });
-
-    }, name + ' must enqueue an attributeChanged reaction when replacing an existing attribute');
-
-    parentElement.parentNode.removeChild(parentElement);
-}
-
 //In parent node, sub node's observeAttribute which depends another attribute can enqueue by changing attribute value
 //Test reflect attribute with content values and dependent attribute 
 function testReflectAttrWithContentValuesAndDepAttr(jsAtName, coAtName, deAtName, jsAtValue1, coAtValue1, jsAtValue2, coAtValue2, deAtValue, name, elementName, pElementName, interfaceName) {
     var parentElement = document.createElement(pElementName);
     document.body.appendChild(parentElement);
 
     test(() => {
         var element = define_build_in_custom_element([coAtName], interfaceName, elementName);
--- a/testing/web-platform/tests/custom-elements/reactions/resources/reactions.js
+++ b/testing/web-platform/tests/custom-elements/reactions/resources/reactions.js
@@ -163,16 +163,51 @@ function testReflectAttributeWithContent
 function testReflectAttribute(jsAttributeName, contentAttributeName, validValue1, validValue2, name, elementName, interfaceName) {
     testReflectAttributeWithContentValues(jsAttributeName, contentAttributeName, validValue1, validValue1, validValue2, validValue2, name, elementName, interfaceName);
 }
 
 function testReflectBooleanAttribute(jsAttributeName, contentAttributeName, name, elementName, interfaceName) {
     testReflectAttributeWithContentValues(jsAttributeName, contentAttributeName, true, '', false, null, name, elementName, interfaceName);
 }
 
+function testReflectAttributeWithContentValuesAndParentNode(jsAttributeName, contentAttributeName, validValue1, contentValue1, validValue2, contentValue2, name, elementName, getParentElement, interfaceName) {
+    let parentElement = getParentElement();
+
+    test(() => {
+        let element = define_build_in_custom_element([contentAttributeName], interfaceName, elementName);
+        let instance = document.createElement(elementName, { is: element.name });
+
+        assert_array_equals(element.takeLog().types(), ['constructed']);
+        parentElement.appendChild(instance);
+        assert_array_equals(element.takeLog().types(), ['connected']);
+        instance[jsAttributeName] = validValue1;
+        let logEntries = element.takeLog();
+        assert_array_equals(logEntries.types(), ['attributeChanged']);
+        assert_attribute_log_entry(logEntries.last(), { name: contentAttributeName, oldValue: null, newValue: contentValue1, namespace: null });
+}, name + ' must enqueue an attributeChanged reaction when adding a new attribute');
+
+    test(() => {
+        let element = define_build_in_custom_element([contentAttributeName], interfaceName, elementName);
+        let instance = document.createElement(elementName, { is: element.name });
+        parentElement.appendChild(instance);
+
+        assert_array_equals(element.takeLog().types(), ['constructed', 'connected']);
+        instance[jsAttributeName] = validValue1;
+        assert_array_equals(element.takeLog().types(), ['attributeChanged']);
+        instance[jsAttributeName] = validValue2;
+        let logEntries = element.takeLog();
+        assert_array_equals(logEntries.types(), ['attributeChanged']);
+        assert_attribute_log_entry(logEntries.last(), { name: contentAttributeName, oldValue: contentValue1, newValue: contentValue2, namespace: null });
+    }, name + ' must enqueue an attributeChanged reaction when replacing an existing attribute');
+}
+
+function testReflectAttributeWithParentNode(jsAttributeName, contentAttributeName, validValue1, validValue2, name, elementName, getParentElement, interfaceName) {
+    testReflectAttributeWithContentValuesAndParentNode(jsAttributeName, contentAttributeName, validValue1, validValue1, validValue2, validValue2, name, elementName, getParentElement, interfaceName);
+}
+
 function testAttributeAdder(testFunction, name) {
     test(function () {
         var element = define_new_custom_element(['id']);
         var instance = document.createElement(element.name);
         assert_array_equals(element.takeLog().types(), ['constructed']);
         testFunction(instance, 'id', 'foo');
         var logEntries = element.takeLog();
         assert_array_equals(logEntries.types(), ['attributeChanged']);