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

Unified Diff: third_party/WebKit/LayoutTests/custom-elements/spec/callback.html

Issue 2060753002: Implement script-side of callback reactions for Custom Elements V1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@callback-ce
Patch Set: rebase Created 4 years, 6 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/imported/wpt/custom-elements/custom-elements-registry/define-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/custom-elements/spec/callback.html
diff --git a/third_party/WebKit/LayoutTests/custom-elements/spec/callback.html b/third_party/WebKit/LayoutTests/custom-elements/spec/callback.html
new file mode 100644
index 0000000000000000000000000000000000000000..4c304f764cb5a4746cb86909c1ce415c43a0eed5
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/custom-elements/spec/callback.html
@@ -0,0 +1,117 @@
+<!DOCTYPE html>
+<title>Custom Elements: Create an element when definition is non-null and synchronous flag not set</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="resources/custom-elements-helpers.js"></script>
+<body>
+<script>
+'use strict';
+
+(() => {
+ // "Upgrade an element"
+ // https://html.spec.whatwg.org/multipage/scripting.html#upgrades
+
+ // 1. For each attribute in element's attribute list, in order, enqueue a
+ // custom element callback reaction with element, callback name
+ // "attributeChangedCallback", and an argument list containing attribute's
+ // local name, null, attribute's value, and attribute's namespace.
+
+ // 2. If element is currently in a shadow-including document, then enqueue a
+ // custom element callback reaction with element, callback name
+ // "connectedCallback", and an empty argument list.
+
+ const constructor = 'constructor';
+ const connected = 'connected';
+ const disconnected = 'disconnected';
+ const attributeChanged = 'attributeChanged';
+
+ function define_logger(w, observedAttributes) {
+ let logs = [];
+ w.customElements.define('a-a', class extends w.HTMLElement {
+ constructor() { super(); logs.push([constructor, this, arguments]); }
+ connectedCallback() { logs.push([connected, this, arguments]); }
+ disconnectedCallback() { logs.push([disconnected, this, arguments]); }
+ static get observedAttributes() { return observedAttributes; }
+ attributeChangedCallback() { logs.push([attributeChanged, this, arguments]); }
+ });
+ return logs;
+ }
+
+ function assert_log_is_type(logs, i, type, element, argv) {
+ assert_equals(logs[i][0], type, `[${i}] should be ${type}`);
+ assert_equals(logs[i][1], element, `this in ${type} should be the element`);
+ if (argv) {
+ assert_array_equals(logs[i][2], argv, `${type} should have arguments ${argv}`);
+ } else {
+ assert_equals(logs[i][2].length, 0, `${type} should have no arguments`);
+ }
+ }
+
+ test_with_window(w => {
+ let document = w.document;
+ let element = document.createElement('a-a');
+ document.body.appendChild(element);
+ let logs = define_logger(w);
+ assert_log_is_type(logs, 0, constructor, element);
+ assert_log_is_type(logs, 1, connected, element);
+ assert_equals(logs.length, 2);
+ }, 'upgrade should enqueue connectedCallback');
+
+ test_with_window(w => {
+ let document = w.document;
+ let element = document.createElement('a-a');
+ element.setAttribute('x', '1');
+ element.setAttribute('y', '2');
+ element.setAttribute('z', '3');
+ document.body.appendChild(element);
+ let logs = define_logger(w, ['x', 'y']);
+ assert_log_is_type(logs, 0, constructor, element);
+ assert_log_is_type(logs, 1, attributeChanged, element, ['x', null, '1', '']);
+ assert_log_is_type(logs, 2, attributeChanged, element, ['y', null, '2', '']);
+ assert_log_is_type(logs, 3, connected, element);
+ assert_equals(logs.length, 4);
+ }, 'upgrade should enqueue attributeChangedCallback and connectedCallback');
+
+ test_with_window(w => {
+ let document = w.document;
+ let element = document.createElement('a-a');
+ element.setAttribute('x', '1');
+ document.body.appendChild(element);
+ let logs = define_logger(w, ['x', 'y']);
+
+ logs.length = 0;
+ element.setAttribute('z', '0');
+ element.setAttribute('y', '2');
+ element.setAttribute('x', '9');
+ assert_log_is_type(logs, 0, attributeChanged, element, ['y', null, '2', '']);
+ assert_log_is_type(logs, 1, attributeChanged, element, ['x', '1', '9', '']);
+ assert_equals(logs.length, 2);
+ }, 'setAttribute should enqueue attributeChangedCallback');
+
+ test_with_window(w => {
+ let document = w.document;
+ let element = document.createElement('a-a');
+ element.setAttribute('x', '1');
+ document.body.appendChild(element);
+ let logs = define_logger(w, ['x']);
+
+ logs.length = 0;
+ element.removeAttribute('x');
+ assert_log_is_type(logs, 0, attributeChanged, element, ['x', '1', null, '']);
+ assert_equals(logs.length, 1);
+ }, 'removeAttribute should enqueue attributeChangedCallback');
+
+ test_with_window(w => {
+ let document = w.document;
+ let element = document.createElement('a-a');
+ document.body.appendChild(element);
+ let logs = define_logger(w);
+
+ logs.length = 0;
+ element.remove();
+ assert_log_is_type(logs, 0, disconnected, element);
+ assert_equals(logs.length, 1);
+ }, 'remove should enqueue disconnectedCallback');
+})();
+</script>
+</body>
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/imported/wpt/custom-elements/custom-elements-registry/define-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698