File: test_bug1261674-1.html

package info (click to toggle)
thunderbird 1%3A143.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,703,968 kB
  • sloc: cpp: 7,770,492; javascript: 5,943,842; ansic: 3,918,754; python: 1,418,263; xml: 653,354; asm: 474,045; java: 183,079; sh: 111,238; makefile: 20,410; perl: 14,359; objc: 13,059; yacc: 4,583; pascal: 3,405; lex: 1,720; ruby: 999; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (111 lines) | stat: -rw-r--r-- 4,056 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1261674
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1261674</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script src="/tests/SimpleTest/paint_listener.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1261674">Mozilla Bug 1261674</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<input id="test_input" type="range" value=5 max=10 min=0>
<script type="text/javascript">

/** Test for Bug 1261674 **/
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(runTests);

function runTests() {
  let input = window.document.getElementById("test_input");

  // focus: whether the target input element is focused
  // deltaY: deltaY of WheelEvent
  // deltaMode: deltaMode of WheelEvent
  // valueChanged: expected value changes after input element handled the wheel event
  let params = [
    {focus: true, deltaY: 1.0, deltaMode: WheelEvent.DOM_DELTA_LINE, valueChanged: -1},
    {focus: true, deltaY: -1.0, deltaMode: WheelEvent.DOM_DELTA_LINE, valueChanged: 1},
    {focus: true, deltaY: 1.0, deltaMode: WheelEvent.DOM_DELTA_PAGE, valueChanged: -1},
    {focus: true, deltaY: -1.0, deltaMode: WheelEvent.DOM_DELTA_PAGE, valueChanged: 1},
    {focus: true, deltaY: 1.0, deltaMode: WheelEvent.DOM_DELTA_PIXEL, valueChanged: 0},
    {focus: true, deltaY: -1.0, deltaMode: WheelEvent.DOM_DELTA_PIXEL, valueChanged: 0},
    {focus: false, deltaY: 1.0, deltaMode: WheelEvent.DOM_DELTA_LINE, valueChanged: 0},
    {focus: false, deltaY: -1.0, deltaMode: WheelEvent.DOM_DELTA_LINE, valueChanged: 0}
  ];

  let testIdx = 0;

  // The expected value of the range field; used in is() check below.
  // Initialized to the value that the field starts out with; subtests will
  // modify this if they expect to modify the value.
  let expectedValue = parseInt(input.value);

  // Actual/expected number of mutations to the range field's value:
  let actualChangeCount = 0;
  let expectedChangeCount = 0;

  const prefName = "dom.input.number_and_range_modified_by_mousewheel";
  let didFlipPref = false;
  let isPrefEnabled = SpecialPowers.getBoolPref(prefName);
  is(isPrefEnabled, false,  "Expecting pref to be disabled by default");
  input.addEventListener("change", () => {
    ++actualChangeCount;
  });

  function runNext() {
    let p = params[testIdx];
    (p.focus) ? input.focus() : input.blur();
    if (isPrefEnabled && p.valueChanged != 0) {
      expectedChangeCount++;
      expectedValue += p.valueChanged;
    }

    sendWheelAndPaint(input, 1, 1, { deltaY: p.deltaY, deltaMode: p.deltaMode },
                      async () => {
      is(parseInt(input.value), expectedValue,
         "Handle wheel in range input test-" + testIdx +
         " with pref " + (isPrefEnabled ? "en" : "dis") + "abled");

      is(actualChangeCount, expectedChangeCount,
         "UA should fire change event when input's value changed");
      if (++testIdx < params.length) {
        // More subtests remain; kick off the next one.
        runNext();
      } else if (!didFlipPref) {
        // Reached the end of the subtest list.  Flip the pref
        // and restart our iteration over the subtests.
        await SpecialPowers.pushPrefEnv({
          set: [[prefName, !isPrefEnabled]],
        });
        isPrefEnabled = !isPrefEnabled;
        didFlipPref = true;
        testIdx = actualChangeCount = expectedChangeCount = 0;
        runNext();
      } else {
        // Reached the end of the subtest list, for both pref settings.
        // We're done!
        SimpleTest.finish();
      }
    });
  }

  input.addEventListener("input", () => {
    ok(input.value == expectedValue,
       "Test-" + testIdx + " receive input event, expect " +
       expectedValue + " get " + input.value);
  });

  runNext();
}

</script>
</body>
</html>