Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/dom/tests/mochitest/webcomponents/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 7 kB image not shown  

Quelle  test_template.html   Sprache: HTML

 
 products/Sources/formale Sprachen/C/Firefox/dom/tests/mochitest/webcomponents/test_template.html


<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=818976
-->

<head>
  <title>Test for template element</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  <script>
    function shouldNotCall() {
      ok(false, "Template contents should be inert.");
    }
  </script>
  <template>
    <script>
      shouldNotCall();
    </script>
  </template>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=818976">Bug 818976</a>
<template id="grabme"><div id="insidetemplate"></div></template>
<template id="justtemplate"></template>
<template id="first">Hi<template>Bye</template></template>
<div><template id="second"><span></span></template></div>
<template id="cloneme"><span>I want a clone</span><span>me too</span></template>
<template id="cycleone"></template>
<template id="cycletwo"><template></template></template>
<template id="cyclethree"></template>
<template id="cyclefour"><template></template></template>
<template id="appendtome"></template>
<template id="insertinme"></template>
<template>
  <script>
    shouldNotCall();
  </script>
</template>
<div id="fillme"></div>
<script>
var templateEl = document.getElementById("grabme");
ok(templateEl, "template element should be in document.");
is(window.getComputedStyle(templateEl).display, "none""Template element should not be visible.");
ok(!document.getElementById("insidetemplate"), "Template content should not be in document.");
is(templateEl.childNodes.length, 0, "Template element should have no children.");
is(templateEl.content.childNodes.length, 1, "Template content should have 1 child
.");

// Make sure that template is owned by different document.
ok(templateEl.content.ownerDocument != templateEl.ownerDocument, "Template should be in a different document because the current document has a browsing context.");
var otherTemplateEl = document.getElementById("first");
is(templateEl.content.ownerDocument, otherTemplateEl.content.ownerDocument, "Template contents within the same document should be owned by the same template contents owner.");

var htmlDoc = document.implementation.createHTMLDocument();
var otherDocTemplateEl = htmlDoc.createElement("template");
isnot(otherDocTemplateEl.content.ownerDocument, htmlDoc, "Template content owner should be a new document.");

var templateOwnerDoc = otherDocTemplateEl.content.ownerDocument;
var docCreatedTemplateEl = templateOwnerDoc.createElement("template");
is(docCreatedTemplateEl.content.ownerDocument, templateOwnerDoc, "Template content owner of template elements created by a template document should be the template document.");

// Tests for XMLSerializer
templateEl = document.getElementById("justtemplate");
var serializer = new XMLSerializer();
is(serializer.serializeToString(templateEl), ''"XMLSerializer should serialize template element.");

templateEl = document.getElementById("first");
is(serializer.serializeToString(templateEl), ''"XMLSerializer should serialize template content.");

// Tests for innerHTML.
is(templateEl.innerHTML, 'Hi'"innerHTML should serialize content.");
// Tests for outerHTML, not specified but should do something reasonable.
is(templateEl.outerHTML, ''"outerHTML should serialize content.");

templateEl.innerHTML = "Hello";
is(templateEl.innerHTML, "Hello""innerHTML of template should be set to 'Hello'");
is(templateEl.childNodes.length, 0, "Template element should have no children.");
is(templateEl.content.childNodes.length, 1, "Template content should have 'Hello' as child.");

// Test for innerHTML on parent of template element.
var templateParent = document.getElementById("second").parentNode;
is(templateParent.innerHTML, ''"InnerHTML on parent of template element should serialize template and template content.");

templateEl.innerHTML = '';
ok(templateEl.content.childNodes[0] instanceof HTMLTemplateElement, "Template content should have