| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
| 5 | <title>dojox.gesture.swipe Unit Test</title> |
| 6 | </head> |
| 7 | <style type="text/css"> |
| 8 | @import "../../../../util/doh/robot/robot.css"; |
| 9 | |
| 10 | #outer { |
| 11 | width: 350px; |
| 12 | height: 200px; |
| 13 | border: 1px solid #54A201; |
| 14 | background-color: #54A201; |
| 15 | } |
| 16 | #inner { |
| 17 | width: 250px; |
| 18 | height: 80px; |
| 19 | border: 1px solid #7FB0DB; |
| 20 | background-color: #7FB0DB |
| 21 | } |
| 22 | |
| 23 | </style> |
| 24 | <script type="text/javascript" src="../../../../dojo/dojo.js" data-dojo-config="isDebug:true"></script> |
| 25 | <script type="text/javascript"> |
| 26 | require([ |
| 27 | "dojo/_base/html", |
| 28 | "dojo/ready", |
| 29 | "dojo/on", |
| 30 | "doh/runner", |
| 31 | "dojox/gesture/swipe" |
| 32 | ], function(html, ready, on, doh, swipe){ |
| 33 | ready(function(){ |
| 34 | var inner = html.byId("inner"); |
| 35 | var h1, h2; |
| 36 | doh.register("dojox.gesture.swipe", [ |
| 37 | function swipe_swipeEnd(){ |
| 38 | var executed, endExecuted; |
| 39 | var swipeType, swipeTarget, swipeDx, swipeDy; |
| 40 | h1 = on(inner, swipe, function(e){ |
| 41 | executed = true; |
| 42 | swipeType = e.type; |
| 43 | swipeTarget = e.target; |
| 44 | swipeDx = e.dx; |
| 45 | swipeDy = e.dy; |
| 46 | }); |
| 47 | var swipeEndType, swipeEndTarget, swipeEndDx, swipeEndDy; |
| 48 | h2 = on(inner, swipe.end, function(e){ |
| 49 | endExecuted = true; |
| 50 | swipeEndType = e.type; |
| 51 | swipeEndTarget = e.target; |
| 52 | swipeEndDx = e.dx; |
| 53 | swipeEndDy = e.dy; |
| 54 | }); |
| 55 | on.emit(inner, 'mousedown', {screenX: 100, screenY: 200}); |
| 56 | on.emit(inner, 'mousemove', {screenX: 260, screenY: 100}); |
| 57 | on.emit(inner, 'mouseup', {screenX: 300, screenY: 80}); |
| 58 | |
| 59 | // swipe assertions |
| 60 | doh.assertEqual('swipe', swipeType); |
| 61 | doh.assertEqual(inner, swipeTarget); |
| 62 | doh.assertEqual(160, swipeDx); |
| 63 | doh.assertEqual(-100, swipeDy); |
| 64 | |
| 65 | // swipe.end assertions |
| 66 | doh.assertEqual('swipe.end', swipeEndType); |
| 67 | doh.assertEqual(inner, swipeEndTarget); |
| 68 | doh.assertEqual(200, swipeEndDx); |
| 69 | doh.assertEqual(-120, swipeEndDy); |
| 70 | |
| 71 | doh.assertTrue(executed, 'dojox.gesture.swipe not fired!'); |
| 72 | doh.assertTrue(endExecuted, 'dojox.gesture.swipe.end not fired!'); |
| 73 | }, |
| 74 | function disconnect(){ |
| 75 | var elements = swipe._elements; |
| 76 | h1.remove(); |
| 77 | doh.assertTrue(elements[0].handles.swipe === 0, 'dojox.gesture.swipe handle not cleared!'); |
| 78 | |
| 79 | h2.remove(); |
| 80 | doh.assertTrue(elements.length === 0, 'dojox.gesture.swipe elements not cleared!'); |
| 81 | }, |
| 82 | function destroy(){ |
| 83 | //re-connect them back |
| 84 | h1 = on(inner, swipe, function(e){ }); |
| 85 | h2 = on(inner, swipe.end, function(e){ }); |
| 86 | //destroy them all |
| 87 | swipe.destroy(); |
| 88 | doh.assertTrue(swipe._elements === null, 'dojox.gesture.swipe not destroyed!'); |
| 89 | } |
| 90 | ]); |
| 91 | doh.run(); |
| 92 | }); |
| 93 | }); |
| 94 | </script> |
| 95 | <body class='claro'> |
| 96 | <div id="outer"> |
| 97 | outer<div id="inner">inner</div> |
| 98 | </div> |
| 99 | </body> |
| 100 | </html> |