summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb/Tests
diff options
context:
space:
mode:
authorLuke <luke.wilde@live.co.uk>2020-08-19 22:30:33 +0100
committerAndreas Kling <kling@serenityos.org>2020-08-21 11:57:11 +0200
commit7902d215b3986148b292b80ac7515974088a98e6 (patch)
tree9c7cbc33e74218656b17e39fa9b240425b44fe92 /Libraries/LibWeb/Tests
parentf48feae0b2a300992479abf0b2ded85e45ac6045 (diff)
downloadserenity-7902d215b3986148b292b80ac7515974088a98e6.zip
LibWeb: Implement <template> parsing
Note that there is currently no way to display them as we can't currently clone nodes. Adds special case for templates for dumping to console. Doesn't add it to the DOM inspector as I'm not sure how to do it.
Diffstat (limited to 'Libraries/LibWeb/Tests')
-rw-r--r--Libraries/LibWeb/Tests/HTML/HTMLTemplateElement.js27
-rw-r--r--Libraries/LibWeb/Tests/Pages/Template.html14
2 files changed, 41 insertions, 0 deletions
diff --git a/Libraries/LibWeb/Tests/HTML/HTMLTemplateElement.js b/Libraries/LibWeb/Tests/HTML/HTMLTemplateElement.js
new file mode 100644
index 0000000000..0b74b2196f
--- /dev/null
+++ b/Libraries/LibWeb/Tests/HTML/HTMLTemplateElement.js
@@ -0,0 +1,27 @@
+loadPage("file:///home/anon/web-tests/Pages/Template.html");
+
+afterInitialPageLoad(() => {
+ test("Basic functionality", () => {
+ const template = document.getElementById("template");
+ expect(template).not.toBeNull();
+
+ // The contents of a template element are not children of the actual element.
+ // The document fragment is not a child of the element either.
+ expect(template.firstChild).toBeNull();
+
+ // FIXME: Add this in once DocumentFragment's constructor is implemented.
+ //expect(template.content).toBeInstanceOf(DocumentFragment);
+ expect(template.content.nodeName).toBe("#document-fragment");
+
+ const templateDiv = template.content.getElementById("templatediv");
+ expect(templateDiv.nodeName).toBe("div");
+ expect(templateDiv.textContent).toBe("Hello template!");
+ });
+
+ test("Templates are inert (e.g. scripts won't run)", () => {
+ // The page has a template element with a script element in it.
+ // Templates are inert, for example, they won't run scripts.
+ // That script will set "templateScriptRan" to true if it ran.
+ expect(window.templateScriptRan).toBeUndefined();
+ });
+});
diff --git a/Libraries/LibWeb/Tests/Pages/Template.html b/Libraries/LibWeb/Tests/Pages/Template.html
new file mode 100644
index 0000000000..e4478f408f
--- /dev/null
+++ b/Libraries/LibWeb/Tests/Pages/Template.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<template id="template">
+ <div id="templatediv">Hello template!</div>
+ <script>
+ // I shouldn't be run.
+ window.templateScriptRan = true;
+ </script>
+</template>
+</body>
+</html>