tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

name-attribute-elements.html (2233B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Named access on the window object - name attribute</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 localNames = ["embed", "form", "img", "object"];
     15 
     16  for (const localName of localNames) {
     17    const element = document.createElement(localName);
     18    element.setAttribute("name", "positive");
     19    document.body.appendChild(element);
     20  }
     21 
     22  localNames.forEach((tagName, index) => {
     23    const element = window.positive[index];
     24    assert_not_equals(element, undefined);
     25    assert_equals(element.localName, localNames[index]);
     26  });
     27 }, "Only elements with specific local names may be returned if their name attribute matches");
     28 
     29 test(t => {
     30  // Not exhaustive
     31  const localNames = [
     32    "a", "area", "frameset",
     33    "div", "span", "style", "script", "h1", "strong", "input",
     34    "audio", "button", "select", "textarea"
     35  ];
     36 
     37  for (const localName of localNames) {
     38    const element = document.createElement(localName);
     39    element.setAttribute("name", "negative");
     40    document.body.appendChild(element);
     41 
     42    t.add_cleanup(() => element.remove());
     43  }
     44 
     45  assert_equals(window.negative, undefined);
     46 }, "Only elements with specific local names may be returned if their name attribute matches (negative test)");
     47 
     48 test(() => {
     49  // Not exhaustive
     50  const localNames = [
     51    "a", "area", "frameset",
     52    "div", "span", "style", "script", "h1", "strong", "input",
     53    "audio", "button", "select", "textarea"
     54  ];
     55 
     56  const img = document.createElement("img");
     57  img.setAttribute("name", "removed");
     58  document.body.appendChild(img);
     59 
     60  for (const localName of localNames) {
     61    const element = document.createElement(localName);
     62    element.setAttribute("name", "removed");
     63    document.body.appendChild(element);
     64    element.remove();
     65  }
     66 
     67  assert_equals(window.removed, img);
     68 }, "Removing an element for which the name attribute is not tracked, must not cause errors upon removing it");
     69 </script>