tor-browser

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

scope-selector.html (1778B)


      1 <!doctype html>
      2 <link rel='help' href='https://drafts.csswg.org/selectors-4/#the-scope-pseudo'>
      3 <meta name='description' content=':scope should match when context object is a ShadowRoot or a DocumentFragment'>
      4 <script src='/resources/testharness.js'></script>
      5 <script src='/resources/testharnessreport.js'></script>
      6 <div id='shadowHost'></div>
      7 <script>
      8 'use strict'
      9 const shadowHost = document.getElementById("shadowHost");
     10 const shadowRoot = shadowHost.attachShadow({mode:'open'})
     11 shadowRoot.appendChild(document.createElement("div"));
     12 
     13 test (() => {
     14  assert_equals(shadowRoot.querySelectorAll(':scope > div').length, 0, 'should not match in shadow root');
     15 });
     16 
     17 const documentFragment = document.createDocumentFragment();
     18 documentFragment.appendChild(document.createElement("div"));
     19 
     20 test(() => {
     21  assert_equals(documentFragment.querySelectorAll(':scope > div').length, 0, 'should not match in document fragment');
     22 });
     23 
     24 test(() => {
     25  assert_equals(shadowRoot.firstChild.querySelector(':scope'), null, 'should return null');
     26  assert_equals(shadowRoot.firstChild.querySelectorAll(':scope').length, 0, 'should return 0');
     27 
     28  assert_equals(shadowRoot.querySelector(':scope'), null, 'should return null');
     29  assert_equals(shadowRoot.querySelectorAll(':scope').length, 0, 'should return 0');
     30 
     31  assert_equals(documentFragment.querySelector(':scope'), null, 'should return null');
     32  assert_equals(documentFragment.querySelectorAll(':scope').length, 0, 'should return 0');
     33 
     34  assert_equals(document.querySelector(':scope'), document.documentElement, 'should return the document element');
     35  assert_equals(document.querySelectorAll(':scope').length, 1, 'should return 1');
     36 }, 'querySelector() with ":scope" should return the document element, if present in the subtree');
     37 </script>