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
|
<!doctype html>
<html>
<head>
<title>Viewport: page and offset values in iframe</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="viewport_support.js"></script>
<style>
iframe {
width: 200px;
height: 300px;
border: 0;
}
</style>
</head>
<body>
<h1>Viewport: Page and offset values in iframe</h1>
<h4>
Test Description: This test checks for correct visualViewport values in
an iframe.
</h4>
<iframe></iframe>
</body>
<script>
var iframe = frames[0].window;
// Add overflow to the iframe so it can scroll.
iframe.document.body.style.width = "2000px";
iframe.document.body.style.height = "2000px";
iframe.scrollTo(1000, 1200);
promise_test(async t => {
assert_equals(visualViewport.scale, 1,
"[PRECONDITION] Start off unzoomed");
assert_equals(visualViewport.offsetLeft, 0,
"[PRECONDITION] No offsetLeft to start");
assert_equals(visualViewport.offsetTop, 0,
"[PRECONDITION] No offsetTop to start");
// The iframe's visual viewport isn't yet offset
assert_equals(iframe.visualViewport.offsetLeft, 0,
"offsetLeft must be 0");
assert_equals(iframe.visualViewport.offsetTop, 0,
"offsetTop must be 0");
// However, page values should reflect layout viewport scrolling.
assert_equals(iframe.visualViewport.pageLeft, 1000,
"pageLeft must reflect location in document.");
assert_equals(iframe.visualViewport.pageTop, 1200,
"pageTop must reflect location in document.");
// Zoom in and pan the viewport to ensure the iframe is independent
// of the root frame.
await pinchZoomIn();
// These values are arbitrary since the amount of pinch-zoom caused
// by pinchZoomIn will differ but we only care that the iframe's
// values aren't changed.
assert_greater_than(visualViewport.scale, 1.2,
"Pinch zoom must have increased scale");
assert_greater_than(visualViewport.offsetLeft, 10,
"Pinch zoom must have offsetLeft visualViewport");
assert_greater_than(visualViewport.offsetTop, 10,
"Pinch zoom must have offsetTop visualViewport");
// The iframe's visualViewport is independent of the root frame's so
// none of the values should have changed.
assert_equals(iframe.visualViewport.offsetLeft, 0,
"After zooming, offsetLeft must remain 0");
assert_equals(iframe.visualViewport.offsetTop, 0,
"After zooming, offsetTop must remain 0");
assert_equals(iframe.visualViewport.pageLeft, 1000,
"After zooming, pageLeft must reflect location in document.");
assert_equals(iframe.visualViewport.pageTop, 1200,
"After zooming, pageTop must reflect location in document.");
assert_equals(iframe.visualViewport.scale, 1,
"Iframe's visualViewport must not be scaled");
}, "VisualViewport page and offset values in iframe");
</script>
</html>
|