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

Unified Diff: third_party/WebKit/LayoutTests/imported/wpt/custom-elements/reactions/resources/reactions.js

Issue 2408083002: Revert of Import wpt@357b83b809e3cbc7a1805e7c3ca108a7980d782f (Closed)
Patch Set: Created 4 years, 2 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: third_party/WebKit/LayoutTests/imported/wpt/custom-elements/reactions/resources/reactions.js
diff --git a/third_party/WebKit/LayoutTests/imported/wpt/custom-elements/reactions/resources/reactions.js b/third_party/WebKit/LayoutTests/imported/wpt/custom-elements/reactions/resources/reactions.js
index c260dc4f3f861a4bd4d939935ff85f9cc9b898c5..0fc2072b8cb0602016c268fcfc2fcab0d34817c8 100644
--- a/third_party/WebKit/LayoutTests/imported/wpt/custom-elements/reactions/resources/reactions.js
+++ b/third_party/WebKit/LayoutTests/imported/wpt/custom-elements/reactions/resources/reactions.js
@@ -1,28 +1,60 @@
let testNumber = 1;
+
+function defineNewCustomElement(observedAttributes) {
+ let log = [];
+ let name = 'custom-element-' + testNumber++;
+
+ class CustomElement extends HTMLElement {
+ constructor() {
+ super();
+ log.push({type: 'constructed', element: this});
+ }
+ attributeChangedCallback(name, oldValue, newValue, namespace) {
+ log.push({type: 'attributeChanged', element: this, name: name, oldValue: oldValue, newValue: newValue, namespace: namespace});
+ }
+ connectedCallback() { log.push({type: 'connected', element: this}); }
+ disconnectedCallback() { log.push({type: 'disconnected', element: this}); }
+ adoptedCallback(oldDocument, newDocument) { log.push({type: 'adopted', element: this, oldDocument: oldDocument, newDocument: newDocument}); }
+ }
+ CustomElement.observedAttributes = observedAttributes || ['id', 'title'];
+
+ customElements.define(name, CustomElement);
+
+ return {
+ name: name,
+ log: function () {
+ let currentLog = log; log = [];
+ return {
+ types: () => currentLog.map((entry) => entry.type),
+ log: (i) => currentLog[i == undefined ? currentLog.length - 1 : i],
+ }
+ }
+ };
+}
function testNodeConnector(testFunction, name) {
let container = document.createElement('div');
container.appendChild(document.createElement('div'));
document.body.appendChild(container);
-
- test(function () {
- var element = define_new_custom_element();
- var instance = document.createElement(element.name);
- assert_array_equals(element.takeLog().types(), ['constructed']);
+
+ test(function () {
+ var element = defineNewCustomElement();
+ var instance = document.createElement(element.name);
+ assert_array_equals(element.log().types(), ['constructed']);
testFunction(container, instance);
- assert_array_equals(element.takeLog().types(), ['connected']);
+ assert_array_equals(element.log().types(), ['connected']);
}, name + ' must enqueue a connected reaction');
test(function () {
- var element = define_new_custom_element();
- var instance = document.createElement(element.name);
- assert_array_equals(element.takeLog().types(), ['constructed']);
+ var element = defineNewCustomElement();
+ var instance = document.createElement(element.name);
+ assert_array_equals(element.log().types(), ['constructed']);
var newDoc = document.implementation.createHTMLDocument();
testFunction(container, instance);
- assert_array_equals(element.takeLog().types(), ['connected']);
+ assert_array_equals(element.log().types(), ['connected']);
testFunction(newDoc.documentElement, instance);
- assert_array_equals(element.takeLog().types(), ['disconnected', 'adopted', 'connected']);
+ assert_array_equals(element.log().types(), ['disconnected', 'adopted', 'connected']);
}, name + ' must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document');
container.parentNode.removeChild(container);
@@ -34,184 +66,156 @@
document.body.appendChild(container);
test(function () {
- var element = define_new_custom_element();
- var instance = document.createElement(element.name);
- assert_array_equals(element.takeLog().types(), ['constructed']);
+ var element = defineNewCustomElement();
+ var instance = document.createElement(element.name);
+ assert_array_equals(element.log().types(), ['constructed']);
container.appendChild(instance);
- assert_array_equals(element.takeLog().types(), ['connected']);
+ assert_array_equals(element.log().types(), ['connected']);
testFunction(instance);
- assert_array_equals(element.takeLog().types(), ['disconnected']);
+ assert_array_equals(element.log().types(), ['disconnected']);
}, name + ' must enqueue a disconnected reaction');
container.parentNode.removeChild(container);
}
-function testCloner(testFunction, name) {
- let container = document.createElement('div');
- container.appendChild(document.createElement('div'));
- document.body.appendChild(container);
-
- test(function () {
- var element = define_new_custom_element(['id']);
- var instance = document.createElement(element.name);
- container.appendChild(instance);
-
- instance.setAttribute('id', 'foo');
- assert_array_equals(element.takeLog().types(), ['constructed', 'connected', 'attributeChanged']);
- var newInstance = testFunction(instance);
- var logEntries = element.takeLog();
- assert_array_equals(logEntries.types(), ['constructed', 'attributeChanged']);
- assert_attribute_log_entry(logEntries.last(), {name: 'id', oldValue: null, newValue: 'foo', namespace: null});
- }, name + ' must enqueue an attributeChanged reaction when cloning an element with an observed attribute');
-
- test(function () {
- var element = define_new_custom_element(['id']);
- var instance = document.createElement(element.name);
- container.appendChild(instance);
-
- instance.setAttribute('lang', 'en');
- assert_array_equals(element.takeLog().types(), ['constructed', 'connected']);
- var newInstance = testFunction(instance);
- assert_array_equals(element.takeLog().types(), ['constructed']);
- }, name + ' must not enqueue an attributeChanged reaction when cloning an element with an unobserved attribute');
-
- test(function () {
- var element = define_new_custom_element(['title', 'class']);
- var instance = document.createElement(element.name);
- container.appendChild(instance);
-
- instance.setAttribute('lang', 'en');
- instance.className = 'foo';
- instance.setAttribute('title', 'hello world');
- assert_array_equals(element.takeLog().types(), ['constructed', 'connected', 'attributeChanged', 'attributeChanged']);
- var newInstance = testFunction(instance);
- var logEntries = element.takeLog();
- assert_array_equals(logEntries.types(), ['constructed', 'attributeChanged', 'attributeChanged']);
- assert_attribute_log_entry(logEntries[1], {name: 'class', oldValue: null, newValue: 'foo', namespace: null});
- assert_attribute_log_entry(logEntries[2], {name: 'title', oldValue: null, newValue: 'hello world', namespace: null});
- }, name + ' must enqueue an attributeChanged reaction when cloning an element only for observed attributes');
-}
-
function testReflectAttribute(jsAttributeName, contentAttributeName, validValue1, validValue2, name) {
test(function () {
- var element = define_new_custom_element([contentAttributeName]);
- var instance = document.createElement(element.name);
- assert_array_equals(element.takeLog().types(), ['constructed']);
+ var element = defineNewCustomElement([contentAttributeName]);
+ var instance = document.createElement(element.name);
+ assert_array_equals(element.log().types(), ['constructed']);
instance[jsAttributeName] = validValue1;
- var logEntries = element.takeLog();
- assert_array_equals(logEntries.types(), ['attributeChanged']);
- assert_attribute_log_entry(logEntries.last(), {name: contentAttributeName, oldValue: null, newValue: validValue1, namespace: null});
- }, name + ' must enqueue an attributeChanged reaction when adding ' + contentAttributeName + ' content attribute');
-
- test(function () {
- var element = define_new_custom_element([contentAttributeName]);
+ var logEntries = element.log();
+ assert_array_equals(logEntries.types(), ['attributeChanged']);
+ assert_equals(logEntries.log().name, contentAttributeName);
+ assert_equals(logEntries.log().oldValue, null);
+ assert_equals(logEntries.log().newValue, validValue1);
+ assert_equals(logEntries.log().namespace, null);
+ }, name + ' must enqueue a attributeChanged reaction when adding ' + contentAttributeName + ' content attribute');
+
+ test(function () {
+ var element = defineNewCustomElement([contentAttributeName]);
var instance = document.createElement(element.name);
instance[jsAttributeName] = validValue1;
- assert_array_equals(element.takeLog().types(), ['constructed', 'attributeChanged']);
+ assert_array_equals(element.log().types(), ['constructed', 'attributeChanged']);
instance[jsAttributeName] = validValue2;
- var logEntries = element.takeLog();
- assert_array_equals(logEntries.types(), ['attributeChanged']);
- assert_attribute_log_entry(logEntries.last(), {name: contentAttributeName, oldValue: validValue1, newValue: validValue2, namespace: null});
- }, name + ' must enqueue an attributeChanged reaction when replacing an existing attribute');
+ var logEntries = element.log();
+ assert_array_equals(logEntries.types(), ['attributeChanged']);
+ assert_equals(logEntries.log().name, contentAttributeName);
+ assert_equals(logEntries.log().oldValue, validValue1);
+ assert_equals(logEntries.log().newValue, validValue2);
+ assert_equals(logEntries.log().namespace, null);
+ }, name + ' must enqueue a attributeChanged reaction when replacing an existing attribute');
}
function testAttributeAdder(testFunction, name) {
test(function () {
- var element = define_new_custom_element(['id']);
- var instance = document.createElement(element.name);
- assert_array_equals(element.takeLog().types(), ['constructed']);
+ var element = defineNewCustomElement();
+ var instance = document.createElement(element.name);
+ assert_array_equals(element.log().types(), ['constructed']);
testFunction(instance, 'id', 'foo');
- var logEntries = element.takeLog();
- assert_array_equals(logEntries.types(), ['attributeChanged']);
- assert_attribute_log_entry(logEntries.last(), {name: 'id', oldValue: null, newValue: 'foo', namespace: null});
- }, name + ' must enqueue an attributeChanged reaction when adding an attribute');
-
- test(function () {
- var element = define_new_custom_element(['class']);
- var instance = document.createElement(element.name);
- assert_array_equals(element.takeLog().types(), ['constructed']);
+ var logEntries = element.log();
+ assert_array_equals(logEntries.types(), ['attributeChanged']);
+ assert_equals(logEntries.log().name, 'id');
+ assert_equals(logEntries.log().oldValue, null);
+ assert_equals(logEntries.log().newValue, 'foo');
+ assert_equals(logEntries.log().namespace, null);
+ }, name + ' must enqueue a attributeChanged reaction when adding an attribute');
+
+ test(function () {
+ var element = defineNewCustomElement();
+ var instance = document.createElement(element.name);
+ assert_array_equals(element.log().types(), ['constructed']);
testFunction(instance, 'data-lang', 'en');
- assert_array_equals(element.takeLog().types(), []);
- }, name + ' must not enqueue an attributeChanged reaction when adding an unobserved attribute');
-
- test(function () {
- var element = define_new_custom_element(['title']);
+ assert_array_equals(element.log().types(), []);
+ }, name + ' must not enqueue a attributeChanged reaction when adding an unobserved attribute');
+
+ test(function () {
+ var element = defineNewCustomElement();
var instance = document.createElement(element.name);
instance.setAttribute('title', 'hello');
- assert_array_equals(element.takeLog().types(), ['constructed', 'attributeChanged']);
+ assert_array_equals(element.log().types(), ['constructed', 'attributeChanged']);
testFunction(instance, 'title', 'world');
- var logEntries = element.takeLog();
- assert_array_equals(logEntries.types(), ['attributeChanged']);
- assert_attribute_log_entry(logEntries.last(), {name: 'title', oldValue: 'hello', newValue: 'world', namespace: null});
- }, name + ' must enqueue an attributeChanged reaction when replacing an existing attribute');
-
- test(function () {
- var element = define_new_custom_element([]);
+ var logEntries = element.log();
+ assert_array_equals(logEntries.types(), ['attributeChanged']);
+ assert_equals(logEntries.log().name, 'title');
+ assert_equals(logEntries.log().oldValue, 'hello');
+ assert_equals(logEntries.log().newValue, 'world');
+ assert_equals(logEntries.log().namespace, null);
+ }, name + ' must enqueue a attributeChanged reaction when replacing an existing attribute');
+
+ test(function () {
+ var element = defineNewCustomElement();
var instance = document.createElement(element.name);
instance.setAttribute('data-lang', 'zh');
- assert_array_equals(element.takeLog().types(), ['constructed']);
+ assert_array_equals(element.log().types(), ['constructed']);
testFunction(instance, 'data-lang', 'en');
- assert_array_equals(element.takeLog().types(), []);
- }, name + ' must enqueue an attributeChanged reaction when replacing an existing unobserved attribute');
+ assert_array_equals(element.log().types(), []);
+ }, name + ' must enqueue a attributeChanged reaction when replacing an existing unobserved attribute');
}
function testAttributeMutator(testFunction, name) {
test(function () {
- var element = define_new_custom_element(['title']);
+ var element = defineNewCustomElement();
var instance = document.createElement(element.name);
instance.setAttribute('title', 'hello');
- assert_array_equals(element.takeLog().types(), ['constructed', 'attributeChanged']);
+ assert_array_equals(element.log().types(), ['constructed', 'attributeChanged']);
testFunction(instance, 'title', 'world');
- var logEntries = element.takeLog();
- assert_array_equals(logEntries.types(), ['attributeChanged']);
- assert_attribute_log_entry(logEntries.last(), {name: 'title', oldValue: 'hello', newValue: 'world', namespace: null});
- }, name + ' must enqueue an attributeChanged reaction when replacing an existing attribute');
-
- test(function () {
- var element = define_new_custom_element(['class']);
+ var logEntries = element.log();
+ assert_array_equals(logEntries.types(), ['attributeChanged']);
+ assert_equals(logEntries.log().name, 'title');
+ assert_equals(logEntries.log().oldValue, 'hello');
+ assert_equals(logEntries.log().newValue, 'world');
+ assert_equals(logEntries.log().namespace, null);
+ }, name + ' must enqueue a attributeChanged reaction when replacing an existing attribute');
+
+ test(function () {
+ var element = defineNewCustomElement();
var instance = document.createElement(element.name);
instance.setAttribute('data-lang', 'zh');
- assert_array_equals(element.takeLog().types(), ['constructed']);
+ assert_array_equals(element.log().types(), ['constructed']);
testFunction(instance, 'data-lang', 'en');
- assert_array_equals(element.takeLog().types(), []);
- }, name + ' must not enqueue an attributeChanged reaction when replacing an existing unobserved attribute');
+ assert_array_equals(element.log().types(), []);
+ }, name + ' must enqueue a attributeChanged reaction when replacing an existing unobserved attribute');
}
function testAttributeRemover(testFunction, name) {
test(function () {
- var element = define_new_custom_element(['title']);
- var instance = document.createElement(element.name);
- assert_array_equals(element.takeLog().types(), ['constructed']);
+ var element = defineNewCustomElement();
+ var instance = document.createElement(element.name);
+ assert_array_equals(element.log().types(), ['constructed']);
testFunction(instance, 'title');
- assert_array_equals(element.takeLog().types(), []);
- }, name + ' must not enqueue an attributeChanged reaction when removing an attribute that does not exist');
-
- test(function () {
- var element = define_new_custom_element([]);
+ assert_array_equals(element.log().types(), []);
+ }, name + ' must not enqueue a attributeChanged reaction when removing an attribute that does not exist');
+
+ test(function () {
+ var element = defineNewCustomElement();
var instance = document.createElement(element.name);
instance.setAttribute('data-lang', 'hello');
- assert_array_equals(element.takeLog().types(), ['constructed']);
+ assert_array_equals(element.log().types(), ['constructed']);
testFunction(instance, 'data-lang');
- assert_array_equals(element.takeLog().types(), []);
- }, name + ' must not enqueue an attributeChanged reaction when removing an unobserved attribute');
-
- test(function () {
- var element = define_new_custom_element(['title']);
+ assert_array_equals(element.log().types(), []);
+ }, name + ' must not enqueue a attributeChanged reaction when removing an unobserved attribute that does not exist');
+
+ test(function () {
+ var element = defineNewCustomElement();
var instance = document.createElement(element.name);
instance.setAttribute('title', 'hello');
- assert_array_equals(element.takeLog().types(), ['constructed', 'attributeChanged']);
+ assert_array_equals(element.log().types(), ['constructed', 'attributeChanged']);
testFunction(instance, 'title');
- var logEntries = element.takeLog();
- assert_array_equals(logEntries.types(), ['attributeChanged']);
- assert_attribute_log_entry(logEntries.last(), {name: 'title', oldValue: 'hello', newValue: null, namespace: null});
- }, name + ' must enqueue an attributeChanged reaction when removing an existing attribute');
-
- test(function () {
- var element = define_new_custom_element([]);
+ var logEntries = element.log();
+ assert_array_equals(logEntries.types(), ['attributeChanged']);
+ assert_equals(logEntries.log().name, 'title');
+ assert_equals(logEntries.log().oldValue, 'hello');
+ assert_equals(logEntries.log().newValue, null);
+ assert_equals(logEntries.log().namespace, null);
+ }, name + ' must enqueue a attributeChanged reaction when removing an existing attribute');
+
+ test(function () {
+ var element = defineNewCustomElement();
var instance = document.createElement(element.name);
instance.setAttribute('data-lang', 'ja');
- assert_array_equals(element.takeLog().types(), ['constructed']);
+ assert_array_equals(element.log().types(), ['constructed']);
testFunction(instance, 'data-lang');
- assert_array_equals(element.takeLog().types(), []);
- }, name + ' must not enqueue an attributeChanged reaction when removing an existing unobserved attribute');
-}
+ assert_array_equals(element.log().types(), []);
+ }, name + ' must not enqueue a attributeChanged reaction when removing an existing unobserved attribute');
+}

Powered by Google App Engine
This is Rietveld 408576698