summaryrefslogtreecommitdiffstats
path: root/layout/generic/test/test_bug1756831.html
blob: c95a79b84e65dd84946f67a963a5222f53351987 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1756831
-->
<head>
  <title>Test for Bug 1756831</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
</head>
<body>


<style>
.scroller {
  height: 300px;
  width: 300px;
  overflow: hidden;
  border: 1px solid grey;
}

.long-content {
  height: 300vh;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.1);
  z-index: 10;
}

</style>
<div id="sc" class="scroller">
  
  <div class="long-content">
    <div style="width: 30px; height: 30px; background: blue;"></div>
    <div class="modal"></div>
  </div>
  
</div>


<script>
SimpleTest.requestFlakyTimeout("need to wait for overlay scrollbars to fade out");
SimpleTest.waitForExplicitFinish();
// Test that mousing over content descendants that are not scrollable does not
// scroll the overlay scrollbars.

/* We are testing overlay scrollbars here, specifically those that display when
   the mouse is moved over scrollable content. The first two prefs are for
   that. We set the prefs that determine the duration of the scrollbar fade out
   so they are uniform for us. It would be nice if we could set a very short
   duration so we didn't have to wait, or a very long duration so as to prevent
   the possibility of the scrollbars disappearing before we take a screenshot
   to compare against, however neither of those are workable. If the duration
   is too short we risk the scrollbars disappearing before we can screenshot
   them. If the duration is too long the test takes a long time. We can't
   change the duration prefs part way through the test because the prefs are
   only read when the a scroll frame is created or when a scroll frame is
   reflowed and we've switched to/from overlay scrollbars. Both of these would
   cause the scrollbars to be shown again which would interrupt the test.
*/

add_task(async function() {
  await SimpleTest.promiseFocus(window);
  await SpecialPowers.pushPrefEnv({"set": [["ui.useOverlayScrollbars", 1],
                                     ["ui.scrollbarDisplayOnMouseMove", 1],
                                     ["ui.scrollbarFadeDuration", 500],
                                     ["ui.scrollbarFadeBeginDelay", 500]]});
  let utils = SpecialPowers.DOMWindowUtils;

  let sc = document.getElementById("sc");
  let boundingClientRect = sc.getBoundingClientRect();

  // The div is initially overflow hidden, so it doesn't have scrollbars,
  // capture that so we can compare against it later.
  let noscrollbars = document.createElement("canvas");
  noscrollbars.setAttribute("width", boundingClientRect.width);
  noscrollbars.setAttribute("height", boundingClientRect.height);
  let ctx = noscrollbars.getContext("2d");
  SpecialPowers.wrap(ctx).drawWindow(window, boundingClientRect.x, boundingClientRect.y,
                 boundingClientRect.width,
                 boundingClientRect.height,
                 "rgb(255,255,255)");

  // dump("noscrollbars " + noscrollbars.toDataURL() + "\n");

  await new Promise(resolve => setTimeout(resolve, 0));

  // make div scrollable
  sc.style.overflow = "auto";

  // and make sure it's reconstructed so the prefs get applied
  document.documentElement.style.display = "table";
  document.documentElement.getBoundingClientRect();
  document.documentElement.style.display = "";
  document.documentElement.getBoundingClientRect();


  const maxRetries = 5;
  let retries = 0;
  let canvasesSame = false;
  while (!canvasesSame && retries < maxRetries) {
    // wait for the scrollbars to fade away, 500+500 from prefs, then a bit more.
    await new Promise(resolve => setTimeout(resolve, 1500));

    let canvas = document.createElement("canvas");
    canvas.setAttribute("width", boundingClientRect.width);
    canvas.setAttribute("height", boundingClientRect.height);
    // take screen shot
    ctx = canvas.getContext("2d");
    SpecialPowers.wrap(ctx).drawWindow(window, boundingClientRect.x, boundingClientRect.y,
                   boundingClientRect.width,
                   boundingClientRect.height,
                   "rgb(255,255,255)");
    canvasesSame = (utils.compareCanvases(noscrollbars, canvas, {}) == 0);
    retries++;
    // dump("differences " + utils.compareCanvases(noscrollbars, canvas, {}));
    // dump("canvas " + canvas.toDataURL() + "\n");
  }

  ok(canvasesSame, "scrollbars disappeared: canvasesSame " + canvasesSame + " retries " + retries)

  // send mouse move that should not show scrollbar
  await synthesizeMouseAtCenter(document.documentElement, { type: "mousemove" });
  await new Promise(r => requestAnimationFrame(r));

  let canvas = document.createElement("canvas");
  canvas.setAttribute("width", boundingClientRect.width);
  canvas.setAttribute("height", boundingClientRect.height);
  ctx = canvas.getContext("2d");
  SpecialPowers.wrap(ctx).drawWindow(window, boundingClientRect.x, boundingClientRect.y,
                 boundingClientRect.width,
                 boundingClientRect.height,
                 "rgb(255,255,255)");

  let differences = utils.compareCanvases(noscrollbars, canvas, {});
  // dump("canvas " + canvas.toDataURL() + "\n");

  ok(differences == 0, "differences " + differences);
});
</script>
</body>
</html>