| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 
 | <!DOCTYPE html>
<html>
<head>
<title>HTML Templates: ownerDocument of cloned template content is set to template content owner</title>
<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<meta name="author" title="Aleksei Yu. Semenov" href="a.semenov@unipro.ru">
<meta name="assert" content="ownerDocument of cloned template content is set to template content owner">
<link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#node-clone-additions">
<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">
function checkOwnerDocument(node, doc) {
    if ((node !== null) && (node !== undefined)) {
        assert_equals(node.ownerDocument, doc,
                'Wrong ownerDocument of the template copy\'s node ' + node.nodeName);
        for (var i = 0; i < node.childNodes.length; i++) {
            if (node.childNodes[i].nodeType === Node.ELEMENT_NODE) {
                checkOwnerDocument(node.childNodes[i], doc);
                if (node.childNodes[i].nodeName === 'TEMPLATE') {
                    checkOwnerDocument(node.childNodes[i].content, doc);
                }
            }
        }
    }
}
test(function () {
    var doc = newHTMLDocument();
    doc.body.innerHTML = '<template id="tmpl1">' +
        '<div id="div1">This is div inside template</div>' +
        '<div id="div2">This is another div inside template</div>' +
        '</template>';
    var template = doc.querySelector('#tmpl1');
    var copy = template.cloneNode(true);
    assert_equals(copy.content.childNodes.length, 2,
            'Wrong number of template content\'s copy child nodes');
    checkOwnerDocument(copy.content, template.content.ownerDocument);
}, 'ownerDocument of cloned template content is set to template content owner. '
       + 'Test cloning with children');
test(function () {
    var doc = newHTMLDocument();
    doc.body.innerHTML = '<template id="tmpl1">' +
        '<div id="div1">This is div inside template</div>' +
        '<div id="div2">This is another div inside template</div>' +
        '</template>';
    var template = doc.querySelector('#tmpl1');
    var copy = template.cloneNode(false);
    assert_equals(copy.content.childNodes.length, 0,
            'Wrong number of template content\'s copy child nodes');
    checkOwnerDocument(copy.content, template.content.ownerDocument);
}, 'ownerDocument of cloned template content is set to template content owner. '
      + 'Test cloning without children');
test(function () {
    var doc = newHTMLDocument();
    doc.body.innerHTML = '<template id="tmpl1">' +
        '<div id="div1">This is div inside template</div>' +
        '<div id="div2">This is another div inside template</div>' +
        '</template>';
    var template = doc.querySelector('#tmpl1');
    var copy = template.cloneNode();
    assert_equals(copy.content.childNodes.length, 0,
            'Wrong number of template content\'s copy child nodes');
    checkOwnerDocument(copy.content, template.content.ownerDocument);
}, 'ownerDocument of cloned template content is set to template content owner. '
      + 'Test cloneNode() with no arguments (false by default)');
test(function () {
    var doc = newHTMLDocument();
    doc.body.innerHTML = '<template id="tmpl1">' +
        '<div id="div1">This is div inside template</div>' +
        '<div id="div2">This is another div inside template</div>' +
        '<template id="tmpl2">' +
        '<div id="div3">This is div inside nested template</div>' +
        '<div id="div4">This is another div inside nested template</div>' +
        '</template>' +
        '</template>';
    var template = doc.querySelector('#tmpl1');
    var copy = template.cloneNode(true);
    assert_equals(copy.content.childNodes.length, 3,
            'Wrong number of template content\'s copy child nodes');
    checkOwnerDocument(copy.content, template.content.ownerDocument);
}, 'ownerDocument of cloned template content is set to template content owner. '
    + 'Test cloning nested template');
testInIFrame('../resources/template-contents.html', function(context) {
    var doc = context.iframes[0].contentDocument;
    var template = doc.body.querySelector('template');
    var copy = template.cloneNode(true);
    checkOwnerDocument(copy.content, template.content.ownerDocument);
}, 'ownerDocument of cloned template content is set to template content owner. '
   + 'Test loading HTML document from file');
</script>
</body>
</html>
 |