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/userdatahandler04";
     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 
     43       docsLoaded = 0;
     44       
     45       var docRef = null;
     46       if (typeof(this.doc) != 'undefined') {
     47         docRef = this.doc;
     48       }
     49       docsLoaded += preload(docRef, "doc", "barfoo");
     50         
     51        if (docsLoaded == 1) {
     52           setUpPageStatus = 'complete';
     53        }
     54     } catch(ex) {
     55     	catchInitializationError(builder, ex);
     56         setUpPageStatus = 'complete';
     57     }
     58 }
     59 
     60 
     61 
     62 //
     63 //   This method is called on the completion of 
     64 //      each asychronous load started in setUpTests.
     65 //
     66 //   When every synchronous loaded document has completed,
     67 //      the page status is changed which allows the
     68 //      body of the test to be executed.
     69 function loadComplete() {
     70     if (++docsLoaded == 1) {
     71         setUpPageStatus = 'complete';
     72     }
     73 }
     74 
     75 //UserDataMonitor's require a document level variable named userDataMonitor
     76 var userDataMonitor;
     77 	 
     78 /**
     79 * 
     80 Call setUserData on a node providing a UserDataHandler and adopt the node.
     81 
     82 * @author Curt Arnold
     83 * @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#ID-handleUserDataEvent
     84 */
     85 function userdatahandler04() {
     86    var success;
     87     if(checkInitialization(builder, "userdatahandler04") != null) return;
     88     var doc;
     89       var node;
     90       var pList;
     91       userDataMonitor = new UserDataMonitor();
     92       
     93       var oldUserData;
     94       var elementNS;
     95       var newNode;
     96       var notifications = new Array();
     97 
     98       var notification;
     99       var operation;
    100       var key;
    101       var data;
    102       var src;
    103       var dst;
    104       var greetingCount = 0;
    105       var salutationCount = 0;
    106       var hello = "Hello";
    107       var mister = "Mr.";
    108       var newDoc;
    109       var rootName;
    110       var rootNS;
    111       var domImpl;
    112       var docType = null;
    113 
    114       var docElem;
    115       
    116       var docRef = null;
    117       if (typeof(this.doc) != 'undefined') {
    118         docRef = this.doc;
    119       }
    120       doc = load(docRef, "doc", "barfoo");
    121       domImpl = doc.implementation;
    122 docElem = doc.documentElement;
    123 
    124       rootNS = docElem.namespaceURI;
    125 
    126       rootName = docElem.tagName;
    127 
    128       newDoc = domImpl.createDocument(rootNS,rootName,docType);
    129       pList = doc.getElementsByTagName("p");
    130       node = pList.item(0);
    131       if (null == userDataMonitor) {
    132          node.setUserData("greeting", hello, null);
    133       } else {
    134           node.setUserData("greeting", hello, userDataMonitor.handle);
    135       }
    136        if (null == userDataMonitor) {
    137          node.setUserData("salutation", mister, null);
    138       } else {
    139           node.setUserData("salutation", mister, userDataMonitor.handle);
    140       }
    141        elementNS = node.namespaceURI;
    142 
    143       newNode = doc.adoptNode(node);
    144       notifications = userDataMonitor.allNotifications;
    145 assertSize("twoNotifications",2,notifications);
    146 for(var indexN100CD = 0;indexN100CD < notifications.length; indexN100CD++) {
    147       notification = notifications[indexN100CD];
    148       operation = notification.operation;
    149 assertEquals("operationIsImport",5,operation);
    150        key = notification.key;
    151 data = notification.data;
    152 
    153 	if(
    154 	("greeting" == key)
    155 	) {
    156 	assertEquals("greetingDataHello",hello,data);
    157        greetingCount += 1;
    158 
    159 	}
    160 	
    161 		else {
    162 			assertEquals("saluationKey","salutation",key);
    163        assertEquals("salutationDataMr",mister,data);
    164        salutationCount += 1;
    165 
    166 		}
    167 	src = notification.src;
    168 assertSame("srcIsNode",node,src);
    169 dst = notification.dst;
    170 assertNull("dstIsNull",dst);
    171     
    172 	}
    173    assertEquals("greetingCountIs1",1,greetingCount);
    174        assertEquals("salutationCountIs1",1,salutationCount);
    175        
    176 }
    177 
    178 
    179 
    180 
    181 function runTest() {
    182    userdatahandler04();
    183 }
    184