andersca | 42ff937 | 2006-05-08 21:30:14 +0000 | [diff] [blame] | 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 | // expose test function names |
| 15 | function exposeTestFunctionNames() |
| 16 | { |
| 17 | return ['Attribute_Nodes']; |
| 18 | } |
| 19 | |
| 20 | var docsLoaded = -1000000; |
| 21 | var builder = null; |
| 22 | |
| 23 | // |
| 24 | // This function is called by the testing framework before |
| 25 | // running the test suite. |
| 26 | // |
| 27 | // If there are no configuration exceptions, asynchronous |
| 28 | // document loading is started. Otherwise, the status |
| 29 | // is set to complete and the exception is immediately |
| 30 | // raised when entering the body of the test. |
| 31 | // |
| 32 | function setUpPage() { |
| 33 | setUpPageStatus = 'running'; |
| 34 | try { |
| 35 | // |
| 36 | // creates test document builder, may throw exception |
| 37 | // |
| 38 | builder = createConfiguredBuilder(); |
| 39 | |
| 40 | docsLoaded = 0; |
| 41 | |
| 42 | var docRef = null; |
| 43 | if (typeof(this.doc) != 'undefined') { |
| 44 | docRef = this.doc; |
| 45 | } |
| 46 | docsLoaded += preload(docRef, "doc", "staff"); |
| 47 | |
| 48 | if (docsLoaded == 1) { |
ap@webkit.org | 32a2593 | 2009-02-23 13:27:32 +0000 | [diff] [blame] | 49 | setUpPageStatus = 'complete'; |
andersca | 42ff937 | 2006-05-08 21:30:14 +0000 | [diff] [blame] | 50 | } |
| 51 | } catch(ex) { |
| 52 | catchInitializationError(builder, ex); |
ap@webkit.org | 32a2593 | 2009-02-23 13:27:32 +0000 | [diff] [blame] | 53 | setUpPageStatus = 'complete'; |
andersca | 42ff937 | 2006-05-08 21:30:14 +0000 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
| 57 | |
| 58 | |
| 59 | // |
| 60 | // This method is called on the completion of |
| 61 | // each asychronous load started in setUpTests. |
| 62 | // |
| 63 | // When every synchronous loaded document has completed, |
| 64 | // the page status is changed which allows the |
| 65 | // body of the test to be executed. |
| 66 | function loadComplete() { |
| 67 | if (++docsLoaded == 1) { |
| 68 | setUpPageStatus = 'complete'; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | |
| 73 | /** |
| 74 | * |
| 75 | S1.2.2 Attribute Nodes - |
| 76 | Create ANY_TYPE XPathResult matching //@*, |
| 77 | check that each matching Node is an Attribute Node, |
| 78 | that parentNodes of returned Attributes are null, |
| 79 | and that ownerElements are in fact Elements. |
| 80 | |
| 81 | * @author Bob Clary |
| 82 | * @see http://www.w3.org/TR/2003/CR-DOM-Level-3-XPath-20030331/xpath#Mapping |
| 83 | * @see http://www.w3.org/TR/2003/CR-DOM-Level-3-XPath-20030331/xpath#XPathEvaluator |
| 84 | * @see http://www.w3.org/TR/2003/CR-DOM-Level-3-XPath-20030331/xpath#XPathEvaluator-createNSResolver |
| 85 | * @see http://www.w3.org/TR/2003/CR-DOM-Level-3-XPath-20030331/xpath#XPathEvaluator-evaluate |
| 86 | * @see http://www.w3.org/TR/2003/CR-DOM-Level-3-XPath-20030331/xpath#XPathNSResolver |
| 87 | * @see http://www.w3.org/TR/2003/CR-DOM-Level-3-XPath-20030331/xpath#XPathResult |
| 88 | * @see http://www.w3.org/TR/2003/CR-DOM-Level-3-XPath-20030331/xpath#XPathResult-iterateNext |
| 89 | */ |
| 90 | function Attribute_Nodes() { |
| 91 | var success; |
| 92 | if(checkInitialization(builder, "Attribute_Nodes") != null) return; |
| 93 | var ANY_TYPE = 0; |
| 94 | var NUMBER_TYPE = 1; |
| 95 | var STRING_TYPE = 2; |
| 96 | var BOOLEAN_TYPE = 3; |
| 97 | var UNORDERED_NODE_ITERATOR_TYPE = 4; |
| 98 | var ORDERED_NODE_ITERATOR_TYPE = 5; |
| 99 | var UNORDERED_NODE_SNAPSHOT_TYPE = 6; |
| 100 | var ORDERED_NODE_SNAPSHOT_TYPE = 7; |
| 101 | var ANY_UNORDERED_NODE_TYPE = 8; |
| 102 | var FIRST_ORDERED_NODE_TYPE = 9; |
| 103 | var doc; |
| 104 | var resolver; |
| 105 | var evaluator; |
| 106 | var contextNode; |
| 107 | var inresult = null; |
| 108 | |
| 109 | var outresult = null; |
| 110 | |
| 111 | var expression = "//@*"; |
| 112 | var xpathType = ANY_TYPE; |
| 113 | var outNode; |
| 114 | var nodeType; |
| 115 | var parent; |
| 116 | var owner; |
| 117 | var ownerType; |
| 118 | |
| 119 | var docRef = null; |
| 120 | if (typeof(this.doc) != 'undefined') { |
| 121 | docRef = this.doc; |
| 122 | } |
| 123 | doc = load(docRef, "doc", "staff"); |
| 124 | evaluator = createXPathEvaluator(doc); |
| 125 | resolver = evaluator.createNSResolver(doc); |
| 126 | contextNode = doc; |
| 127 | outresult = evaluator.evaluate(expression,contextNode,resolver,xpathType,inresult); |
| 128 | outNode = outresult.iterateNext(); |
| 129 | |
| 130 | while( |
| 131 | |
| 132 | (outNode != null) |
| 133 | |
| 134 | ) { |
| 135 | nodeType = outNode.nodeType; |
| 136 | |
| 137 | assertEquals("S1.2.2-Attribute-Nodes-nodeType",2,nodeType); |
| 138 | parent = outNode.parentNode; |
| 139 | |
| 140 | assertNull("S1.2.2-Attribute-Nodes-parentNode",parent); |
| 141 | owner = outNode.ownerElement; |
| 142 | |
| 143 | ownerType = owner.nodeType; |
| 144 | |
| 145 | assertEquals("S1.2.2-Attribute-Nodes-owner-nodeType",1,ownerType); |
| 146 | outNode = outresult.iterateNext(); |
| 147 | |
| 148 | } |
| 149 | |
| 150 | } |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | function runTest() { |
| 156 | Attribute_Nodes(); |
| 157 | } |