Commit 7702fe9e authored by Mason Freed's avatar Mason Freed Committed by Commit Bot

Add a perf test for cloning of templates containing Declarative Shadow DOM

With declarative Shadow DOM, the clone method has been updated to clone
templates that contain attached shadow DOM. This perf test exercises
that functionality.

Bug: 1042130
Change-Id: Ic31a298c722e10c55e130f704af9c7ccf4c8c72d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2448649
Commit-Queue: Mason Freed <masonfreed@chromium.org>
Commit-Queue: Kouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Auto-Submit: Mason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814372}
parent a44e52e0
<!DOCTYPE html>
<html>
<body>
<script src="../resources/runner.js"></script>
<script>
const hostChildren = 100;
function createDeepShadowTemplateContent(levels, slotted) {
const nestedContent = levels > 0 ? createDeepShadowTemplateContent(levels-1) : '<span>End</span>';
if (slotted) {
return `<div><template shadowroot=open><slot></slot></template>${nestedContent}</div>`;
} else {
return `<div><template shadowroot=open>${nestedContent}</template></div>`;
}
}
// Build templates once
const templateSlotted = document.createElement('template');
document.body.appendChild(templateSlotted);
templateSlotted.innerHTML = createDeepShadowTemplateContent(hostChildren, true);
const templateNested = document.createElement('template');
document.body.appendChild(templateNested);
templateNested.innerHTML = createDeepShadowTemplateContent(hostChildren, false);
if (!templateSlotted.content.firstChild.shadowRoot) {
PerfTestRunner.logFatalError("Declarative Shadow DOM must be enabled for this test.");
}
PerfTestRunner.measureRunsPerSecond({
description: "This benchmark tests cloning of templates containing declarative Shadow DOM",
setup: function() {
const wrapper = document.createElement('div');
wrapper.id = 'wrapper';
document.body.appendChild(wrapper);
},
run: function() {
const wrapper = document.querySelector('#wrapper');
for (var i = 0; i < 100; i++) {
wrapper.appendChild(templateSlotted.content.cloneNode(true));
wrapper.appendChild(templateNested.content.cloneNode(true));
}
},
teardown: function() {
wrapper.remove();
}});
</script>
</body>
</html>
\ No newline at end of file
......@@ -237,6 +237,7 @@
"stories": [
"css-parser-yui.html",
"declarative-shadow-dom.html",
"declarative-shadow-dom-cloning.html",
"html-parser-threaded.html",
"html-parser.html",
"html5-full-render.html",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment