name-attribute.window.js (1939B)
1 // META: script=/common/get-host-info.sub.js 2 3 [ 4 "frame", // This works without <frameset>, so great 5 "iframe", 6 "object", 7 "embed", 8 ].forEach(element => { 9 [ 10 null, 11 "", 12 "initialvalue" 13 ].forEach(initialNameValue => { 14 [ 15 "same-origin", 16 "cross-origin" 17 ].forEach(originType => { 18 async_test(t => { 19 const ident = element + initialNameValue + originType, 20 file = `${new URL("resources/post-to-parent.html", location.href).pathname}?ident=${ident}`, 21 child = originType === "same-origin" ? file : `${get_host_info().HTTP_REMOTE_ORIGIN}${file}`, 22 frame = document.createElement(element), 23 expectedNameValue = initialNameValue || ""; 24 let state = "set"; 25 const listener = t.step_func(e => { 26 if (e.data.ident === ident) { 27 assert_equals(e.data.name, expectedNameValue); // This check is always the same 28 if (state === "set") { 29 frame.setAttribute("name", "meh"); 30 state = "remove" 31 e.source.postMessage(null, "*"); 32 return; 33 } 34 if (state === "remove") { 35 frame.removeAttribute("name"); 36 state = "done"; 37 e.source.postMessage(null, "*"); 38 return; 39 } 40 if (state === "done") { 41 t.done(); 42 } 43 } 44 }); 45 frame.setAttribute(element === "object" ? "data" : "src", child); 46 if (initialNameValue !== null) { 47 frame.setAttribute("name", initialNameValue); 48 } 49 t.add_cleanup(() => { 50 self.removeEventListener("message", listener); 51 frame.remove(); 52 }); 53 self.addEventListener("message", listener); 54 document.body.append(frame); 55 }, `${originType} <${element}${initialNameValue !== null ? ' name=' + initialNameValue : ''}>`); 56 }); 57 }); 58 });