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

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

Issue 2446483002: Import wpt@c5a14f553cba5f197743b9af605a84eddd8692a2 (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 1
2 let testNumber = 1; 2 let testNumber = 1;
3 3
4 function testNodeConnector(testFunction, name) { 4 function testNodeConnector(testFunction, name) {
5 let container = document.createElement('div'); 5 let container = document.createElement('div');
6 container.appendChild(document.createElement('div')); 6 container.appendChild(document.createElement('div'));
7 document.body.appendChild(container); 7 document.body.appendChild(container);
8 8
9 test(function () { 9 test(function () {
10 var element = define_new_custom_element(); 10 var element = define_new_custom_element();
(...skipping 21 matching lines...) Expand all
32 let container = document.createElement('div'); 32 let container = document.createElement('div');
33 container.appendChild(document.createElement('div')); 33 container.appendChild(document.createElement('div'));
34 document.body.appendChild(container); 34 document.body.appendChild(container);
35 35
36 test(function () { 36 test(function () {
37 var element = define_new_custom_element(); 37 var element = define_new_custom_element();
38 var instance = document.createElement(element.name); 38 var instance = document.createElement(element.name);
39 assert_array_equals(element.takeLog().types(), ['constructed']); 39 assert_array_equals(element.takeLog().types(), ['constructed']);
40 container.appendChild(instance); 40 container.appendChild(instance);
41 assert_array_equals(element.takeLog().types(), ['connected']); 41 assert_array_equals(element.takeLog().types(), ['connected']);
42 testFunction(instance); 42 testFunction(instance, window);
43 assert_array_equals(element.takeLog().types(), ['disconnected']); 43 assert_array_equals(element.takeLog().types(), ['disconnected']);
44 }, name + ' must enqueue a disconnected reaction'); 44 }, name + ' must enqueue a disconnected reaction');
45 45
46 container.parentNode.removeChild(container); 46 container.parentNode.removeChild(container);
47 } 47 }
48 48
49 function testInsertingMarkup(testFunction, name) {
50 let container = document.createElement('div');
51 container.appendChild(document.createElement('div'));
52 document.body.appendChild(container);
53
54 test(function () {
55 var element = define_new_custom_element();
56 testFunction(container, `<${element.name}></${element.name}>`);
57 assert_array_equals(element.takeLog().types(), ['constructed', 'connecte d']);
58 }, name + ' must enqueue a connected reaction for a newly constructed custom element');
59
60 test(function () {
61 var element = define_new_custom_element(['title']);
62 testFunction(container, `<${element.name} id="hello" title="hi"></${elem ent.name}>`);
63 var logEntries = element.takeLog();
64 assert_array_equals(logEntries.types(), ['constructed', 'attributeChange d', 'connected']);
65 assert_attribute_log_entry(logEntries[1], {name: 'title', oldValue: null , newValue: 'hi', namespace: null});
66 }, name + ' must enqueue a attributeChanged reaction for a newly constructed custom element');
67
68 container.parentNode.removeChild(container);
69 }
70
71 function testParsingMarkup(testFunction, name) {
72 test(function () {
73 var element = define_new_custom_element(['id']);
74 assert_array_equals(element.takeLog().types(), []);
75 var instance = testFunction(document, `<${element.name} id="hello" class ="foo"></${element.name}>`);
76 assert_equals(Object.getPrototypeOf(instance.querySelector(element.name) ), element.class.prototype);
77 var logEntries = element.takeLog();
78 assert_array_equals(logEntries.types(), ['constructed', 'attributeChange d']);
79 assert_attribute_log_entry(logEntries[1], {name: 'id', oldValue: null, n ewValue: 'hello', namespace: null});
80 }, name + ' must construct a custom element');
81 }
82
49 function testCloner(testFunction, name) { 83 function testCloner(testFunction, name) {
50 let container = document.createElement('div'); 84 let container = document.createElement('div');
51 container.appendChild(document.createElement('div')); 85 container.appendChild(document.createElement('div'));
52 document.body.appendChild(container); 86 document.body.appendChild(container);
53 87
54 test(function () { 88 test(function () {
55 var element = define_new_custom_element(['id']); 89 var element = define_new_custom_element(['id']);
56 var instance = document.createElement(element.name); 90 var instance = document.createElement(element.name);
57 container.appendChild(instance); 91 container.appendChild(instance);
58 92
(...skipping 26 matching lines...) Expand all
85 instance.setAttribute('title', 'hello world'); 119 instance.setAttribute('title', 'hello world');
86 assert_array_equals(element.takeLog().types(), ['constructed', 'connecte d', 'attributeChanged', 'attributeChanged']); 120 assert_array_equals(element.takeLog().types(), ['constructed', 'connecte d', 'attributeChanged', 'attributeChanged']);
87 var newInstance = testFunction(instance); 121 var newInstance = testFunction(instance);
88 var logEntries = element.takeLog(); 122 var logEntries = element.takeLog();
89 assert_array_equals(logEntries.types(), ['constructed', 'attributeChange d', 'attributeChanged']); 123 assert_array_equals(logEntries.types(), ['constructed', 'attributeChange d', 'attributeChanged']);
90 assert_attribute_log_entry(logEntries[1], {name: 'class', oldValue: null , newValue: 'foo', namespace: null}); 124 assert_attribute_log_entry(logEntries[1], {name: 'class', oldValue: null , newValue: 'foo', namespace: null});
91 assert_attribute_log_entry(logEntries[2], {name: 'title', oldValue: null , newValue: 'hello world', namespace: null}); 125 assert_attribute_log_entry(logEntries[2], {name: 'title', oldValue: null , newValue: 'hello world', namespace: null});
92 }, name + ' must enqueue an attributeChanged reaction when cloning an elemen t only for observed attributes'); 126 }, name + ' must enqueue an attributeChanged reaction when cloning an elemen t only for observed attributes');
93 } 127 }
94 128
95 function testReflectAttribute(jsAttributeName, contentAttributeName, validValue1 , validValue2, name) { 129 function testReflectAttributeWithContentValues(jsAttributeName, contentAttribute Name, validValue1, contentValue1, validValue2, contentValue2, name) {
96 test(function () { 130 test(function () {
97 var element = define_new_custom_element([contentAttributeName]); 131 var element = define_new_custom_element([contentAttributeName]);
98 var instance = document.createElement(element.name); 132 var instance = document.createElement(element.name);
99 assert_array_equals(element.takeLog().types(), ['constructed']); 133 assert_array_equals(element.takeLog().types(), ['constructed']);
100 instance[jsAttributeName] = validValue1; 134 instance[jsAttributeName] = validValue1;
101 var logEntries = element.takeLog(); 135 var logEntries = element.takeLog();
102 assert_array_equals(logEntries.types(), ['attributeChanged']); 136 assert_array_equals(logEntries.types(), ['attributeChanged']);
103 assert_attribute_log_entry(logEntries.last(), {name: contentAttributeNam e, oldValue: null, newValue: validValue1, namespace: null}); 137
138 assert_attribute_log_entry(logEntries.last(), {name: contentAttributeNam e, oldValue: null, newValue: contentValue1, namespace: null});
104 }, name + ' must enqueue an attributeChanged reaction when adding ' + conten tAttributeName + ' content attribute'); 139 }, name + ' must enqueue an attributeChanged reaction when adding ' + conten tAttributeName + ' content attribute');
105 140
106 test(function () { 141 test(function () {
107 var element = define_new_custom_element([contentAttributeName]); 142 var element = define_new_custom_element([contentAttributeName]);
108 var instance = document.createElement(element.name); 143 var instance = document.createElement(element.name);
109 instance[jsAttributeName] = validValue1; 144 instance[jsAttributeName] = validValue1;
110 assert_array_equals(element.takeLog().types(), ['constructed', 'attribut eChanged']); 145 assert_array_equals(element.takeLog().types(), ['constructed', 'attribut eChanged']);
111 instance[jsAttributeName] = validValue2; 146 instance[jsAttributeName] = validValue2;
112 var logEntries = element.takeLog(); 147 var logEntries = element.takeLog();
113 assert_array_equals(logEntries.types(), ['attributeChanged']); 148 assert_array_equals(logEntries.types(), ['attributeChanged']);
114 assert_attribute_log_entry(logEntries.last(), {name: contentAttributeNam e, oldValue: validValue1, newValue: validValue2, namespace: null}); 149 assert_attribute_log_entry(logEntries.last(), {name: contentAttributeNam e, oldValue: contentValue1, newValue: contentValue2, namespace: null});
115 }, name + ' must enqueue an attributeChanged reaction when replacing an exis ting attribute'); 150 }, name + ' must enqueue an attributeChanged reaction when replacing an exis ting attribute');
116 } 151 }
117 152
153 function testReflectAttribute(jsAttributeName, contentAttributeName, validValue1 , validValue2, name) {
154 testReflectAttributeWithContentValues(jsAttributeName, contentAttributeName, validValue1, validValue1, validValue2, validValue2, name);
155 }
156
157 function testReflectBooleanAttribute(jsAttributeName, contentAttributeName, name ) {
158 testReflectAttributeWithContentValues(jsAttributeName, contentAttributeName, true, '', false, null, name);
159 }
160
118 function testAttributeAdder(testFunction, name) { 161 function testAttributeAdder(testFunction, name) {
119 test(function () { 162 test(function () {
120 var element = define_new_custom_element(['id']); 163 var element = define_new_custom_element(['id']);
121 var instance = document.createElement(element.name); 164 var instance = document.createElement(element.name);
122 assert_array_equals(element.takeLog().types(), ['constructed']); 165 assert_array_equals(element.takeLog().types(), ['constructed']);
123 testFunction(instance, 'id', 'foo'); 166 testFunction(instance, 'id', 'foo');
124 var logEntries = element.takeLog(); 167 var logEntries = element.takeLog();
125 assert_array_equals(logEntries.types(), ['attributeChanged']); 168 assert_array_equals(logEntries.types(), ['attributeChanged']);
126 assert_attribute_log_entry(logEntries.last(), {name: 'id', oldValue: nul l, newValue: 'foo', namespace: null}); 169 assert_attribute_log_entry(logEntries.last(), {name: 'id', oldValue: nul l, newValue: 'foo', namespace: null});
127 }, name + ' must enqueue an attributeChanged reaction when adding an attribu te'); 170 }, name + ' must enqueue an attributeChanged reaction when adding an attribu te');
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 test(function () { 213 test(function () {
171 var element = define_new_custom_element(['class']); 214 var element = define_new_custom_element(['class']);
172 var instance = document.createElement(element.name); 215 var instance = document.createElement(element.name);
173 instance.setAttribute('data-lang', 'zh'); 216 instance.setAttribute('data-lang', 'zh');
174 assert_array_equals(element.takeLog().types(), ['constructed']); 217 assert_array_equals(element.takeLog().types(), ['constructed']);
175 testFunction(instance, 'data-lang', 'en'); 218 testFunction(instance, 'data-lang', 'en');
176 assert_array_equals(element.takeLog().types(), []); 219 assert_array_equals(element.takeLog().types(), []);
177 }, name + ' must not enqueue an attributeChanged reaction when replacing an existing unobserved attribute'); 220 }, name + ' must not enqueue an attributeChanged reaction when replacing an existing unobserved attribute');
178 } 221 }
179 222
180 function testAttributeRemover(testFunction, name) { 223 function testAttributeRemover(testFunction, name, options) {
181 test(function () { 224 if (options && !options.onlyExistingAttribute) {
182 var element = define_new_custom_element(['title']); 225 test(function () {
183 var instance = document.createElement(element.name); 226 var element = define_new_custom_element(['title']);
184 assert_array_equals(element.takeLog().types(), ['constructed']); 227 var instance = document.createElement(element.name);
185 testFunction(instance, 'title'); 228 assert_array_equals(element.takeLog().types(), ['constructed']);
186 assert_array_equals(element.takeLog().types(), []); 229 testFunction(instance, 'title');
187 }, name + ' must not enqueue an attributeChanged reaction when removing an a ttribute that does not exist'); 230 assert_array_equals(element.takeLog().types(), []);
231 }, name + ' must not enqueue an attributeChanged reaction when removing an attribute that does not exist');
232 }
188 233
189 test(function () { 234 test(function () {
190 var element = define_new_custom_element([]); 235 var element = define_new_custom_element([]);
191 var instance = document.createElement(element.name); 236 var instance = document.createElement(element.name);
192 instance.setAttribute('data-lang', 'hello'); 237 instance.setAttribute('data-lang', 'hello');
193 assert_array_equals(element.takeLog().types(), ['constructed']); 238 assert_array_equals(element.takeLog().types(), ['constructed']);
194 testFunction(instance, 'data-lang'); 239 testFunction(instance, 'data-lang');
195 assert_array_equals(element.takeLog().types(), []); 240 assert_array_equals(element.takeLog().types(), []);
196 }, name + ' must not enqueue an attributeChanged reaction when removing an u nobserved attribute'); 241 }, name + ' must not enqueue an attributeChanged reaction when removing an u nobserved attribute');
197 242
(...skipping 10 matching lines...) Expand all
208 253
209 test(function () { 254 test(function () {
210 var element = define_new_custom_element([]); 255 var element = define_new_custom_element([]);
211 var instance = document.createElement(element.name); 256 var instance = document.createElement(element.name);
212 instance.setAttribute('data-lang', 'ja'); 257 instance.setAttribute('data-lang', 'ja');
213 assert_array_equals(element.takeLog().types(), ['constructed']); 258 assert_array_equals(element.takeLog().types(), ['constructed']);
214 testFunction(instance, 'data-lang'); 259 testFunction(instance, 'data-lang');
215 assert_array_equals(element.takeLog().types(), []); 260 assert_array_equals(element.takeLog().types(), []);
216 }, name + ' must not enqueue an attributeChanged reaction when removing an e xisting unobserved attribute'); 261 }, name + ' must not enqueue an attributeChanged reaction when removing an e xisting unobserved attribute');
217 } 262 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698