|
2 | 2 | <html>
|
3 | 3 | <head>
|
4 | 4 | <title>touchscreen_test</title>
|
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
5 | 6 | <script src="test_bootstrap.js"></script>
|
6 | 7 | <script type="text/javascript">
|
7 | 8 | goog.require('bot.Touchscreen');
|
8 | 9 | goog.require('bot.action');
|
| 10 | + goog.require('bot.dom'); |
| 11 | + goog.require('goog.Promise'); |
9 | 12 | goog.require('goog.events');
|
10 | 13 | goog.require('goog.events.EventType');
|
11 | 14 | goog.require('goog.math.Coordinate');
|
|
18 | 21 | var lowerTarget;
|
19 | 22 | var innerCaptureTarget;
|
20 | 23 | var noTouchTarget;
|
| 24 | + var coordsTarget; |
21 | 25 |
|
22 | 26 | var touchscreen;
|
23 | 27 | var events = [];
|
|
45 | 49 | captureTarget = document.getElementById('captureTarget');
|
46 | 50 | innerCaptureTarget = document.getElementById('innerCaptureTarget');
|
47 | 51 | noTouchTarget = document.getElementById('notouch');
|
| 52 | + coordsTarget = document.getElementById('coordsTarget'); |
48 | 53 | }
|
49 | 54 |
|
50 | 55 | function setUp() {
|
|
55 | 60 | goog.events.removeAll(captureTarget);
|
56 | 61 | goog.events.removeAll(innerCaptureTarget);
|
57 | 62 | goog.events.removeAll(noTouchTarget);
|
| 63 | + goog.events.removeAll(coordsTarget); |
58 | 64 |
|
59 | 65 | goog.events.listen(target, TOUCH_EVENTS, function(e) {
|
60 | 66 | events.push(e.type);
|
|
81 | 87 | events.push(e.type);
|
82 | 88 | events.push(e.target);
|
83 | 89 | });
|
| 90 | + goog.events.listen(coordsTarget, goog.events.EventType.TOUCHSTART, |
| 91 | + function(e) { |
| 92 | + var event = e.getBrowserEvent(); |
| 93 | + if (event.changedTouches.length == 1) { |
| 94 | + events.push(event.changedTouches[0].clientX); |
| 95 | + events.push(event.changedTouches[0].clientY); |
| 96 | + events.push(event.changedTouches[0].pageX); |
| 97 | + events.push(event.changedTouches[0].pageY); |
| 98 | + } |
| 99 | + }); |
84 | 100 | }
|
85 | 101 |
|
86 | 102 | function msPointerDownEvents(elem) {
|
|
458 | 474 | assertEvents(events);
|
459 | 475 | }
|
460 | 476 | }
|
| 477 | + |
| 478 | + function testTouchEventCoords() { |
| 479 | + if (!bot.events.SUPPORTS_TOUCH_EVENTS || bot.userAgent.IE_DOC_10) { |
| 480 | + return; |
| 481 | + } |
| 482 | + window.scrollTo(20, 30); |
| 483 | + // Yield to ensure all browsers apply the scrolling change. |
| 484 | + // Relying on the implicit tick in a promise resolution is enough. |
| 485 | + return goog.Promise.resolve().then(function() { |
| 486 | + var coords = bot.dom.getClientRect(coordsTarget); |
| 487 | + touchscreen.move(coordsTarget, new goog.math.Coordinate(0, 0)); |
| 488 | + touchscreen.press(); |
| 489 | + touchscreen.release(); |
| 490 | + // The client coords of the touch event should be the top left of the |
| 491 | + // target and the page coords should include the scroll offset. |
| 492 | + assertEvents([coords.left, coords.top, |
| 493 | + coords.left + 20, coords.top + 30]); |
| 494 | + }); |
| 495 | + } |
461 | 496 | </script>
|
462 | 497 | </head>
|
463 | 498 | <body>
|
|
502 | 537 | -ms-touch-action:auto">
|
503 | 538 | no touch
|
504 | 539 | </div>
|
| 540 | + <div id="coordsTarget" |
| 541 | + style="background-color:magenta; |
| 542 | + width:8000px; |
| 543 | + height:8000px; |
| 544 | + -ms-touch-action:none"> |
| 545 | + coords target |
| 546 | + </div> |
505 | 547 | </body>
|
506 | 548 | </html>
|
0 commit comments