tor-browser

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

anchor-with-inline-element.html (2793B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>summary element: clicking on anchor containing inline element</title>
      4 <link rel="author" title="Yu Han" href="mailto:yuzhehan@chromium.org">
      5 <link rel="help" href="https://html.spec.whatwg.org/C/#the-summary-element">
      6 <link rel="help" href="https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-a-element">
      7 <script src="/resources/testharness.js"></script>
      8 <script src="/resources/testharnessreport.js"></script>
      9 
     10 <details id="details_i">
     11  <summary>Anchor text is wrapped with &lt;i&gt; tag <a href="#with_i_tag"><i id="with_i">permalink</i></a></summary>
     12  <p>asdf</p>
     13 </details>
     14 
     15 <details id="details_span">
     16  <summary>This one uses &lt;span&gt;. <a href="#with_span_tag"><span id="with_span">permalink</span></a></summary>
     17  <p>asdf</p>
     18 </details>
     19 
     20 <details id="details_svg">
     21  <summary>
     22    <svg style="width: 100px;" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
     23      <a href="#inside_svg_w_circle">
     24        <circle id="svg_circle" cx="50" cy="40" r="35"/>
     25      </a>
     26      <a href="#inside_svg_w_text">
     27        <text id="svg_text" x="50" y="90" text-anchor="middle">
     28          &lt;circle&gt;
     29        </text>
     30      </a>
     31    </svg>
     32  </summary>
     33  <p>asdf</p>
     34 </details>
     35 
     36 <script>
     37 function testClickingOnInlineElement(detailsId, targetId, expected, testName) {
     38  const details = document.getElementById(detailsId);
     39  const target = document.getElementById(targetId);
     40  const test = async_test(testName);
     41 
     42  const promise = new Promise((resolve, reject) => {
     43    window.onhashchange = test.step_func_done(() => {
     44      assert_false(details.open);
     45      assert_equals(location.hash, expected);
     46      resolve();
     47    });
     48  });
     49 
     50  if (target.click) {
     51    target.click();
     52  }
     53  else {
     54    // svg element don't have click method
     55    target.dispatchEvent(new MouseEvent('click', {
     56      view: window,
     57      bubbles: true,
     58      cancelable: true
     59    }));
     60  }
     61  return promise;
     62 };
     63 
     64 async function testAll() {
     65  try {
     66    await testClickingOnInlineElement("details_i", "with_i", "#with_i_tag", "Expected <a> containing <i> to navigate");
     67    await testClickingOnInlineElement("details_span", "with_span", "#with_span_tag", "Expected <a> containing <span> to navigate");
     68    await testClickingOnInlineElement("details_svg", "svg_circle", "#inside_svg_w_circle", "Expected <a>, inside svg, containing <circle> to navigate");
     69    await testClickingOnInlineElement("details_svg", "svg_text", "#inside_svg_w_text", "Expected <a>, inside svg, containing <text> to navigate");
     70  } catch (exception) {
     71    assert_unreached("should NOT-THROW exception");
     72  }
     73 };
     74 
     75 var allTests = async_test("Clicking on anchor with embedded inline element should navigate instead of opening details");
     76 testAll().then(()=>{ allTests.done(); });
     77 </script>