4 <title>Touch Adjustment : Testing that a drag/drop will start on a long press - bug
92914</title>
5 <script src=
"../resources/js-test.js"></script>
6 <script src=
"resources/touchadjustment.js"></script>
19 <p><a href=
"" id=
"link1">I
</a> propose to consider
<a href=
"" id=
"link2">the question
</a>,
"Can machines think?"<br>This should begin with definitions of the meaning of the terms
"machine" and
<a href=
"" id=
"link3">"think."</a></p>
22 <p id='description'
></p>
23 <div id='console'
></div>
28 // Set up shortcut access to elements
30 ['sandbox', 'link1', 'link2', 'link3'].forEach(function(a
) {
31 e
[a
] = document
.getElementById(a
);
34 document
.ondragstart = function(e
) { debug("PASS"); e
.preventDefault();}
36 function testLongPress(touchpoint
)
38 if (eventSender
.gestureLongPress
)
39 eventSender
.gestureLongPress(touchpoint
.x
, touchpoint
.y
, touchpoint
.width
, touchpoint
.height
);
41 debug("gestureLongPress not implemented by this platform.");
44 function testDirectTouch(element
)
46 // Touch directly in the center of the element.
47 var touchpoint
= offsetTouchPoint(findAbsoluteBounds(element
), 'center', 0, 20, 30);
48 if (document
.elementFromPoint(touchpoint
.x
, touchpoint
.y
) != element
)
49 testFailed('Direct touch ended up on some other element');
50 testLongPress(touchpoint
);
53 function testIndirectTouch(element
)
55 // Touch just right of the element.
56 var touchpoint
= offsetTouchPoint(findAbsoluteBounds(element
), 'right', 10, 30, 20);
57 if (isDescendantOf(element
, document
.elementFromPoint(touchpoint
.x
, touchpoint
.y
)))
58 testFailed('Indirect touch ended up still on top of the element');
59 testLongPress(touchpoint
);
62 function isDescendantOf(parent
, child
)
73 function testDirectTouches()
75 debug('Testing direct hits.');
76 testDirectTouch(e
.link1
);
77 testDirectTouch(e
.link2
);
78 testDirectTouch(e
.link3
);
81 function testIndirectTouches()
83 debug('Testing indirect hits.');
84 testIndirectTouch(e
.link1
);
85 testIndirectTouch(e
.link2
);
86 testIndirectTouch(e
.link3
);
91 if (window
.testRunner
&& window
.internals
&& internals
.touchNodeAdjustedToBestClickableNode
) {
92 internals
.settings
.setTouchDragDropEnabled(true);
93 description('Tests if a long press gesture on links will trigger a drag/drop when touch adjustment is used.');
95 testIndirectTouches();
96 e
.sandbox
.style
.display
= 'none';