OLD | NEW |
1 function create_window_in_test(t, srcdoc) { | 1 function create_window_in_test(t, srcdoc) { |
2 let p = new Promise((resolve) => { | 2 let p = new Promise((resolve) => { |
3 let f = document.createElement('iframe'); | 3 let f = document.createElement('iframe'); |
4 f.srcdoc = srcdoc ? srcdoc : ''; | 4 f.srcdoc = srcdoc ? srcdoc : ''; |
5 f.onload = (event) => { | 5 f.onload = (event) => { |
6 let w = f.contentWindow; | 6 let w = f.contentWindow; |
7 t.add_cleanup(() => f.parentNode && f.remove()); | 7 t.add_cleanup(() => f.parentNode && f.remove()); |
8 resolve(w); | 8 resolve(w); |
9 }; | 9 }; |
10 document.body.appendChild(f); | 10 document.body.appendChild(f); |
11 }); | 11 }); |
12 return p; | 12 return p; |
13 } | 13 } |
14 | 14 |
15 function test_with_window(f, name, srcdoc) { | 15 function test_with_window(f, name, srcdoc) { |
16 promise_test((t) => { | 16 promise_test((t) => { |
17 return create_window_in_test(t, srcdoc) | 17 return create_window_in_test(t, srcdoc) |
18 .then((w) => { | 18 .then((w) => { |
19 f(w); | 19 f(w, w.document); |
20 }); | 20 }); |
21 }, name); | 21 }, name); |
22 } | 22 } |
23 | 23 |
| 24 function define_custom_element_in_window(window, name, observedAttributes) { |
| 25 let log = []; |
| 26 |
| 27 class CustomElement extends window.HTMLElement { |
| 28 constructor() { |
| 29 super(); |
| 30 log.push(create_constructor_log(this)); |
| 31 } |
| 32 attributeChangedCallback(...args) { |
| 33 log.push(create_attribute_changed_callback_log(this, ...args)); |
| 34 } |
| 35 connectedCallback() { log.push(create_connected_callback_log(this)); } |
| 36 disconnectedCallback() { log.push(create_disconnected_callback_log(this)
); } |
| 37 adoptedCallback(oldDocument, newDocument) { log.push({type: 'adopted', e
lement: this, oldDocument: oldDocument, newDocument: newDocument}); } |
| 38 } |
| 39 CustomElement.observedAttributes = observedAttributes; |
| 40 |
| 41 window.customElements.define(name, CustomElement); |
| 42 |
| 43 return { |
| 44 name: name, |
| 45 class: CustomElement, |
| 46 takeLog: function () { |
| 47 let currentLog = log; log = []; |
| 48 currentLog.types = () => currentLog.map((entry) => entry.type); |
| 49 currentLog.last = () => currentLog[currentLog.length - 1]; |
| 50 return currentLog; |
| 51 } |
| 52 }; |
| 53 } |
| 54 |
| 55 function create_constructor_log(element) { |
| 56 return {type: 'constructed', element: element}; |
| 57 } |
| 58 |
| 59 function assert_constructor_log_entry(log, element) { |
| 60 assert_equals(log.type, 'constructed'); |
| 61 assert_equals(log.element, element); |
| 62 } |
| 63 |
| 64 function create_connected_callback_log(element) { |
| 65 return {type: 'connected', element: element}; |
| 66 } |
| 67 |
| 68 function assert_connected_log_entry(log, element) { |
| 69 assert_equals(log.type, 'connected'); |
| 70 assert_equals(log.element, element); |
| 71 } |
| 72 |
| 73 function create_disconnected_callback_log(element) { |
| 74 return {type: 'disconnected', element: element}; |
| 75 } |
| 76 |
| 77 function assert_disconnected_log_entry(log, element) { |
| 78 assert_equals(log.type, 'disconnected'); |
| 79 assert_equals(log.element, element); |
| 80 } |
| 81 |
24 function create_attribute_changed_callback_log(element, name, oldValue, newValue
, namespace) { | 82 function create_attribute_changed_callback_log(element, name, oldValue, newValue
, namespace) { |
25 return { | 83 return { |
26 type: 'attributeChanged', | 84 type: 'attributeChanged', |
27 element: element, | 85 element: element, |
28 name: name, | 86 name: name, |
29 namespace: namespace, | 87 namespace: namespace, |
30 oldValue: oldValue, | 88 oldValue: oldValue, |
31 newValue: newValue, | 89 newValue: newValue, |
32 actualValue: element.getAttributeNS(namespace, name) | 90 actualValue: element.getAttributeNS(namespace, name) |
33 }; | 91 }; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 xhr.overrideMimeType('text/xml'); | 212 xhr.overrideMimeType('text/xml'); |
155 xhr.onload = function () { resolve(xhr.responseXML); } | 213 xhr.onload = function () { resolve(xhr.responseXML); } |
156 xhr.onerror = function () { reject('Failed to fetch the docu
ment'); } | 214 xhr.onerror = function () { reject('Failed to fetch the docu
ment'); } |
157 xhr.send(); | 215 xhr.send(); |
158 }); | 216 }); |
159 }, | 217 }, |
160 hasBrowsingContext: false, | 218 hasBrowsingContext: false, |
161 } | 219 } |
162 ]; | 220 ]; |
163 } | 221 } |
OLD | NEW |