1 2 /* 3 Copyright 2001-2004 World Wide Web Consortium, 4 (Massachusetts Institute of Technology, European Research Consortium 5 for Informatics and Mathematics, Keio University). All 6 Rights Reserved. This work is distributed under the W3C Software License [1] in the 7 hope that it will be useful, but WITHOUT ANY WARRANTY; without even 8 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 10 [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 11 */ 12 13 14 15 /** 16 * Gets URI that identifies the test. 17 * @return uri identifier of test 18 */ 19 function getTargetURI() { 20 return "http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodereplacechild21"; 21 } 22 23 var docsLoaded = -1000000; 24 var builder = null; 25 26 // 27 // This function is called by the testing framework before 28 // running the test suite. 29 // 30 // If there are no configuration exceptions, asynchronous 31 // document loading is started. Otherwise, the status 32 // is set to complete and the exception is immediately 33 // raised when entering the body of the test. 34 // 35 function setUpPage() { 36 setUpPageStatus = 'running'; 37 try { 38 // 39 // creates test document builder, may throw exception 40 // 41 builder = createConfiguredBuilder(); 42 setImplementationAttribute("namespaceAware", true); 43 44 docsLoaded = 0; 45 46 var docRef = null; 47 if (typeof(this.doc) != 'undefined') { 48 docRef = this.doc; 49 } 50 docsLoaded += preload(docRef, "doc", "hc_staff"); 51 52 var doc1Ref = null; 53 if (typeof(this.doc1) != 'undefined') { 54 doc1Ref = this.doc1; 55 } 56 docsLoaded += preload(doc1Ref, "doc1", "hc_staff"); 57 58 if (docsLoaded == 2) { 59 setUpPageStatus = 'complete'; 60 } 61 } catch(ex) { 62 catchInitializationError(builder, ex); 63 setUpPageStatus = 'complete'; 64 } 65 } 66 67 68 69 // 70 // This method is called on the completion of 71 // each asychronous load started in setUpTests. 72 // 73 // When every synchronous loaded document has completed, 74 // the page status is changed which allows the 75 // body of the test to be executed. 76 function loadComplete() { 77 if (++docsLoaded == 2) { 78 setUpPageStatus = 'complete'; 79 } 80 } 81 82 83 /** 84 * 85 The method replaceChild replaces the child node oldChild with newChild in the list of 86 children, and returns the oldChild node. 87 88 Using replaceChild on this DocumentType node attempt to replace an Entity node with 89 a notation node of retieved from the DTD of another document and verify if a 90 NO_MODIFICATION_ALLOWED_ERR is thrown since DocumentType node is read-only. 91 Also try replacing the docType with an entity node and see if the same exception gets thrown. 92 93 * @author IBM 94 * @author Neil Delima 95 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#ID-785887307 96 */ 97 function nodereplacechild21() { 98 var success; 99 if(checkInitialization(builder, "nodereplacechild21") != null) return; 100 var doc; 101 var docType; 102 var entitiesMap; 103 var ent; 104 var doc1; 105 var docType1; 106 var notationsMap; 107 var notation; 108 var replacedChild; 109 110 var docRef = null; 111 if (typeof(this.doc) != 'undefined') { 112 docRef = this.doc; 113 } 114 doc = load(docRef, "doc", "hc_staff"); 115 docType = doc.doctype; 116 117 entitiesMap = docType.entities; 118 119 ent = entitiesMap.getNamedItem("alpha"); 120 121 var doc1Ref = null; 122 if (typeof(this.doc1) != 'undefined') { 123 doc1Ref = this.doc1; 124 } 125 doc1 = load(doc1Ref, "doc1", "hc_staff"); 126 docType1 = doc1.doctype; 127 128 notationsMap = docType1.notations; 129 130 notation = notationsMap.getNamedItem("notation1"); 131 132 { 133 success = false; 134 try { 135 replacedChild = docType.replaceChild(notation,ent); 136 } 137 catch(ex) { 138 success = (typeof(ex.code) != 'undefined' && ex.code == 7); 139 } 140 assertTrue("NO_MODIFICATION_ALLOWED_ERR1_nodereplacechild21",success); 141 } 142 143 { 144 success = false; 145 try { 146 replacedChild = docType.replaceChild(ent,docType); 147 } 148 catch(ex) { 149 success = (typeof(ex.code) != 'undefined' && ex.code == 7); 150 } 151 assertTrue("NO_MODIFICATION_ALLOWED_ERR2_nodereplacechild21",success); 152 } 153 154 } 155 156 157 158 159 function runTest() { 160 nodereplacechild21(); 161 } 162