summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_doubletap_zoom_bug1702464.html
blob: 34d06fc039f9a9bd9dd7e732241333e35051afe3 (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=2100"/>
  <title>Check that double tapping internal calculations correctly convert the tap point</title>
  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
  <script type="application/javascript" src="apz_test_utils.js"></script>
  <script src="/tests/SimpleTest/paint_listener.js"></script>
  <script type="application/javascript">

async function test() {
  let useTouchpad = (location.search == "?touchpad");

  const deviceScale = window.devicePixelRatio;
  let target2 = document.getElementById("target2")

  info("deviceScale " + deviceScale);
  info("window.innerwh " + window.innerWidth + " " + window.innerHeight);
  info("vv " + visualViewport.offsetLeft + " " + visualViewport.offsetTop + " " + visualViewport.width + " " + visualViewport.height);

  let resolution = await getResolution();
  let vvHeightAtUnitZoom = visualViewport.height * resolution;

  // The max amount of zoom is 10 (as defined in dom/base/nsViewportInfo.h),
  // but that includes the deviceScale (bug 1700865 is filed about this), so
  // this is the max amount of zoom that double tap can increase by.
  let maxPinchZoom = 10/deviceScale;

  // Compute the visual viewport size at that max zoom.
  let minVVHeight = vvHeightAtUnitZoom / maxPinchZoom;

  // Make the element height to just fit inside the minimum visual viewport
  // height, minus the margins that get added for the zoom target rect (15 on
  // each side) and a little wiggle room just in case (rounding, etc).
  let elementHeight = Math.floor(minVVHeight) - 2*15 - 4;

  ok(elementHeight > 10, "tall enough element");

  // And then make the element skinnier than the window size so it triggers
  // the bug. (half the aspect ratio minus 5 just to be sure)
  let elementWidth = Math.max(12, Math.floor(elementHeight * window.innerWidth / (2 * window.innerHeight)) - 5);

  info("element size " + elementWidth + " " + elementHeight);

  target2.style.width = elementWidth + "px";
  target2.style.height = elementHeight + "px";

  await promiseApzFlushedRepaints();

  resolution = await getResolution();
  ok(resolution > 0,
     "The initial_resolution is " + resolution + ", which is some sane value");

  // Check that double-tapping once zooms in
  await doubleTapOn(document.getElementById("target1"), 10, 10, useTouchpad);
  var prev_resolution = resolution;
  resolution = await getResolution();
  ok(resolution > prev_resolution, "The first double-tap has increased the resolution to " + resolution);

  // Check that double-tapping the smaller element zooms in more
  await doubleTapOn(target2, 8, elementHeight-8, useTouchpad);
  prev_resolution = resolution;
  resolution = await getResolution();
  ok(resolution > prev_resolution, "The second double-tap has increased the resolution to " + resolution);

  let rect = target2.getBoundingClientRect();
  info("rect " + rect.x + " " + rect.y + " " + rect.width + " " + rect.height);
  info("vv " + visualViewport.offsetLeft + " " + visualViewport.offsetTop + " " + visualViewport.width + " " + visualViewport.height);

  ok(visualViewport.offsetLeft < rect.x, "visual viewport contains zoom element left");
  ok(visualViewport.offsetTop < rect.y, "visual viewport contains zoom element top");
  ok(visualViewport.offsetLeft + visualViewport.width > rect.x + rect.width, "visual viewport contains zoom element right");
  ok(visualViewport.offsetTop + visualViewport.height > rect.y + rect.height, "visual viewport contains zoom element bottom");
}

waitUntilApzStable()
.then(test)
.then(subtestDone, subtestFailed);

  </script>
</head>
<body>

<div id="target1" style="background: blue; width: 50vw; height: 200px; position: absolute; top: 50vh;">
  <div id="target2" style="background: green; width: 50px; height: 135px; position: absolute; right: 0;"></div>
</div>

</body>
</html>