1 var inputEventCounter = 0;
2 var changeEventCounter = 0;
5 function testSpinButtonChangeAndInputEvents(inputType, initialValue, expectedValue, maximumValue)
7 description('Test for event dispatching by spin buttons in a type=' + inputType + ' input.');
8 if (!window.eventSender) {
9 debug('No eventSender');
13 var parent = document.createElement('div');
14 document.body.appendChild(parent);
15 parent.innerHTML = '<input id=test><input id=another>';
16 testInput = document.getElementById('test');
17 var anotherInput = document.getElementById('another');
19 testInput.type = inputType;
20 if (maximumValue != undefined)
21 testInput.setAttribute("max", maximumValue);
22 testInput.setAttribute("value", initialValue);
23 testInput.onchange = function() { changeEventCounter++; };
24 testInput.oninput = function() { inputEventCounter++; };
26 debug('Initial state');
27 eventSender.mouseMoveTo(0, 0);
28 shouldEvaluateTo('changeEventCounter', 0);
29 shouldEvaluateTo('inputEventCounter', 0);
32 debug('Click the upper button');
33 // Move the cursor on the upper button.
34 var spinButton = getElementByPseudoId(internals.oldestShadowRoot(testInput), "-webkit-inner-spin-button");
35 eventSender.mouseMoveTo(testInput.offsetLeft + spinButton.offsetLeft, testInput.offsetTop + testInput.offsetHeight / 4);
36 eventSender.mouseDown();
37 debug('Triggers only input event on mouseDown');
38 shouldBeEqualToString('testInput.value', expectedValue);
39 shouldEvaluateTo('changeEventCounter', 0);
40 shouldEvaluateTo('inputEventCounter', 1);
41 debug('Triggers only change event on mouseUp');
42 eventSender.mouseUp();
43 shouldBeEqualToString('testInput.value', expectedValue);
44 shouldEvaluateTo('changeEventCounter', 1);
45 shouldEvaluateTo('inputEventCounter', 1);
47 if (testInput.hasAttribute("max")) {
48 debug('Click again, but the value is not changed.');
49 eventSender.mouseDown();
50 eventSender.mouseUp();
51 shouldBeEqualToString('testInput.value', expectedValue);
52 shouldEvaluateTo('changeEventCounter', 1);
53 shouldEvaluateTo('inputEventCounter', 1);
56 debug('Focus on another field');
58 shouldEvaluateTo('changeEventCounter', 1);
59 shouldEvaluateTo('inputEventCounter', 1);
61 parent.innerHTML = '';