test_bug1261674-1.html (4055B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1261674 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1261674</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <script src="/tests/SimpleTest/EventUtils.js"></script> 11 <script src="/tests/SimpleTest/paint_listener.js"></script> 12 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 13 </head> 14 <body> 15 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1261674">Mozilla Bug 1261674</a> 16 <p id="display"></p> 17 <div id="content" style="display: none"> 18 </div> 19 <input id="test_input" type="range" value=5 max=10 min=0> 20 <script type="text/javascript"> 21 22 /** Test for Bug 1261674 */ 23 SimpleTest.waitForExplicitFinish(); 24 SimpleTest.waitForFocus(runTests); 25 26 function runTests() { 27 let input = window.document.getElementById("test_input"); 28 29 // focus: whether the target input element is focused 30 // deltaY: deltaY of WheelEvent 31 // deltaMode: deltaMode of WheelEvent 32 // valueChanged: expected value changes after input element handled the wheel event 33 let params = [ 34 {focus: true, deltaY: 1.0, deltaMode: WheelEvent.DOM_DELTA_LINE, valueChanged: -1}, 35 {focus: true, deltaY: -1.0, deltaMode: WheelEvent.DOM_DELTA_LINE, valueChanged: 1}, 36 {focus: true, deltaY: 1.0, deltaMode: WheelEvent.DOM_DELTA_PAGE, valueChanged: -1}, 37 {focus: true, deltaY: -1.0, deltaMode: WheelEvent.DOM_DELTA_PAGE, valueChanged: 1}, 38 {focus: true, deltaY: 1.0, deltaMode: WheelEvent.DOM_DELTA_PIXEL, valueChanged: 0}, 39 {focus: true, deltaY: -1.0, deltaMode: WheelEvent.DOM_DELTA_PIXEL, valueChanged: 0}, 40 {focus: false, deltaY: 1.0, deltaMode: WheelEvent.DOM_DELTA_LINE, valueChanged: 0}, 41 {focus: false, deltaY: -1.0, deltaMode: WheelEvent.DOM_DELTA_LINE, valueChanged: 0} 42 ]; 43 44 let testIdx = 0; 45 46 // The expected value of the range field; used in is() check below. 47 // Initialized to the value that the field starts out with; subtests will 48 // modify this if they expect to modify the value. 49 let expectedValue = parseInt(input.value); 50 51 // Actual/expected number of mutations to the range field's value: 52 let actualChangeCount = 0; 53 let expectedChangeCount = 0; 54 55 const prefName = "dom.input.number_and_range_modified_by_mousewheel"; 56 let didFlipPref = false; 57 let isPrefEnabled = SpecialPowers.getBoolPref(prefName); 58 is(isPrefEnabled, false, "Expecting pref to be disabled by default"); 59 input.addEventListener("change", () => { 60 ++actualChangeCount; 61 }); 62 63 function runNext() { 64 let p = params[testIdx]; 65 (p.focus) ? input.focus() : input.blur(); 66 if (isPrefEnabled && p.valueChanged != 0) { 67 expectedChangeCount++; 68 expectedValue += p.valueChanged; 69 } 70 71 sendWheelAndPaint(input, 1, 1, { deltaY: p.deltaY, deltaMode: p.deltaMode }, 72 async () => { 73 is(parseInt(input.value), expectedValue, 74 "Handle wheel in range input test-" + testIdx + 75 " with pref " + (isPrefEnabled ? "en" : "dis") + "abled"); 76 77 is(actualChangeCount, expectedChangeCount, 78 "UA should fire change event when input's value changed"); 79 if (++testIdx < params.length) { 80 // More subtests remain; kick off the next one. 81 runNext(); 82 } else if (!didFlipPref) { 83 // Reached the end of the subtest list. Flip the pref 84 // and restart our iteration over the subtests. 85 await SpecialPowers.pushPrefEnv({ 86 set: [[prefName, !isPrefEnabled]], 87 }); 88 isPrefEnabled = !isPrefEnabled; 89 didFlipPref = true; 90 testIdx = actualChangeCount = expectedChangeCount = 0; 91 runNext(); 92 } else { 93 // Reached the end of the subtest list, for both pref settings. 94 // We're done! 95 SimpleTest.finish(); 96 } 97 }); 98 } 99 100 input.addEventListener("input", () => { 101 ok(input.value == expectedValue, 102 "Test-" + testIdx + " receive input event, expect " + 103 expectedValue + " get " + input.value); 104 }); 105 106 runNext(); 107 } 108 109 </script> 110 </body> 111 </html>