Home | History | Annotate | Download | only in core
      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/documentnormalizedocument06";
     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", "barfoo");
     51         
     52        if (docsLoaded == 1) {
     53           setUpPageStatus = 'complete';
     54        }
     55     } catch(ex) {
     56     	catchInitializationError(builder, ex);
     57         setUpPageStatus = 'complete';
     58     }
     59 }
     60 
     61 
     62 
     63 //
     64 //   This method is called on the completion of 
     65 //      each asychronous load started in setUpTests.
     66 //
     67 //   When every synchronous loaded document has completed,
     68 //      the page status is changed which allows the
     69 //      body of the test to be executed.
     70 function loadComplete() {
     71     if (++docsLoaded == 1) {
     72         setUpPageStatus = 'complete';
     73     }
     74 }
     75 
     76 //DOMErrorMonitor's require a document level variable named errorMonitor
     77 var errorMonitor;
     78 	 
     79 /**
     80 * 
     81 Add a CDATASection containing "]]>" perform normalization with split-cdata-sections=true.  Should result
     82 in an warning.
     83 
     84 * @author Curt Arnold
     85 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#Document3-normalizeDocument
     86 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#parameter-split-cdata-sections
     87 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#ERROR-DOMError-severity
     88 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#ERROR-DOMError-message
     89 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#ERROR-DOMError-type
     90 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#ERROR-DOMError-relatedException
     91 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#ERROR-DOMError-relatedData
     92 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#ERROR-DOMError-location
     93 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#DOMLocator-line-number
     94 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#DOMLocator-column-number
     95 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#DOMLocator-byteOffset
     96 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#DOMLocator-utf16Offset
     97 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#DOMLocator-node
     98 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#DOMLocator-uri
     99 * @see http://www.w3.org/Bugs/Public/show_bug.cgi?id=542
    100 */
    101 function documentnormalizedocument06() {
    102    var success;
    103     if(checkInitialization(builder, "documentnormalizedocument06") != null) return;
    104     var doc;
    105       var elem;
    106       var domConfig;
    107       var elemList;
    108       var newChild;
    109       var oldChild;
    110       var retval;
    111       errorMonitor = new DOMErrorMonitor();
    112       
    113       var errors = new Array();
    114 
    115       var error;
    116       var splittedCount = 0;
    117       var severity;
    118       var problemNode;
    119       var location;
    120       var lineNumber;
    121       var columnNumber;
    122       var byteOffset;
    123       var utf16Offset;
    124       var uri;
    125       var type;
    126       var message;
    127       var relatedException;
    128       var relatedData;
    129       var length;
    130       var nodeType;
    131       var nodeValue;
    132       
    133       var docRef = null;
    134       if (typeof(this.doc) != 'undefined') {
    135         docRef = this.doc;
    136       }
    137       doc = load(docRef, "doc", "barfoo");
    138       elemList = doc.getElementsByTagName("p");
    139       elem = elemList.item(0);
    140       newChild = doc.createCDATASection("this is not ]]> good");
    141       oldChild = elem.firstChild;
    142 
    143       retval = elem.replaceChild(newChild,oldChild);
    144       domConfig = doc.domConfig;
    145 
    146       domConfig.setParameter("split-cdata-sections", true);
    147 	 domConfig.setParameter("error-handler", errorMonitor.handleError);
    148 	 doc.normalizeDocument();
    149       newChild = elem.firstChild;
    150 
    151       nodeValue = newChild.nodeValue;
    152 
    153       nodeType = newChild.nodeType;
    154 
    155       
    156 			{
    157 			assertFalse("wasSplit",
    158 	((4 == nodeType) && (nodeValue.indexOf("]]>") >= 0))
    159 );
    160 errors = errorMonitor.allErrors;
    161 for(var indexN1010C = 0;indexN1010C < errors.length; indexN1010C++) {
    162       error = errors[indexN1010C];
    163       type = error.type;
    164 
    165       severity = error.severity;
    166 
    167       
    168 	if(
    169 	("cdata-sections-splitted" == type)
    170 	) {
    171 	relatedData = error.relatedData;
    172 
    173       assertSame("relatedData",newChild,relatedData);
    174 assertEquals("severity",1,severity);
    175        message = error.message;
    176 
    177       length = message.length;
    178       	assertTrue("messageNotEmpty",
    179       
    180 	(length > 0)
    181 );
    182 relatedException = error.relatedException;
    183 
    184       location = error.location;
    185 
    186       problemNode = location.relatedNode;
    187 
    188       assertSame("relatedNode",newChild,problemNode);
    189 lineNumber = location.lineNumber;
    190 
    191       columnNumber = location.columnNumber;
    192 
    193       byteOffset = location.byteOffset;
    194 
    195       utf16Offset = location.utf16Offset;
    196 
    197       uri = location.uri;
    198 
    199       splittedCount += 1;
    200 
    201 	}
    202 	
    203 		else {
    204 			assertEquals("anyOthersShouldBeWarnings",1,severity);
    205        
    206 		}
    207 	
    208 	}
    209    assertEquals("oneSplittedWarning",1,splittedCount);
    210        
    211 }
    212 
    213 
    214 
    215 
    216 function runTest() {
    217    documentnormalizedocument06();
    218 }
    219