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/reaction-timing.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/reaction-timing.html')
-rw-r--r-- | testing/web-platform/tests/custom-elements/reaction-timing.html | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/testing/web-platform/tests/custom-elements/reaction-timing.html b/testing/web-platform/tests/custom-elements/reaction-timing.html new file mode 100644 index 000000000..9e5bafbed --- /dev/null +++ b/testing/web-platform/tests/custom-elements/reaction-timing.html @@ -0,0 +1,88 @@ +<!DOCTYPE html> +<html> +<head> +<title>Custom Elements: Custom element reactions must be invoked before returning to author scripts</title> +<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org"> +<meta name="assert" content="Custom element reactions must be invoked before returning to author scripts"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#invoke-custom-element-reactions"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +</head> +<body> +<div id="log"></div> +<script> + +class MyCustomElement extends HTMLElement { + attributeChangedCallback(...args) { + this.handler(...args); + } + + handler() { } +} +MyCustomElement.observedAttributes = ['data-title', 'title']; +customElements.define('my-custom-element', MyCustomElement); + +test(function () { + var instance = document.createElement('my-custom-element'); + var anotherInstance = document.createElement('my-custom-element'); + + var callbackOrder = []; + instance.handler = function () { + callbackOrder.push([this, 'begin']); + anotherInstance.setAttribute('data-title', 'baz'); + callbackOrder.push([this, 'end']); + } + anotherInstance.handler = function () { + callbackOrder.push([this, 'begin']); + callbackOrder.push([this, 'end']); + } + + instance.setAttribute('title', 'foo'); + assert_equals(callbackOrder.length, 4); + + assert_array_equals(callbackOrder[0], [instance, 'begin']); + assert_array_equals(callbackOrder[1], [anotherInstance, 'begin']); + assert_array_equals(callbackOrder[2], [anotherInstance, 'end']); + assert_array_equals(callbackOrder[3], [instance, 'end']); + +}, 'setAttribute and removeAttribute must enqueue and invoke attributeChangedCallback'); + +test(function () { + var shouldCloneAnotherInstance = false; + var anotherInstanceClone; + var log = []; + + class SelfCloningElement extends HTMLElement { + constructor() { + super(); + log.push([this, 'begin']); + if (shouldCloneAnotherInstance) { + shouldCloneAnotherInstance = false; + anotherInstanceClone = anotherInstance.cloneNode(false); + } + log.push([this, 'end']); + } + } + customElements.define('self-cloning-element', SelfCloningElement); + + var instance = document.createElement('self-cloning-element'); + var anotherInstance = document.createElement('self-cloning-element'); + shouldCloneAnotherInstance = true; + + assert_equals(log.length, 4); + var instanceClone = instance.cloneNode(false); + + assert_equals(log.length, 8); + assert_array_equals(log[0], [instance, 'begin']); + assert_array_equals(log[1], [instance, 'end']); + assert_array_equals(log[2], [anotherInstance, 'begin']); + assert_array_equals(log[3], [anotherInstance, 'end']); + assert_array_equals(log[4], [instanceClone, 'begin']); + assert_array_equals(log[5], [anotherInstanceClone, 'begin']); + assert_array_equals(log[6], [anotherInstanceClone, 'end']); + assert_array_equals(log[7], [instanceClone, 'end']); +}, 'Calling Node.prototype.cloneNode(false) must push a new element queue to the processing stack'); + +</script> +</body> +</html> |