| OLD | NEW | 
| (Empty) |  | 
 |    1 <!DOCTYPE html> | 
 |    2 <!--  | 
 |    3 Distributed under both the W3C Test Suite License [1] and the W3C | 
 |    4 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the | 
 |    5 policies and contribution forms [3]. | 
 |    6  | 
 |    7 [1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license | 
 |    8 [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license | 
 |    9 [3] http://www.w3.org/2004/10/27-testcases | 
 |   10  --> | 
 |   11 <html> | 
 |   12 <head> | 
 |   13 <title>Shadow DOM Test: Non-element node cannot be a shadow host</title> | 
 |   14 <link rel="author" title="Aleksei Yu. Semenov" href="mailto:sgrekhov@unipro.ru"> | 
 |   15 <link rel="author" title="Mikhail Fursov" href="mailto:mfursov@unipro.ru"> | 
 |   16 <link rel="author" title="Yuta Kitamura" href="mailto:yutak@google.com"> | 
 |   17 <link rel="help" href="http://www.w3.org/TR/2013/WD-shadow-dom-20130514/#partial
     -element-methods"> | 
 |   18 <meta name="assert" content="Nodes, that are not elements, are not allowed to be
     come shadow hosts."> | 
 |   19 <script src="../../../../../../resources/testharness.js"></script> | 
 |   20 <script src="../../../../../../resources/testharnessreport.js"></script> | 
 |   21 <script src="../../../testcommon.js"></script> | 
 |   22 <link rel="stylesheet" href="../../../../../../resources/testharness.css"> | 
 |   23 </head> | 
 |   24 <body> | 
 |   25 <div id="log"></div> | 
 |   26 <script> | 
 |   27 var XHTML_NAMESPACE = 'http://www.w3.org/1999/xhtml'; | 
 |   28  | 
 |   29 function createTextNode() { | 
 |   30     var doc = document.implementation.createHTMLDocument('Test Document'); | 
 |   31     var node = doc.createTextNode('Text Node'); | 
 |   32     doc.body.appendChild(node); | 
 |   33     return node; | 
 |   34 } | 
 |   35  | 
 |   36 function createCommentNode() { | 
 |   37     var doc = document.implementation.createHTMLDocument('Test Document'); | 
 |   38     var node = doc.createComment('Comment Node'); | 
 |   39     doc.body.appendChild(node); | 
 |   40     return node; | 
 |   41 } | 
 |   42  | 
 |   43 function createCDATASectionNode() { | 
 |   44     var doc = document.implementation.createDocument(XHTML_NAMESPACE, 'html'); | 
 |   45     var node = doc.createCDATASection('CDATA Section Node'); | 
 |   46     doc.documentElement.appendChild(node); | 
 |   47     return node; | 
 |   48 } | 
 |   49  | 
 |   50 function createAttributeNode() { | 
 |   51     var doc = document.implementation.createDocument(XHTML_NAMESPACE, 'html'); | 
 |   52     var node = doc.createAttribute('attribute-node'); | 
 |   53     doc.documentElement.setAttributeNode(node); | 
 |   54     return node; | 
 |   55 } | 
 |   56  | 
 |   57 function createDocumentFragmentNode() { | 
 |   58     var doc = document.implementation.createDocument(XHTML_NAMESPACE, 'html'); | 
 |   59     var node = doc.createDocumentFragment(); | 
 |   60     doc.documentElement.appendChild(node); | 
 |   61     return node; | 
 |   62 } | 
 |   63  | 
 |   64 function createEntityReferenceNode() { | 
 |   65     var doc = document.implementation.createDocument(XHTML_NAMESPACE, 'html'); | 
 |   66     var node = doc.createEntityReference('entity-reference-node'); | 
 |   67     doc.documentElement.appendChild(node); | 
 |   68     return node; | 
 |   69 } | 
 |   70  | 
 |   71 function createProcessingInstructionNode() { | 
 |   72     var doc = document.implementation.createDocument(XHTML_NAMESPACE, 'html'); | 
 |   73     var node = doc.createProcessingInstruction('processing-instruction-node'); | 
 |   74     doc.documentElement.appendChild(node); | 
 |   75     return node; | 
 |   76 } | 
 |   77  | 
 |   78 function createDocumentNode() { | 
 |   79     return document.implementation.createDocument(XHTML_NAMESPACE, 'html'); | 
 |   80 } | 
 |   81  | 
 |   82 var factories = [ | 
 |   83     ['a text node', createTextNode], | 
 |   84     ['a comment node', createCommentNode], | 
 |   85     ['a CDATA section node', createCDATASectionNode], | 
 |   86     ['an attribute node', createAttributeNode], | 
 |   87     ['a document fragment node', createDocumentFragmentNode], | 
 |   88     ['an entity reference node', createEntityReferenceNode], | 
 |   89     ['a processing instruction node', createProcessingInstructionNode], | 
 |   90     ['a document node', createDocumentNode] | 
 |   91 ]; | 
 |   92  | 
 |   93 // Non-element nodes should not have createShadowRoot() method. | 
 |   94 var noCreateShadowRootTestParameters = factories.map( | 
 |   95     function (nameAndFactory) { | 
 |   96         var name = nameAndFactory[0]; | 
 |   97         var factory = nameAndFactory[1]; | 
 |   98         return [ | 
 |   99             'Checks whether ' + name + ' does not have createShadowRoot() ' + | 
 |  100                 'method.', | 
 |  101             factory | 
 |  102         ]; | 
 |  103     }); | 
 |  104  | 
 |  105 function testNoCreateShadowRoot(factory) { | 
 |  106     var node = factory(); | 
 |  107     assert_equals(node.createShadowRoot, undefined); | 
 |  108 } | 
 |  109  | 
 |  110 generate_tests(testNoCreateShadowRoot, noCreateShadowRootTestParameters); | 
 |  111  | 
 |  112 // When createShadowRoot() is called on non-element nodes, it should throw | 
 |  113 // InvalidNodeTypeError (step 1 of section 10.2.2). | 
 |  114 function testThrowInvalidNodeTypeError(factory) { | 
 |  115     var node = factory(); | 
 |  116     node.createShadowRoot = Element.prototype.createShadowRoot; | 
 |  117     assert_throws('InvalidNodeTypeError', | 
 |  118                   function () { node.createShadowRoot(); }); | 
 |  119 } | 
 |  120  | 
 |  121 var throwInvalidNodeTypeErrorTestParameters = factories.map( | 
 |  122     function (nameAndFactory) { | 
 |  123         var name = nameAndFactory[0]; | 
 |  124         var factory = nameAndFactory[1]; | 
 |  125         return [ | 
 |  126             'When createShadowRoot() is called on ' + name + ', ' + | 
 |  127                 'InvalidNodeTypeError should be thrown.', | 
 |  128             factory | 
 |  129         ]; | 
 |  130     }); | 
 |  131  | 
 |  132 generate_tests(testThrowInvalidNodeTypeError, | 
 |  133                throwInvalidNodeTypeErrorTestParameters); | 
 |  134 </script> | 
 |  135 </body> | 
 |  136 </html> | 
| OLD | NEW |