Commit 44e1ecc1 authored by François Beaufort's avatar François Beaufort Committed by Commit Bot

[Picture-in-Picture] Fix browser_tests flakyness.

This makes sure video loaded in a iframe is loaded before attempting
requesting Picture-in-Picture in browser_tests.

Bug: 853643
Change-Id: I2ad236ac24d42a89194e3dbb9ace4b9f56961d92
Reviewed-on: https://chromium-review.googlesource.com/1103570
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarapacible <apacible@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569581}
parent 888b6b53
......@@ -598,6 +598,12 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
? render_frame_hosts[1]
: render_frame_hosts[0];
// Wait for video metadata to load.
base::string16 expected_title = base::ASCIIToUTF16("loadedmetadata");
EXPECT_EQ(expected_title,
content::TitleWatcher(active_web_contents, expected_title)
.WaitAndGetTitle());
std::string result;
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
iframe, "enterPictureInPicture();", &result));
......@@ -611,17 +617,8 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
EXPECT_FALSE(window_controller()->GetWindowForTesting()->IsVisible());
}
// Same as above for a cross-origin iframe.
// Flaky on windows and Linux: crbug/854349
#if defined(OS_WIN) || defined(OS_LINUX)
#define MAYBE_CrossOriginFrameEnterLeaveCloseWindow \
DISABLED_CrossOriginFrameEnterLeaveCloseWindow
#else
#define MAYBE_CrossOriginFrameEnterLeaveCloseWindow \
CrossOriginFrameEnterLeaveCloseWindow
#endif
IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
MAYBE_CrossOriginFrameEnterLeaveCloseWindow) {
CrossOriginFrameEnterLeaveCloseWindow) {
GURL embed_url = embedded_test_server()->GetURL(
"a.com", "/media/picture-in-picture/iframe-content.html");
GURL main_url = embedded_test_server()->GetURL(
......@@ -645,6 +642,12 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
? render_frame_hosts[1]
: render_frame_hosts[0];
// Wait for video metadata to load.
base::string16 expected_title = base::ASCIIToUTF16("loadedmetadata");
EXPECT_EQ(expected_title,
content::TitleWatcher(active_web_contents, expected_title)
.WaitAndGetTitle());
std::string result;
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
iframe, "enterPictureInPicture();", &result));
......
......@@ -9,6 +9,10 @@
<script>
const video = document.querySelector('video');
video.addEventListener('loadedmetadata', function() {
window.parent.postMessage({ loadedmetadata: true }, '*');
});
function enterPictureInPicture() {
video.requestPictureInPicture().then(() => {
domAutomationController.send('done');
......
......@@ -18,5 +18,11 @@
function removeFrame() {
document.body.removeChild(document.querySelector('iframe'));
}
window.addEventListener('message', function(event) {
if (event.data.loadedmetadata) {
document.title = 'loadedmetadata';
}
});
</script>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment