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

Unified Diff: LayoutTests/imported/web-platform-tests/custom-elements/custom-element-lifecycle/types-of-callbacks/attribute-changed-callback-set-attribute-test.html

Issue 560893005: First checked-in import of the W3C's test suites. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: add new expectations for newly failing w3c tests Created 6 years, 3 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: LayoutTests/imported/web-platform-tests/custom-elements/custom-element-lifecycle/types-of-callbacks/attribute-changed-callback-set-attribute-test.html
diff --git a/LayoutTests/imported/web-platform-tests/custom-elements/custom-element-lifecycle/types-of-callbacks/attribute-changed-callback-set-attribute-test.html b/LayoutTests/imported/web-platform-tests/custom-elements/custom-element-lifecycle/types-of-callbacks/attribute-changed-callback-set-attribute-test.html
new file mode 100644
index 0000000000000000000000000000000000000000..fd81fea907b4289fd062d6bf1b46bc88a7607952
--- /dev/null
+++ b/LayoutTests/imported/web-platform-tests/custom-elements/custom-element-lifecycle/types-of-callbacks/attribute-changed-callback-set-attribute-test.html
@@ -0,0 +1,339 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Test attributeChanged callback is called if custom element attribute value is set</title>
+<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
+<meta name="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru">
+<meta name="assert" content="attributeChanged callback ... must be enqueued whenever custom element's attribute is added, changed or 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>
+<link rel="stylesheet" href="../../../../../resources/testharness.css">
+</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();
+ customElement.setAttribute('class', 'someClass');
+ assert_equals(proto.attributeChangedCallbackCalledCounter, 1,
+ 'Callback attributeChanged should be called');
+}, 'Test attributeChanged callback is called if attribute value is set by method ' +
+ 'setAttribute(). The custom element is created via constructor.');
+
+
+test(function() {
+ var doc = newHTMLDocument();
+ var proto = newHTMLElementPrototype();
+ var GeneratedConstructor = doc.registerElement('x-b', {prototype: proto});
+
+ var customElement = new GeneratedConstructor();
+ customElement.setAttribute('class', 'someClass');
+ assert_array_equals(proto.attributeChangedCallbackArgs, ['class', null, 'someClass'],
+ 'Unexpected callback attributeChanged arguments');
+}, 'Test attributeChanged callback arguments if attribute value is set by method ' +
+ 'setAttribute(). The custom element is created via constructor.');
+
+
+test(function() {
+ var doc = newHTMLDocument();
+ var proto = newHTMLElementPrototype();
+ var GeneratedConstructor = doc.registerElement('x-c', {prototype: proto});
+
+ var customElement = new GeneratedConstructor();
+ customElement.classList.add('someClass');
+ assert_equals(proto.attributeChangedCallbackCalledCounter, 1,
+ 'Callback attributeChanged should be called');
+}, 'Test attributeChanged callback is called if attribute value is set by method ' +
+ 'classList.add(). The custom element is created via constructor.');
+
+
+test(function() {
+ var doc = newHTMLDocument();
+ var proto = newHTMLElementPrototype();
+ var GeneratedConstructor = doc.registerElement('x-d', {prototype: proto});
+
+ var customElement = new GeneratedConstructor();
+ customElement.classList.add('someClass');
+ assert_array_equals(proto.attributeChangedCallbackArgs, ['class', null, 'someClass'],
+ 'Unexpected callback attributeChanged arguments');
+}, 'Test attributeChanged callback arguments if attribute value is set by method ' +
+ 'classList.add(). The custom element is created via constructor.');
+
+
+test(function() {
+ var doc = newHTMLDocument();
+ var proto = newHTMLElementPrototype();
+ var GeneratedConstructor = doc.registerElement('x-e', {prototype: proto});
+
+ var customElement = new GeneratedConstructor();
+ customElement.classList.toggle('someClass');
+ assert_equals(proto.attributeChangedCallbackCalledCounter, 1,
+ 'Callback attributeChanged should be called');
+}, 'Test attributeChanged callback is called if attribute value is set by method ' +
+ 'classList.toggle(). The custom element is created via constructor.');
+
+
+test(function() {
+ var doc = newHTMLDocument();
+ var proto = newHTMLElementPrototype();
+ var GeneratedConstructor = doc.registerElement('x-f', {prototype: proto});
+
+ var customElement = new GeneratedConstructor();
+ customElement.classList.toggle('someClass');
+ assert_array_equals(proto.attributeChangedCallbackArgs, ['class', null, 'someClass'],
+ 'Unexpected callback attributeChanged arguments');
+}, 'Test attributeChanged callback arguments if attribute value is set by method ' +
+ 'classList.toggle(). The custom element is created via constructor.');
+
+
+test(function() {
+ var doc = newHTMLDocument();
+ var proto = newHTMLElementPrototype();
+ var GeneratedConstructor = doc.registerElement('x-g', {prototype: proto});
+
+ var customElement = new GeneratedConstructor();
+ customElement.className = 'someClass';
+ assert_equals(proto.attributeChangedCallbackCalledCounter, 1,
+ 'Callback attributeChanged should be called');
+}, 'Test attributeChanged callback is called if attribute value is set as property. ' +
+ 'The custom element is created via constructor.');
+
+
+test(function() {
+ var doc = newHTMLDocument();
+ var proto = newHTMLElementPrototype();
+ var GeneratedConstructor = doc.registerElement('x-h', {prototype: proto});
+
+ var customElement = new GeneratedConstructor();
+ customElement.className = 'someClass';
+ assert_array_equals(proto.attributeChangedCallbackArgs, ['class', null, 'someClass'],
+ 'Unexpected callback attributeChanged arguments');
+}, 'Test attributeChanged callback arguments if attribute value is set as property. '+
+ 'The custom element is created via constructor.');
+
+
+test(function() {
+ var doc = newHTMLDocument();
+ var proto = newHTMLElementPrototype();
+ doc.registerElement('x-i', {prototype: proto});
+
+ doc.body.innerHTML = '<x-i id="x-i" class="theClass"></x-i>';
+ assert_equals(proto.attributeChangedCallbackCalledCounter, 0,
+ 'Callback attributeChanged should not be called');
+}, 'Test attributeChanged callback is not called if attribute value is specified in HTML. '+
+ 'The custom element is created via innerHTML property.');
+
+
+test(function() {
+ var doc = newHTMLDocument();
+ var proto = newHTMLElementPrototype();
+ doc.registerElement('x-j', {prototype: proto});
+
+ doc.body.innerHTML = '<x-j id="x-j" class="theClass"></x-j>';
+ var customElement = doc.querySelector('#x-j');
+ customElement.setAttribute('class', 'someClass');
+ assert_equals(proto.attributeChangedCallbackCalledCounter, 1,
+ 'Callback attributeChanged should be called');
+}, 'Test attributeChanged callback is called if attribute value is set by method setAttribute(). '+
+ 'The custom element is created via innerHTML property.');
+
+
+test(function() {
+ var doc = newHTMLDocument();
+ var proto = newHTMLElementPrototype();
+ doc.registerElement('x-k', {prototype: proto});
+
+ doc.body.innerHTML = '<x-k id="x-k"></x-k>';
+ var customElement = doc.querySelector('#x-k');
+ customElement.setAttribute('class', 'someClass');
+ assert_array_equals(proto.attributeChangedCallbackArgs, ['class', null, 'someClass'],
+ 'Unexpected callback attributeChanged arguments');
+}, 'Test attributeChanged callback arguments if attribute value is set by method setAttribute(). '+
+ 'The custom element is created via innerHTML property.');
+
+
+test(function() {
+ var doc = newHTMLDocument();
+
+ doc.body.innerHTML = '<x-l id="x-l"></x-l>';
+ var customElement = doc.querySelector('#x-l');
+ // this call shouldn't invoke or enqueue the callback
+ customElement.setAttribute('class', 'someClass');
+
+ var proto = newHTMLElementPrototype();
+ doc.registerElement('x-l', {prototype: proto});
+ assert_equals(proto.attributeChangedCallbackCalledCounter, 0,
+ 'Callback attributeChanged should not be called');
+ // this one should
+ customElement.setAttribute('class', 'someClass2');
+ assert_equals(proto.attributeChangedCallbackCalledCounter, 1,
+ 'Callback attributeChanged should be called');
+}, 'Test attributeChanged callback is not called if attribute value of unresolved element '+
+ 'is set by method setAttribute().');
+
+
+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();
+ customElement.setAttribute('class', 'someClass');
+ assert_equals(proto.attributeChangedCallbackCalledCounter, 1,
+ 'Callback attributeChanged should be called');
+ });
+}, 'Test attributeChanged callback of the custom element that extends some HTML element. ' +
+ 'Test that the callback is called');
+
+
+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-1', {
+ prototype: proto,
+ extends: element
+ });
+
+ var customElement = new GeneratedConstructor();
+ customElement.classList.add('someClass');
+ assert_equals(proto.attributeChangedCallbackCalledCounter, 1,
+ 'Callback attributeChanged should be called');
+ });
+}, 'Test attributeChanged callback is called if attribute is set by method classList.add(). '+
+ 'The custom element extends some HTML element.');
+
+
+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 + '-2', {
+ prototype: proto,
+ extends: element
+ });
+
+ var customElement = new GeneratedConstructor();
+ customElement.setAttribute('class', 'someClass');
+ assert_array_equals(proto.attributeChangedCallbackArgs, ['class', null, 'someClass'],
+ 'Unexpected callback attributeChanged arguments');
+ });
+}, 'Test attributeChanged callback arguments if attribute value is set by method setAttribute(). '+
+ 'The custom element extends some HTML element.');
+
+
+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');
+ assert_equals(proto.attributeChangedCallbackCalledCounter, 1,
+ 'Callback attributeChanged should be called');
+}, 'Test attributeChanged callback is called if attribute value is set by method setAttribute(). '+
+ 'The document has browsing context.');
+
+
+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');
+ assert_array_equals(proto.attributeChangedCallbackArgs, ['class', null, 'someClass'],
+ 'Unexpected callback attributeChanged arguments');
+}, 'Test attributeChanged callback arguments if attribute value is set by method setAttribute(). '+
+ 'The document has browsing context.');
+
+
+testInIFrame('../../resources/x-element.html', function(doc) {
+ var proto = newHTMLElementPrototype();
+ doc.registerElement('x-element', {prototype: proto});
+
+ var customElement = doc.querySelector('#x-element');
+ customElement.classList.add('someClass');
+ assert_equals(proto.attributeChangedCallbackCalledCounter, 1,
+ 'Callback attributeChanged should be called');
+}, 'Test attributeChanged callback is called if attribute value is set by method classList.add(). '+
+ 'The document has browsing context.');
+
+
+testInIFrame('../../resources/x-element.html', function(doc) {
+ var proto = newHTMLElementPrototype();
+ doc.registerElement('x-element', {prototype: proto});
+
+ var customElement = doc.querySelector('#x-element');
+ customElement.classList.add('someClass');
+ assert_array_equals(proto.attributeChangedCallbackArgs, ['class', null, 'someClass'],
+ 'Unexpected callback attributeChanged arguments');
+}, 'Test attributeChanged callback arguments if attribute value is set by method classList.add(). '+
+ 'The document has browsing context.');
+
+
+testInIFrame('../../resources/x-element.html', function(doc) {
+ var customElement = doc.querySelector('#x-element');
+ // this call shouldn't invoke or enqueue the callback
+ customElement.setAttribute('name', 'someName');
+
+ var proto = newHTMLElementPrototype();
+ doc.registerElement('x-element', {prototype: proto});
+ assert_equals(proto.attributeChangedCallbackCalledCounter, 0,
+ 'Callback attributeChanged should not be called');
+ // this one should
+ customElement.setAttribute('class', 'someClass');
+ assert_equals(proto.attributeChangedCallbackCalledCounter, 1,
+ 'Callback attributeChanged should be called');
+}, 'Test attributeChanged callback is not called if attribute value of unresolved element '+
+ 'is set by method setAttribute(). The document has browsing context.');
+
+
+testInIFrame('../../resources/x-element.html', function(doc) {
+ 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();
+ customElement.setAttribute('class', 'someClass');
+ assert_equals(proto.attributeChangedCallbackCalledCounter, 1,
+ 'Callback attributeChanged should be called');
+ });
+}, 'Test attributeChanged callback is called if attribute value is set by method setAttribute(). '+
+ 'The document has browsing context. The custom element extends some HTML element.');
+
+
+testInIFrame('../../resources/x-element.html', function(doc) {
+ HTML5_ELEMENTS.forEach(function(element) {
+ var obj = doc.createElement(element);
+ var proto = newCustomElementPrototype(obj.constructor.prototype);
+ var GeneratedConstructor = doc.registerElement('x-' + element + '-' + element + '-2', {
+ prototype: proto,
+ extends: element
+ });
+
+ var customElement = new GeneratedConstructor();
+ customElement.setAttribute('class', 'someClass');
+ assert_array_equals(proto.attributeChangedCallbackArgs, ['class', null, 'someClass'],
+ 'Unexpected callback attributeChanged arguments');
+ });
+}, 'Test attributeChanged callback arguments if attribute value is set by method setAttribute(). '+
+ 'The document has browsing context. The custom element extends some HTML element.');
+</script>
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698