| 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); |
| 20 }); | 20 }); |
| 21 }, name); | 21 }, name); |
| 22 } | 22 } |
| 23 | |
| 24 function create_attribute_changed_callback_log(element, name, oldValue, newValue
, namespace) { | |
| 25 return { | |
| 26 type: 'attributeChanged', | |
| 27 element: element, | |
| 28 name: name, | |
| 29 namespace: namespace, | |
| 30 oldValue: oldValue, | |
| 31 newValue: newValue, | |
| 32 actualValue: element.getAttributeNS(namespace, name) | |
| 33 }; | |
| 34 } | |
| 35 | |
| 36 function assert_attribute_log_entry(log, expected) { | |
| 37 assert_equals(log.type, 'attributeChanged'); | |
| 38 assert_equals(log.name, expected.name); | |
| 39 assert_equals(log.oldValue, expected.oldValue); | |
| 40 assert_equals(log.newValue, expected.newValue); | |
| 41 assert_equals(log.actualValue, expected.newValue); | |
| 42 assert_equals(log.namespace, expected.namespace); | |
| 43 } | |
| 44 | |
| 45 | |
| 46 function define_new_custom_element(observedAttributes) { | |
| 47 let log = []; | |
| 48 let name = 'custom-element-' + define_new_custom_element._element_number++; | |
| 49 | |
| 50 class CustomElement extends HTMLElement { | |
| 51 constructor() { | |
| 52 super(); | |
| 53 log.push({type: 'constructed', element: this}); | |
| 54 } | |
| 55 attributeChangedCallback(...args) { | |
| 56 log.push(create_attribute_changed_callback_log(this, ...args)); | |
| 57 } | |
| 58 connectedCallback() { log.push({type: 'connected', element: this}); } | |
| 59 disconnectedCallback() { log.push({type: 'disconnected', element: this})
; } | |
| 60 adoptedCallback(oldDocument, newDocument) { log.push({type: 'adopted', e
lement: this, oldDocument: oldDocument, newDocument: newDocument}); } | |
| 61 } | |
| 62 CustomElement.observedAttributes = observedAttributes; | |
| 63 | |
| 64 customElements.define(name, CustomElement); | |
| 65 | |
| 66 return { | |
| 67 name: name, | |
| 68 takeLog: function () { | |
| 69 let currentLog = log; log = []; | |
| 70 currentLog.types = () => currentLog.map((entry) => entry.type); | |
| 71 currentLog.last = () => currentLog[currentLog.length - 1]; | |
| 72 return currentLog; | |
| 73 } | |
| 74 }; | |
| 75 } | |
| 76 define_new_custom_element._element_number = 1; | |
| 77 | |
| 78 function document_types() { | |
| 79 return [ | |
| 80 { | |
| 81 name: 'the document', | |
| 82 create: function () { return Promise.resolve(document); }, | |
| 83 isOwner: true, | |
| 84 hasBrowsingContext: true, | |
| 85 }, | |
| 86 { | |
| 87 name: 'the document of the template elements', | |
| 88 create: function () { | |
| 89 return new Promise(function (resolve) { | |
| 90 var template = document.createElementNS('http://www.w3.org/1
999/xhtml', 'template'); | |
| 91 var doc = template.content.ownerDocument; | |
| 92 if (!doc.documentElement) | |
| 93 doc.appendChild(doc.createElement('html')); | |
| 94 resolve(doc); | |
| 95 }); | |
| 96 }, | |
| 97 hasBrowsingContext: false, | |
| 98 }, | |
| 99 { | |
| 100 name: 'a new document', | |
| 101 create: function () { | |
| 102 return new Promise(function (resolve) { | |
| 103 var doc = new Document(); | |
| 104 doc.appendChild(doc.createElement('html')); | |
| 105 resolve(doc); | |
| 106 }); | |
| 107 }, | |
| 108 hasBrowsingContext: false, | |
| 109 }, | |
| 110 { | |
| 111 name: 'a cloned document', | |
| 112 create: function () { | |
| 113 return new Promise(function (resolve) { | |
| 114 var doc = document.cloneNode(false); | |
| 115 doc.appendChild(doc.createElement('html')); | |
| 116 resolve(doc); | |
| 117 }); | |
| 118 }, | |
| 119 hasBrowsingContext: false, | |
| 120 }, | |
| 121 { | |
| 122 name: 'a document created by createHTMLDocument', | |
| 123 create: function () { | |
| 124 return Promise.resolve(document.implementation.createHTMLDocumen
t()); | |
| 125 }, | |
| 126 hasBrowsingContext: false, | |
| 127 }, | |
| 128 { | |
| 129 name: 'an HTML document created by createDocument', | |
| 130 create: function () { | |
| 131 return Promise.resolve(document.implementation.createDocument('h
ttp://www.w3.org/1999/xhtml', 'html', null)); | |
| 132 }, | |
| 133 hasBrowsingContext: false, | |
| 134 }, | |
| 135 { | |
| 136 name: 'the document of an iframe', | |
| 137 create: function () { | |
| 138 return new Promise(function (resolve, reject) { | |
| 139 var iframe = document.createElement('iframe'); | |
| 140 iframe.onload = function () { resolve(iframe.contentDocument
); } | |
| 141 iframe.onerror = function () { reject('Failed to load an emp
ty iframe'); } | |
| 142 document.body.appendChild(iframe); | |
| 143 }); | |
| 144 }, | |
| 145 hasBrowsingContext: true, | |
| 146 }, | |
| 147 { | |
| 148 name: 'an HTML document fetched by XHR', | |
| 149 create: function () { | |
| 150 return new Promise(function (resolve, reject) { | |
| 151 var xhr = new XMLHttpRequest(); | |
| 152 xhr.open('GET', 'resources/empty-html-document.html'); | |
| 153 xhr.overrideMimeType('text/xml'); | |
| 154 xhr.onload = function () { resolve(xhr.responseXML); } | |
| 155 xhr.onerror = function () { reject('Failed to fetch the docu
ment'); } | |
| 156 xhr.send(); | |
| 157 }); | |
| 158 }, | |
| 159 hasBrowsingContext: false, | |
| 160 } | |
| 161 ]; | |
| 162 } | |
| OLD | NEW |