/
iframe_visibility.html
115 lines (103 loc) · 4.23 KB
/
iframe_visibility.html
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!doctype html>
<meta charset="utf-8">
<head>
<title>Iframe visibility tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
async_test(function(t) {
var expectedVisibilities = [false, true];
var receivedVisibilities = [];
var iframe = document.createElement("iframe");
iframe.mozbrowser = true;
iframe.src = "helper.html";
//Alternate the iframe's visibility and fire mozbrowservisibilitychange
iframe.onload = t.step_func(function() {
iframe.setVisible(false);
iframe.setVisible(true);
});
iframe.addEventListener("mozbrowservisibilitychange", t.step_func(e => {
assert_equals(iframe.getVisible(), e.detail.visible);
receivedVisibilities.push(e.detail.visible);
if (receivedVisibilities.length == expectedVisibilities.length) {
assert_array_equals(receivedVisibilities, expectedVisibilities);
t.done();
}
}));
document.body.appendChild(iframe);
}, "Iframe visibility setter/getter");
async_test(function(t) {
var iframe = document.createElement("iframe");
iframe.mozbrowser = true;
iframe.src = "helper.html";
var start = null;
document.body.appendChild(iframe);
iframe.onload = t.step_func(function() {
var element = iframe.contentWindow.document.querySelector("p");
var animationCompletesAfterResumingVisibility = false;
var nonVisibleAnimationStopped = false;
element.style.position = 'relative';
element.style.right = "0px";
var step = t.step_func(function(timestamp) {
if (!start) start = timestamp;
var progress = timestamp - start;
element.style.right = Math.min(progress/5, 100) + "px";
if (progress < 500) {
iframe.contentWindow.requestAnimationFrame(step);
}
});
iframe.setVisible(false);
iframe.contentWindow.setTimeout(t.step_func(function(){
nonVisibleAnimationStopped = element.style.right === '0px';
iframe.setVisible(true);
}),1000);
iframe.contentWindow.setTimeout(t.step_func(function(){
animationCompletesAfterResumingVisibility = element.style.right === '100px';
assert_true(nonVisibleAnimationStopped);
assert_true(animationCompletesAfterResumingVisibility);
t.done();
}),2000);
iframe.contentWindow.requestAnimationFrame(step);
});
}, 'Requesting animation frame composites only when frame is visible');
async_test(function(t) {
var iframe = document.createElement("iframe");
iframe.src = "http://web-platform.test:8000/common/blank.html";
iframe.mozbrowser = true;
iframe.onload = t.step_func(function() {
iframe.addEventListener("mozbrowservisibilitychange", t.step_func(function() {
var startTime = Date.now();
iframe.contentWindow.setTimeout(t.step_func(function() {
assert_true(Date.now() - startTime >= 1000);
t.done();
}), 1);
}));
iframe.setVisible(false);
});
document.body.appendChild(iframe);
}, 'Minimum setTimeout of 1s when pipeline is invisible');
async_test(function(t) {
var iframe = document.createElement("iframe");
var destination = "helper.html";
iframe.src = "http://web-platform.test:8000/common/blank.html";
iframe.mozbrowser = true;
iframe.onload = t.step_func(function() {
iframe.addEventListener("mozbrowservisibilitychange", t.step_func(function() {
iframe.src = destination;
}));
if (iframe.src !== destination) {
iframe.setVisible(false);
} else {
var startTime = Date.now();
iframe.contentWindow.setTimeout(t.step_func(function() {
assert_true(Date.now() - startTime >= 1000);
t.done();
}), 1);
}
});
document.body.appendChild(iframe);
}, 'Minimum setTimeout of 1s persists after new page is loaded');
</script>
</body>