test_nodeinsertbefore.html (5651B)
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"> 2 <html> 3 <head> 4 <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 6 <title>http://www.w3.org/2001/DOM-Test-Suite/level1/core/nodeinsertbefore</title> 7 <link href="activity-home.css" rel="stylesheet" type="text/css"> 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <script type="text/javascript" src="DOMTestCase.js"></script> 11 <script type="text/javascript" src="exclusions.js"></script> 12 <script type="text/javascript"> 13 // expose test function names 14 function exposeTestFunctionNames() 15 { 16 return ['nodeinsertbefore']; 17 } 18 19 var docsLoaded = -1000000; 20 var builder = null; 21 22 // 23 // This function is called by the testing framework before 24 // running the test suite. 25 // 26 // If there are no configuration exceptions, asynchronous 27 // document loading is started. Otherwise, the status 28 // is set to complete and the exception is immediately 29 // raised when entering the body of the test. 30 // 31 function setUpPage() { 32 setUpPageStatus = 'running'; 33 try { 34 // 35 // creates test document builder, may throw exception 36 // 37 builder = createConfiguredBuilder(); 38 39 docsLoaded = 0; 40 41 var docRef = null; 42 if (typeof(this.doc) != 'undefined') { 43 docRef = this.doc; 44 } 45 docsLoaded += preload(docRef, "doc", "staff"); 46 47 if (docsLoaded == 1) { 48 setUpPage = 'complete'; 49 } 50 } catch(ex) { 51 catchInitializationError(builder, ex); 52 setUpPage = 'complete'; 53 } 54 } 55 56 // 57 // This method is called on the completion of 58 // each asychronous load started in setUpTests. 59 // 60 // When every synchronous loaded document has completed, 61 // the page status is changed which allows the 62 // body of the test to be executed. 63 function loadComplete() { 64 if (++docsLoaded == 1) { 65 setUpPageStatus = 'complete'; 66 runJSUnitTests(); 67 markTodos(); 68 SimpleTest.finish(); 69 } 70 } 71 72 var docName = 'nodeinsertbefore'; 73 74 75 76 window.doc = window; 77 SimpleTest.waitForExplicitFinish(); 78 addLoadEvent(setUpPage); 79 80 81 /** 82 * 83 The "insertBefore(newChild,refChild)" method inserts the 84 node "newChild" before the node "refChild". 85 86 Insert a newly created Element node before the eigth 87 child of the second employee and check the "newChild" 88 and "refChild" after insertion for correct placement. 89 90 * @author NIST 91 * @author Mary Brady 92 * @see http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-952280727 93 */ 94 function nodeinsertbefore() { 95 var success; 96 if(checkInitialization(builder, "nodeinsertbefore") != null) return; 97 var doc; 98 var elementList; 99 var employeeNode; 100 var childList; 101 var refChild; 102 var newChild; 103 var child; 104 var childName; 105 var length; 106 var insertedNode; 107 var actual = new Array(); 108 109 expectedWithWhitespace = new Array(); 110 expectedWithWhitespace[0] = "#text"; 111 expectedWithWhitespace[1] = "employeeId"; 112 expectedWithWhitespace[2] = "#text"; 113 expectedWithWhitespace[3] = "name"; 114 expectedWithWhitespace[4] = "#text"; 115 expectedWithWhitespace[5] = "position"; 116 expectedWithWhitespace[6] = "#text"; 117 expectedWithWhitespace[7] = "newChild"; 118 expectedWithWhitespace[8] = "salary"; 119 expectedWithWhitespace[9] = "#text"; 120 expectedWithWhitespace[10] = "gender"; 121 expectedWithWhitespace[11] = "#text"; 122 expectedWithWhitespace[12] = "address"; 123 expectedWithWhitespace[13] = "#text"; 124 125 expectedWithoutWhitespace = new Array(); 126 expectedWithoutWhitespace[0] = "employeeId"; 127 expectedWithoutWhitespace[1] = "name"; 128 expectedWithoutWhitespace[2] = "position"; 129 expectedWithoutWhitespace[3] = "newChild"; 130 expectedWithoutWhitespace[4] = "salary"; 131 expectedWithoutWhitespace[5] = "gender"; 132 expectedWithoutWhitespace[6] = "address"; 133 134 var expected = new Array(); 135 136 137 var docRef = null; 138 if (typeof(this.doc) != 'undefined') { 139 docRef = this.doc; 140 } 141 doc = load(docRef, "doc", "staff"); 142 elementList = doc.getElementsByTagName("employee"); 143 employeeNode = elementList.item(1); 144 childList = employeeNode.childNodes; 145 146 length = childList.length; 147 148 149 if( 150 (6 == length) 151 ) { 152 refChild = childList.item(3); 153 expected = expectedWithoutWhitespace; 154 155 } 156 157 else { 158 refChild = childList.item(7); 159 expected = expectedWithWhitespace; 160 161 } 162 newChild = doc.createElement("newChild"); 163 insertedNode = employeeNode.insertBefore(newChild,refChild); 164 for(var indexN65756 = 0;indexN65756 < childList.length; indexN65756++) { 165 child = childList.item(indexN65756); 166 childName = child.nodeName; 167 168 actual[actual.length] = childName; 169 170 } 171 assertEqualsList("nodeNames",expected,actual); 172 173 } 174 175 </script> 176 </head> 177 <body> 178 <h2>Test http://www.w3.org/2001/DOM-Test-Suite/level1/core/nodeinsertbefore</h2> 179 <p></p> 180 <p> 181 Copyright (c) 2001-2004 World Wide Web Consortium, 182 (Massachusetts Institute of Technology, European Research Consortium 183 for Informatics and Mathematics, Keio University). All 184 Rights Reserved. This work is distributed under the <a href="http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231">W3C(r) Software License</a> in the 185 hope that it will be useful, but WITHOUT ANY WARRANTY; without even 186 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 187 </p> 188 </body> 189 </html>