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

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

mercurial