mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Auto merge of #10225 - jmr0:visibility_api, r=jdm
Implement non-visible pipeline and iframe visibility methods This addresses #9566 and a good part of #9751, specifically: * Pipeline has a notion of visibility * IFrame setVisible/getVisible interface with IFrame's pipeline visibility * IFrame mozbrowservisibilitychange responds to changes in visibility * Pipeline visibility is used to limit animations (requestAnimationFrame does not tick animations when hidden) and to increase timer intervals (currently set to a minimum of 1 second while hidden) Absent for now are any changes to the Document API and general implementation of the Page Visibility API, since the more interesting parts require knowledge of whether the user agent is minimized, OS screen locked, etc. cc @paulrouget @jdm <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10225) <!-- Reviewable:end -->
This commit is contained in:
commit
d620ab71c4
14 changed files with 382 additions and 24 deletions
|
@ -6550,6 +6550,12 @@
|
|||
"url": "/_mozilla/mozilla/mozbrowser/iframe_reload_twice.html"
|
||||
}
|
||||
],
|
||||
"mozilla/mozbrowser/iframe_visibility.html": [
|
||||
{
|
||||
"path": "mozilla/mozbrowser/iframe_visibility.html",
|
||||
"url": "/_mozilla/mozilla/mozbrowser/iframe_visibility.html"
|
||||
}
|
||||
],
|
||||
"mozilla/mozbrowser/mozbrowser_click_fires_openwindow.html": [
|
||||
{
|
||||
"path": "mozilla/mozbrowser/mozbrowser_click_fires_openwindow.html",
|
||||
|
|
6
tests/wpt/mozilla/tests/mozilla/mozbrowser/helper.html
Normal file
6
tests/wpt/mozilla/tests/mozilla/mozbrowser/helper.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<body>
|
||||
<p>test</p>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,92 @@
|
|||
<!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');
|
||||
</script>
|
||||
</body>
|
Loading…
Add table
Add a link
Reference in a new issue