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.

#11329

Bug: 806249
Change-Id: I6185253dfa4aae5111e87553581b8464032558d1
  • Loading branch information
Hexcles authored and Chrome-bot committed Jul 16, 2018
1 parent f9e7716 commit e2ee3d1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 18 deletions.
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
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
@@ -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
@@ -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
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
@@ -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 e2ee3d1

Please sign in to comment.