summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/visual-viewport/viewport-scrollbars-cause-resize-in-iframe.html
blob: ce9ec3276886b5786ffe1309251469e92f29e1a9 (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
<!doctype html>
<title>Viewport: Scrollbars Cause Resize</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="viewport_support.js"></script>
<h1>Viewport: Scrollbars Cause Resize In IFrame</h1>
<h4>
    Test Description: This test checks that the appearance of classic
    scrollbars will cause a resize event to be fired at window.visualViewport in iframe.
</h4>
<iframe srcdoc="<p>Hello, world!</p>"></iframe>
<script>
  async_test(t => {
    window.onload = () => {
      const iframe = document.querySelector("iframe");

      let resize_event_count = 0;
      iframe.contentWindow.visualViewport.addEventListener("resize", () => {
        resize_event_count++;
      });

      const originalVisualViewportWidth = iframe.contentWindow.visualViewport.width;

      iframe.contentDocument.body.style.height = "10000px";
      // Force layout to queue a resize event at this moment.
      iframe.contentDocument.body.clientWidth;

      requestAnimationFrame(t.step_func_done(() => {
        // it's uncontrollable whether the test will run
        // with classic or overlay scrollbars in the case of Mac,
        // so the check has to be conditional.
        const width_changed = iframe.contentWindow.visualViewport.width !== originalVisualViewportWidth;
        assert_equals(resize_event_count, width_changed ? 1 : 0);
      }));
    }
  }, "the appearance of classic scrollbars will fire a resize event" +
      "at window.visualViewport in iframe");
</script>
<div id="log"></div>