dom/events/test/test_bug648573.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=648573 
     5 -->
     6 <head>
     7   <title>Test for Bug 648573</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=648573">Mozilla Bug 648573</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 648573 **/
    22 var utils = SpecialPowers.getDOMWindowUtils(window);
    24 ok(!utils.mayHaveTouchEventListeners,
    25   "There shouldn't be any touch event listeners yet.");
    27 ok("createTouch" in document, "Should have createTouch function");
    28 ok("createTouchList" in document, "Should have createTouchList function");
    29 ok(document.createEvent("touchevent"), "Should be able to create TouchEvent objects");
    31 var t1 = document.createTouch(window, document, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
    32 is(t1.target, document, "Wrong target");
    33 is(t1.identifier, 1, "Wrong identifier");
    34 is(t1.pageX, 2, "Wrong pageX");
    35 is(t1.pageY, 3, "Wrong pageY");
    36 is(t1.screenX, 4, "Wrong screenX");
    37 is(t1.screenY, 5, "Wrong screenY");
    38 is(t1.clientX, 6, "Wrong clientX");
    39 is(t1.clientY, 7, "Wrong clientY");
    40 is(t1.radiusX, 8, "Wrong radiusX");
    41 is(t1.radiusY, 9, "Wrong radiusY");
    42 is(t1.rotationAngle, 10, "Wrong rotationAngle");
    43 is(t1.force, 11, "Wrong force");
    45 var t2 = document.createTouch();
    47 var l1 = document.createTouchList(t1);
    48 is(l1.length, 1, "Wrong length");
    49 is(l1.item(0), t1, "Wront item (1)");
    50 is(l1[0], t1, "Wront item (2)");
    52 var l2 = document.createTouchList([t1, t2]);
    53 is(l2.length, 2, "Wrong length");
    54 is(l2.item(0), t1, "Wront item (3)");
    55 is(l2.item(1), t2, "Wront item (4)");
    56 is(l2[0], t1, "Wront item (5)");
    57 is(l2[1], t2, "Wront item (6)");
    59 var l3 = document.createTouchList();
    61 var e = document.createEvent("touchevent");
    62 e.initTouchEvent("touchmove", true, true, window, 0, true, true, true, true,
    63                  l1, l2, l3);
    64 is(e.touches, l1, "Wrong list (1)");
    65 is(e.targetTouches, l2, "Wrong list (2)");
    66 is(e.changedTouches, l3, "Wrong list (3)");
    67 ok(e.altKey, "Alt should be true");
    68 ok(e.metaKey, "Meta should be true");
    69 ok(e.ctrlKey, "Ctrl should be true");
    70 ok(e.shiftKey, "Shift should be true");
    73 var events =
    74   ["touchstart",
    75    "touchend",
    76    "touchmove",
    77    "touchenter",
    78    "touchleave",
    79    "touchcancel"];
    81 function runEventTest(type) {
    82   var e = document.createEvent("touchevent");
    83   e.initTouchEvent(type, true, true, window, 0, true, true, true, true,
    84                    l1, l2, l3);
    85   var t = document.createElement("div");
    86   // Testing target.onFoo;
    87   var didCall = false;
    88   t["on" + type] = function (evt) {                       
    89     is(evt, e, "Wrong event");
    90     evt.target.didCall = true;
    91   }
    92   t.dispatchEvent(e);
    93   ok(t.didCall, "Should have called the listener(1)");
    95   // Testing <element onFoo="">
    96   t = document.createElement("div");
    97   t.setAttribute("on" + type, "this.didCall = true;");
    98   t.dispatchEvent(e);
    99   ok(t.didCall, "Should have called the listener(2)");
   100 }
   102 for (var i = 0; i < events.length; ++i) {
   103   runEventTest(events[i]);
   104 }
   106 ok(utils.mayHaveTouchEventListeners,
   107   "There should be touch event listeners.");
   108 </script>
   109 </pre>
   110 </body>
   111 </html>

mercurial