summaryrefslogtreecommitdiffstats
path: root/layout/reftests/scrolling/fractional-scroll-area.html
blob: cba421499ca589e534821fd9112f387c4396be67 (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
<!DOCTYPE html>
<html class="reftest-wait">
<meta charset="utf-8">
<title>Fractional scroll area position / size</title>

<style>

body {
  margin: 0;
}

#scrollbox {
  width: 200px;
  overflow: hidden;
  background: red;
}

#scrolled-content {
  background: lime;
  box-sizing: border-box;
  border: solid black;
  border-width: 1px 0;
}

</style>

<div id="scrollbox">
  <div id="scrolled-content"></div>
</div>

<script>

function getFloatQueryParams(defaultValues) {
  let result = Object.assign({}, defaultValues);
  for (let chunk of location.search.substr(1).split("&")) {
    let parts = chunk.split("=");
    result[parts[0]] = parseFloat(parts[1]);
  }
  return result;
}

let params = getFloatQueryParams({
  top: 0,
  outerBottom: 100,
  innerBottom: 100,
  borderTop: 0,
  borderBottom: 0,
  scrollBefore: 0,
  scrollAfter: undefined,
  offsetAfter: undefined,
});

let scrollArea = document.getElementById("scrollbox");
let scrolledContent = document.getElementById("scrolled-content");

scrollArea.style.marginTop = params.top + "px";
scrollArea.style.height = (params.outerBottom - params.top) + "px";
scrolledContent.style.height =  (params.innerBottom - params.top) + "px";

scrollArea.scrollTop = 1;
scrollArea.scrollTop = 2;
scrollArea.scrollTop = params.scrollBefore;

window.addEventListener("MozReftestInvalidate", function () {
  if (params.scrollAfter !== undefined) {
    scrollArea.scrollTop = params.scrollAfter;
  }
  if (params.offsetAfter !== undefined) {
    document.body.style.marginTop = params.offsetAfter + "px";
  }
  document.documentElement.className = "";
});

</script>