test_HTMLSelectElement19.html (8371B)
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 content="text/html; charset=UTF-8" http-equiv="Content-Type"> 6 <title>http://www.w3.org/2001/DOM-Test-Suite/level2/html/HTMLSelectElement19</title> 7 <link type="text/css" rel="stylesheet" href="/tests/SimpleTest/test.css"> 8 <script src="/tests/SimpleTest/SimpleTest.js" type="text/javascript"></script> 9 <script src="DOMTestCase.js" type="text/javascript"></script> 10 <script type="text/javascript"> 11 // expose test function names 12 function exposeTestFunctionNames() 13 { 14 return ['HTMLSelectElement19']; 15 } 16 17 var docsLoaded = -1000000; 18 var builder = null; 19 20 // 21 // This function is called by the testing framework before 22 // running the test suite. 23 // 24 // If there are no configuration exceptions, asynchronous 25 // document loading is started. Otherwise, the status 26 // is set to complete and the exception is immediately 27 // raised when entering the body of the test. 28 // 29 function setUpPage() { 30 setUpPageStatus = 'running'; 31 try { 32 // 33 // creates test document builder, may throw exception 34 // 35 builder = createConfiguredBuilder(); 36 37 docsLoaded = 0; 38 39 var docRef = null; 40 if (typeof(this.doc) != 'undefined') { 41 docRef = this.doc; 42 } 43 docsLoaded += preload(docRef, "doc", "select"); 44 45 if (docsLoaded == 1) { 46 setUpPage = 'complete'; 47 } 48 } catch(ex) { 49 catchInitializationError(builder, ex); 50 setUpPage = 'complete'; 51 } 52 } 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 SimpleTest.finish(); 68 } 69 } 70 71 72 /** 73 * 74 Add a new option before the selected node using HTMLSelectElement.add. 75 76 * @author Curt Arnold 77 * @see http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-html#ID-14493106 78 */ 79 function HTMLSelectElement19() { 80 var success; 81 if(checkInitialization(builder, "HTMLSelectElement19") != null) return; 82 var nodeList; 83 var testNode; 84 var doc; 85 var optLength; 86 var selected; 87 var newOpt; 88 var newOptText; 89 var opt; 90 var optText; 91 var optValue; 92 var retNode; 93 var options; 94 var selectedNode; 95 96 var docRef = null; 97 if (typeof(this.doc) != 'undefined') { 98 docRef = this.doc; 99 } 100 doc = load(docRef, "doc", "select"); 101 nodeList = doc.getElementsByTagName("select"); 102 assertSize("Asize",3,nodeList); 103 testNode = nodeList.item(0); 104 newOpt = doc.createElement("option"); 105 newOptText = doc.createTextNode("EMP31415"); 106 retNode = newOpt.appendChild(newOptText); 107 options = testNode.options; 108 109 selectedNode = options.item(0); 110 testNode.add(newOpt,selectedNode); 111 optLength = testNode.length; 112 113 assertEquals("optLength",6,optLength); 114 selected = testNode.selectedIndex; 115 116 assertEquals("selected",1,selected); 117 options = testNode.options; 118 119 opt = options.item(0); 120 optText = opt.firstChild; 121 122 optValue = optText.nodeValue; 123 124 assertEquals("lastValue","EMP31415",optValue); 125 126 } 127 128 </script> 129 </head> 130 <body> 131 <h2>Test http://www.w3.org/2001/DOM-Test-Suite/level2/html/HTMLSelectElement19</h2> 132 <p><test name='HTMLSelectElement19' schemaLocation='http://www.w3.org/2001/DOM-Test-Suite/Level-1 dom1.xsd'><br> <metadata><br> <title>HTMLSelectElement19</title> 133 <br> <creator>Curt Arnold</creator> 134 <br> <description> 135 Add a new option before the selected node using HTMLSelectElement.add. 136 </description> 137 <br> <date qualifier='created'>2004-03-18</date> 138 <br> <subject resource='<a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-html#ID-14493106">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-html#ID-14493106</a>'/> 139 <br></metadata><br> <var name='nodeList' type='NodeList'/><br> <var name='testNode' type='Node'/><br> <var name='doc' type='Document'/><br> <var name='optLength' type='int'/><br> <var name='selected' type='int'/><br> <var name='newOpt' type='Element'/><br> <var name='newOptText' type='Text'/><br> <var name='opt' type='Element'/><br> <var name='optText' type='Text'/><br> <var name='optValue' type='DOMString'/><br> <var name='retNode' type='Node'/><br> <var name='options' type='HTMLCollection'/><br> <var name='selectedNode' type='Node'/><br> <load var='doc' href='select' willBeModified='true'/><br> <getElementsByTagName interface='Document' obj='doc' var='nodeList' tagname='"select"'/><br> <assertSize collection='nodeList' size='3' <a id="Asize">id='Asize'</a>/><br> <item interface='NodeList' obj='nodeList' var='testNode' index='0'/><br> <createElement var='newOpt' obj='doc' tagName='"option"'/><br> <createTextNode var='newOptText' obj='doc' data='"EMP31415"'/><br> <appendChild var='retNode' obj='newOpt' newChild='newOptText'/><br> <options var='options' obj='testNode'/><br> <item var='selectedNode' obj='options' index='0' interface='HTMLCollection'/><br> <add interface='HTMLSelectElement' obj='testNode' element='newOpt' before='selectedNode'/><br> <length interface='HTMLSelectElement' obj='testNode' var='optLength'/><br> <assertEquals actual='optLength' expected='6' <a id="optLength">id='optLength'</a> ignoreCase='false'/><br> <selectedIndex interface='HTMLSelectElement' obj='testNode' var='selected'/><br> <assertEquals actual='selected' expected='1' <a id="selected">id='selected'</a> ignoreCase='false'/><br> <options var='options' obj='testNode'/><br> <item var='opt' obj='options' index='0' interface='HTMLCollection'/><br> <firstChild var='optText' obj='opt' interface='Node'/><br> <nodeValue var='optValue' obj='optText'/><br> <assertEquals actual='optValue' expected='"EMP31415"' <a id="lastValue">id='lastValue'</a> ignoreCase='false'/><br></test><br> 140 </p> 141 <p> 142 Copyright (c) 2001-2004 World Wide Web Consortium, 143 (Massachusetts Institute of Technology, Institut National de 144 Recherche en Informatique et en Automatique, Keio University). All 145 Rights Reserved. This program is distributed under the W3C's Software 146 Intellectual Property License. This program is distributed in the 147 hope that it will be useful, but WITHOUT ANY WARRANTY; without even 148 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 149 PURPOSE. 150 </p> 151 <p>See W3C License <a href="http://www.w3.org/Consortium/Legal/">http://www.w3.org/Consortium/Legal/</a> 152 for more details.</p> 153 <iframe name="doc" src="files/select.html"></iframe> 154 <br> 155 </body> 156 </html>