1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/test/test_eventctors.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,870 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=675884 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 675884</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.13 +</head> 1.14 +<body> 1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=675884">Mozilla Bug 675884</a> 1.16 +<p id="display"></p> 1.17 +<div id="content" style="display: none"> 1.18 + 1.19 +</div> 1.20 +<pre id="test"> 1.21 +<script type="application/javascript"> 1.22 + 1.23 +/** Test for Bug 675884 **/ 1.24 + 1.25 +var receivedEvent; 1.26 +document.addEventListener("hello", function(e) { receivedEvent = e; }, true); 1.27 + 1.28 +// Event 1.29 +var e; 1.30 +var ex = false; 1.31 +try { 1.32 + e = new Event(); 1.33 +} catch(exp) { 1.34 + ex = true; 1.35 +} 1.36 +ok(ex, "First parameter is required!"); 1.37 +ex = false; 1.38 + 1.39 +try { 1.40 + e = new Event("foo", 123); 1.41 +} catch(exp) { 1.42 + ex = true; 1.43 +} 1.44 +ok(ex, "2nd parameter should be an object!"); 1.45 +ex = false; 1.46 + 1.47 +try { 1.48 + e = new Event("foo", "asdf"); 1.49 +} catch(exp) { 1.50 + ex = true; 1.51 +} 1.52 +ok(ex, "2nd parameter should be an object!"); 1.53 +ex = false; 1.54 + 1.55 + 1.56 +try { 1.57 + e = new Event("foo", false); 1.58 +} catch(exp) { 1.59 + ex = true; 1.60 +} 1.61 +ok(ex, "2nd parameter should be an object!"); 1.62 +ex = false; 1.63 + 1.64 + 1.65 +e = new Event("hello"); 1.66 +is(e.type, "hello", "Wrong event type!"); 1.67 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.68 +e.isTrusted = true; 1.69 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.70 + 1.71 +try { 1.72 + e.__defineGetter__("isTrusted", function() { return true }); 1.73 +} catch (exp) { 1.74 + ex = true; 1.75 +} 1.76 +ok(ex, "Shouldn't be able to re-define the getter for isTrusted."); 1.77 +ex = false; 1.78 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.79 + 1.80 +ok(!("isTrusted" in Object.getPrototypeOf(e))) 1.81 + 1.82 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.83 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.84 +is(e.eventPhase, Event.NONE, "Wrong event phase"); 1.85 +document.dispatchEvent(e); 1.86 +is(e.eventPhase, Event.NONE, "Wrong event phase"); 1.87 +is(receivedEvent, e, "Wrong event!"); 1.88 + 1.89 +e = new Event("hello", null); 1.90 +is(e.type, "hello", "Wrong event type!"); 1.91 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.92 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.93 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.94 +is(e.eventPhase, Event.NONE, "Wrong event phase"); 1.95 +document.dispatchEvent(e); 1.96 +is(e.eventPhase, Event.NONE, "Wrong event phase"); 1.97 +is(receivedEvent, e, "Wrong event!"); 1.98 + 1.99 +e = new Event("hello", undefined); 1.100 +is(e.type, "hello", "Wrong event type!"); 1.101 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.102 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.103 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.104 +is(e.eventPhase, Event.NONE, "Wrong event phase"); 1.105 +document.dispatchEvent(e); 1.106 +is(e.eventPhase, Event.NONE, "Wrong event phase"); 1.107 +is(receivedEvent, e, "Wrong event!"); 1.108 + 1.109 +e = new Event("hello", {}); 1.110 +is(e.type, "hello", "Wrong event type!"); 1.111 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.112 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.113 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.114 +is(e.eventPhase, Event.NONE, "Wrong event phase"); 1.115 +document.dispatchEvent(e); 1.116 +is(e.eventPhase, Event.NONE, "Wrong event phase"); 1.117 +is(receivedEvent, e, "Wrong event!"); 1.118 + 1.119 +e = new Event("hello", { bubbles: true, cancelable: true }); 1.120 +is(e.type, "hello", "Wrong event type!"); 1.121 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.122 +ok(e.bubbles, "Event should bubble!"); 1.123 +ok(e.cancelable, "Event should be cancelable!"); 1.124 +document.dispatchEvent(e); 1.125 +is(receivedEvent, e, "Wrong event!"); 1.126 + 1.127 +// CustomEvent 1.128 + 1.129 +try { 1.130 + e = new CustomEvent(); 1.131 +} catch(exp) { 1.132 + ex = true; 1.133 +} 1.134 +ok(ex, "First parameter is required!"); 1.135 +ex = false; 1.136 + 1.137 +e = new CustomEvent("hello"); 1.138 +is(e.type, "hello", "Wrong event type!"); 1.139 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.140 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.141 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.142 +document.dispatchEvent(e); 1.143 +is(receivedEvent, e, "Wrong event!"); 1.144 + 1.145 +e = new CustomEvent("hello", { bubbles: true, cancelable: true, detail: window }); 1.146 +is(e.type, "hello", "Wrong event type!"); 1.147 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.148 +ok(e.bubbles, "Event should bubble!"); 1.149 +ok(e.cancelable, "Event should be cancelable!"); 1.150 +is(e.detail, window , "Wrong event.detail!"); 1.151 +document.dispatchEvent(e); 1.152 +is(receivedEvent, e, "Wrong event!"); 1.153 + 1.154 +e = new CustomEvent("hello", { cancelable: true, detail: window }); 1.155 +is(e.type, "hello", "Wrong event type!"); 1.156 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.157 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.158 +ok(e.cancelable, "Event should be cancelable!"); 1.159 +is(e.detail, window , "Wrong event.detail!"); 1.160 + 1.161 +e = new CustomEvent("hello", { detail: 123 }); 1.162 +is(e.detail, 123, "Wrong event.detail!"); 1.163 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.164 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.165 + 1.166 +var dict = { get detail() { return document.body } }; 1.167 +e = new CustomEvent("hello", dict); 1.168 +is(e.detail, dict.detail, "Wrong event.detail!"); 1.169 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.170 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.171 + 1.172 +var dict = { get detail() { throw "foo"; } }; 1.173 + 1.174 +try { 1.175 + e = new CustomEvent("hello", dict); 1.176 +} catch (exp) { 1.177 + ex = true; 1.178 +} 1.179 +ok(ex, "Should have thrown an exception!"); 1.180 +ex = false; 1.181 + 1.182 +// BlobEvent 1.183 + 1.184 +try { 1.185 + e = new BlobEvent(); 1.186 +} catch(exp) { 1.187 + ex = true; 1.188 +} 1.189 +ok(ex, "First parameter is required!"); 1.190 +ex = false; 1.191 + 1.192 +e = new BlobEvent("hello"); 1.193 +is(e.type, "hello", "Wrong event type!"); 1.194 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.195 +try { 1.196 + e.__defineGetter__("isTrusted", function() { return true }); 1.197 +} catch (exp) { 1.198 + ex = true; 1.199 +} 1.200 +ok(ex, "Shouldn't be able to re-define the getter for isTrusted."); 1.201 +ex = false; 1.202 +ok(!e.isTrusted, "BlobEvent shouldn't be trusted!"); 1.203 + 1.204 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.205 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.206 +document.dispatchEvent(e); 1.207 +is(receivedEvent, e, "Wrong event!"); 1.208 + 1.209 +var blob = Blob(); 1.210 +e = new BlobEvent("hello", { bubbles: true, cancelable: true, data: blob }); 1.211 +is(e.type, "hello", "Wrong event type!"); 1.212 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.213 +ok(e.bubbles, "Event should bubble!"); 1.214 +ok(e.cancelable, "Event should be cancelable!"); 1.215 +is(e.data, blob , "Wrong event.data!"); 1.216 +document.dispatchEvent(e); 1.217 +is(receivedEvent, e, "Wrong event!"); 1.218 + 1.219 + 1.220 +e = new BlobEvent("hello", {data: blob}); 1.221 +is(e.type, "hello", "Wrong event type!"); 1.222 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.223 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.224 +ok(!e.cancelable, "Event should be cancelable1!"); 1.225 +is(e.data, blob , "Wrong event.data!"); 1.226 + 1.227 +e = new BlobEvent("hello", { data: null }); 1.228 +is(e.data, null, "Wrong event.data!"); 1.229 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.230 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.231 +blob = null; 1.232 +// CloseEvent 1.233 + 1.234 +try { 1.235 + e = new CloseEvent(); 1.236 +} catch(exp) { 1.237 + ex = true; 1.238 +} 1.239 +ok(ex, "First parameter is required!"); 1.240 +ex = false; 1.241 + 1.242 +e = new CloseEvent("hello"); 1.243 +is(e.type, "hello", "Wrong event type!"); 1.244 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.245 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.246 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.247 +is(e.wasClean, false, "wasClean should be false!"); 1.248 +is(e.code, 0, "code should be 0!"); 1.249 +is(e.reason, "", "reason should be ''!"); 1.250 +document.dispatchEvent(e); 1.251 +is(receivedEvent, e, "Wrong event!"); 1.252 + 1.253 +e = new CloseEvent("hello", 1.254 + { bubbles: true, cancelable: true, wasClean: true, code: 1, reason: "foo" }); 1.255 +is(e.type, "hello", "Wrong event type!"); 1.256 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.257 +ok(e.bubbles, "Event should bubble!"); 1.258 +ok(e.cancelable, "Event should be cancelable!"); 1.259 +is(e.wasClean, true, "wasClean should be true!"); 1.260 +is(e.code, 1, "code should be 1!"); 1.261 +is(e.reason, "foo", "reason should be 'foo'!"); 1.262 +document.dispatchEvent(e); 1.263 +is(receivedEvent, e, "Wrong event!"); 1.264 + 1.265 +e = new CloseEvent("hello", 1.266 + { bubbles: true, cancelable: true, wasClean: true, code: 1 }); 1.267 +is(e.type, "hello", "Wrong event type!"); 1.268 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.269 +ok(e.bubbles, "Event should bubble!"); 1.270 +ok(e.cancelable, "Event should be cancelable!"); 1.271 +is(e.wasClean, true, "wasClean should be true!"); 1.272 +is(e.code, 1, "code should be 1!"); 1.273 +is(e.reason, "", "reason should be ''!"); 1.274 +document.dispatchEvent(e); 1.275 +is(receivedEvent, e, "Wrong event!"); 1.276 + 1.277 + 1.278 +// HashChangeEvent 1.279 + 1.280 +try { 1.281 + e = new HashChangeEvent(); 1.282 +} catch(exp) { 1.283 + ex = true; 1.284 +} 1.285 +ok(ex, "First parameter is required!"); 1.286 +ex = false; 1.287 + 1.288 +e = new HashChangeEvent("hello"); 1.289 +is(e.type, "hello", "Wrong event type!"); 1.290 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.291 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.292 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.293 +is(e.oldURL, "", "oldURL should be ''"); 1.294 +is(e.newURL, "", "newURL should be ''"); 1.295 +document.dispatchEvent(e); 1.296 +is(receivedEvent, e, "Wrong event!"); 1.297 + 1.298 +e = new HashChangeEvent("hello", 1.299 + { bubbles: true, cancelable: true, oldURL: "old", newURL: "new" }); 1.300 +is(e.type, "hello", "Wrong event type!"); 1.301 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.302 +ok(e.bubbles, "Event should bubble!"); 1.303 +ok(e.cancelable, "Event should be cancelable!"); 1.304 +is(e.oldURL, "old", "oldURL should be 'old'"); 1.305 +is(e.newURL, "new", "newURL should be 'new'"); 1.306 +document.dispatchEvent(e); 1.307 +is(receivedEvent, e, "Wrong event!"); 1.308 + 1.309 +e = new HashChangeEvent("hello", 1.310 + { bubbles: true, cancelable: true, newURL: "new" }); 1.311 +is(e.type, "hello", "Wrong event type!"); 1.312 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.313 +ok(e.bubbles, "Event should bubble!"); 1.314 +ok(e.cancelable, "Event should be cancelable!"); 1.315 +is(e.oldURL, "", "oldURL should be ''"); 1.316 +is(e.newURL, "new", "newURL should be 'new'"); 1.317 +document.dispatchEvent(e); 1.318 +is(receivedEvent, e, "Wrong event!"); 1.319 + 1.320 +// InputEvent 1.321 + 1.322 +e = new InputEvent("hello"); 1.323 +is(e.type, "hello", "Wrong event type!"); 1.324 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.325 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.326 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.327 +is(e.detail, 0, "detail should be 0"); 1.328 +ok(!e.isComposing, "isComposing should be false"); 1.329 + 1.330 +e = new InputEvent("hi!", { bubbles: true, detail: 5, isComposing: false }); 1.331 +is(e.type, "hi!", "Wrong event type!"); 1.332 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.333 +ok(e.bubbles, "Event should bubble!"); 1.334 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.335 +is(e.detail, 5, "detail should be 5"); 1.336 +ok(!e.isComposing, "isComposing should be false"); 1.337 + 1.338 +e = new InputEvent("hi!", { cancelable: true, detail: 0, isComposing: true }); 1.339 +is(e.type, "hi!", "Wrong event type!"); 1.340 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.341 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.342 +ok(e.cancelable, "Event should be cancelable!"); 1.343 +is(e.detail, 0, "detail should be 0"); 1.344 +ok(e.isComposing, "isComposing should be true"); 1.345 + 1.346 +// KeyboardEvent 1.347 + 1.348 +try { 1.349 + e = new KeyboardEvent(); 1.350 +} catch(exp) { 1.351 + ex = true; 1.352 +} 1.353 +ok(ex, "KeyboardEvent: First parameter is required!"); 1.354 +ex = false; 1.355 + 1.356 +e = new KeyboardEvent("hello"); 1.357 +ok(e.type, "hello", "KeyboardEvent: Wrong event type!"); 1.358 +ok(!e.isTrusted, "KeyboardEvent: Event shouldn't be trusted!"); 1.359 +ok(!e.bubbles, "KeyboardEvent: Event shouldn't bubble!"); 1.360 +ok(!e.cancelable, "KeyboardEvent: Event shouldn't be cancelable!"); 1.361 +document.dispatchEvent(e); 1.362 +is(receivedEvent, e, "KeyboardEvent: Wrong event!"); 1.363 + 1.364 +var keyboardEventProps = 1.365 +[ 1.366 + { bubbles: false }, 1.367 + { cancelable: false }, 1.368 + { view: null }, 1.369 + { detail: 0 }, 1.370 + { key: "" }, 1.371 + { location: 0 }, 1.372 + { ctrlKey: false }, 1.373 + { shiftKey: false }, 1.374 + { altKey: false }, 1.375 + { metaKey: false }, 1.376 + { repeat: false }, 1.377 + { isComposing: false }, 1.378 + { charCode: 0 }, 1.379 + { keyCode: 0 }, 1.380 + { which: 0 }, 1.381 +]; 1.382 + 1.383 +var testKeyboardProps = 1.384 +[ 1.385 + { bubbles: true }, 1.386 + { cancelable: true }, 1.387 + { view: window }, 1.388 + { detail: 1 }, 1.389 + { key: "CustomKey" }, 1.390 + { location: 1 }, 1.391 + { ctrlKey: true }, 1.392 + { shiftKey: true }, 1.393 + { altKey: true }, 1.394 + { metaKey: true }, 1.395 + { repeat: true }, 1.396 + { isComposing: true }, 1.397 + { charCode: 2 }, 1.398 + { keyCode: 3 }, 1.399 + { which: 4 }, 1.400 + { charCode: 5, which: 6 }, 1.401 + { keyCode: 7, which: 8 }, 1.402 + { keyCode: 9, charCode: 10 }, 1.403 + { keyCode: 11, charCode: 12, which: 13 }, 1.404 +]; 1.405 + 1.406 +var defaultKeyboardEventValues = {}; 1.407 +for (var i = 0; i < keyboardEventProps.length; ++i) { 1.408 + for (prop in keyboardEventProps[i]) { 1.409 + ok(prop in e, "keyboardEvent: KeyboardEvent doesn't have property " + prop + "!"); 1.410 + defaultKeyboardEventValues[prop] = keyboardEventProps[i][prop]; 1.411 + } 1.412 +} 1.413 + 1.414 +while (testKeyboardProps.length) { 1.415 + var p = testKeyboardProps.shift(); 1.416 + e = new KeyboardEvent("foo", p); 1.417 + for (var def in defaultKeyboardEventValues) { 1.418 + if (!(def in p)) { 1.419 + is(e[def], defaultKeyboardEventValues[def], 1.420 + "KeyboardEvent: Wrong default value for " + def + "!"); 1.421 + } else { 1.422 + is(e[def], p[def], 1.423 + "KeyboardEvent: Wrong event init value for " + def + "!"); 1.424 + } 1.425 + } 1.426 +} 1.427 + 1.428 +// PageTransitionEvent 1.429 + 1.430 +try { 1.431 + e = new PageTransitionEvent(); 1.432 +} catch(exp) { 1.433 + ex = true; 1.434 +} 1.435 +ok(ex, "First parameter is required!"); 1.436 +ex = false; 1.437 + 1.438 +e = new PageTransitionEvent("hello"); 1.439 +is(e.type, "hello", "Wrong event type!"); 1.440 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.441 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.442 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.443 +is(e.persisted, false, "persisted should be false"); 1.444 +document.dispatchEvent(e); 1.445 +is(receivedEvent, e, "Wrong event!"); 1.446 + 1.447 +e = new PageTransitionEvent("hello", 1.448 + { bubbles: true, cancelable: true, persisted: true}); 1.449 +is(e.type, "hello", "Wrong event type!"); 1.450 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.451 +ok(e.bubbles, "Event should bubble!"); 1.452 +ok(e.cancelable, "Event should be cancelable!"); 1.453 +is(e.persisted, true, "persisted should be true"); 1.454 +document.dispatchEvent(e); 1.455 +is(receivedEvent, e, "Wrong event!"); 1.456 + 1.457 +e = new PageTransitionEvent("hello", { persisted: true}); 1.458 +is(e.type, "hello", "Wrong event type!"); 1.459 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.460 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.461 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.462 +is(e.persisted, true, "persisted should be true"); 1.463 +document.dispatchEvent(e); 1.464 +is(receivedEvent, e, "Wrong event!"); 1.465 + 1.466 +// PopStateEvent 1.467 + 1.468 +try { 1.469 + e = new PopStateEvent(); 1.470 +} catch(exp) { 1.471 + ex = true; 1.472 +} 1.473 +ok(ex, "First parameter is required!"); 1.474 +ex = false; 1.475 + 1.476 +e = new PopStateEvent("hello"); 1.477 +is(e.type, "hello", "Wrong event type!"); 1.478 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.479 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.480 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.481 +is(e.state, null, "persisted should be null"); 1.482 +document.dispatchEvent(e); 1.483 +is(receivedEvent, e, "Wrong event!"); 1.484 + 1.485 +e = new PopStateEvent("hello", 1.486 + { bubbles: true, cancelable: true, state: window}); 1.487 +is(e.type, "hello", "Wrong event type!"); 1.488 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.489 +ok(e.bubbles, "Event should bubble!"); 1.490 +ok(e.cancelable, "Event should be cancelable!"); 1.491 +is(e.state, window, "persisted should be window"); 1.492 +document.dispatchEvent(e); 1.493 +is(receivedEvent, e, "Wrong event!"); 1.494 + 1.495 + 1.496 +e = new PopStateEvent("hello", { state: window}); 1.497 +is(e.type, "hello", "Wrong event type!"); 1.498 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.499 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.500 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.501 +is(e.state, window, "persisted should be window"); 1.502 +document.dispatchEvent(e); 1.503 +is(receivedEvent, e, "Wrong event!"); 1.504 + 1.505 +// UIEvent 1.506 + 1.507 +try { 1.508 + e = new UIEvent(); 1.509 +} catch(exp) { 1.510 + ex = true; 1.511 +} 1.512 +ok(ex, "First parameter is required!"); 1.513 +ex = false; 1.514 + 1.515 +try { 1.516 + e = new UIEvent("foo", { view: {} }); 1.517 + e.view.onunload; 1.518 +} catch(exp) { 1.519 + ex = true; 1.520 +} 1.521 +ok(ex, "{} isn't a valid value."); 1.522 +ex = false; 1.523 + 1.524 +try { 1.525 + e = new UIEvent("foo", { view: null }); 1.526 +} catch(exp) { 1.527 + ex = true; 1.528 +} 1.529 +ok(!ex, "null is a valid value."); 1.530 +is(e.view, null); 1.531 +ex = false; 1.532 + 1.533 +e = new UIEvent("hello"); 1.534 +is(e.type, "hello", "Wrong event type!"); 1.535 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.536 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.537 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.538 +is(e.detail, 0, "detail should be 0"); 1.539 +is(e.view, null, "view should be null"); 1.540 +document.dispatchEvent(e); 1.541 +is(receivedEvent, e, "Wrong event!"); 1.542 + 1.543 +e = new UIEvent("hello", 1.544 + { bubbles: true, cancelable: true, view: window, detail: 1}); 1.545 +is(e.type, "hello", "Wrong event type!"); 1.546 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.547 +ok(e.bubbles, "Event should bubble!"); 1.548 +ok(e.cancelable, "Event should be cancelable!"); 1.549 +is(e.detail, 1, "detail should be 1"); 1.550 +is(e.view, window, "view should be window"); 1.551 +document.dispatchEvent(e); 1.552 +is(receivedEvent, e, "Wrong event!"); 1.553 + 1.554 +// StorageEvent 1.555 + 1.556 +e = document.createEvent("StorageEvent"); 1.557 +ok(e, "Should have created an event!"); 1.558 + 1.559 +try { 1.560 + e = new StorageEvent(); 1.561 +} catch(exp) { 1.562 + ex = true; 1.563 +} 1.564 +ok(ex, "First parameter is required!"); 1.565 +ex = false; 1.566 + 1.567 +e = new StorageEvent("hello"); 1.568 +is(e.type, "hello", "Wrong event type!"); 1.569 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.570 +ok(!e.bubbles, "Event shouldn't bubble!"); 1.571 +ok(!e.cancelable, "Event shouldn't be cancelable!"); 1.572 +is(e.key, null, "key should be null"); 1.573 +is(e.oldValue, null, "oldValue should be null"); 1.574 +is(e.newValue, null, "newValue should be null"); 1.575 +is(e.url, "", "url should be ''"); 1.576 +document.dispatchEvent(e); 1.577 +is(receivedEvent, e, "Wrong event!"); 1.578 + 1.579 +e = new StorageEvent("hello", 1.580 + { bubbles: true, cancelable: true, key: "key", 1.581 + oldValue: "oldValue", newValue: "newValue", url: "url", 1.582 + storageArea: localStorage }); 1.583 +is(e.type, "hello", "Wrong event type!"); 1.584 +ok(!e.isTrusted, "Event shouldn't be trusted!"); 1.585 +ok(e.bubbles, "Event should bubble!"); 1.586 +ok(e.cancelable, "Event should be cancelable!"); 1.587 +is(e.key, "key", "Wrong value"); 1.588 +is(e.oldValue, "oldValue", "Wrong value"); 1.589 +is(e.newValue, "newValue", "Wrong value"); 1.590 +is(e.url, "url", "Wrong value"); 1.591 +is(e.storageArea, localStorage, "Wrong value"); 1.592 +document.dispatchEvent(e); 1.593 +is(receivedEvent, e, "Wrong event!"); 1.594 + 1.595 +// DeviceProximityEvent 1.596 +e = new DeviceProximityEvent("hello", {min: 0, value: 1, max: 2}); 1.597 +is(e.type, "hello", "Wrong event type!"); 1.598 +ok(!e.isTrusted, "Event should not be trusted"); 1.599 +is(e.value, 1, "value should be 1"); 1.600 +is(e.min, 0, "min should be 0"); 1.601 +is(e.max, 2, "max should be 2"); 1.602 +document.dispatchEvent(e); 1.603 +is(receivedEvent, e, "Wrong event!"); 1.604 +e = new DeviceProximityEvent("hello"); 1.605 +is(e.value, Infinity, "Uninitialized value should be infinity"); 1.606 +is(e.min, -Infinity, "Uninitialized min should be -infinity"); 1.607 +is(e.max, Infinity, "Uninitialized max should be infinity"); 1.608 + 1.609 +// UserProximityEvent 1.610 +e = new UserProximityEvent("hello", {near: true}); 1.611 +is(e.type, "hello", "Wrong event type!"); 1.612 +ok(!e.isTrusted, "Event should not be trusted"); 1.613 +is(e.near, true, "near should be true"); 1.614 +document.dispatchEvent(e); 1.615 +is(receivedEvent, e, "Wrong event!"); 1.616 + 1.617 +// DeviceLightEvent 1.618 +e = new DeviceLightEvent("hello", {value: 1} ); 1.619 +is(e.type, "hello", "Wrong event type!"); 1.620 +ok(!e.isTrusted, "Event should not be trusted"); 1.621 +is(e.value, 1, "value should be 1"); 1.622 +document.dispatchEvent(e); 1.623 +is(receivedEvent, e, "Wrong event!"); 1.624 +e = new DeviceLightEvent("hello", {value: Infinity} ); 1.625 +is(e.value, Infinity, "value should be positive infinity"); 1.626 +e = new DeviceLightEvent("hello", {value: -Infinity} ); 1.627 +is(e.value, -Infinity, "value should be negative infinity"); 1.628 +e = new DeviceLightEvent("hello"); 1.629 +is(e.value, Infinity, "Uninitialized value should be positive infinity"); 1.630 + 1.631 +// DeviceOrientationEvent 1.632 +e = new DeviceOrientationEvent("hello"); 1.633 +is(e.type, "hello", "Wrong event type!"); 1.634 +ok(!e.isTrusted, "Event should not be trusted"); 1.635 +is(e.alpha, 0); 1.636 +is(e.beta, 0); 1.637 +is(e.gamma, 0); 1.638 +is(e.absolute, false); 1.639 + 1.640 +e = new DeviceOrientationEvent("hello", { alpha: 1, beta: 2, gamma: 3, absolute: true } ); 1.641 +is(e.type, "hello", "Wrong event type!"); 1.642 +ok(!e.isTrusted, "Event should not be trusted"); 1.643 +is(e.alpha, 1); 1.644 +is(e.beta, 2); 1.645 +is(e.gamma, 3); 1.646 +is(e.absolute, true); 1.647 +document.dispatchEvent(e); 1.648 +is(receivedEvent, e, "Wrong event!"); 1.649 + 1.650 +// MouseEvent 1.651 + 1.652 +try { 1.653 + e = new MouseEvent(); 1.654 +} catch(exp) { 1.655 + ex = true; 1.656 +} 1.657 +ok(ex, "MouseEvent: First parameter is required!"); 1.658 +ex = false; 1.659 + 1.660 +e = new MouseEvent("hello"); 1.661 +is(e.type, "hello", "MouseEvent: Wrong event type!"); 1.662 +ok(!e.isTrusted, "MouseEvent: Event shouldn't be trusted!"); 1.663 +ok(!e.bubbles, "MouseEvent: Event shouldn't bubble!"); 1.664 +ok(!e.cancelable, "MouseEvent: Event shouldn't be cancelable!"); 1.665 +document.dispatchEvent(e); 1.666 +is(receivedEvent, e, "MouseEvent: Wrong event!"); 1.667 + 1.668 +var mouseEventProps = 1.669 +[ { screenX: 0 }, 1.670 + { screenY: 0 }, 1.671 + { clientX: 0 }, 1.672 + { clientY: 0 }, 1.673 + { ctrlKey: false }, 1.674 + { shiftKey: false }, 1.675 + { altKey: false }, 1.676 + { metaKey: false }, 1.677 + { button: 0 }, 1.678 + { buttons: 0 }, 1.679 + { relatedTarget: null } 1.680 +]; 1.681 + 1.682 +var testProps = 1.683 +[ 1.684 + { screenX: 1 }, 1.685 + { screenY: 2 }, 1.686 + { clientX: 3 }, 1.687 + { clientY: 4 }, 1.688 + { ctrlKey: true }, 1.689 + { shiftKey: true }, 1.690 + { altKey: true }, 1.691 + { metaKey: true }, 1.692 + { button: 5 }, 1.693 + { buttons: 6 }, 1.694 + { relatedTarget: window } 1.695 +]; 1.696 + 1.697 +var defaultMouseEventValues = {}; 1.698 +for (var i = 0; i < mouseEventProps.length; ++i) { 1.699 + for (prop in mouseEventProps[i]) { 1.700 + ok(prop in e, "MouseEvent: MouseEvent doesn't have property " + prop + "!"); 1.701 + defaultMouseEventValues[prop] = mouseEventProps[i][prop]; 1.702 + } 1.703 +} 1.704 + 1.705 +while (testProps.length) { 1.706 + var p = testProps.shift(); 1.707 + e = new MouseEvent("foo", p); 1.708 + for (var def in defaultMouseEventValues) { 1.709 + if (!(def in p)) { 1.710 + is(e[def], defaultMouseEventValues[def], 1.711 + "MouseEvent: Wrong default value for " + def + "!"); 1.712 + } else { 1.713 + is(e[def], p[def], "MouseEvent: Wrong event init value for " + def + "!"); 1.714 + } 1.715 + } 1.716 +} 1.717 + 1.718 +// PopupBlockedEvent 1.719 + 1.720 +try { 1.721 + e = new PopupBlockedEvent(); 1.722 +} catch(exp) { 1.723 + ex = true; 1.724 +} 1.725 +ok(ex, "PopupBlockedEvent: First parameter is required!"); 1.726 +ex = false; 1.727 + 1.728 +e = new PopupBlockedEvent("hello"); 1.729 +is(e.type, "hello", "PopupBlockedEvent: Wrong event type!"); 1.730 +ok(!e.isTrusted, "PopupBlockedEvent: Event shouldn't be trusted!"); 1.731 +ok(!e.bubbles, "PopupBlockedEvent: Event shouldn't bubble!"); 1.732 +ok(!e.cancelable, "PopupBlockedEvent: Event shouldn't be cancelable!"); 1.733 +document.dispatchEvent(e); 1.734 +is(receivedEvent, e, "PopupBlockedEvent: Wrong event!"); 1.735 + 1.736 +e = new PopupBlockedEvent("hello", 1.737 + { requestingWindow: window, 1.738 + popupWindowFeatures: "features", 1.739 + popupWindowName: "name" 1.740 + }); 1.741 +is(e.requestingWindow, window); 1.742 +is(e.popupWindowFeatures, "features"); 1.743 +is(e.popupWindowName, "name"); 1.744 + 1.745 + 1.746 +// SmartCardEvent 1.747 + 1.748 +try { 1.749 + e = new SmartCardEvent(); 1.750 +} catch(exp) { 1.751 + ex = true; 1.752 +} 1.753 +ok(ex, "SmartCardEvent: First parameter is required!"); 1.754 +ex = false; 1.755 + 1.756 +e = new SmartCardEvent("hello"); 1.757 +is(e.type, "hello", "SmartCardEvent: Wrong event type!"); 1.758 +ok(!e.isTrusted, "SmartCardEvent: Event shouldn't be trusted!"); 1.759 +ok(!e.bubbles, "SmartCardEvent: Event shouldn't bubble!"); 1.760 +ok(!e.cancelable, "SmartCardEvent: Event shouldn't be cancelable!"); 1.761 +is(e.tokenName, ""); 1.762 +document.dispatchEvent(e); 1.763 +is(receivedEvent, e, "SmartCardEvent: Wrong event!"); 1.764 + 1.765 +e = new SmartCardEvent("hello", { tokenName: "foo" }); 1.766 +is(e.tokenName, "foo"); 1.767 + 1.768 +// WheelEvent 1.769 + 1.770 +try { 1.771 + e = new WheelEvent(); 1.772 +} catch(exp) { 1.773 + ex = true; 1.774 +} 1.775 +ok(ex, "WheelEvent: First parameter is required!"); 1.776 +ex = false; 1.777 + 1.778 +e = new WheelEvent("hello"); 1.779 +is(e.type, "hello", "WheelEvent: Wrong event type!"); 1.780 +ok(!e.isTrusted, "WheelEvent: Event shouldn't be trusted!"); 1.781 +ok(!e.bubbles, "WheelEvent: Event shouldn't bubble!"); 1.782 +ok(!e.cancelable, "WheelEvent: Event shouldn't be cancelable!"); 1.783 +document.dispatchEvent(e); 1.784 +is(receivedEvent, e, "WheelEvent: Wrong event!"); 1.785 + 1.786 +var wheelEventProps = 1.787 +[ { screenX: 0 }, 1.788 + { screenY: 0 }, 1.789 + { clientX: 0 }, 1.790 + { clientY: 0 }, 1.791 + { ctrlKey: false }, 1.792 + { shiftKey: false }, 1.793 + { altKey: false }, 1.794 + { metaKey: false }, 1.795 + { button: 0 }, 1.796 + { buttons: 0 }, 1.797 + { relatedTarget: null }, 1.798 + { deltaX: 0.0 }, 1.799 + { deltaY: 0.0 }, 1.800 + { deltaZ: 0.0 }, 1.801 + { deltaMode: 0 } 1.802 +]; 1.803 + 1.804 +var testWheelProps = 1.805 +[ 1.806 + { screenX: 1 }, 1.807 + { screenY: 2 }, 1.808 + { clientX: 3 }, 1.809 + { clientY: 4 }, 1.810 + { ctrlKey: true }, 1.811 + { shiftKey: true }, 1.812 + { altKey: true }, 1.813 + { metaKey: true }, 1.814 + { button: 5 }, 1.815 + { buttons: 6 }, 1.816 + { relatedTarget: window }, 1.817 + { deltaX: 7.8 }, 1.818 + { deltaY: 9.1 }, 1.819 + { deltaZ: 2.3 }, 1.820 + { deltaMode: 4 } 1.821 +]; 1.822 + 1.823 +var defaultWheelEventValues = {}; 1.824 +for (var i = 0; i < wheelEventProps.length; ++i) { 1.825 + for (prop in wheelEventProps[i]) { 1.826 + ok(prop in e, "WheelEvent: WheelEvent doesn't have property " + prop + "!"); 1.827 + defaultWheelEventValues[prop] = wheelEventProps[i][prop]; 1.828 + } 1.829 +} 1.830 + 1.831 +while (testWheelProps.length) { 1.832 + var p = testWheelProps.shift(); 1.833 + e = new WheelEvent("foo", p); 1.834 + for (var def in defaultWheelEventValues) { 1.835 + if (!(def in p)) { 1.836 + is(e[def], defaultWheelEventValues[def], 1.837 + "WheelEvent: Wrong default value for " + def + "!"); 1.838 + } else { 1.839 + is(e[def], p[def], "WheelEvent: Wrong event init value for " + def + "!"); 1.840 + } 1.841 + } 1.842 +} 1.843 + 1.844 +// TransitionEvent 1.845 +e = new TransitionEvent("hello", { propertyName: "color", elapsedTime: 3.5, pseudoElement: "", foobar: "baz" }) 1.846 +is("propertyName" in e, true, "Transition events have propertyName property"); 1.847 +is("foobar" in e, false, "Transition events do not copy random properties from event init"); 1.848 +is(e.propertyName, "color", "Transition event copies propertyName from TransitionEventInit"); 1.849 +is(e.elapsedTime, 3.5, "Transition event copies elapsedTime from TransitionEventInit"); 1.850 +is(e.pseudoElement, "", "Transition event copies pseudoElement from TransitionEventInit"); 1.851 +is(e.bubbles, false, "Lack of bubbles property in TransitionEventInit"); 1.852 +is(e.cancelable, false, "Lack of cancelable property in TransitionEventInit"); 1.853 +is(e.type, "hello", "Wrong event type!"); 1.854 +is(e.isTrusted, false, "Event shouldn't be trusted!"); 1.855 +is(e.eventPhase, Event.NONE, "Wrong event phase"); 1.856 + 1.857 +// AnimationEvent 1.858 +e = new AnimationEvent("hello", { animationName: "bounce3", elapsedTime: 3.5, pseudoElement: "", foobar: "baz" }) 1.859 +is("animationName" in e, true, "Animation events have animationName property"); 1.860 +is("foobar" in e, false, "Animation events do not copy random properties from event init"); 1.861 +is(e.animationName, "bounce3", "Animation event copies animationName from AnimationEventInit"); 1.862 +is(e.elapsedTime, 3.5, "Animation event copies elapsedTime from AnimationEventInit"); 1.863 +is(e.pseudoElement, "", "Animation event copies pseudoElement from AnimationEventInit"); 1.864 +is(e.bubbles, false, "Lack of bubbles property in AnimationEventInit"); 1.865 +is(e.cancelable, false, "Lack of cancelable property in AnimationEventInit"); 1.866 +is(e.type, "hello", "Wrong event type!"); 1.867 +is(e.isTrusted, false, "Event shouldn't be trusted!"); 1.868 +is(e.eventPhase, Event.NONE, "Wrong event phase"); 1.869 + 1.870 +</script> 1.871 +</pre> 1.872 +</body> 1.873 +</html>