summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_bug1280013.html
blob: 6b7d5cf4c371f5522e15b0fdfdf46df5b14b8fe8 (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
<!DOCTYPE HTML>
<html style="overflow:hidden">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=width-device; initial-scale=1.0">
  <title>Test for bug 1280013</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() {
  ok(screen.height > 500, "Screen height must be at least 500 pixels for this test to work");

  // Scroll down to the iframe. Do it in two drags instead of one in case the
  // device screen is short.
  let transformEnd = promiseTransformEnd();
  await synthesizeNativeTouchDrag(window, 10, 200, 0, -175);
  await transformEnd;

  transformEnd = promiseTransformEnd();
  await synthesizeNativeTouchDrag(window, 10, 200, 0, -175);
  await transformEnd;

  // Now the top of the visible area should be at y=350 of the top-level page,
  // so if the screen is >= 500px tall, the entire iframe should be visible, at
  // least vertically.

  // However, because of the overflow:hidden on the root elements, all this
  // scrolling is happening in APZ and is not reflected in the main-thread
  // scroll position (it is stored in the callback transform instead). We check
  // this by checking the scroll offset.
  await promiseOnlyApzControllerFlushed();
  is(window.scrollY, 0, "Main-thread scroll position is still at 0");

  // Scroll the iframe by 150px.
  var subframe = document.getElementById("subframe");
  transformEnd = promiseTransformEnd();
  await synthesizeNativeTouchDrag(subframe, 10, 100, 0, -150);
  await transformEnd;

  // Flush any pending paints on the APZ side, and wait for the main thread
  // to process them all so that we get the correct test data
  await promiseApzFlushedRepaints();

  // get the displayport for the subframe
  var utils = SpecialPowers.getDOMWindowUtils(window);
  var contentPaints = utils.getContentAPZTestData().paints;
  var lastPaint = convertScrollFrameData(getLastNonemptyBucket(contentPaints).scrollFrames);
  var foundIt = 0;
  for (var scrollId in lastPaint) {
    if (("contentDescription" in lastPaint[scrollId]) &&
        (lastPaint[scrollId].contentDescription.includes("tall_html"))) {
      var dp = getPropertyAsRect(lastPaint, scrollId, "displayport");
      ok(dp.y <= 0, "The displayport top should be less than or equal to zero to cover the visible part of the subframe; it is " + dp.y);
      ok(dp.y + dp.height >= subframe.clientHeight, "The displayport bottom should be greater than the clientHeight; it is " + (dp.y + dp.height));
      foundIt++;
    }
  }
  is(foundIt, 1, "Found exactly one displayport for the subframe we were interested in.");
}

SpecialPowers.getDOMWindowUtils(window).setResolutionAndScaleTo(2.0);
waitUntilApzStable()
.then(test)
.then(subtestDone, subtestFailed);

  </script>
</head>
<body style="overflow:hidden">
  The iframe below is at (0, 400). Scroll it into view, and then scroll the contents. The content should be fully rendered in high-resolution.
  <iframe id="subframe" style="position:absolute; left: 0px; top: 400px; width: 300px; height: 175px" src="helper_tall.html"></iframe>
</body>
</html>