3 <script src=
"../../resources/js-test.js"></script>
18 margin: -
90px
0 0 100px;
21 border:
1px solid silver;
33 #test2
> div
> input {
41 display: inline-block;
53 <input type=
"text" value=
"input">
56 <div id=
"console"></div>
60 function isAcceptable(expected
, result
)
62 for (var i
= 0; i
< 4; i
++) {
63 if (Math
.abs(expected
[i
] - result
[i
]) > TOLERANCE
)
69 function simulateElementClick(element
, expected
)
71 element
.scrollIntoView(true);
72 if (!window
.eventSender
)
73 return 'This test requires eventSender';
76 function listener(event
)
78 result
= [event
.offsetX
, event
.offsetY
, event
.layerX
, event
.layerY
];
81 var rect
= element
.getBoundingClientRect();
82 element
.addEventListener('click', listener
, false);
83 eventSender
.mouseMoveTo(rect
.left
+ rect
.width
/ 2, rect
.top
+ rect
.height
/ 2);
84 eventSender
.mouseDown();
85 eventSender
.mouseUp();
86 element
.removeEventListener('click', listener
, false);
88 if (result
&& isAcceptable(expected
, result
))
89 return expected
.join(', ');
91 return result
.join(', ');
94 var testElement
= document
.getElementById('test1');
95 var spanElement
= testElement
.getElementsByTagName('span')[0];
96 var testElement2
= document
.getElementById('test2');
97 var inputElement
= testElement2
.getElementsByTagName('input')[0];
99 shouldBe("simulateElementClick(testElement, [100, 100, 200, 200]);", "'100, 100, 200, 200'");
100 shouldBe("simulateElementClick(spanElement, [16, 10, 16, 10]);", "'16, 10, 16, 10'");
101 shouldBe("simulateElementClick(inputElement, [40, 10, 40, 10]);", "'40, 10, 40, 10'");