| <html> |
| <head> |
| <script src="../fast/js/resources/js-test-pre.js"></script> |
| <style> |
| .testcontainer { position: absolute; top: 0px; left: 0px; font: 16px Ahem; line-height: 20px } |
| </style> |
| </head> |
| <body onload="runTests()"> |
| |
| <div class=testcontainer> |
| <p style="width: 22em;"> |
| <a id="1" href="#1">some link</a><br> |
| <a id="2" href="#2">some link breaking lines</a> and <a id="3" href="#3">link</a><br> |
| hola mundo! <a id="4" href="#4">a split up link</a><br> |
| hello world <a id="5" href="#5">some link also breaking</a><br> |
| hi there <a id="6" href="#6">some link that is breaking multiple lines just for the very fun of it</a><br><br> |
| </p> |
| </div> |
| |
| |
| <p id='description'></p> |
| <div id='console'></div> |
| |
| <script> |
| var element; |
| var adjustedNode; |
| function testRoundTouch(x, y, radius) |
| { |
| var x = x - radius; |
| var y = y - radius; |
| var width = radius * 2; |
| var height = radius * 2; |
| var adjustedNode = internals.touchNodeAdjustedToBestClickableNode(x, y, width, height, document); |
| if (adjustedNode && adjustedNode.nodeType == 3) // TEXT node |
| adjustedNode = adjustedNode.parentNode; |
| return adjustedNode; |
| } |
| |
| function testDirectTouches() |
| { |
| debug('Test some direct hits.'); |
| |
| adjustedNode = testRoundTouch(30, 25, 10) |
| shouldBeEqualToString('adjustedNode.id', '1'); |
| |
| adjustedNode = testRoundTouch(20, 65, 10) |
| shouldBeEqualToString('adjustedNode.id', '2'); |
| |
| adjustedNode = testRoundTouch(220, 85, 10) |
| shouldBeEqualToString('adjustedNode.id', '4'); |
| |
| adjustedNode = testRoundTouch(80, 195, 10) |
| shouldBeEqualToString('adjustedNode.id', '6'); |
| } |
| |
| function testDirectMisses() |
| { |
| debug('Test a few direct misses.'); |
| |
| // Hit 'and' betwen link 2 and 3 |
| adjustedNode = testRoundTouch(120, 75, 6) |
| shouldBeNull('adjustedNode'); |
| |
| // Hit 'hi there' above and to the left of link 6. |
| adjustedNode = testRoundTouch(72, 166, 6) |
| shouldBeNull('adjustedNode'); |
| |
| } |
| |
| function testIndirectTouches() |
| { |
| debug('Test some in-direct hits.'); |
| |
| adjustedNode = testRoundTouch(50, 60, 20) |
| shouldBeEqualToString('adjustedNode.id', '2'); |
| |
| adjustedNode = testRoundTouch(172, 82, 20) |
| shouldBeEqualToString('adjustedNode.id', '3'); |
| |
| adjustedNode = testRoundTouch(230, 74, 20) |
| shouldBeEqualToString('adjustedNode.id', '4'); |
| |
| adjustedNode = testRoundTouch(30, 100, 20) |
| shouldBeEqualToString('adjustedNode.id', '4'); |
| |
| adjustedNode = testRoundTouch(24, 170, 20) |
| shouldBeEqualToString('adjustedNode.id', '6'); |
| |
| } |
| |
| function runTests() |
| { |
| if (window.testRunner && window.internals && internals.touchNodeAdjustedToBestClickableNode) { |
| description('Test touch-adjustment on inline links. Making sure we can hit over line-breaks, and can miss when tapping between parts of a line-broken link.'); |
| testRunner.dumpAsText(); |
| testRunner.waitUntilDone(); |
| testDirectTouches(); |
| testDirectMisses(); |
| testIndirectTouches(); |
| isSuccessfullyParsed(); |
| testRunner.notifyDone(); |
| } |
| } |
| </script> |
| </body> |
| </html> |