OLD | NEW |
1 | |
2 /* | 1 /* |
3 Copyright © 2001-2004 World Wide Web Consortium, | 2 Copyright © 2001-2004 World Wide Web Consortium, |
4 (Massachusetts Institute of Technology, European Research Consortium | 3 (Massachusetts Institute of Technology, European Research Consortium |
5 for Informatics and Mathematics, Keio University). All | 4 for Informatics and Mathematics, Keio University). All |
6 Rights Reserved. This work is distributed under the W3C® Software License [1] i
n the | 5 Rights Reserved. This work is distributed under the W3C® Software License [1] i
n the |
7 hope that it will be useful, but WITHOUT ANY WARRANTY; without even | 6 hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
8 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 7 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
9 | 8 |
10 [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 | 9 [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 |
11 */ | 10 */ |
12 | 11 |
13 | |
14 | |
15 /** | 12 /** |
16 * Gets URI that identifies the test. | 13 * Gets URI that identifies the test. |
17 * @return uri identifier of test | 14 * @return uri identifier of test |
18 */ | 15 */ |
19 function getTargetURI() { | 16 function getTargetURI() { |
20 return "http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent1
3"; | 17 return "http://www.w3.org/2001/DOM-Test-Suite/level2/events/dispatchEvent1
3"; |
21 } | 18 } |
22 | 19 |
23 var docsLoaded = -1000000; | 20 var docsLoaded = -1000000; |
24 var builder = null; | 21 var builder = null; |
25 | 22 |
26 // | 23 // |
27 // This function is called by the testing framework before | 24 // This function is called by the testing framework before |
28 // running the test suite. | 25 // running the test suite. |
29 // | 26 // |
30 // If there are no configuration exceptions, asynchronous | 27 // If there are no configuration exceptions, asynchronous |
31 // document loading is started. Otherwise, the status | 28 // document loading is started. Otherwise, the status |
32 // is set to complete and the exception is immediately | 29 // is set to complete and the exception is immediately |
33 // raised when entering the body of the test. | 30 // raised when entering the body of the test. |
34 // | 31 // |
35 function setUpPage() { | 32 function setUpPage() { |
36 setUpPageStatus = 'running'; | 33 setUpPageStatus = 'running'; |
37 try { | 34 try { |
38 // | 35 // |
39 // creates test document builder, may throw exception | 36 // creates test document builder, may throw exception |
40 // | 37 // |
41 builder = createConfiguredBuilder(); | 38 builder = createConfiguredBuilder(); |
42 | 39 |
43 docsLoaded = 0; | 40 docsLoaded = 0; |
44 | 41 |
45 var docRef = null; | 42 var docRef = null; |
46 if (typeof(this.doc) != 'undefined') { | 43 if (typeof(this.doc) != 'undefined') { |
47 docRef = this.doc; | 44 docRef = this.doc; |
48 } | 45 } |
49 docsLoaded += preload(docRef, "doc", "hc_staff"); | 46 docsLoaded += preload(docRef, "doc", "hc_staff"); |
50 | 47 |
51 if (docsLoaded == 1) { | 48 if (docsLoaded == 1) { |
52 setUpPageStatus = 'complete'; | 49 setUpPageStatus = 'complete'; |
53 } | 50 } |
54 } catch(ex) { | 51 } catch(ex) { |
55 » catchInitializationError(builder, ex); | 52 catchInitializationError(builder, ex); |
56 setUpPageStatus = 'complete'; | 53 setUpPageStatus = 'complete'; |
57 } | 54 } |
58 } | 55 } |
59 | 56 |
60 | |
61 | |
62 // | 57 // |
63 // This method is called on the completion of | 58 // This method is called on the completion of |
64 // each asychronous load started in setUpTests. | 59 // each asychronous load started in setUpTests. |
65 // | 60 // |
66 // When every synchronous loaded document has completed, | 61 // When every synchronous loaded document has completed, |
67 // the page status is changed which allows the | 62 // the page status is changed which allows the |
68 // body of the test to be executed. | 63 // body of the test to be executed. |
69 function loadComplete() { | 64 function loadComplete() { |
70 if (++docsLoaded == 1) { | 65 if (++docsLoaded == 1) { |
71 setUpPageStatus = 'complete'; | 66 setUpPageStatus = 'complete'; |
72 } | 67 } |
73 } | 68 } |
74 | 69 |
75 | |
76 /** | 70 /** |
77 * Inner class implementation for variable listener1 | 71 * Inner class implementation for variable listener1 |
78 */ | 72 */ |
79 var listener1; | 73 var listener1; |
80 | 74 |
81 /** | 75 /** |
82 * Constructor | 76 * Constructor |
83 | 77 |
84 * @param events Value from value attribute of nested var element | 78 * @param events Value from value attribute of nested var element |
85 * @param listeners Value from value attribute of nested var element | 79 * @param listeners Value from value attribute of nested var element |
86 */ | 80 */ |
87 » | 81 |
88 function EventListenerN1003B(events, listeners) { | 82 function EventListenerN1003B(events, listeners) { |
89 this.events = events; | 83 this.events = events; |
90 this.listeners = listeners; | 84 this.listeners = listeners; |
91 } | 85 } |
92 | 86 |
93 /** | 87 /** |
94 * | 88 * |
95 This method is called whenever an event occurs of the type for which theEventLis
tenerinterface was registered. | 89 This method is called whenever an event occurs of the type for which theEventLis
tenerinterface was registered. |
96 | 90 |
97 * @param evt | 91 * @param evt |
98 TheEventcontains contextual information about the event. It also contains thesto
pPropagationand preventDefaultmethods which are used in determining the event's
flow and default action. | 92 TheEventcontains contextual information about the event. It also contains thesto
pPropagationand preventDefaultmethods which are used in determining the event's
flow and default action. |
99 | 93 |
100 */ | 94 */ |
101 EventListenerN1003B.prototype.handleEvent = function(evt) { | 95 EventListenerN1003B.prototype.handleEvent = function(evt) { |
102 // | 96 // |
103 // bring class variables into function scope | 97 // bring class variables into function scope |
104 // | 98 // |
105 var events = listener1.events; | 99 var events = listener1.events; |
106 var listeners = listener1.listeners; | 100 var listeners = listener1.listeners; |
107 var target; | 101 var target; |
108 var listener; | 102 var listener; |
109 events[events.length] = evt; | 103 events[events.length] = evt; |
110 target = evt.currentTarget; | 104 target = evt.currentTarget; |
111 | 105 |
112 for(var indexN10065 = 0;indexN10065 < listeners.length; indexN10065++) { | 106 for(var indexN10065 = 0;indexN10065 < listeners.length; indexN10065++) { |
113 listener = listeners[indexN10065]; | 107 listener = listeners[indexN10065]; |
114 target.removeEventListener("foo", listener.handleEvent, false); | 108 target.removeEventListener("foo", listener.handleEvent, false); |
115 » | 109 |
116 » } | 110 } |
117 } | 111 } |
118 | 112 |
119 /** | 113 /** |
120 * Inner class implementation for variable listener2 | 114 * Inner class implementation for variable listener2 |
121 */ | 115 */ |
122 var listener2; | 116 var listener2; |
123 | 117 |
124 /** | 118 /** |
125 * Constructor | 119 * Constructor |
126 | 120 |
127 * @param events Value from value attribute of nested var element | 121 * @param events Value from value attribute of nested var element |
128 * @param listeners Value from value attribute of nested var element | 122 * @param listeners Value from value attribute of nested var element |
129 */ | 123 */ |
130 » | 124 |
131 function EventListenerN10074(events, listeners) { | 125 function EventListenerN10074(events, listeners) { |
132 this.events = events; | 126 this.events = events; |
133 this.listeners = listeners; | 127 this.listeners = listeners; |
134 } | 128 } |
135 | 129 |
136 /** | 130 /** |
137 * | 131 * |
138 This method is called whenever an event occurs of the type for which theEventLis
tenerinterface was registered. | 132 This method is called whenever an event occurs of the type for which theEventLis
tenerinterface was registered. |
139 | 133 |
140 * @param evt | 134 * @param evt |
141 TheEventcontains contextual information about the event. It also contains thesto
pPropagationand preventDefaultmethods which are used in determining the event's
flow and default action. | 135 TheEventcontains contextual information about the event. It also contains thesto
pPropagationand preventDefaultmethods which are used in determining the event's
flow and default action. |
142 | 136 |
143 */ | 137 */ |
144 EventListenerN10074.prototype.handleEvent = function(evt) { | 138 EventListenerN10074.prototype.handleEvent = function(evt) { |
145 // | 139 // |
146 // bring class variables into function scope | 140 // bring class variables into function scope |
147 // | 141 // |
148 var events = listener2.events; | 142 var events = listener2.events; |
149 var listeners = listener2.listeners; | 143 var listeners = listener2.listeners; |
150 var target; | 144 var target; |
151 var listener; | 145 var listener; |
152 events[events.length] = evt; | 146 events[events.length] = evt; |
153 target = evt.currentTarget; | 147 target = evt.currentTarget; |
154 | 148 |
155 for(var indexN10098 = 0;indexN10098 < listeners.length; indexN10098++) { | 149 for(var indexN10098 = 0;indexN10098 < listeners.length; indexN10098++) { |
156 listener = listeners[indexN10098]; | 150 listener = listeners[indexN10098]; |
157 target.removeEventListener("foo", listener.handleEvent, false); | 151 target.removeEventListener("foo", listener.handleEvent, false); |
158 » | 152 |
159 » } | 153 } |
160 } | 154 } |
161 | 155 |
162 /** | 156 /** |
163 * | 157 * |
164 Two listeners are registered on the same target, each of which will remove both
itself and | 158 Two listeners are registered on the same target, each of which will remove both
itself and |
165 the other on the first event. Only one should see the event since event listene
rs | 159 the other on the first event. Only one should see the event since event listene
rs |
166 can never be invoked after being removed. | 160 can never be invoked after being removed. |
167 | 161 |
168 * @author Curt Arnold | 162 * @author Curt Arnold |
169 * @see http://www.w3.org/TR/DOM-Level-2-Events/events#Events-EventTarget-dispatc
hEvent | 163 * @see http://www.w3.org/TR/DOM-Level-2-Events/events#Events-EventTarget-dispatc
hEvent |
170 * @see http://www.w3.org/TR/DOM-Level-2-Events/events#xpointer(id('Events-EventT
arget-dispatchEvent')/raises/exception[@name='EventException']/descr/p[substring
-before(.,':')='UNSPECIFIED_EVENT_TYPE_ERR']) | 164 * @see http://www.w3.org/TR/DOM-Level-2-Events/events#xpointer(id('Events-EventT
arget-dispatchEvent')/raises/exception[@name='EventException']/descr/p[substring
-before(.,':')='UNSPECIFIED_EVENT_TYPE_ERR']) |
171 */ | 165 */ |
172 function dispatchEvent13() { | 166 function dispatchEvent13() { |
173 var success; | 167 var success; |
174 if(checkInitialization(builder, "dispatchEvent13") != null) return; | 168 if(checkInitialization(builder, "dispatchEvent13") != null) return; |
175 var doc; | 169 var doc; |
176 var target; | 170 var target; |
177 var evt; | 171 var evt; |
178 var preventDefault; | 172 var preventDefault; |
179 var listeners = new Array(); | 173 var listeners = new Array(); |
180 | 174 |
181 var events = new Array(); | 175 var events = new Array(); |
182 | 176 |
183 listener1 = new EventListenerN1003B(events, listeners); | 177 listener1 = new EventListenerN1003B(events, listeners); |
184 » | 178 |
185 listener2 = new EventListenerN10074(events, listeners); | 179 listener2 = new EventListenerN10074(events, listeners); |
186 » | 180 |
187 | |
188 var docRef = null; | 181 var docRef = null; |
189 if (typeof(this.doc) != 'undefined') { | 182 if (typeof(this.doc) != 'undefined') { |
190 docRef = this.doc; | 183 docRef = this.doc; |
191 } | 184 } |
192 doc = load(docRef, "doc", "hc_staff"); | 185 doc = load(docRef, "doc", "hc_staff"); |
193 listeners[listeners.length] = listener1; | 186 listeners[listeners.length] = listener1; |
194 listeners[listeners.length] = listener2; | 187 listeners[listeners.length] = listener2; |
195 doc.addEventListener("foo", listener1.handleEvent, false); | 188 doc.addEventListener("foo", listener1.handleEvent, false); |
196 doc.addEventListener("foo", listener2.handleEvent, false); | 189 doc.addEventListener("foo", listener2.handleEvent, false); |
197 evt = doc.createEvent("Events"); | 190 evt = doc.createEvent("Events"); |
198 evt.initEvent("foo",true,false); | 191 evt.initEvent("foo",true,false); |
199 preventDefault = doc.dispatchEvent(evt); | 192 preventDefault = doc.dispatchEvent(evt); |
200 assertSize("eventCount",1,events); | 193 assertSize("eventCount",1,events); |
201 | 194 |
202 } | 195 } |
203 | 196 |
204 | |
205 | |
206 | |
207 function runTest() { | 197 function runTest() { |
208 dispatchEvent13(); | 198 dispatchEvent13(); |
209 } | 199 } |
OLD | NEW |