1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/dom-level2-core/test_setAttributeNodeNS01.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,149 @@ 1.4 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"> 1.5 +<html> 1.6 +<head> 1.7 +<META http-equiv="Content-Type" content="text/html; charset=UTF-8"> 1.8 +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 1.9 +<title>http://www.w3.org/2001/DOM-Test-Suite/level2/core/setAttributeNodeNS01</title> 1.10 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"> 1.11 +<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 +<script type="text/javascript" src="DOMTestCase.js"></script> 1.13 +<script type="text/javascript" src="exclusions.js"></script> 1.14 +<script type="text/javascript"> 1.15 +// expose test function names 1.16 +function exposeTestFunctionNames() 1.17 +{ 1.18 +return ['setAttributeNodeNS01']; 1.19 +} 1.20 + 1.21 +var docsLoaded = -1000000; 1.22 +var builder = null; 1.23 + 1.24 +// 1.25 +// This function is called by the testing framework before 1.26 +// running the test suite. 1.27 +// 1.28 +// If there are no configuration exceptions, asynchronous 1.29 +// document loading is started. Otherwise, the status 1.30 +// is set to complete and the exception is immediately 1.31 +// raised when entering the body of the test. 1.32 +// 1.33 +function setUpPage() { 1.34 + setUpPageStatus = 'running'; 1.35 + try { 1.36 + // 1.37 + // creates test document builder, may throw exception 1.38 + // 1.39 + builder = createConfiguredBuilder(); 1.40 + 1.41 + docsLoaded = 0; 1.42 + 1.43 + var docRef = null; 1.44 + if (typeof(this.doc) != 'undefined') { 1.45 + docRef = this.doc; 1.46 + } 1.47 + docsLoaded += preload(docRef, "doc", "staffNS"); 1.48 + 1.49 + if (docsLoaded == 1) { 1.50 + setUpPage = 'complete'; 1.51 + } 1.52 + } catch(ex) { 1.53 + catchInitializationError(builder, ex); 1.54 + setUpPage = 'complete'; 1.55 + } 1.56 +} 1.57 + 1.58 +// 1.59 +// This method is called on the completion of 1.60 +// each asychronous load started in setUpTests. 1.61 +// 1.62 +// When every synchronous loaded document has completed, 1.63 +// the page status is changed which allows the 1.64 +// body of the test to be executed. 1.65 +function loadComplete() { 1.66 + if (++docsLoaded == 1) { 1.67 + setUpPageStatus = 'complete'; 1.68 + runJSUnitTests(); 1.69 + markTodos(); 1.70 + SimpleTest.finish(); 1.71 + } 1.72 +} 1.73 + 1.74 +var docName = 'setAttributeNodeNS01'; 1.75 + 1.76 + 1.77 +/** 1.78 +* 1.79 + The "setAttributeNode(newAttr)" method raises an 1.80 + "INUSE_ATTRIBUTE_ERR DOMException if the "newAttr" 1.81 + is already an attribute of another element. 1.82 + 1.83 + Retrieve the first emp:address and append 1.84 + a newly created element. The "createAttributeNS(namespaceURI,qualifiedName)" 1.85 + and "setAttributeNodeNS(newAttr)" methods are invoked 1.86 + to create and add a new attribute to the newly created 1.87 + Element. The "setAttributeNodeNS(newAttr)" method is 1.88 + once again called to add the new attribute causing an 1.89 + exception to be raised since the attribute is already 1.90 + an attribute of another element. 1.91 + 1.92 +* @author NIST 1.93 +* @author Mary Brady 1.94 +* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='INUSE_ATTRIBUTE_ERR']) 1.95 +* @see http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElSetAtNodeNS 1.96 +* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-ElSetAtNodeNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='INUSE_ATTRIBUTE_ERR']) 1.97 +*/ 1.98 +function setAttributeNodeNS01() { 1.99 + var success; 1.100 + if(checkInitialization(builder, "setAttributeNodeNS01") != null) return; 1.101 + var namespaceURI = "http://www.newattr.com"; 1.102 + var qualifiedName = "emp:newAttr"; 1.103 + var doc; 1.104 + var newElement; 1.105 + var newAttr; 1.106 + var elementList; 1.107 + var testAddr; 1.108 + var appendedChild; 1.109 + var setAttr1; 1.110 + var setAttr2; 1.111 + 1.112 + var docRef = null; 1.113 + if (typeof(this.doc) != 'undefined') { 1.114 + docRef = this.doc; 1.115 + } 1.116 + doc = load(docRef, "doc", "staffNS"); 1.117 + elementList = doc.getElementsByTagName("emp:address"); 1.118 + testAddr = elementList.item(0); 1.119 + assertNotNull("empAddrNotNull",testAddr); 1.120 +newElement = doc.createElement("newElement"); 1.121 + appendedChild = testAddr.appendChild(newElement); 1.122 + newAttr = doc.createAttributeNS(namespaceURI,qualifiedName); 1.123 + setAttr1 = newElement.setAttributeNodeNS(newAttr); 1.124 + 1.125 + { 1.126 + success = false; 1.127 + try { 1.128 + setAttr2 = testAddr.setAttributeNodeNS(newAttr); 1.129 + } 1.130 + catch(ex) { 1.131 + success = (typeof(ex.code) != 'undefined' && ex.code == 10); 1.132 + } 1.133 + assertTrue("throw_INUSE_ATTRIBUTE_ERR",success); 1.134 + } 1.135 + 1.136 +} 1.137 + 1.138 +</script> 1.139 +</head> 1.140 +<body> 1.141 +<h2>Test http://www.w3.org/2001/DOM-Test-Suite/level2/core/setAttributeNodeNS01</h2> 1.142 +<p></p> 1.143 +<p> 1.144 +Copyright (c) 2001-2004 World Wide Web Consortium, 1.145 +(Massachusetts Institute of Technology, European Research Consortium 1.146 +for Informatics and Mathematics, Keio University). All 1.147 +Rights Reserved. This work is distributed under the <a href="http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231">W3C(r) Software License</a> in the 1.148 +hope that it will be useful, but WITHOUT ANY WARRANTY; without even 1.149 +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 1.150 +</p> 1.151 +</body> 1.152 +</html>