summaryrefslogtreecommitdiffstats
path: root/dom/base/test/file_viewport_metrics_on_landscape_content.html
blob: 02b079aeace4ce19c4298015c33956d4882e66ee (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
<!DOCTYPE HTML>
<html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=0.5">
<style>
html {
  scrollbar-width: none; /* avoid scrollbar width is included in some metrics */
}
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: none;
}
#twice-width {
  width: 200%;
  height: 100%;
  position: absolute;
}
</style>
<div id="twice-width"></div>
<script>

const is = opener.is.bind(opener);
const todo_is = opener.todo_is.bind(opener);
const add_task = opener.add_task.bind(opener);
const original_finish = opener.SimpleTest.finish;
const SimpleTest = opener.SimpleTest;

SimpleTest.finish = function finish() {
  self.close();
  original_finish();
}

add_task(async () => {
  // Explicitly set to 0.5x so that this test doesn't need to reply on our
  // auto initial-scale calculation.
  SpecialPowers.getDOMWindowUtils(window).setResolutionAndScaleTo(0.5);
  is(window.visualViewport.scale, 0.5, "The content should be scaled by 0.5x");

  // Now the visual viewport size is same as the layout viewport.
  const layoutViewportHeight = window.visualViewport.height;

  todo_is(window.innerHeight, layoutViewportHeight,
     "window.innerHeight should reflect the layout viewport (Bug 1598487)");
  is(document.documentElement.scrollHeight, layoutViewportHeight,
     "The root element's scrollHeight should be the layout viewport height");
  is(document.documentElement.getBoundingClientRect().height,
     layoutViewportHeight / 2,
     "The content height should be half of the layout viewport height");

  // Set scale to 1.0x so that the visual viport size becomes 0.5x of the layout
  // viewport.
  SpecialPowers.getDOMWindowUtils(window).setResolutionAndScaleTo(1);
  is(window.visualViewport.scale, 1, "The content should be scaled by 1.0x");
  is(window.visualViewport.height, layoutViewportHeight / 2,
     "Now the visual viewport height should be changed to half of the layout " +
     "viewport height");
  todo_is(window.innerHeight, layoutViewportHeight,
          "window.innerHeight shouldn't be changed (Bug 1598487)");
  is(document.documentElement.scrollHeight, layoutViewportHeight,
     "The root element's scrollHeight shouldn't be changed");
});
</script>
</html>