<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>189164</bug_id>
          
          <creation_ts>2018-08-30 11:18:04 -0700</creation_ts>
          <short_desc>Document.p.contains returns true for nodes in shadow tree</short_desc>
          <delta_ts>2020-09-28 16:48:49 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=216656</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>148695</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Justin Ridgewell">jridgewell</reporter>
          <assigned_to name="Ryosuke Niwa">rniwa</assigned_to>
          <cc>cdumez</cc>
    
    <cc>darin</cc>
    
    <cc>jridgewell</cc>
    
    <cc>rniwa</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1455305</commentid>
    <comment_count>0</comment_count>
      <attachid>348515</attachid>
    <who name="Justin Ridgewell">jridgewell</who>
    <bug_when>2018-08-30 11:18:04 -0700</bug_when>
    <thetext>Created attachment 348515
Document contains test case

`Document.p.contains` currently returns true for nodes inside a shadow tree. This incorrect according to the [spec](https://dom.spec.whatwg.org/#dom-node-contains), which uses &quot;inclusive descendant&quot; not &quot;shadow-including inclusive descendant&quot;.

Note that `Element.p.contains` always does the right thing for nodes in a shadow tree.

Steps to reproduce:
- Go to https://output.jsbin.com/gasefow/quiet
- Observe &quot;Doc contains node in shadow tree&quot; is written to the page


This report invalidates the bug at https://bugs.webkit.org/show_bug.cgi?id=119371 (which asks for for `Node.p.contains` to  return true).
Further reading at https://www.w3.org/Bugs/Public/show_bug.cgi?id=22141, which argued for the broken `Document.p.contains` behavior. Instead of breaking contains, `Node.p.isConnected` was added in https://github.com/w3c/webcomponents/issues/81.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1692230</commentid>
    <comment_count>1</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2020-09-26 15:22:49 -0700</bug_when>
    <thetext>This works for me now.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1692583</commentid>
    <comment_count>2</comment_count>
    <who name="Justin Ridgewell">jridgewell</who>
    <bug_when>2020-09-28 10:06:24 -0700</bug_when>
    <thetext>I tested with Safari TP 113, and it still fails. Is there a recent commit that fixes the behavior?

To be clear, we do not want to see any output on the test page, it should be blank. Safari still shows &quot;Doc contains node in shadow tree&quot; for me.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1692687</commentid>
    <comment_count>3</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2020-09-28 15:26:40 -0700</bug_when>
    <thetext>(In reply to Justin Ridgewell from comment #2)
&gt; I tested with Safari TP 113, and it still fails. Is there a recent commit
&gt; that fixes the behavior?
&gt; 
&gt; To be clear, we do not want to see any output on the test page, it should be
&gt; blank. Safari still shows &quot;Doc contains node in shadow tree&quot; for me.

Oh, weird. I don&apos;t know what I was testing but you&apos;re right this is definitely broken.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1692689</commentid>
    <comment_count>4</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2020-09-28 15:31:55 -0700</bug_when>
    <thetext>Ah, okay, I know what happened there. Darin fixed this in https://trac.webkit.org/r267220.

Node::isDescendantOf has a special code for when &quot;other&quot; node is a document node.

Before r267220, we had the following code, which incorrectly assumed that any node which is connected to &quot;other&quot; is a descendent of &quot;other&quot;:
    if (other.isDocumentNode())
        return &amp;document() == &amp;other &amp;&amp; !isDocumentNode() &amp;&amp; isConnected();

After r267220, now correctly checks that the root node of the current tree is same as &quot;other&quot;:
    if (other.isDocumentNode())
        return &amp;treeScope().rootNode() == &amp;other &amp;&amp; !isDocumentNode() &amp;&amp; isConnected();

I expect this bug will be fixed the next STP.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1692691</commentid>
    <comment_count>5</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2020-09-28 15:32:36 -0700</bug_when>
    <thetext>&lt;rdar://problem/69720558&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1692693</commentid>
    <comment_count>6</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2020-09-28 15:33:15 -0700</bug_when>
    <thetext>Actually, let&apos;s add a test for this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1692694</commentid>
    <comment_count>7</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2020-09-28 15:33:29 -0700</bug_when>
    <thetext>Adding a test.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1692698</commentid>
    <comment_count>8</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2020-09-28 15:47:12 -0700</bug_when>
    <thetext>I knew I was fixing a bug. I’m embarrassed that I didn’t add a test case for it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1692700</commentid>
    <comment_count>9</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2020-09-28 16:03:34 -0700</bug_when>
    <thetext>And really surprised WPT doesn’t already have one!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1692702</commentid>
    <comment_count>10</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2020-09-28 16:09:54 -0700</bug_when>
    <thetext>(In reply to Darin Adler from comment #9)
&gt; And really surprised WPT doesn’t already have one!

Yeah!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1692711</commentid>
    <comment_count>11</comment_count>
      <attachid>409929</attachid>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2020-09-28 16:43:47 -0700</bug_when>
    <thetext>Created attachment 409929
Adds a test</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1692713</commentid>
    <comment_count>12</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2020-09-28 16:48:49 -0700</bug_when>
    <thetext>Committed r267719: &lt;https://trac.webkit.org/changeset/267719&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>348515</attachid>
            <date>2018-08-30 11:18:04 -0700</date>
            <delta_ts>2020-09-28 15:21:25 -0700</delta_ts>
            <desc>Document contains test case</desc>
            <filename>doc-contains-sd.js</filename>
            <type>text/html</type>
            <size>269</size>
            <attacher name="Justin Ridgewell">jridgewell</attacher>
            
              <data encoding="base64">dmFyIGRpdiA9IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJ2RpdicpOwp2YXIgc2QgPSBkaXYuYXR0
YWNoU2hhZG93KHsgbW9kZTogJ29wZW4nIH0pOwpzZC5hcHBlbmRDaGlsZChkb2N1bWVudC5jcmVh
dGVFbGVtZW50KCdzcGFuJykpOwoKaWYgKGRvY3VtZW50LmNvbnRhaW5zKHNkLmZpcnN0Q2hpbGQp
KSB7CiAgZG9jdW1lbnQuYm9keS5pbm5lckhUTUwgPSAnPGgxIHN0eWxlPSJjb2xvcjogcmVkIj5E
b2MgY29udGFpbnMgbm9kZSBpbiBzaGFkb3cgdHJlZTwvaDE+JzsKfQo=
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>409929</attachid>
            <date>2020-09-28 16:43:47 -0700</date>
            <delta_ts>2020-09-28 16:45:51 -0700</delta_ts>
            <desc>Adds a test</desc>
            <filename>bug-189164-20200928164347.patch</filename>
            <type>text/plain</type>
            <size>3471</size>
            <attacher name="Ryosuke Niwa">rniwa</attacher>
            
              <data encoding="base64">SW5kZXg6IExheW91dFRlc3RzL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBMYXlvdXRUZXN0cy9D
aGFuZ2VMb2cJKHJldmlzaW9uIDI2NzcxOCkKKysrIExheW91dFRlc3RzL0NoYW5nZUxvZwkod29y
a2luZyBjb3B5KQpAQCAtMSwzICsxLDE1IEBACisyMDIwLTA5LTI4ICBSeW9zdWtlIE5pd2EgIDxy
bml3YUB3ZWJraXQub3JnPgorCisgICAgICAgIERvY3VtZW50LnAuY29udGFpbnMgcmV0dXJucyB0
cnVlIGZvciBub2RlcyBpbiBzaGFkb3cgdHJlZQorICAgICAgICBodHRwczovL2J1Z3Mud2Via2l0
Lm9yZy9zaG93X2J1Zy5jZ2k/aWQ9MTg5MTY0CisKKyAgICAgICAgUmV2aWV3ZWQgYnkgTk9CT0RZ
IChPT1BTISkuCisKKyAgICAgICAgQWRkZWQgYSByZWdyZXNzaW9uIGFmdGVyIHIyNjcyMjAgaGFk
IGZpeGVkIHRoaXMgYnVnLgorCisgICAgICAgICogZmFzdC9zaGFkb3ctZG9tL2RvY3VtZW50LWNv
bnRhaW5zLXJldHVybnMtZmFsc2UtZm9yLW5vZGUtaW5zaWRlLXNoYWRvdy10cmVlLWV4cGVjdGVk
LnR4dDogQWRkZWQuCisgICAgICAgICogZmFzdC9zaGFkb3ctZG9tL2RvY3VtZW50LWNvbnRhaW5z
LXJldHVybnMtZmFsc2UtZm9yLW5vZGUtaW5zaWRlLXNoYWRvdy10cmVlLmh0bWw6IEFkZGVkLgor
CiAyMDIwLTA5LTI4ICBGdWppaSBIaXJvbm9y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xkQmVUcnVl
KCdkb2N1bWVudC5ib2R5LmFwcGVuZENoaWxkKHNoYWRvd0hvc3QpOyBzaGFkb3dIb3N0LmlzQ29u
bmVjdGVkJyk7CitzaG91bGRCZVRydWUoJ3NoYWRvd1Jvb3QuaXNDb25uZWN0ZWQnKTsKK3Nob3Vs
ZEJlVHJ1ZSgnc2hhZG93Um9vdENoaWxkLmlzQ29ubmVjdGVkJyk7CitzaG91bGRCZVRydWUoJ2Rv
Y3VtZW50LmNvbnRhaW5zKHNoYWRvd0hvc3QpJyk7CitzaG91bGRCZUZhbHNlKCdkb2N1bWVudC5j
b250YWlucyhzaGFkb3dSb290KScpOworc2hvdWxkQmVGYWxzZSgnZG9jdW1lbnQuY29udGFpbnMo
c2hhZG93Um9vdENoaWxkKScpOworCis8L3NjcmlwdD4KKzwvYm9keT4KKzwvaHRtbD4K
</data>
<flag name="review"
          id="425758"
          type_id="1"
          status="+"
          setter="darin"
    />
          </attachment>
      

    </bug>

</bugzilla>