diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/custom-elements/v0/custom-element-lifecycle/types-of-callbacks/attribute-changed-callback-remove-attribute-test.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/custom-elements/v0/custom-element-lifecycle/types-of-callbacks/attribute-changed-callback-remove-attribute-test.html')
-rw-r--r-- | testing/web-platform/tests/custom-elements/v0/custom-element-lifecycle/types-of-callbacks/attribute-changed-callback-remove-attribute-test.html | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/testing/web-platform/tests/custom-elements/v0/custom-element-lifecycle/types-of-callbacks/attribute-changed-callback-remove-attribute-test.html b/testing/web-platform/tests/custom-elements/v0/custom-element-lifecycle/types-of-callbacks/attribute-changed-callback-remove-attribute-test.html new file mode 100644 index 000000000..fb451b074 --- /dev/null +++ b/testing/web-platform/tests/custom-elements/v0/custom-element-lifecycle/types-of-callbacks/attribute-changed-callback-remove-attribute-test.html @@ -0,0 +1,166 @@ +<!DOCTYPE html> +<html> +<head> +<title>Test attribute removing to check attributeChanged callback of a custom element</title> +<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru"> +<meta name="assert" content="attributeChanged callback must be enqueued whenever custom element's attribute is removed"> +<link rel="help" href="http://www.w3.org/TR/custom-elements/#types-of-callbacks"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="../../testcommon.js"></script> +</head> +<body> +<div id="log"></div> +<script> +test(function() { + var doc = newHTMLDocument(); + var proto = newHTMLElementPrototype(); + var GeneratedConstructor = doc.registerElement('x-a', {prototype: proto}); + + var customElement = new GeneratedConstructor(); + //attributeChangedCallback should be called the first time here + customElement.setAttribute('class', 'someClass'); + //attributeChangedCallback should be called the second time here + customElement.removeAttribute('class'); + assert_equals(proto.attributeChangedCallbackCalledCounter, 2, 'Callback attributeChanged should be called ' + + 'after setAttribute() and removeAttribute() calls'); +}, 'Test attributeChanged callback if attribute is removed. ' + + 'The custom element created via constructor'); + + +test(function() { + var doc = newHTMLDocument(); + HTML5_ELEMENTS.forEach(function(element) { + var obj = doc.createElement(element); + var proto = newCustomElementPrototype(obj.constructor.prototype); + var GeneratedConstructor = doc.registerElement('x-' + element + '-' + element + '-1', { + prototype: proto, + extends: element + }); + + var customElement = new GeneratedConstructor(); + //attributeChangedCallback should be called the first time here + customElement.setAttribute('class', 'someClass'); + //attributeChangedCallback should be called the second time here + customElement.removeAttribute('class'); + assert_equals(proto.attributeChangedCallbackCalledCounter, 2, + 'Callback attributeChanged should be called ' + + 'after setAttribute() and removeAttribute() calls for "' + element + '"'); + }); +}, 'Test attributeChanged callback if attribute is removed. ' + + 'The custom element created via constructor and extends HTML element'); + + +test(function() { + var doc = newHTMLDocument(); + var proto = newHTMLElementPrototype(); + doc.registerElement('x-b', {prototype: proto}); + + doc.body.innerHTML = '<x-b id="x-b" class="theClass"></x-b>'; + var customElement = doc.querySelector('#x-b'); + customElement.removeAttribute('class'); + assert_equals(proto.attributeChangedCallbackCalledCounter, 1, + 'Callback attributeChanged should be called ' + + 'after removeAttribute() call'); +}, 'Test attributeChanged callback if attribute is removed. ' + + 'The custom element created via innerHTML property'); + + +test(function() { + var doc = newHTMLDocument(); + var proto = newHTMLElementPrototype(); + doc.registerElement('x-c', {prototype: proto}); + + doc.body.innerHTML = '<x-c id="x-c" class="theClass"></x-c>'; + var customElement = doc.querySelector('#x-c'); + customElement.removeAttribute('class'); + assert_equals(proto.attributeChangedCallbackArgs[2], null, + 'Removing an attribute should invoke ' + + 'the attributeChanged callback with a null new value'); + assert_array_equals(proto.attributeChangedCallbackArgs, + ['class', 'theClass', null], + 'Unexpected attributeChanged callback arguments'); +}, 'Test attributeChanged callback arguments if attribute is removed. ' + + 'The custom element created via innerHTML property'); + + +test(function() { + var doc = newHTMLDocument(); + var proto = newHTMLElementPrototype(); + + doc.body.innerHTML = '<x-d id="x-d" class="theClass"></x-d>'; + var customElement = doc.querySelector('#x-d'); + // this should not call or enqueue attributeChangedCallback + customElement.setAttribute('class', 'someClass'); + // this one should not too + customElement.removeAttribute('class'); + assert_equals(proto.attributeChangedCallbackCalledCounter, 0, + 'Callback attributeChanged should not be called'); + + doc.registerElement('x-d', {prototype: proto}); + // this call invokes attributeChangedCallback + customElement.setAttribute('name', 'someName'); + // and this one + customElement.removeAttribute('name'); + assert_equals(proto.attributeChangedCallbackCalledCounter, 2, + 'Callback attributeChanged should be called ' + + 'after setAttribute() and removeAttribute() calls'); +}, 'Test attributeChanged callback is not called if attribute is removed. ' + + 'The custom element created via innerHTML property and unresolved at first'); + + +testInIFrame('../../resources/x-element.html', function(doc) { + var proto = newHTMLElementPrototype(); + doc.registerElement('x-element', {prototype: proto}); + + var customElement = doc.querySelector('#x-element'); + customElement.setAttribute('class', 'someClass'); + customElement.removeAttribute('class'); + assert_equals(proto.attributeChangedCallbackCalledCounter, 2, + 'Callback attributeChanged should be called ' + + 'after setAttribute() and removeAttribute() calls'); +}, 'Test attributeChanged callback is called if attribute is removed. ' + + 'The custom element created via constructor and the document has browsing context'); + + +testInIFrame('../../resources/x-element.html', function(doc) { + var proto = newHTMLElementPrototype(); + doc.registerElement('x-element', {prototype: proto}); + + doc.body.innerHTML = '<x-element id="x-element" class="theClass"></x-element>'; + var customElement = doc.querySelector('#x-element'); + customElement.removeAttribute('class'); + assert_equals(proto.attributeChangedCallbackArgs[2], null, + 'Removing an attribute should invoke ' + + 'the attributeChanged callback with a null new value'); + assert_array_equals(proto.attributeChangedCallbackArgs, + ['class', 'theClass', null], + 'Unexpected attributeChanged callback arguments'); +}, 'Test attributeChanged callback arguments if attribute is removed. ' + + 'The custom element created via innerHTML property and the document has browsing context'); + + +testInIFrame('../../resources/x-element.html', function(doc) { + var customElement = doc.querySelector('#x-element'); + // this should not call or enqueue attributeChangedCallback + customElement.setAttribute('name', 'someName'); + // this one too + customElement.removeAttribute('name'); + + var proto = newHTMLElementPrototype(); + doc.registerElement('x-element', {prototype: proto}); + assert_equals(proto.attributeChangedCallbackCalledCounter, 0, + 'Callback attributeChanged should not be called'); + // this call invokes attributeChangedCallback + customElement.setAttribute('class', 'someClass'); + // this call invokes attributeChangedCallback at second time + customElement.removeAttribute('class'); + assert_equals(proto.attributeChangedCallbackCalledCounter, 2, + 'Callback attributeChanged should be called ' + + 'after setAttribute() and removeAttribute() calls'); +}, 'Test attributeChanged callback if attribute is removed. ' + + 'The custom element created via innerHTML property and unresolved at first. ' + + 'The document has browsing context'); +</script> +</body> +</html> |