changing.html (2485B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Named access on the window object - changing attributes</title> 4 <link rel="author" title="Matthew Phillips" href="mailto:matthew@matthewphillips.info"> 5 <link rel="help" href="https://html.spec.whatwg.org/#named-access-on-the-window-object"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 9 <body> 10 <script> 11 "use strict"; 12 13 test(() => { 14 const img = document.createElement("img"); 15 document.body.appendChild(img); 16 img.setAttribute("id", "changing-one"); 17 assert_equals(window["changing-one"], img); 18 19 img.setAttribute("id", "changing-two"); 20 assert_false("changing-one" in window); 21 assert_equals(window["changing-two"], img); 22 }, "Changing an attribute must update the named properties (id)"); 23 24 test(() => { 25 const img = document.createElement("img"); 26 document.body.appendChild(img); 27 img.setAttribute("name", "changing-name-one"); 28 assert_equals(window["changing-name-one"], img); 29 30 img.setAttribute("name", "changing-name-two"); 31 assert_false("changing-name-one" in window); 32 assert_equals(window["changing-name-two"], img); 33 34 }, "Changing an attribute must update the named properties (name)"); 35 36 test(() => { 37 const img = document.createElement("img"); 38 document.body.appendChild(img); 39 img.setAttribute("name", "still-match"); 40 img.setAttribute("id", "still-match"); 41 assert_equals(window["still-match"], img); 42 43 img.setAttribute("id", "other"); 44 assert_equals(window["still-match"], img); 45 }, "Changing an attribute must not remove the named properties if a different attribute still matches (id)"); 46 47 test(() => { 48 const img = document.createElement("img"); 49 document.body.appendChild(img); 50 img.setAttribute("name", "still-match-name"); 51 img.setAttribute("id", "still-match-name"); 52 assert_equals(window["still-match-name"], img); 53 54 img.setAttribute("name", "other"); 55 assert_equals(window["still-match-name"], img); 56 }, "Changing an attribute must not remove the named properties if a different attribute still matches (name)"); 57 58 test(() => { 59 const img = document.createElement("img"); 60 img.setAttribute("alt", "Cat pictures on the internet"); 61 img.setAttribute("id", "no-errors"); 62 document.body.appendChild(img); 63 assert_equals(window["no-errors"], img); 64 65 img.setAttribute("alt", "Dog pictures on the internet"); 66 assert_equals(window["no-errors"], img); 67 }, "Changing an attribute that is not id or name must not cause errors"); 68 </script>