123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954 |
- <!DOCTYPE HTML>
- <html>
- <!--
- https://bugzilla.mozilla.org/show_bug.cgi?id=675884
- -->
- <head>
- <title>Test for Bug 675884</title>
- <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
- <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
- </head>
- <body>
- <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=675884">Mozilla Bug 675884</a>
- <p id="display"></p>
- <div id="content" style="display: none">
-
- </div>
- <pre id="test">
- <script type="application/javascript">
- /** Test for Bug 675884 **/
- var receivedEvent;
- document.addEventListener("hello", function(e) { receivedEvent = e; }, true);
- function isMethodResultInitializer(aPropName)
- {
- return aPropName.startsWith("modifier");
- }
- function getPropValue(aEvent, aPropName)
- {
- if (aPropName.startsWith("modifier")) {
- return aEvent.getModifierState(aPropName.substr("modifier".length));
- }
- return aEvent[aPropName];
- }
- // Event
- var e;
- var ex = false;
- try {
- e = new Event();
- } catch(exp) {
- ex = true;
- }
- ok(ex, "First parameter is required!");
- ex = false;
- try {
- e = new Event("foo", 123);
- } catch(exp) {
- ex = true;
- }
- ok(ex, "2nd parameter should be an object!");
- ex = false;
- try {
- e = new Event("foo", "asdf");
- } catch(exp) {
- ex = true;
- }
- ok(ex, "2nd parameter should be an object!");
- ex = false;
- try {
- e = new Event("foo", false);
- } catch(exp) {
- ex = true;
- }
- ok(ex, "2nd parameter should be an object!");
- ex = false;
- e = new Event("hello");
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- e.isTrusted = true;
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- try {
- e.__defineGetter__("isTrusted", function() { return true });
- } catch (exp) {
- ex = true;
- }
- ok(ex, "Shouldn't be able to re-define the getter for isTrusted.");
- ex = false;
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!("isTrusted" in Object.getPrototypeOf(e)))
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- is(e.eventPhase, Event.NONE, "Wrong event phase");
- document.dispatchEvent(e);
- is(e.eventPhase, Event.NONE, "Wrong event phase");
- is(receivedEvent, e, "Wrong event!");
- e = new Event("hello", null);
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- is(e.eventPhase, Event.NONE, "Wrong event phase");
- document.dispatchEvent(e);
- is(e.eventPhase, Event.NONE, "Wrong event phase");
- is(receivedEvent, e, "Wrong event!");
- e = new Event("hello", undefined);
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- is(e.eventPhase, Event.NONE, "Wrong event phase");
- document.dispatchEvent(e);
- is(e.eventPhase, Event.NONE, "Wrong event phase");
- is(receivedEvent, e, "Wrong event!");
- e = new Event("hello", {});
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- is(e.eventPhase, Event.NONE, "Wrong event phase");
- document.dispatchEvent(e);
- is(e.eventPhase, Event.NONE, "Wrong event phase");
- is(receivedEvent, e, "Wrong event!");
- e = new Event("hello", { bubbles: true, cancelable: true });
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(e.bubbles, "Event should bubble!");
- ok(e.cancelable, "Event should be cancelable!");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- // CustomEvent
- try {
- e = new CustomEvent();
- } catch(exp) {
- ex = true;
- }
- ok(ex, "First parameter is required!");
- ex = false;
- e = new CustomEvent("hello");
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- e = new CustomEvent("hello", { bubbles: true, cancelable: true, detail: window });
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(e.bubbles, "Event should bubble!");
- ok(e.cancelable, "Event should be cancelable!");
- is(e.detail, window , "Wrong event.detail!");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- e = new CustomEvent("hello", { cancelable: true, detail: window });
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(e.cancelable, "Event should be cancelable!");
- is(e.detail, window , "Wrong event.detail!");
- e = new CustomEvent("hello", { detail: 123 });
- is(e.detail, 123, "Wrong event.detail!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- var dict = { get detail() { return document.body } };
- e = new CustomEvent("hello", dict);
- is(e.detail, dict.detail, "Wrong event.detail!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- var dict = { get detail() { throw "foo"; } };
- try {
- e = new CustomEvent("hello", dict);
- } catch (exp) {
- ex = true;
- }
- ok(ex, "Should have thrown an exception!");
- ex = false;
- // BlobEvent
- try {
- e = new BlobEvent();
- } catch(exp) {
- ex = true;
- }
- ok(ex, "First parameter is required!");
- ex = false;
- e = new BlobEvent("hello");
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- try {
- e.__defineGetter__("isTrusted", function() { return true });
- } catch (exp) {
- ex = true;
- }
- ok(ex, "Shouldn't be able to re-define the getter for isTrusted.");
- ex = false;
- ok(!e.isTrusted, "BlobEvent shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- var blob = new Blob();
- e = new BlobEvent("hello", { bubbles: true, cancelable: true, data: blob });
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(e.bubbles, "Event should bubble!");
- ok(e.cancelable, "Event should be cancelable!");
- is(e.data, blob , "Wrong event.data!");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- e = new BlobEvent("hello", {data: blob});
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event should be cancelable1!");
- is(e.data, blob , "Wrong event.data!");
- e = new BlobEvent("hello", { data: null });
- is(e.data, null, "Wrong event.data!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- blob = null;
- // CloseEvent
- try {
- e = new CloseEvent();
- } catch(exp) {
- ex = true;
- }
- ok(ex, "First parameter is required!");
- ex = false;
- e = new CloseEvent("hello");
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- is(e.wasClean, false, "wasClean should be false!");
- is(e.code, 0, "code should be 0!");
- is(e.reason, "", "reason should be ''!");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- e = new CloseEvent("hello",
- { bubbles: true, cancelable: true, wasClean: true, code: 1, reason: "foo" });
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(e.bubbles, "Event should bubble!");
- ok(e.cancelable, "Event should be cancelable!");
- is(e.wasClean, true, "wasClean should be true!");
- is(e.code, 1, "code should be 1!");
- is(e.reason, "foo", "reason should be 'foo'!");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- e = new CloseEvent("hello",
- { bubbles: true, cancelable: true, wasClean: true, code: 1 });
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(e.bubbles, "Event should bubble!");
- ok(e.cancelable, "Event should be cancelable!");
- is(e.wasClean, true, "wasClean should be true!");
- is(e.code, 1, "code should be 1!");
- is(e.reason, "", "reason should be ''!");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- // HashChangeEvent
- try {
- e = new HashChangeEvent();
- } catch(exp) {
- ex = true;
- }
- ok(ex, "First parameter is required!");
- ex = false;
- e = new HashChangeEvent("hello");
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- is(e.oldURL, "", "oldURL should be ''");
- is(e.newURL, "", "newURL should be ''");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- e = new HashChangeEvent("hello",
- { bubbles: true, cancelable: true, oldURL: "old", newURL: "new" });
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(e.bubbles, "Event should bubble!");
- ok(e.cancelable, "Event should be cancelable!");
- is(e.oldURL, "old", "oldURL should be 'old'");
- is(e.newURL, "new", "newURL should be 'new'");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- e = new HashChangeEvent("hello",
- { bubbles: true, cancelable: true, newURL: "new" });
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(e.bubbles, "Event should bubble!");
- ok(e.cancelable, "Event should be cancelable!");
- is(e.oldURL, "", "oldURL should be ''");
- is(e.newURL, "new", "newURL should be 'new'");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- // InputEvent
- e = new InputEvent("hello");
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- is(e.detail, 0, "detail should be 0");
- ok(!e.isComposing, "isComposing should be false");
- e = new InputEvent("hi!", { bubbles: true, detail: 5, isComposing: false });
- is(e.type, "hi!", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(e.bubbles, "Event should bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- is(e.detail, 5, "detail should be 5");
- ok(!e.isComposing, "isComposing should be false");
- e = new InputEvent("hi!", { cancelable: true, detail: 0, isComposing: true });
- is(e.type, "hi!", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(e.cancelable, "Event should be cancelable!");
- is(e.detail, 0, "detail should be 0");
- ok(e.isComposing, "isComposing should be true");
- // KeyboardEvent
- try {
- e = new KeyboardEvent();
- } catch(exp) {
- ex = true;
- }
- ok(ex, "KeyboardEvent: First parameter is required!");
- ex = false;
- e = new KeyboardEvent("hello");
- ok(e.type, "hello", "KeyboardEvent: Wrong event type!");
- ok(!e.isTrusted, "KeyboardEvent: Event shouldn't be trusted!");
- ok(!e.bubbles, "KeyboardEvent: Event shouldn't bubble!");
- ok(!e.cancelable, "KeyboardEvent: Event shouldn't be cancelable!");
- document.dispatchEvent(e);
- is(receivedEvent, e, "KeyboardEvent: Wrong event!");
- var keyboardEventProps =
- [
- { bubbles: false },
- { cancelable: false },
- { view: null },
- { detail: 0 },
- { key: "" },
- { code: "" },
- { location: 0 },
- { ctrlKey: false },
- { shiftKey: false },
- { altKey: false },
- { metaKey: false },
- { modifierAltGraph: false },
- { modifierCapsLock: false },
- { modifierFn: false },
- { modifierFnLock: false },
- { modifierNumLock: false },
- { modifierOS: false },
- { modifierScrollLock: false },
- { modifierSymbol: false },
- { modifierSymbolLock: false },
- { repeat: false },
- { isComposing: false },
- { charCode: 0 },
- { keyCode: 0 },
- { which: 0 },
- ];
- var testKeyboardProps =
- [
- { bubbles: true },
- { cancelable: true },
- { view: window },
- { detail: 1 },
- { key: "CustomKey" },
- { code: "CustomCode" },
- { location: 1 },
- { ctrlKey: true },
- { shiftKey: true },
- { altKey: true },
- { metaKey: true },
- { modifierAltGraph: true },
- { modifierCapsLock: true },
- { modifierFn: true },
- { modifierFnLock: true },
- { modifierNumLock: true },
- { modifierOS: true },
- { modifierScrollLock: true },
- { modifierSymbol: true },
- { modifierSymbolLock: true },
- { repeat: true },
- { isComposing: true },
- { charCode: 2 },
- { keyCode: 3 },
- { which: 4 },
- { charCode: 5, which: 6 },
- { keyCode: 7, which: 8 },
- { keyCode: 9, charCode: 10 },
- { keyCode: 11, charCode: 12, which: 13 },
- ];
- var codeEnabled = SpecialPowers.getBoolPref("dom.keyboardevent.code.enabled");
- var defaultKeyboardEventValues = {};
- for (var i = 0; i < keyboardEventProps.length; ++i) {
- for (prop in keyboardEventProps[i]) {
- if (!codeEnabled && prop == "code") {
- continue;
- }
- if (!isMethodResultInitializer(prop)) {
- ok(prop in e, "keyboardEvent: KeyboardEvent doesn't have property " + prop + "!");
- }
- defaultKeyboardEventValues[prop] = keyboardEventProps[i][prop];
- }
- }
- while (testKeyboardProps.length) {
- var p = testKeyboardProps.shift();
- e = new KeyboardEvent("foo", p);
- for (var def in defaultKeyboardEventValues) {
- if (!codeEnabled && def == "code") {
- continue;
- }
- if (!(def in p)) {
- is(getPropValue(e, def), defaultKeyboardEventValues[def],
- "KeyboardEvent: Wrong default value for " + def + "!");
- } else {
- is(getPropValue(e, def), p[def],
- "KeyboardEvent: Wrong event init value for " + def + "!");
- }
- }
- }
- // PageTransitionEvent
- try {
- e = new PageTransitionEvent();
- } catch(exp) {
- ex = true;
- }
- ok(ex, "First parameter is required!");
- ex = false;
- e = new PageTransitionEvent("hello");
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- is(e.persisted, false, "persisted should be false");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- e = new PageTransitionEvent("hello",
- { bubbles: true, cancelable: true, persisted: true});
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(e.bubbles, "Event should bubble!");
- ok(e.cancelable, "Event should be cancelable!");
- is(e.persisted, true, "persisted should be true");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- e = new PageTransitionEvent("hello", { persisted: true});
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- is(e.persisted, true, "persisted should be true");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- // PopStateEvent
- try {
- e = new PopStateEvent();
- } catch(exp) {
- ex = true;
- }
- ok(ex, "First parameter is required!");
- ex = false;
- e = new PopStateEvent("hello");
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- is(e.state, null, "persisted should be null");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- e = new PopStateEvent("hello",
- { bubbles: true, cancelable: true, state: window});
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(e.bubbles, "Event should bubble!");
- ok(e.cancelable, "Event should be cancelable!");
- is(e.state, window, "persisted should be window");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- e = new PopStateEvent("hello", { state: window});
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- is(e.state, window, "persisted should be window");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- // UIEvent
- try {
- e = new UIEvent();
- } catch(exp) {
- ex = true;
- }
- ok(ex, "First parameter is required!");
- ex = false;
- try {
- e = new UIEvent("foo", { view: {} });
- e.view.onunload;
- } catch(exp) {
- ex = true;
- }
- ok(ex, "{} isn't a valid value.");
- ex = false;
- try {
- e = new UIEvent("foo", { view: null });
- } catch(exp) {
- ex = true;
- }
- ok(!ex, "null is a valid value.");
- is(e.view, null);
- ex = false;
- e = new UIEvent("hello");
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- is(e.detail, 0, "detail should be 0");
- is(e.view, null, "view should be null");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- e = new UIEvent("hello",
- { bubbles: true, cancelable: true, view: window, detail: 1});
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(e.bubbles, "Event should bubble!");
- ok(e.cancelable, "Event should be cancelable!");
- is(e.detail, 1, "detail should be 1");
- is(e.view, window, "view should be window");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- // StorageEvent
- e = document.createEvent("StorageEvent");
- ok(e, "Should have created an event!");
- try {
- e = new StorageEvent();
- } catch(exp) {
- ex = true;
- }
- ok(ex, "First parameter is required!");
- ex = false;
- e = new StorageEvent("hello");
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(!e.bubbles, "Event shouldn't bubble!");
- ok(!e.cancelable, "Event shouldn't be cancelable!");
- is(e.key, null, "key should be null");
- is(e.oldValue, null, "oldValue should be null");
- is(e.newValue, null, "newValue should be null");
- is(e.url, "", "url should be ''");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- e = new StorageEvent("hello",
- { bubbles: true, cancelable: true, key: "key",
- oldValue: "oldValue", newValue: "newValue", url: "url",
- storageArea: localStorage });
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event shouldn't be trusted!");
- ok(e.bubbles, "Event should bubble!");
- ok(e.cancelable, "Event should be cancelable!");
- is(e.key, "key", "Wrong value");
- is(e.oldValue, "oldValue", "Wrong value");
- is(e.newValue, "newValue", "Wrong value");
- is(e.url, "url", "Wrong value");
- is(e.storageArea, localStorage, "Wrong value");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- // DeviceProximityEvent
- e = new DeviceProximityEvent("hello", {min: 0, value: 1, max: 2});
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event should not be trusted");
- is(e.value, 1, "value should be 1");
- is(e.min, 0, "min should be 0");
- is(e.max, 2, "max should be 2");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- e = new DeviceProximityEvent("hello");
- is(e.value, Infinity, "Uninitialized value should be infinity");
- is(e.min, -Infinity, "Uninitialized min should be -infinity");
- is(e.max, Infinity, "Uninitialized max should be infinity");
- // UserProximityEvent
- e = new UserProximityEvent("hello", {near: true});
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event should not be trusted");
- is(e.near, true, "near should be true");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- // DeviceLightEvent
- e = new DeviceLightEvent("hello", {value: 1} );
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event should not be trusted");
- is(e.value, 1, "value should be 1");
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- e = new DeviceLightEvent("hello", {value: Infinity} );
- is(e.value, Infinity, "value should be positive infinity");
- e = new DeviceLightEvent("hello", {value: -Infinity} );
- is(e.value, -Infinity, "value should be negative infinity");
- e = new DeviceLightEvent("hello");
- is(e.value, Infinity, "Uninitialized value should be positive infinity");
- // DeviceOrientationEvent
- e = new DeviceOrientationEvent("hello");
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event should not be trusted");
- is(e.alpha, null);
- is(e.beta, null);
- is(e.gamma, null);
- is(e.absolute, false);
- e = new DeviceOrientationEvent("hello", { alpha: 1, beta: 2, gamma: 3, absolute: true } );
- is(e.type, "hello", "Wrong event type!");
- ok(!e.isTrusted, "Event should not be trusted");
- is(e.alpha, 1);
- is(e.beta, 2);
- is(e.gamma, 3);
- is(e.absolute, true);
- document.dispatchEvent(e);
- is(receivedEvent, e, "Wrong event!");
- // MouseEvent
- try {
- e = new MouseEvent();
- } catch(exp) {
- ex = true;
- }
- ok(ex, "MouseEvent: First parameter is required!");
- ex = false;
- e = new MouseEvent("hello", { buttons: 1, movementX: 2, movementY: 3});
- is(e.type, "hello", "MouseEvent: Wrong event type!");
- ok(!e.isTrusted, "MouseEvent: Event shouldn't be trusted!");
- ok(!e.bubbles, "MouseEvent: Event shouldn't bubble!");
- ok(!e.cancelable, "MouseEvent: Event shouldn't be cancelable!");
- is(e.buttons, 1);
- is(e.movementX, 2);
- is(e.movementY, 3);
- document.dispatchEvent(e);
- is(receivedEvent, e, "MouseEvent: Wrong event!");
- var mouseEventProps =
- [ { screenX: 0 },
- { screenY: 0 },
- { clientX: 0 },
- { clientY: 0 },
- { ctrlKey: false },
- { shiftKey: false },
- { altKey: false },
- { metaKey: false },
- { modifierAltGraph: false },
- { modifierCapsLock: false },
- { modifierFn: false },
- { modifierFnLock: false },
- { modifierNumLock: false },
- { modifierOS: false },
- { modifierScrollLock: false },
- { modifierSymbol: false },
- { modifierSymbolLock: false },
- { button: 0 },
- { buttons: 0 },
- { relatedTarget: null },
- ];
- var testProps =
- [
- { screenX: 1 },
- { screenY: 2 },
- { clientX: 3 },
- { clientY: 4 },
- { ctrlKey: true },
- { shiftKey: true },
- { altKey: true },
- { metaKey: true },
- { modifierAltGraph: true },
- { modifierCapsLock: true },
- { modifierFn: true },
- { modifierFnLock: true },
- { modifierNumLock: true },
- { modifierOS: true },
- { modifierScrollLock: true },
- { modifierSymbol: true },
- { modifierSymbolLock: true },
- { button: 5 },
- { buttons: 6 },
- { relatedTarget: window }
- ];
- var defaultMouseEventValues = {};
- for (var i = 0; i < mouseEventProps.length; ++i) {
- for (prop in mouseEventProps[i]) {
- if (!isMethodResultInitializer(prop)) {
- ok(prop in e, "MouseEvent: MouseEvent doesn't have property " + prop + "!");
- }
- defaultMouseEventValues[prop] = mouseEventProps[i][prop];
- }
- }
- while (testProps.length) {
- var p = testProps.shift();
- e = new MouseEvent("foo", p);
- for (var def in defaultMouseEventValues) {
- if (!(def in p)) {
- is(getPropValue(e, def), defaultMouseEventValues[def],
- "MouseEvent: Wrong default value for " + def + "!");
- } else {
- is(getPropValue(e, def), p[def], "MouseEvent: Wrong event init value for " + def + "!");
- }
- }
- }
- // PopupBlockedEvent
- try {
- e = new PopupBlockedEvent();
- } catch(exp) {
- ex = true;
- }
- ok(ex, "PopupBlockedEvent: First parameter is required!");
- ex = false;
- e = new PopupBlockedEvent("hello");
- is(e.type, "hello", "PopupBlockedEvent: Wrong event type!");
- ok(!e.isTrusted, "PopupBlockedEvent: Event shouldn't be trusted!");
- ok(!e.bubbles, "PopupBlockedEvent: Event shouldn't bubble!");
- ok(!e.cancelable, "PopupBlockedEvent: Event shouldn't be cancelable!");
- document.dispatchEvent(e);
- is(receivedEvent, e, "PopupBlockedEvent: Wrong event!");
- e = new PopupBlockedEvent("hello",
- { requestingWindow: window,
- popupWindowFeatures: "features",
- popupWindowName: "name"
- });
- is(e.requestingWindow, window);
- is(e.popupWindowFeatures, "features");
- is(e.popupWindowName, "name");
- // WheelEvent
- try {
- e = new WheelEvent();
- } catch(exp) {
- ex = true;
- }
- ok(ex, "WheelEvent: First parameter is required!");
- ex = false;
- e = new WheelEvent("hello", { buttons: 1, movementX: 2, movementY: 3});
- is(e.type, "hello", "WheelEvent: Wrong event type!");
- is(e.buttons, 1);
- is(e.movementX, 2);
- is(e.movementY, 3);
- ok(!e.isTrusted, "WheelEvent: Event shouldn't be trusted!");
- ok(!e.bubbles, "WheelEvent: Event shouldn't bubble!");
- ok(!e.cancelable, "WheelEvent: Event shouldn't be cancelable!");
- document.dispatchEvent(e);
- is(receivedEvent, e, "WheelEvent: Wrong event!");
- var wheelEventProps =
- [ { screenX: 0 },
- { screenY: 0 },
- { clientX: 0 },
- { clientY: 0 },
- { ctrlKey: false },
- { shiftKey: false },
- { altKey: false },
- { metaKey: false },
- { modifierAltGraph: false },
- { modifierCapsLock: false },
- { modifierFn: false },
- { modifierFnLock: false },
- { modifierNumLock: false },
- { modifierOS: false },
- { modifierScrollLock: false },
- { modifierSymbol: false },
- { modifierSymbolLock: false },
- { button: 0 },
- { buttons: 0 },
- { relatedTarget: null },
- { deltaX: 0.0 },
- { deltaY: 0.0 },
- { deltaZ: 0.0 },
- { deltaMode: 0 }
- ];
- var testWheelProps =
- [
- { screenX: 1 },
- { screenY: 2 },
- { clientX: 3 },
- { clientY: 4 },
- { ctrlKey: true },
- { shiftKey: true },
- { altKey: true },
- { metaKey: true },
- { modifierAltGraph: true },
- { modifierCapsLock: true },
- { modifierFn: true },
- { modifierFnLock: true },
- { modifierNumLock: true },
- { modifierOS: true },
- { modifierScrollLock: true },
- { modifierSymbol: true },
- { modifierSymbolLock: true },
- { button: 5 },
- { buttons: 6 },
- { relatedTarget: window },
- { deltaX: 7.8 },
- { deltaY: 9.1 },
- { deltaZ: 2.3 },
- { deltaMode: 4 }
- ];
- var defaultWheelEventValues = {};
- for (var i = 0; i < wheelEventProps.length; ++i) {
- for (prop in wheelEventProps[i]) {
- if (!isMethodResultInitializer(prop)) {
- ok(prop in e, "WheelEvent: WheelEvent doesn't have property " + prop + "!");
- }
- defaultWheelEventValues[prop] = wheelEventProps[i][prop];
- }
- }
- while (testWheelProps.length) {
- var p = testWheelProps.shift();
- e = new WheelEvent("foo", p);
- for (var def in defaultWheelEventValues) {
- if (!(def in p)) {
- is(getPropValue(e, def), defaultWheelEventValues[def],
- "WheelEvent: Wrong default value for " + def + "!");
- } else {
- is(getPropValue(e, def), p[def], "WheelEvent: Wrong event init value for " + def + "!");
- }
- }
- }
- // DragEvent
- try {
- e = new DragEvent();
- } catch(exp) {
- ex = true;
- }
- ok(ex, "DragEvent: First parameter is required!");
- ex = false;
- e = new DragEvent("hello", { buttons: 1, movementX: 2, movementY: 3});
- is(e.type, "hello", "DragEvent: Wrong event type!");
- is(e.buttons, 1);
- is(e.movementX, 2);
- is(e.movementY, 3);
- document.dispatchEvent(e);
- is(receivedEvent, e, "DragEvent: Wrong event!");
- // TransitionEvent
- e = new TransitionEvent("hello", { propertyName: "color", elapsedTime: 3.5, pseudoElement: "", foobar: "baz" })
- is("propertyName" in e, true, "Transition events have propertyName property");
- is("foobar" in e, false, "Transition events do not copy random properties from event init");
- is(e.propertyName, "color", "Transition event copies propertyName from TransitionEventInit");
- is(e.elapsedTime, 3.5, "Transition event copies elapsedTime from TransitionEventInit");
- is(e.pseudoElement, "", "Transition event copies pseudoElement from TransitionEventInit");
- is(e.bubbles, false, "Lack of bubbles property in TransitionEventInit");
- is(e.cancelable, false, "Lack of cancelable property in TransitionEventInit");
- is(e.type, "hello", "Wrong event type!");
- is(e.isTrusted, false, "Event shouldn't be trusted!");
- is(e.eventPhase, Event.NONE, "Wrong event phase");
- // AnimationEvent
- e = new AnimationEvent("hello", { animationName: "bounce3", elapsedTime: 3.5, pseudoElement: "", foobar: "baz" })
- is("animationName" in e, true, "Animation events have animationName property");
- is("foobar" in e, false, "Animation events do not copy random properties from event init");
- is(e.animationName, "bounce3", "Animation event copies animationName from AnimationEventInit");
- is(e.elapsedTime, 3.5, "Animation event copies elapsedTime from AnimationEventInit");
- is(e.pseudoElement, "", "Animation event copies pseudoElement from AnimationEventInit");
- is(e.bubbles, false, "Lack of bubbles property in AnimationEventInit");
- is(e.cancelable, false, "Lack of cancelable property in AnimationEventInit");
- is(e.type, "hello", "Wrong event type!");
- is(e.isTrusted, false, "Event shouldn't be trusted!");
- is(e.eventPhase, Event.NONE, "Wrong event phase");
- </script>
- </pre>
- </body>
- </html>
|