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/nodereplacechild10";
     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 Document 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 	NOT_FOUND_ERR or WRONG_DOCUMENT_ERR or HIERARCHY_REQUEST err is thrown.  
     91 
     92 * @author IBM
     93 * @author Neil Delima
     94 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#ID-785887307
     95 */
     96 function nodereplacechild10() {
     97    var success;
     98     if(checkInitialization(builder, "nodereplacechild10") != null) return;
     99     var doc;
    100       var docType;
    101       var entitiesMap;
    102       var ent;
    103       var doc1;
    104       var docType1;
    105       var notationsMap;
    106       var notation;
    107       var replaced;
    108       
    109       var docRef = null;
    110       if (typeof(this.doc) != 'undefined') {
    111         docRef = this.doc;
    112       }
    113       doc = load(docRef, "doc", "hc_staff");
    114       docType = doc.doctype;
    115 
    116       entitiesMap = docType.entities;
    117 
    118       ent = entitiesMap.getNamedItem("alpha");
    119       
    120       var doc1Ref = null;
    121       if (typeof(this.doc1) != 'undefined') {
    122         doc1Ref = this.doc1;
    123       }
    124       doc1 = load(doc1Ref, "doc1", "hc_staff");
    125       docType1 = doc1.doctype;
    126 
    127       notationsMap = docType1.notations;
    128 
    129       notation = notationsMap.getNamedItem("notation1");
    130       
    131       try {
    132       replaced = doc.replaceChild(notation,ent);
    133       
    134       } catch (ex) {
    135 		  if (typeof(ex.code) != 'undefined') {      
    136        switch(ex.code) {
    137        case /* NOT_FOUND_ERR */ 8 :
    138        break;
    139       case /* WRONG_DOCUMENT_ERR */ 4 :
    140        break;
    141       case /* HIERARCHY_REQUEST_ERR */ 3 :
    142        break;
    143           default:
    144           throw ex;
    145           }
    146        } else { 
    147        throw ex;
    148         }
    149          }
    150         
    151 }
    152 
    153 
    154 
    155 
    156 function runTest() {
    157    nodereplacechild10();
    158 }
    159