dom/events/test/test_eventctors.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=675884
     5 -->
     6 <head>
     7   <title>Test for Bug 675884</title>
     8   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    10 </head>
    11 <body>
    12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=675884">Mozilla Bug 675884</a>
    13 <p id="display"></p>
    14 <div id="content" style="display: none">
    16 </div>
    17 <pre id="test">
    18 <script type="application/javascript">
    20 /** Test for Bug 675884 **/
    22 var receivedEvent;
    23 document.addEventListener("hello", function(e) { receivedEvent = e; }, true);
    25 // Event
    26 var e;
    27 var ex = false;
    28 try {
    29   e = new Event();
    30 } catch(exp) {
    31   ex = true;
    32 }
    33 ok(ex, "First parameter is required!");
    34 ex = false;
    36 try {
    37   e = new Event("foo", 123);
    38 } catch(exp) {
    39   ex = true;
    40 }
    41 ok(ex, "2nd parameter should be an object!");
    42 ex = false;
    44 try {
    45   e = new Event("foo", "asdf");
    46 } catch(exp) {
    47   ex = true;
    48 }
    49 ok(ex, "2nd parameter should be an object!");
    50 ex = false;
    53 try {
    54   e = new Event("foo", false);
    55 } catch(exp) {
    56   ex = true;
    57 }
    58 ok(ex, "2nd parameter should be an object!");
    59 ex = false;
    62 e = new Event("hello");
    63 is(e.type, "hello", "Wrong event type!");
    64 ok(!e.isTrusted, "Event shouldn't be trusted!");
    65 e.isTrusted = true;
    66 ok(!e.isTrusted, "Event shouldn't be trusted!");
    68 try {
    69   e.__defineGetter__("isTrusted", function() { return true });
    70 } catch (exp) {
    71   ex = true;
    72 }
    73 ok(ex, "Shouldn't be able to re-define the getter for isTrusted.");
    74 ex = false;
    75 ok(!e.isTrusted, "Event shouldn't be trusted!");
    77 ok(!("isTrusted" in Object.getPrototypeOf(e)))
    79 ok(!e.bubbles, "Event shouldn't bubble!");
    80 ok(!e.cancelable, "Event shouldn't be cancelable!");
    81 is(e.eventPhase, Event.NONE, "Wrong event phase");
    82 document.dispatchEvent(e);
    83 is(e.eventPhase, Event.NONE, "Wrong event phase");
    84 is(receivedEvent, e, "Wrong event!");
    86 e = new Event("hello", null);
    87 is(e.type, "hello", "Wrong event type!");
    88 ok(!e.isTrusted, "Event shouldn't be trusted!");
    89 ok(!e.bubbles, "Event shouldn't bubble!");
    90 ok(!e.cancelable, "Event shouldn't be cancelable!");
    91 is(e.eventPhase, Event.NONE, "Wrong event phase");
    92 document.dispatchEvent(e);
    93 is(e.eventPhase, Event.NONE, "Wrong event phase");
    94 is(receivedEvent, e, "Wrong event!");
    96 e = new Event("hello", undefined);
    97 is(e.type, "hello", "Wrong event type!");
    98 ok(!e.isTrusted, "Event shouldn't be trusted!");
    99 ok(!e.bubbles, "Event shouldn't bubble!");
   100 ok(!e.cancelable, "Event shouldn't be cancelable!");
   101 is(e.eventPhase, Event.NONE, "Wrong event phase");
   102 document.dispatchEvent(e);
   103 is(e.eventPhase, Event.NONE, "Wrong event phase");
   104 is(receivedEvent, e, "Wrong event!");
   106 e = new Event("hello", {});
   107 is(e.type, "hello", "Wrong event type!");
   108 ok(!e.isTrusted, "Event shouldn't be trusted!");
   109 ok(!e.bubbles, "Event shouldn't bubble!");
   110 ok(!e.cancelable, "Event shouldn't be cancelable!");
   111 is(e.eventPhase, Event.NONE, "Wrong event phase");
   112 document.dispatchEvent(e);
   113 is(e.eventPhase, Event.NONE, "Wrong event phase");
   114 is(receivedEvent, e, "Wrong event!");
   116 e = new Event("hello", { bubbles: true, cancelable: true });
   117 is(e.type, "hello", "Wrong event type!");
   118 ok(!e.isTrusted, "Event shouldn't be trusted!");
   119 ok(e.bubbles, "Event should bubble!");
   120 ok(e.cancelable, "Event should be cancelable!");
   121 document.dispatchEvent(e);
   122 is(receivedEvent, e, "Wrong event!");
   124 // CustomEvent
   126 try {
   127   e = new CustomEvent();
   128 } catch(exp) {
   129   ex = true;
   130 }
   131 ok(ex, "First parameter is required!");
   132 ex = false;
   134 e = new CustomEvent("hello");
   135 is(e.type, "hello", "Wrong event type!");
   136 ok(!e.isTrusted, "Event shouldn't be trusted!");
   137 ok(!e.bubbles, "Event shouldn't bubble!");
   138 ok(!e.cancelable, "Event shouldn't be cancelable!");
   139 document.dispatchEvent(e);
   140 is(receivedEvent, e, "Wrong event!");
   142 e = new CustomEvent("hello", { bubbles: true, cancelable: true, detail: window });
   143 is(e.type, "hello", "Wrong event type!");
   144 ok(!e.isTrusted, "Event shouldn't be trusted!");
   145 ok(e.bubbles, "Event should bubble!");
   146 ok(e.cancelable, "Event should be cancelable!");
   147 is(e.detail, window , "Wrong event.detail!");
   148 document.dispatchEvent(e);
   149 is(receivedEvent, e, "Wrong event!");
   151 e = new CustomEvent("hello", { cancelable: true, detail: window });
   152 is(e.type, "hello", "Wrong event type!");
   153 ok(!e.isTrusted, "Event shouldn't be trusted!");
   154 ok(!e.bubbles, "Event shouldn't bubble!");
   155 ok(e.cancelable, "Event should be cancelable!");
   156 is(e.detail, window , "Wrong event.detail!");
   158 e = new CustomEvent("hello", { detail: 123 });
   159 is(e.detail, 123, "Wrong event.detail!");
   160 ok(!e.bubbles, "Event shouldn't bubble!");
   161 ok(!e.cancelable, "Event shouldn't be cancelable!");
   163 var dict = { get detail() { return document.body } };
   164 e = new CustomEvent("hello", dict);
   165 is(e.detail, dict.detail, "Wrong event.detail!");
   166 ok(!e.bubbles, "Event shouldn't bubble!");
   167 ok(!e.cancelable, "Event shouldn't be cancelable!");
   169 var dict = { get detail() { throw "foo"; } };
   171 try {
   172   e = new CustomEvent("hello", dict);
   173 } catch (exp) {
   174   ex = true;
   175 }
   176 ok(ex, "Should have thrown an exception!");
   177 ex = false;
   179 // BlobEvent
   181 try {
   182   e = new BlobEvent();
   183 } catch(exp) {
   184   ex = true;
   185 }
   186 ok(ex, "First parameter is required!");
   187 ex = false;
   189 e = new BlobEvent("hello");
   190 is(e.type, "hello", "Wrong event type!");
   191 ok(!e.isTrusted, "Event shouldn't be trusted!");
   192 try {
   193   e.__defineGetter__("isTrusted", function() { return true });
   194 } catch (exp) {
   195   ex = true;
   196 }
   197 ok(ex, "Shouldn't be able to re-define the getter for isTrusted.");
   198 ex = false;
   199 ok(!e.isTrusted, "BlobEvent shouldn't be trusted!");
   201 ok(!e.bubbles, "Event shouldn't bubble!");
   202 ok(!e.cancelable, "Event shouldn't be cancelable!");
   203 document.dispatchEvent(e);
   204 is(receivedEvent, e, "Wrong event!");
   206 var blob = Blob();
   207 e = new BlobEvent("hello", { bubbles: true, cancelable: true, data: blob });
   208 is(e.type, "hello", "Wrong event type!");
   209 ok(!e.isTrusted, "Event shouldn't be trusted!");
   210 ok(e.bubbles, "Event should bubble!");
   211 ok(e.cancelable, "Event should be cancelable!");
   212 is(e.data, blob , "Wrong event.data!");
   213 document.dispatchEvent(e);
   214 is(receivedEvent, e, "Wrong event!");
   217 e = new BlobEvent("hello", {data: blob});
   218 is(e.type, "hello", "Wrong event type!");
   219 ok(!e.isTrusted, "Event shouldn't be trusted!");
   220 ok(!e.bubbles, "Event shouldn't bubble!");
   221 ok(!e.cancelable, "Event should be cancelable1!");
   222 is(e.data, blob , "Wrong event.data!");
   224 e = new BlobEvent("hello", { data: null });
   225 is(e.data, null, "Wrong event.data!");
   226 ok(!e.bubbles, "Event shouldn't bubble!");
   227 ok(!e.cancelable, "Event shouldn't be cancelable!");
   228 blob = null;
   229 // CloseEvent
   231 try {
   232   e = new CloseEvent();
   233 } catch(exp) {
   234   ex = true;
   235 }
   236 ok(ex, "First parameter is required!");
   237 ex = false;
   239 e = new CloseEvent("hello");
   240 is(e.type, "hello", "Wrong event type!");
   241 ok(!e.isTrusted, "Event shouldn't be trusted!");
   242 ok(!e.bubbles, "Event shouldn't bubble!");
   243 ok(!e.cancelable, "Event shouldn't be cancelable!");
   244 is(e.wasClean, false, "wasClean should be false!");
   245 is(e.code, 0, "code should be 0!");
   246 is(e.reason, "", "reason should be ''!");
   247 document.dispatchEvent(e);
   248 is(receivedEvent, e, "Wrong event!");
   250 e = new CloseEvent("hello",
   251   { bubbles: true, cancelable: true, wasClean: true, code: 1, reason: "foo" });
   252 is(e.type, "hello", "Wrong event type!");
   253 ok(!e.isTrusted, "Event shouldn't be trusted!");
   254 ok(e.bubbles, "Event should bubble!");
   255 ok(e.cancelable, "Event should be cancelable!");
   256 is(e.wasClean, true, "wasClean should be true!");
   257 is(e.code, 1, "code should be 1!");
   258 is(e.reason, "foo", "reason should be 'foo'!");
   259 document.dispatchEvent(e);
   260 is(receivedEvent, e, "Wrong event!");
   262 e = new CloseEvent("hello",
   263   { bubbles: true, cancelable: true, wasClean: true, code: 1 });
   264 is(e.type, "hello", "Wrong event type!");
   265 ok(!e.isTrusted, "Event shouldn't be trusted!");
   266 ok(e.bubbles, "Event should bubble!");
   267 ok(e.cancelable, "Event should be cancelable!");
   268 is(e.wasClean, true, "wasClean should be true!");
   269 is(e.code, 1, "code should be 1!");
   270 is(e.reason, "", "reason should be ''!");
   271 document.dispatchEvent(e);
   272 is(receivedEvent, e, "Wrong event!");
   275 // HashChangeEvent
   277 try {
   278   e = new HashChangeEvent();
   279 } catch(exp) {
   280   ex = true;
   281 }
   282 ok(ex, "First parameter is required!");
   283 ex = false;
   285 e = new HashChangeEvent("hello");
   286 is(e.type, "hello", "Wrong event type!");
   287 ok(!e.isTrusted, "Event shouldn't be trusted!");
   288 ok(!e.bubbles, "Event shouldn't bubble!");
   289 ok(!e.cancelable, "Event shouldn't be cancelable!");
   290 is(e.oldURL, "", "oldURL should be ''");
   291 is(e.newURL, "", "newURL should be ''");
   292 document.dispatchEvent(e);
   293 is(receivedEvent, e, "Wrong event!");
   295 e = new HashChangeEvent("hello",
   296   { bubbles: true, cancelable: true, oldURL: "old", newURL: "new" });
   297 is(e.type, "hello", "Wrong event type!");
   298 ok(!e.isTrusted, "Event shouldn't be trusted!");
   299 ok(e.bubbles, "Event should bubble!");
   300 ok(e.cancelable, "Event should be cancelable!");
   301 is(e.oldURL, "old", "oldURL should be 'old'");
   302 is(e.newURL, "new", "newURL should be 'new'");
   303 document.dispatchEvent(e);
   304 is(receivedEvent, e, "Wrong event!");
   306 e = new HashChangeEvent("hello",
   307   { bubbles: true, cancelable: true, newURL: "new" });
   308 is(e.type, "hello", "Wrong event type!");
   309 ok(!e.isTrusted, "Event shouldn't be trusted!");
   310 ok(e.bubbles, "Event should bubble!");
   311 ok(e.cancelable, "Event should be cancelable!");
   312 is(e.oldURL, "", "oldURL should be ''");
   313 is(e.newURL, "new", "newURL should be 'new'");
   314 document.dispatchEvent(e);
   315 is(receivedEvent, e, "Wrong event!");
   317 // InputEvent
   319 e = new InputEvent("hello");
   320 is(e.type, "hello", "Wrong event type!");
   321 ok(!e.isTrusted, "Event shouldn't be trusted!");
   322 ok(!e.bubbles, "Event shouldn't bubble!");
   323 ok(!e.cancelable, "Event shouldn't be cancelable!");
   324 is(e.detail, 0, "detail should be 0");
   325 ok(!e.isComposing, "isComposing should be false");
   327 e = new InputEvent("hi!", { bubbles: true, detail: 5, isComposing: false });
   328 is(e.type, "hi!", "Wrong event type!");
   329 ok(!e.isTrusted, "Event shouldn't be trusted!");
   330 ok(e.bubbles, "Event should bubble!");
   331 ok(!e.cancelable, "Event shouldn't be cancelable!");
   332 is(e.detail, 5, "detail should be 5");
   333 ok(!e.isComposing, "isComposing should be false");
   335 e = new InputEvent("hi!", { cancelable: true, detail: 0, isComposing: true });
   336 is(e.type, "hi!", "Wrong event type!");
   337 ok(!e.isTrusted, "Event shouldn't be trusted!");
   338 ok(!e.bubbles, "Event shouldn't bubble!");
   339 ok(e.cancelable, "Event should be cancelable!");
   340 is(e.detail, 0, "detail should be 0");
   341 ok(e.isComposing, "isComposing should be true");
   343 // KeyboardEvent
   345 try {
   346   e = new KeyboardEvent();
   347 } catch(exp) {
   348   ex = true;
   349 }
   350 ok(ex, "KeyboardEvent: First parameter is required!");
   351 ex = false;
   353 e = new KeyboardEvent("hello");
   354 ok(e.type, "hello", "KeyboardEvent: Wrong event type!");
   355 ok(!e.isTrusted, "KeyboardEvent: Event shouldn't be trusted!");
   356 ok(!e.bubbles, "KeyboardEvent: Event shouldn't bubble!");
   357 ok(!e.cancelable, "KeyboardEvent: Event shouldn't be cancelable!");
   358 document.dispatchEvent(e);
   359 is(receivedEvent, e, "KeyboardEvent: Wrong event!");
   361 var keyboardEventProps =
   362 [
   363   { bubbles: false },
   364   { cancelable: false },
   365   { view: null },
   366   { detail: 0 },
   367   { key: "" },
   368   { location: 0 },
   369   { ctrlKey: false },
   370   { shiftKey: false },
   371   { altKey: false },
   372   { metaKey: false },
   373   { repeat: false },
   374   { isComposing: false },
   375   { charCode: 0 },
   376   { keyCode: 0 },
   377   { which: 0 },
   378 ];
   380 var testKeyboardProps =
   381 [
   382   { bubbles: true },
   383   { cancelable: true },
   384   { view: window },
   385   { detail: 1 },
   386   { key: "CustomKey" },
   387   { location: 1 },
   388   { ctrlKey: true },
   389   { shiftKey: true },
   390   { altKey: true },
   391   { metaKey: true },
   392   { repeat: true },
   393   { isComposing: true },
   394   { charCode: 2 },
   395   { keyCode: 3 },
   396   { which: 4 },
   397   { charCode: 5, which: 6 },
   398   { keyCode: 7, which: 8 },
   399   { keyCode: 9, charCode: 10 },
   400   { keyCode: 11, charCode: 12, which: 13 },
   401 ];
   403 var defaultKeyboardEventValues = {};
   404 for (var i = 0; i < keyboardEventProps.length; ++i) {
   405   for (prop in keyboardEventProps[i]) {
   406     ok(prop in e, "keyboardEvent: KeyboardEvent doesn't have property " + prop + "!");
   407     defaultKeyboardEventValues[prop] = keyboardEventProps[i][prop]; 
   408   }
   409 }
   411 while (testKeyboardProps.length) {
   412   var p = testKeyboardProps.shift();
   413   e = new KeyboardEvent("foo", p);
   414   for (var def in defaultKeyboardEventValues) {
   415     if (!(def in p)) {
   416       is(e[def], defaultKeyboardEventValues[def],
   417          "KeyboardEvent: Wrong default value for " + def + "!");
   418     } else {
   419       is(e[def], p[def],
   420          "KeyboardEvent: Wrong event init value for " + def + "!");
   421     }
   422   }
   423 }
   425 // PageTransitionEvent
   427 try {
   428   e = new PageTransitionEvent();
   429 } catch(exp) {
   430   ex = true;
   431 }
   432 ok(ex, "First parameter is required!");
   433 ex = false;
   435 e = new PageTransitionEvent("hello");
   436 is(e.type, "hello", "Wrong event type!");
   437 ok(!e.isTrusted, "Event shouldn't be trusted!");
   438 ok(!e.bubbles, "Event shouldn't bubble!");
   439 ok(!e.cancelable, "Event shouldn't be cancelable!");
   440 is(e.persisted, false, "persisted should be false");
   441 document.dispatchEvent(e);
   442 is(receivedEvent, e, "Wrong event!");
   444 e = new PageTransitionEvent("hello",
   445   { bubbles: true, cancelable: true, persisted: true});
   446 is(e.type, "hello", "Wrong event type!");
   447 ok(!e.isTrusted, "Event shouldn't be trusted!");
   448 ok(e.bubbles, "Event should bubble!");
   449 ok(e.cancelable, "Event should be cancelable!");
   450 is(e.persisted, true, "persisted should be true");
   451 document.dispatchEvent(e);
   452 is(receivedEvent, e, "Wrong event!");
   454 e = new PageTransitionEvent("hello", { persisted: true});
   455 is(e.type, "hello", "Wrong event type!");
   456 ok(!e.isTrusted, "Event shouldn't be trusted!");
   457 ok(!e.bubbles, "Event shouldn't bubble!");
   458 ok(!e.cancelable, "Event shouldn't be cancelable!");
   459 is(e.persisted, true, "persisted should be true");
   460 document.dispatchEvent(e);
   461 is(receivedEvent, e, "Wrong event!");
   463 // PopStateEvent
   465 try {
   466   e = new PopStateEvent();
   467 } catch(exp) {
   468   ex = true;
   469 }
   470 ok(ex, "First parameter is required!");
   471 ex = false;
   473 e = new PopStateEvent("hello");
   474 is(e.type, "hello", "Wrong event type!");
   475 ok(!e.isTrusted, "Event shouldn't be trusted!");
   476 ok(!e.bubbles, "Event shouldn't bubble!");
   477 ok(!e.cancelable, "Event shouldn't be cancelable!");
   478 is(e.state, null, "persisted should be null");
   479 document.dispatchEvent(e);
   480 is(receivedEvent, e, "Wrong event!");
   482 e = new PopStateEvent("hello",
   483   { bubbles: true, cancelable: true, state: window});
   484 is(e.type, "hello", "Wrong event type!");
   485 ok(!e.isTrusted, "Event shouldn't be trusted!");
   486 ok(e.bubbles, "Event should bubble!");
   487 ok(e.cancelable, "Event should be cancelable!");
   488 is(e.state, window, "persisted should be window");
   489 document.dispatchEvent(e);
   490 is(receivedEvent, e, "Wrong event!");
   493 e = new PopStateEvent("hello", { state: window});
   494 is(e.type, "hello", "Wrong event type!");
   495 ok(!e.isTrusted, "Event shouldn't be trusted!");
   496 ok(!e.bubbles, "Event shouldn't bubble!");
   497 ok(!e.cancelable, "Event shouldn't be cancelable!");
   498 is(e.state, window, "persisted should be window");
   499 document.dispatchEvent(e);
   500 is(receivedEvent, e, "Wrong event!");
   502 // UIEvent
   504 try {
   505   e = new UIEvent();
   506 } catch(exp) {
   507   ex = true;
   508 }
   509 ok(ex, "First parameter is required!");
   510 ex = false;
   512 try {
   513   e = new UIEvent("foo", { view: {} });
   514   e.view.onunload;
   515 } catch(exp) {
   516   ex = true;
   517 }
   518 ok(ex, "{} isn't a valid value.");
   519 ex = false;
   521 try {
   522   e = new UIEvent("foo", { view: null });
   523 } catch(exp) {
   524   ex = true;
   525 }
   526 ok(!ex, "null is a valid value.");
   527 is(e.view, null);
   528 ex = false;
   530 e = new UIEvent("hello");
   531 is(e.type, "hello", "Wrong event type!");
   532 ok(!e.isTrusted, "Event shouldn't be trusted!");
   533 ok(!e.bubbles, "Event shouldn't bubble!");
   534 ok(!e.cancelable, "Event shouldn't be cancelable!");
   535 is(e.detail, 0, "detail should be 0");
   536 is(e.view, null, "view should be null");
   537 document.dispatchEvent(e);
   538 is(receivedEvent, e, "Wrong event!");
   540 e = new UIEvent("hello",
   541   { bubbles: true, cancelable: true, view: window, detail: 1});
   542 is(e.type, "hello", "Wrong event type!");
   543 ok(!e.isTrusted, "Event shouldn't be trusted!");
   544 ok(e.bubbles, "Event should bubble!");
   545 ok(e.cancelable, "Event should be cancelable!");
   546 is(e.detail, 1, "detail should be 1");
   547 is(e.view, window, "view should be window");
   548 document.dispatchEvent(e);
   549 is(receivedEvent, e, "Wrong event!");
   551 // StorageEvent
   553 e = document.createEvent("StorageEvent");
   554 ok(e, "Should have created an event!");
   556 try {
   557   e = new StorageEvent();
   558 } catch(exp) {
   559   ex = true;
   560 }
   561 ok(ex, "First parameter is required!");
   562 ex = false;
   564 e = new StorageEvent("hello");
   565 is(e.type, "hello", "Wrong event type!");
   566 ok(!e.isTrusted, "Event shouldn't be trusted!");
   567 ok(!e.bubbles, "Event shouldn't bubble!");
   568 ok(!e.cancelable, "Event shouldn't be cancelable!");
   569 is(e.key, null, "key should be null");
   570 is(e.oldValue, null, "oldValue should be null");
   571 is(e.newValue, null, "newValue should be null");
   572 is(e.url, "", "url should be ''");
   573 document.dispatchEvent(e);
   574 is(receivedEvent, e, "Wrong event!");
   576 e = new StorageEvent("hello",
   577   { bubbles: true, cancelable: true, key: "key",
   578     oldValue: "oldValue", newValue: "newValue", url: "url",
   579     storageArea: localStorage });
   580 is(e.type, "hello", "Wrong event type!");
   581 ok(!e.isTrusted, "Event shouldn't be trusted!");
   582 ok(e.bubbles, "Event should bubble!");
   583 ok(e.cancelable, "Event should be cancelable!");
   584 is(e.key, "key", "Wrong value");
   585 is(e.oldValue, "oldValue", "Wrong value");
   586 is(e.newValue, "newValue", "Wrong value");
   587 is(e.url, "url", "Wrong value");
   588 is(e.storageArea, localStorage, "Wrong value");
   589 document.dispatchEvent(e);
   590 is(receivedEvent, e, "Wrong event!");
   592 // DeviceProximityEvent
   593 e = new DeviceProximityEvent("hello", {min: 0, value: 1, max: 2});
   594 is(e.type, "hello", "Wrong event type!");
   595 ok(!e.isTrusted, "Event should not be trusted");
   596 is(e.value, 1, "value should be 1");
   597 is(e.min, 0, "min should be 0");
   598 is(e.max, 2, "max should be 2");
   599 document.dispatchEvent(e);
   600 is(receivedEvent, e, "Wrong event!");
   601 e = new DeviceProximityEvent("hello");
   602 is(e.value, Infinity, "Uninitialized value should be infinity");
   603 is(e.min, -Infinity, "Uninitialized min should be -infinity");
   604 is(e.max, Infinity, "Uninitialized max should be infinity");
   606 // UserProximityEvent
   607 e = new UserProximityEvent("hello", {near: true});
   608 is(e.type, "hello", "Wrong event type!");
   609 ok(!e.isTrusted, "Event should not be trusted");
   610 is(e.near, true, "near should be true");
   611 document.dispatchEvent(e);
   612 is(receivedEvent, e, "Wrong event!");
   614 // DeviceLightEvent
   615 e = new DeviceLightEvent("hello", {value: 1} );
   616 is(e.type, "hello", "Wrong event type!");
   617 ok(!e.isTrusted, "Event should not be trusted");
   618 is(e.value, 1, "value should be 1");
   619 document.dispatchEvent(e);
   620 is(receivedEvent, e, "Wrong event!");
   621 e = new DeviceLightEvent("hello", {value: Infinity} );
   622 is(e.value, Infinity, "value should be positive infinity");
   623 e = new DeviceLightEvent("hello", {value: -Infinity} );
   624 is(e.value, -Infinity, "value should be negative infinity");
   625 e = new DeviceLightEvent("hello");
   626 is(e.value, Infinity, "Uninitialized value should be positive infinity");
   628 // DeviceOrientationEvent
   629 e = new DeviceOrientationEvent("hello");
   630 is(e.type, "hello", "Wrong event type!");
   631 ok(!e.isTrusted, "Event should not be trusted");
   632 is(e.alpha, 0);
   633 is(e.beta, 0);
   634 is(e.gamma, 0);
   635 is(e.absolute, false);
   637 e = new DeviceOrientationEvent("hello", { alpha: 1, beta: 2, gamma: 3, absolute: true } );
   638 is(e.type, "hello", "Wrong event type!");
   639 ok(!e.isTrusted, "Event should not be trusted");
   640 is(e.alpha, 1);
   641 is(e.beta, 2);
   642 is(e.gamma, 3);
   643 is(e.absolute, true);
   644 document.dispatchEvent(e);
   645 is(receivedEvent, e, "Wrong event!");
   647 // MouseEvent
   649 try {
   650   e = new MouseEvent();
   651 } catch(exp) {
   652   ex = true;
   653 }
   654 ok(ex, "MouseEvent: First parameter is required!");
   655 ex = false;
   657 e = new MouseEvent("hello");
   658 is(e.type, "hello", "MouseEvent: Wrong event type!");
   659 ok(!e.isTrusted, "MouseEvent: Event shouldn't be trusted!");
   660 ok(!e.bubbles, "MouseEvent: Event shouldn't bubble!");
   661 ok(!e.cancelable, "MouseEvent: Event shouldn't be cancelable!");
   662 document.dispatchEvent(e);
   663 is(receivedEvent, e, "MouseEvent: Wrong event!");
   665 var mouseEventProps =
   666 [ { screenX: 0 },
   667   { screenY: 0 },
   668   { clientX: 0 },
   669   { clientY: 0 },
   670   { ctrlKey: false },
   671   { shiftKey: false },
   672   { altKey: false },
   673   { metaKey: false },
   674   { button: 0 },
   675   { buttons: 0 },
   676   { relatedTarget: null }
   677 ];
   679 var testProps =
   680 [
   681   { screenX: 1 },
   682   { screenY: 2 },
   683   { clientX: 3 },
   684   { clientY: 4 },
   685   { ctrlKey: true },
   686   { shiftKey: true },
   687   { altKey: true },
   688   { metaKey: true },
   689   { button: 5 },
   690   { buttons: 6 },
   691   { relatedTarget: window }
   692 ];
   694 var defaultMouseEventValues = {};
   695 for (var i = 0; i < mouseEventProps.length; ++i) {
   696   for (prop in mouseEventProps[i]) {
   697     ok(prop in e, "MouseEvent: MouseEvent doesn't have property " + prop + "!");
   698     defaultMouseEventValues[prop] = mouseEventProps[i][prop]; 
   699   }
   700 }
   702 while (testProps.length) {
   703   var p = testProps.shift();
   704   e = new MouseEvent("foo", p);
   705   for (var def in defaultMouseEventValues) {
   706     if (!(def in p)) {
   707       is(e[def], defaultMouseEventValues[def],
   708          "MouseEvent: Wrong default value for " + def + "!");
   709     } else {
   710       is(e[def], p[def], "MouseEvent: Wrong event init value for " + def + "!");
   711     }
   712   }
   713 }
   715 // PopupBlockedEvent
   717 try {
   718   e = new PopupBlockedEvent();
   719 } catch(exp) {
   720   ex = true;
   721 }
   722 ok(ex, "PopupBlockedEvent: First parameter is required!");
   723 ex = false;
   725 e = new PopupBlockedEvent("hello");
   726 is(e.type, "hello", "PopupBlockedEvent: Wrong event type!");
   727 ok(!e.isTrusted, "PopupBlockedEvent: Event shouldn't be trusted!");
   728 ok(!e.bubbles, "PopupBlockedEvent: Event shouldn't bubble!");
   729 ok(!e.cancelable, "PopupBlockedEvent: Event shouldn't be cancelable!");
   730 document.dispatchEvent(e);
   731 is(receivedEvent, e, "PopupBlockedEvent: Wrong event!");
   733 e = new PopupBlockedEvent("hello",
   734                           { requestingWindow: window,
   735                             popupWindowFeatures: "features",
   736                             popupWindowName: "name"
   737                           });
   738 is(e.requestingWindow, window);
   739 is(e.popupWindowFeatures, "features");
   740 is(e.popupWindowName, "name");
   743 // SmartCardEvent
   745 try {
   746   e = new SmartCardEvent();
   747 } catch(exp) {
   748   ex = true;
   749 }
   750 ok(ex, "SmartCardEvent: First parameter is required!");
   751 ex = false;
   753 e = new SmartCardEvent("hello");
   754 is(e.type, "hello", "SmartCardEvent: Wrong event type!");
   755 ok(!e.isTrusted, "SmartCardEvent: Event shouldn't be trusted!");
   756 ok(!e.bubbles, "SmartCardEvent: Event shouldn't bubble!");
   757 ok(!e.cancelable, "SmartCardEvent: Event shouldn't be cancelable!");
   758 is(e.tokenName, "");
   759 document.dispatchEvent(e);
   760 is(receivedEvent, e, "SmartCardEvent: Wrong event!");
   762 e = new SmartCardEvent("hello", { tokenName: "foo" });
   763 is(e.tokenName, "foo");
   765 // WheelEvent
   767 try {
   768   e = new WheelEvent();
   769 } catch(exp) {
   770   ex = true;
   771 }
   772 ok(ex, "WheelEvent: First parameter is required!");
   773 ex = false;
   775 e = new WheelEvent("hello");
   776 is(e.type, "hello", "WheelEvent: Wrong event type!");
   777 ok(!e.isTrusted, "WheelEvent: Event shouldn't be trusted!");
   778 ok(!e.bubbles, "WheelEvent: Event shouldn't bubble!");
   779 ok(!e.cancelable, "WheelEvent: Event shouldn't be cancelable!");
   780 document.dispatchEvent(e);
   781 is(receivedEvent, e, "WheelEvent: Wrong event!");
   783 var wheelEventProps =
   784 [ { screenX: 0 },
   785   { screenY: 0 },
   786   { clientX: 0 },
   787   { clientY: 0 },
   788   { ctrlKey: false },
   789   { shiftKey: false },
   790   { altKey: false },
   791   { metaKey: false },
   792   { button: 0 },
   793   { buttons: 0 },
   794   { relatedTarget: null },
   795   { deltaX: 0.0 },
   796   { deltaY: 0.0 },
   797   { deltaZ: 0.0 },
   798   { deltaMode: 0 }
   799 ];
   801 var testWheelProps =
   802 [
   803   { screenX: 1 },
   804   { screenY: 2 },
   805   { clientX: 3 },
   806   { clientY: 4 },
   807   { ctrlKey: true },
   808   { shiftKey: true },
   809   { altKey: true },
   810   { metaKey: true },
   811   { button: 5 },
   812   { buttons: 6 },
   813   { relatedTarget: window },
   814   { deltaX: 7.8 },
   815   { deltaY: 9.1 },
   816   { deltaZ: 2.3 },
   817   { deltaMode: 4 }
   818 ];
   820 var defaultWheelEventValues = {};
   821 for (var i = 0; i < wheelEventProps.length; ++i) {
   822   for (prop in wheelEventProps[i]) {
   823     ok(prop in e, "WheelEvent: WheelEvent doesn't have property " + prop + "!");
   824     defaultWheelEventValues[prop] = wheelEventProps[i][prop]; 
   825   }
   826 }
   828 while (testWheelProps.length) {
   829   var p = testWheelProps.shift();
   830   e = new WheelEvent("foo", p);
   831   for (var def in defaultWheelEventValues) {
   832     if (!(def in p)) {
   833       is(e[def], defaultWheelEventValues[def],
   834          "WheelEvent: Wrong default value for " + def + "!");
   835     } else {
   836       is(e[def], p[def], "WheelEvent: Wrong event init value for " + def + "!");
   837     }
   838   }
   839 }
   841 // TransitionEvent
   842 e = new TransitionEvent("hello", { propertyName: "color", elapsedTime: 3.5, pseudoElement: "", foobar: "baz" })
   843 is("propertyName" in e, true, "Transition events have propertyName property");
   844 is("foobar" in e, false, "Transition events do not copy random properties from event init");
   845 is(e.propertyName, "color", "Transition event copies propertyName from TransitionEventInit");
   846 is(e.elapsedTime, 3.5, "Transition event copies elapsedTime from TransitionEventInit");
   847 is(e.pseudoElement, "", "Transition event copies pseudoElement from TransitionEventInit");
   848 is(e.bubbles, false, "Lack of bubbles property in TransitionEventInit");
   849 is(e.cancelable, false, "Lack of cancelable property in TransitionEventInit");
   850 is(e.type, "hello", "Wrong event type!");
   851 is(e.isTrusted, false, "Event shouldn't be trusted!");
   852 is(e.eventPhase, Event.NONE, "Wrong event phase");
   854 // AnimationEvent
   855 e = new AnimationEvent("hello", { animationName: "bounce3", elapsedTime: 3.5, pseudoElement: "", foobar: "baz" })
   856 is("animationName" in e, true, "Animation events have animationName property");
   857 is("foobar" in e, false, "Animation events do not copy random properties from event init");
   858 is(e.animationName, "bounce3", "Animation event copies animationName from AnimationEventInit");
   859 is(e.elapsedTime, 3.5, "Animation event copies elapsedTime from AnimationEventInit");
   860 is(e.pseudoElement, "", "Animation event copies pseudoElement from AnimationEventInit");
   861 is(e.bubbles, false, "Lack of bubbles property in AnimationEventInit");
   862 is(e.cancelable, false, "Lack of cancelable property in AnimationEventInit");
   863 is(e.type, "hello", "Wrong event type!");
   864 is(e.isTrusted, false, "Event shouldn't be trusted!");
   865 is(e.eventPhase, Event.NONE, "Wrong event phase");
   867 </script>
   868 </pre>
   869 </body>
   870 </html>

mercurial