chromium/third_party/blink/web_tests/external/wpt/html/semantics/scripting-1/the-template-element/template-element/content-attribute.html

<!DOCTYPE html>
<html>
<head>
<title>HTML Templates: Content attribute of template element is read-only</title>
<meta name="author" title="Sergey G. Grekhov" href="mailto:[email protected]">
<meta name="author" title="Aleksei Yu. Semenov" href="mailto:[email protected]">
<meta name="assert" content="Content attribute of template element is read-only">
<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#template-element">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src='/html/resources/common.js'></script>
</head>
<body>
<div id="log"></div>
<script type="text/javascript">

test(function() {
    var doc = newHTMLDocument();
    var template = doc.createElement('template');

    assert_readonly(template, 'content',
            'Content attribute of template element should be read-only');

}, 'Content attribute of template element is read-only. ' +
    'Test empty template');


test(function() {
    var doc = newHTMLDocument();
    var template = doc.createElement('template');
    var el1 = doc.createElement('div');
    var el2 = doc.createElement('span');
    el1.appendChild(el2);

    template.content.appendChild(el1);

    assert_readonly(template, 'content',
            'Content attribute of template element should be read-only');

}, 'Content attribute of template element is read-only. ' +
    'Test not empty template populated by appendchild()');


test(function() {
    var doc = newHTMLDocument();
    doc.body.innerHTML = '<template>Text<div>DIV</div></template>';

    var template = doc.querySelector('template');

    assert_readonly(template, 'content',
            'Content attribute of template element should be read-only');

}, 'Content attribute of template element is read-only. ' +
    'Test not empty template populated by innerHTML');


test(function() {
    var doc = newHTMLDocument();
    doc.body.innerHTML = '<template id="template1" content="Some text as a content"></template>';

    var template = doc.querySelector('#template1');

    assert_readonly(template, 'content',
            'Content attribute of template element should be read-only');

}, 'Content attribute of template element is read-only. ' +
    'Test that custom content attribute named \'content\' doesn\'t ' +
    'make content IDL attribute writable');


test(function() {
    var doc = newHTMLDocument();
    doc.body.innerHTML = '<template id="template1" content="<div id=div1>Div content</div>"></template>';

    var template = doc.querySelector('#template1');

    assert_readonly(template, 'content',
            'Content attribute of template element should be read-only');

    assert_equals(template.content.childNodes.length, 0,
            'Content attribute of template element should be read-only');

}, 'Content attribute of template element is read-only. ' +
    'Test that custom content attribute named \'content\' doesn\'t ' +
    'affect content IDL attribute');


testInIFrame('../resources/template-contents-attribute.html', function(context) {
    var doc = context.iframes[0].contentDocument;

    var template = doc.body.querySelector('template');

    assert_readonly(template, 'content',
            'Content attribute of template element should be read-only');

}, 'Content attribute of template element is read-only. '
    + 'Text value of content attribute of template tag should be ignored, '
    + 'when loading document from a file');


testInIFrame('../resources/template-contents.html', function(context) {
    var doc = context.iframes[0].contentDocument;

    var template = doc.body.querySelector('template');

    assert_readonly(template, 'content',
            'Content attribute of template element should be read-only');

}, 'Content attribute of template element is read-only. '
    + 'Test content attribute of a document loaded from a file');

</script>
</body>
</html>