Skip to content

Commit

Permalink
[Picture-in-Picture] Fix web platform tests that time out.
Browse files Browse the repository at this point in the history
This makes sure web platform tests for Picture-in-Picture do not time
out when Picture-in-Picture API is not available.

Besides, wpt/picture-in-picture/request-picture-in-picture is split
to work around a flaky timeout in WPT upstream that's related to
#10398

Note: based on #11329

Bug: 806249
Change-Id: I6185253dfa4aae5111e87553581b8464032558d1
Reviewed-on: https://chromium-review.googlesource.com/1107626
Reviewed-by: Robert Ma <[email protected]>
Reviewed-by: Mounir Lamouri <[email protected]>
Commit-Queue: François Beaufort <[email protected]>
Cr-Commit-Position: refs/heads/master@{#576804}
  • Loading branch information
Hexcles authored and Chrome-bot committed Jul 20, 2018
1 parent 0cc3831 commit cae6050
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

async_test(t => {
test_feature_availability('picture-in-picture', t, cross_origin_src,
expect_feature_available_default,);
expect_feature_available_default);
}, header + ' allows cross-origin iframes.');

</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

async_test(t => {
test_feature_availability('picture-in-picture', t, cross_origin_src,
expect_feature_unavailable_default,);
expect_feature_unavailable_default);
}, header + ' disallows cross-origin iframes.');
</script>
</body>
5 changes: 4 additions & 1 deletion feature-policy/resources/picture-in-picture.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
function isPictureInPictureAllowed() {
if (!('pictureInPictureEnabled' in document))
return Promise.resolve(false);

return new Promise(resolve => {
let video = document.createElement('video');
video.src = '/media/movie_5.ogv';
Expand All @@ -13,4 +16,4 @@ function isPictureInPictureAllowed() {
});
};
});
}
}
22 changes: 22 additions & 0 deletions picture-in-picture/request-picture-in-picture-twice.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<title>Test request Picture-in-Picture on two videos</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/picture-in-picture-helpers.js"></script>
<body></body>
<script>
promise_test(async t => {
const video1 = await loadVideo();
const video2 = await loadVideo();
return callWithTrustedClick(() => {
const first = video1.requestPictureInPicture();
const second = video2.requestPictureInPicture();
return Promise.all([
first,
promise_rejects(t, 'NotAllowedError', second)
]);
});
}, 'request Picture-in-Picture consumes user gesture');
</script>
13 changes: 0 additions & 13 deletions picture-in-picture/request-picture-in-picture.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,4 @@
const video = await loadVideo();
return promise_rejects(t, 'NotAllowedError', video.requestPictureInPicture());
}, 'request Picture-in-Picture requires a user gesture');

promise_test(async t => {
const video1 = await loadVideo();
const video2 = await loadVideo();
return callWithTrustedClick(() => {
const first = video1.requestPictureInPicture();
const second = video2.requestPictureInPicture();
return Promise.all([
first,
promise_rejects(t, 'NotAllowedError', second)
]);
});
}, 'request Picture-in-Picture consumes user gesture');
</script>
10 changes: 8 additions & 2 deletions picture-in-picture/resources/picture-in-picture-helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
if (!('pictureInPictureEnabled' in document)) {
HTMLVideoElement.prototype.requestPictureInPicture = function() {
return Promise.reject('Picture-in-Picture API is not available');
}
}

function callWithTrustedClick(callback) {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
let button = document.createElement('button');
button.textContent = 'click to continue test';
button.style.display = 'block';
Expand All @@ -10,7 +16,7 @@ function callWithTrustedClick(callback) {
resolve(callback());
};
document.body.appendChild(button);
test_driver.click(button);
test_driver.click(button).catch(_ => reject('Click failed'));
});
}

Expand Down

0 comments on commit cae6050

Please sign in to comment.