Skip to content

Commit

Permalink
Add HTMLButtonElement interface to custom element test
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyu3x committed Mar 21, 2018
1 parent af3876f commit 58fba0d
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 7 deletions.
112 changes: 112 additions & 0 deletions tests/custom-elements/reactions/HTMLButtonElement.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<!DOCTYPE html>
<title>Custom Elements: CEReactions on HTMLButtonElement interface</title>
<meta name="author" title="Zhang xiaoyu" href="[email protected]">
<meta name="assert" content=" autofocus, disabled, formAction, formEnctype, formMethod, formNoValidate, formTarget, name, type, value of HTMLButtonElement interface must have CEReactions">
<meta name="help" content="https://html.spec.whatwg.org/#htmlbuttonelement">
<script src="/tests/custom-elements/resources/testharness.js"></script>
<script src="/tests/custom-elements/resources/testharnessreport.js"></script>
<script src="./custom-elements-helpers.js"></script>
<script src="./reactions.js"></script>
<body>
<script>

//In parent node, sub node's observeAttribute can enqueue by changing attribute value
//Re->reflect, At->attribute, P->parent, Co->content
function testReAtWithPNodeWithCoValues(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);
}

//Package JS attribute with parent Node to test
function testReAtWithPNode(jsAtName, coAtName, jsAtValue1, jsAtValue2, name, elementName, pElementName, interfaceName) {
testReAtWithPNodeWithCoValues(jsAtName, coAtName, jsAtValue1, jsAtValue1, jsAtValue2, jsAtValue2, name, elementName, pElementName, interfaceName);
}

//In parent node, sub node's observeAttribute which depends another attribute can enqueue by changing attribute value
//Re->reflect, At->attribute, De->depdent, Co->content
function testReAtWithDeAtWithCoValues(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);
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.setAttribute(deAtName, deAtValue);
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);
instance.setAttribute(deAtName, deAtValue);
instance[jsAtName] = jsAtValue1;

assert_array_equals(element.takeLog().types(), ['constructed', 'connected', '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);
}

//Package JS attribute depends another atrribute
function testReAtWithDeAt(jsAtName, coAtName, deAtName, jsAtValue1, jsAtValue2, deAtValue, name, elementName, pElementName, interfaceName) {
testReAtWithDeAtWithCoValues(jsAtName, coAtName, deAtName, jsAtValue1, jsAtValue1, jsAtValue2, jsAtValue2, deAtValue, name, elementName, pElementName, interfaceName);
}

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);
testReAtWithPNode('type', 'type', 'submit', 'reset', 'type on HTMLButtonElement', 'button', 'form', HTMLButtonElement);
testReAtWithDeAt('formAction', 'formaction', 'type', 'intel.asp', 'intel1.asp', 'submit', 'formAction on HTMLButtonElement', 'button', 'form', HTMLButtonElement);
testReAtWithDeAt('formEnctype', 'formenctype', 'type', 'text/plain', 'multipart/form-data', 'submit', 'formEnctype on HTMLButtonElement', 'button', 'form', HTMLButtonElement);
testReAtWithDeAt('formMethod', 'formmethod', 'type', 'get', 'post', 'submit', 'formMethod on HTMLButtonElement', 'button', 'form', HTMLButtonElement);
testReAtWithDeAtWithCoValues('formNoValidate', 'formnoValidate', 'type', true, 'true', false, 'false', 'submit', 'formNoValidate on HTMLButtonElement', 'button', 'form', HTMLButtonElement);
testReAtWithDeAt('formTarget', 'formtarget', 'type', '_blank', '_self', 'submit', 'formTarget on HTMLButtonElement', 'button', 'form', HTMLButtonElement);

</script>
</body>
24 changes: 17 additions & 7 deletions tests/custom-elements/reactions/reactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,15 @@ function testCloner(testFunction, name) {
}, name + ' must enqueue an attributeChanged reaction when cloning an element only for observed attributes');
}

function testReflectAttributeWithContentValues(jsAttributeName, contentAttributeName, validValue1, contentValue1, validValue2, contentValue2, name) {
function testReflectAttributeWithContentValues(jsAttributeName, contentAttributeName, validValue1, contentValue1, validValue2, contentValue2, name, elementName, interfaceName) {
test(function () {
var element = define_new_custom_element([contentAttributeName]);
var instance = document.createElement(element.name);
if(elementName === undefined) {
var element = define_new_custom_element([contentAttributeName]);
var instance = document.createElement(element.name);
} else {
var element = define_build_in_custom_element([contentAttributeName], interfaceName, elementName);
var instance = document.createElement(elementName, { is: element.name});
}
assert_array_equals(element.takeLog().types(), ['constructed']);
instance[jsAttributeName] = validValue1;
var logEntries = element.takeLog();
Expand All @@ -139,8 +144,13 @@ function testReflectAttributeWithContentValues(jsAttributeName, contentAttribute
}, name + ' must enqueue an attributeChanged reaction when adding ' + contentAttributeName + ' content attribute');

test(function () {
var element = define_new_custom_element([contentAttributeName]);
var instance = document.createElement(element.name);
if(elementName === undefined) {
var element = define_new_custom_element([contentAttributeName]);
var instance = document.createElement(element.name);
} else {
var element = define_build_in_custom_element([contentAttributeName], interfaceName, elementName);
var instance = document.createElement(elementName, { is: element.name});
}
instance[jsAttributeName] = validValue1;
assert_array_equals(element.takeLog().types(), ['constructed', 'attributeChanged']);
instance[jsAttributeName] = validValue2;
Expand All @@ -150,8 +160,8 @@ function testReflectAttributeWithContentValues(jsAttributeName, contentAttribute
}, name + ' must enqueue an attributeChanged reaction when replacing an existing attribute');
}

function testReflectAttribute(jsAttributeName, contentAttributeName, validValue1, validValue2, name) {
testReflectAttributeWithContentValues(jsAttributeName, contentAttributeName, validValue1, validValue1, validValue2, validValue2, name);
function testReflectAttribute(jsAttributeName, contentAttributeName, validValue1, validValue2, name, elementName, interfaceName) {
testReflectAttributeWithContentValues(jsAttributeName, contentAttributeName, validValue1, validValue1, validValue2, validValue2, name, elementName, interfaceName);
}

function testReflectBooleanAttribute(jsAttributeName, contentAttributeName, name) {
Expand Down

0 comments on commit 58fba0d

Please sign in to comment.