2 <title>Touch Adjustment: Shouldn't return pseudo elements - bug 395942</title>
3 <script src="../resources/js-test.js"></script>
4 <script src="resources/touchadjustment.js"></script>
14 background-color: blue;
23 <p id='description'></p>
24 <div id='console'></div>
33 function runTouchTests() {
34 element = document.getElementById("targetDiv");
35 element.addEventListener('click', function() {}, false);
36 document.addEventListener('click', function() {}, false);
38 targetBounds = findAbsoluteBounds(element);
40 // Adjust for offset to the pseudo element
42 left: targetBounds.left + 50,
43 top: targetBounds.top,
49 var offset = touchRadius / 2;
50 var midX = targetBounds.left + targetBounds.width / 2;
51 var midY = targetBounds.top + targetBounds.height / 2;
53 debug('Test touch area contained within the pseudo element.');
54 testTouch(midX, midY, touchRadius, targetBounds);
57 debug('Overlapping touch above the target should snap to the top of the pseudo element.');
58 testTouch(midX, targetBounds.top - offset, touchRadius, targetBounds);
61 debug('Overlapping touch below the target should snap to the bottom of the pseudo element.');
62 testTouch(midX, targetBounds.top + targetBounds.height + offset, touchRadius, targetBounds);
65 debug('Overlapping touch left of the target should snap to the left side of the pseudo element.');
66 testTouch(targetBounds.left - offset, midY, touchRadius, targetBounds);
69 debug('Overlapping touch right of the target should snap to the right side of the pseudo element.');
70 testTouch(targetBounds.left + targetBounds.width + offset, midY, touchRadius, targetBounds);
74 function testTouch(touchX, touchY, radius, targetBounds) {
82 adjustedNode = internals.touchNodeAdjustedToBestClickableNode(touchBounds.x, touchBounds.y, touchBounds.width, touchBounds.height, document);
83 shouldBe('adjustedNode.id', 'element.id');
84 adjustedPoint = internals.touchPositionAdjustedToBestClickableNode(touchBounds.x, touchBounds.y, touchBounds.width, touchBounds.height, document);
86 shouldBeTrue('adjustedPoint.x >= targetBounds.left');
87 shouldBeTrue('adjustedPoint.x <= targetBounds.left + targetBounds.width');
88 shouldBeTrue('adjustedPoint.y >= targetBounds.top');
89 shouldBeTrue('adjustedPoint.y <= targetBounds.top + targetBounds.height');
90 shouldBeTrue('adjustedPoint.x >= touchBounds.x');
91 shouldBeTrue('adjustedPoint.x <= touchBounds.x + touchBounds.width');
92 shouldBeTrue('adjustedPoint.y >= touchBounds.y');
93 shouldBeTrue('adjustedPoint.y <= touchBounds.y + touchBounds.height');
96 description('Test touch adjustment over pseudo elements. Pseudo elements should be candidates for adjustment, but should not themselves be returned as valid target nodes.');
98 if (window.internals) {