Skip to content

Commit

Permalink
Bug 1888532 [wpt PR 45415] - Add a test of the ordering of getHTML se…
Browse files Browse the repository at this point in the history
…rialization, a=testonly

Automatic update from web-platform-tests
Add a test of the ordering of getHTML serialization

This adds a test to verify that the serialized version of a shadow
root:
 1. has the `<template shadowroot>` first, before any children,
    regardless of where the initial DSD content put them.
 2. has the various shadowroot* attributes in a well defined order,
    again regardless of where the initial DSD put them.

This came from a comment on the spec PR, here:
 whatwg/html#10139 (comment)

(Note that Github currently doesn't properly handle links to
"Resolved" conversations, and the above conversation is resolved.
So I guess trust me that the request was to add testing for this
case!)

Bug: 41490936
Change-Id: I7866b61b768f645d61142a1fd4a9490ee0732dc2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5405665
Reviewed-by: David Baron <[email protected]>
Commit-Queue: Mason Freed <[email protected]>
Auto-Submit: Mason Freed <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1279973}

--

wpt-commits: 6a072aeb9fcbaa56cab5e168cba7b706268c4d05
wpt-pr: 45415
  • Loading branch information
mfreed7 authored and moz-wptsync-bot committed Apr 10, 2024
1 parent 40af884 commit 4b9fa3e
Showing 1 changed file with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!DOCTYPE html>
<title>getHTML ordering behavior</title>
<link rel='author' href='mailto:[email protected]'>
<link rel='help' href='https://github.com/whatwg/html/pull/10139'>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>


<div id=tests>
<div data-name="base">
<template shadowrootmode=open shadowrootdelegatesfocus shadowrootserializable shadowrootclonable>
<slot></slot>
</template>
<span class=content>Content 1</span>
<span class=content>Content 2</span>
</div>

<div data-name="template position">
<span class=content>Content 1</span>
<template shadowrootmode=open shadowrootdelegatesfocus shadowrootserializable shadowrootclonable>
<slot></slot>
</template>
<span class=content>Content 2</span>
</div>

<div data-name="attribute position">
<template shadowrootclonable shadowrootserializable shadowrootdelegatesfocus shadowrootmode=open>
<slot></slot>
</template>
<span class=content>Content 1</span>
<span class=content>Content 2</span>
</div>

<div data-name="both template and attribute position">
<span class=content>Content 1</span>
<span class=content>Content 2</span>
<template shadowrootclonable shadowrootserializable shadowrootdelegatesfocus shadowrootmode=open>
<slot></slot>
</template>
</div>
</div>

<script>
function removeWhitespaceNodes(el) {
el.shadowRoot && removeWhitespaceNodes(el.shadowRoot);
var iter = document.createNodeIterator(el, NodeFilter.SHOW_TEXT,
(node) => (node.data.replace(/\s/g,'').length === 0) ?
NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT);
let node;
while (node = iter.nextNode()) {
node.remove();
}
return el;
}
const serialize = (host) => host.getHTML({shadowRoots: [host.shadowRoot]});

const testCases = Array.from(document.querySelectorAll('#tests>div'));
assert_true(testCases.length > 1);
const baseHost = removeWhitespaceNodes(testCases[0]);
const correctSerialization = serialize(baseHost);
baseHost.remove();
for(let i=1;i<testCases.length;++i) {
const thisHost = removeWhitespaceNodes(testCases[i]);
test(t => {
assert_equals(serialize(thisHost),correctSerialization,'Serialization should be identical');
thisHost.remove();
},thisHost.dataset.name);
}
</script>

0 comments on commit 4b9fa3e

Please sign in to comment.