summaryrefslogtreecommitdiffstats
path: root/layout/xul/test/test_bug159346.xul
blob: 4ef34fe323a15a7cd37146d39e8f251d7700fd43 (plain)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        xmlns:html="http://www.w3.org/1999/xhtml"
        title="Test for Bug 159346">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=159346
-->

  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>

<scrollbar id="scrollbar" curpos="0" maxpos="500"/>

<script class="testbody" type="application/javascript">
<![CDATA[

var scrollbar = document.getElementById("scrollbar");
var downButton =
  document.getAnonymousElementByAttribute(scrollbar, "sbattr",
                                          "scrollbar-down-bottom");

function init()
{
  downButton.style.display = "-moz-box";
  SimpleTest.executeSoon(doTest1);
}

function getCurrentPos()
{
  return Number(scrollbar.getAttribute("curpos"));
}

function doTest1()
{
  var lastPos = 0;

  synthesizeMouseAtCenter(downButton, { type: "mousedown" });
  ok(getCurrentPos() > lastPos,
     "scrollbar didn't change curpos by mousedown #1");
  lastPos = getCurrentPos();

  setTimeout(function () {
    ok(getCurrentPos() > lastPos,
       "scrollbar didn't change curpos by auto repeat #1");
    synthesizeMouseAtCenter(downButton, { type: "mouseup" });
    lastPos = getCurrentPos();

    setTimeout(function () {
      is(getCurrentPos(), lastPos,
         "scrollbar changed curpos after mouseup #1");
      SimpleTest.executeSoon(doTest2);
    }, 1000);
  }, 1000);
}

function doTest2()
{
  SpecialPowers.setIntPref("ui.scrollbarButtonAutoRepeatBehavior", 0);

  scrollbar.setAttribute("curpos", 0);
  var lastPos = 0;

  synthesizeMouseAtCenter(downButton, { type: "mousedown" });
  ok(getCurrentPos() > lastPos,
     "scrollbar didn't change curpos by mousedown #2");
  lastPos = getCurrentPos();

  synthesizeMouse(downButton, -10, -10, { type: "mousemove" });
  lastPos = getCurrentPos();

  setTimeout(function () {
    is(getCurrentPos(), lastPos,
       "scrollbar changed curpos by auto repeat when cursor is outside of scrollbar button #2");
    synthesizeMouseAtCenter(downButton, { type: "mousemove" });
    lastPos = getCurrentPos();

    setTimeout(function () {
      ok(getCurrentPos() > lastPos,
         "scrollbar didn't change curpos by mousemove after cursor is back on the scrollbar button #2");
      synthesizeMouseAtCenter(downButton, { type: "mouseup" });
      SimpleTest.executeSoon(doTest3);
    }, 1000);
  }, 1000);
}

function doTest3()
{
  SpecialPowers.setIntPref("ui.scrollbarButtonAutoRepeatBehavior", 1);

  scrollbar.setAttribute("curpos", 0);
  var lastPos = 0;

  synthesizeMouseAtCenter(downButton, { type: "mousedown" });
  ok(getCurrentPos() > lastPos,
     "scrollbar didn't change curpos by mousedown #3");
  synthesizeMouse(downButton, -10, -10, { type: "mousemove" });
  lastPos = getCurrentPos();

  setTimeout(function () {
    ok(getCurrentPos() > lastPos,
       "scrollbar didn't change curpos by auto repeat when cursor is outside of scrollbar button #3");
    synthesizeMouseAtCenter(downButton, { type: "mousemove" });
    lastPos = getCurrentPos();

    setTimeout(function () {
      ok(getCurrentPos() > lastPos,
         "scrollbar didn't change curpos by mousemove after cursor is back on the scrollbar button #3");
      synthesizeMouseAtCenter(downButton, { type: "mouseup" });

      SpecialPowers.clearUserPref("ui.scrollbarButtonAutoRepeatBehavior");
      SimpleTest.finish();
    }, 1000);
  }, 1000);
}

SimpleTest.waitForExplicitFinish();

]]>
</script>

<body  id="html_body" xmlns="http://www.w3.org/1999/xhtml">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=159346">Mozilla Bug 159346</a>
<p id="display"></p>

<pre id="test">
</pre>
<script>
addLoadEvent(init);
</script>
</body>


</window>