tor-browser

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

scroll-to-the-fragment-in-shadow-tree.html (6240B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title>Shadow DOM: The indicated part of the document should not match an element inside a shadow tree</title>
      5 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
      6 <meta name="assert" content="An element inside a shadow tree should not be the indicated part of the document even if its ID is exactly equal to the decoded fragid or its name attribute is exactly equal to the fragid">
      7 <link rel="help" href="https://html.spec.whatwg.org/multipage/browsers.html#scroll-to-the-fragment-identifier">
      8 <meta name="viewport" content="width=device-width,initial-scale=1">
      9 <script src="/resources/testharness.js"></script>
     10 <script src="/resources/testharnessreport.js"></script>
     11 </head>
     12 <body>
     13 <div id="log"></div>
     14 <div id="testContainer"></div>
     15 <script>
     16 
     17 var tests = [
     18    {test: async_test('The user agent scroll to the fragment when there is an element with an ID exactly equal to the decoded fragid'),
     19        execute: testScrollingToElementInDocumentTree.bind(this, 'div')},
     20    {test: async_test('The user agent scroll to the fragment when there is an anchor element with a name attribute exactly equal to the decoded fragid'),
     21        execute: testScrollingToElementInDocumentTree.bind(this, 'a')},
     22 
     23    {test: async_test('The user agent should not scroll to an element with an ID exactly equal to the decoded fragid in an open shadow tree'),
     24        execute: testScrollingToElementInShadowTree.bind(this, 'div', 'open')},
     25    {test: async_test('The user agent should not scroll to an element with an ID exactly equal to the decoded fragid in a closed shadow tree'),
     26        execute: testScrollingToElementInShadowTree.bind(this, 'div', 'closed')},
     27    {test: async_test('The user agent should not scroll to an anchor element with a name attribute exactly equal to the decoded fragid in an open shadow tree'),
     28        execute: testScrollingToElementInShadowTree.bind(this, 'a', 'open')},
     29    {test: async_test('The user agent should not scroll to an anchor element with a name attribute exactly equal to the decoded fragid in a closed shadow tree'),
     30        execute: testScrollingToElementInShadowTree.bind(this, 'a', 'closed')},
     31 
     32    {test: async_test('The user agent should scroll to an element with an ID exactly equal to the decoded fragid in the document tree'
     33        + ' even if there was another element with the same ID inside an open shadow tree earlier in tree order'),
     34        execute: testScrollingToElementInDocumentTreeAfterElementInShadowTreeWithSameID.bind(this, 'div', 'open')},
     35    {test: async_test('The user agent should scroll to an element with an ID exactly equal to the decoded fragid in the document tree'
     36        + ' even if there was another element with the same ID inside a closed shadow tree earlier in tree order'),
     37        execute: testScrollingToElementInDocumentTreeAfterElementInShadowTreeWithSameID.bind(this, 'div', 'closed')},
     38    {test: async_test('The user agent should scroll to an anchor element with a name attribute exactly equal to the decoded fragid in the document tree'
     39        + ' even if there was another element with the same ID inside an open shadow tree earlier in tree order'),
     40        execute: testScrollingToElementInDocumentTreeAfterElementInShadowTreeWithSameID.bind(this, 'a', 'open')},
     41    {test: async_test('The user agent should scroll to an anchor element with a name attribute exactly equal to the decoded fragid in the document tree'
     42        + ' even if there was another element with the same ID inside a closed shadow tree earlier in tree order'),
     43        execute: testScrollingToElementInDocumentTreeAfterElementInShadowTreeWithSameID.bind(this, 'a', 'closed')},
     44 ];
     45 
     46 function executeNextTest()
     47 {
     48    window.scrollTo(0, 0);
     49 
     50    currentFragIdSuffix++;
     51    var nextTest = tests.shift();
     52    if (!nextTest)
     53        return;
     54    setTimeout(function () {
     55        nextTest.execute(nextTest.test);
     56    }, 0);
     57 }
     58 
     59 var testContainer = document.getElementById('testContainer');
     60 var currentFragIdSuffix = 0;
     61 
     62 function tallElementMarkup()
     63 {
     64    return '<div style="height: ' + (window.innerHeight * 2) + 'px"><a href="#fragid' + currentFragIdSuffix + '">Go to fragment</a></div>';
     65 }
     66 
     67 function targetMarkup(elementType)
     68 {
     69    return elementType == 'div' ? ('<div id="fragid' + currentFragIdSuffix + '">hello</div>') : ('<a name="fragid' + currentFragIdSuffix + '">hello</a>');
     70 }
     71 
     72 function clickFirstAnchorAndRunStep(test, step)
     73 {
     74    setTimeout(function () {
     75        testContainer.querySelector('a').click();
     76        setTimeout(function () {
     77            test.step(step);
     78            testContainer.innerHTML = '';
     79            test.done();
     80            executeNextTest();
     81        }, 0);
     82    }, 0);
     83 }
     84 
     85 function testScrollingToElementInDocumentTree(elementType, test)
     86 {
     87    test.step(function () {
     88        testContainer.innerHTML = tallElementMarkup() + targetMarkup(elementType);
     89        assert_equals(window.pageYOffset, 0);
     90    });
     91    clickFirstAnchorAndRunStep(test, function () {
     92        assert_not_equals(window.pageYOffset, 0);
     93    });
     94 }
     95 
     96 function testScrollingToElementInShadowTree(elementType, mode, test)
     97 {
     98    test.step(function () {
     99        testContainer.innerHTML = tallElementMarkup() + '<div id="host"></div>';
    100        var host = document.querySelector('#host');
    101        var shadowRoot = host.attachShadow({mode: mode});
    102        shadowRoot.innerHTML = targetMarkup(elementType);
    103        assert_equals(window.pageYOffset, 0);
    104    });
    105    clickFirstAnchorAndRunStep(test, function () {
    106        assert_equals(window.pageYOffset, 0);
    107    });
    108 }
    109 
    110 function testScrollingToElementInDocumentTreeAfterElementInShadowTreeWithSameID(elementType, mode, test)
    111 {
    112    test.step(function () {
    113        testContainer.innerHTML = tallElementMarkup() + '<div id="host"></div>' + tallElementMarkup() + targetMarkup(elementType);
    114        var host = document.querySelector('#host');
    115        var shadowRoot = host.attachShadow({mode: mode});
    116        shadowRoot.innerHTML = targetMarkup(elementType);
    117        assert_equals(window.pageYOffset, 0);
    118    });
    119    clickFirstAnchorAndRunStep(test, function () {
    120        assert_true(window.pageYOffset > testContainer.querySelector('#host').offsetTop);
    121    });
    122 }
    123 
    124 executeNextTest();
    125 
    126 </script>
    127 </body>
    128 </html>