Commit 118bcd19 authored by Mounir Lamouri's avatar Mounir Lamouri Committed by Commit Bot

Picture-in-Picture: set playback state when setting a new surface.

When EmbedSurface() is called, always check the playback state of the
associated media player if there is one so we can guarantee that the
Picture-in-Picture window matches the current known state.

Bug: 868449
Change-Id: Iad61dcc67d5b6f4acc75dc5490883ea9733e75ad
Reviewed-on: https://chromium-review.googlesource.com/1153464Reviewed-by: default avatarapacible <apacible@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579052}
parent 82e3a34a
......@@ -8,6 +8,7 @@
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
......@@ -17,11 +18,13 @@
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "media/base/media_switches.h"
#include "net/dns/mock_host_resolver.h"
#if !defined(OS_ANDROID)
#include "chrome/browser/ui/views/overlay/overlay_window_views.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/widget/widget_observer.h"
#endif
......@@ -948,4 +951,58 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
EXPECT_FALSE(in_picture_in_picture);
}
// Tests that the play/pause icon state is properly updated when a
// Picture-in-Picture is created after a reload.
IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
PlayPauseStateAtCreation) {
LoadTabAndEnterPictureInPicture(browser());
content::WebContents* active_web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(content::ExecuteScript(active_web_contents, "video.play();"));
bool is_paused = true;
EXPECT_TRUE(ExecuteScriptAndExtractBool(active_web_contents, "isPaused();",
&is_paused));
EXPECT_FALSE(is_paused);
EXPECT_TRUE(window_controller()->GetWindowForTesting()->IsVisible());
EXPECT_TRUE(
window_controller()->GetWindowForTesting()->GetVideoLayer()->visible());
OverlayWindowViews* overlay_window = static_cast<OverlayWindowViews*>(
window_controller()->GetWindowForTesting());
EXPECT_TRUE(overlay_window->play_pause_controls_view_for_testing()
->toggled_for_testing());
ASSERT_TRUE(
content::ExecuteScript(active_web_contents, "exitPictureInPicture();"));
content::TestNavigationObserver observer(active_web_contents, 1);
chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB);
observer.Wait();
{
content::WebContents* active_web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
active_web_contents, "enterPictureInPicture();", &result));
EXPECT_TRUE(result);
bool is_paused = false;
EXPECT_TRUE(ExecuteScriptAndExtractBool(active_web_contents, "isPaused();",
&is_paused));
EXPECT_TRUE(is_paused);
OverlayWindowViews* overlay_window = static_cast<OverlayWindowViews*>(
window_controller()->GetWindowForTesting());
EXPECT_FALSE(overlay_window->play_pause_controls_view_for_testing()
->toggled_for_testing());
}
}
#endif // !defined(OS_ANDROID)
......@@ -621,6 +621,7 @@ void OverlayWindowViews::ClickCustomControl(const std::string& control_id) {
controller_->ClickCustomControl(control_id);
}
views::View* OverlayWindowViews::play_pause_controls_view_for_testing() const {
views::ToggleImageButton*
OverlayWindowViews::play_pause_controls_view_for_testing() const {
return play_pause_controls_view_.get();
}
......@@ -65,7 +65,7 @@ class OverlayWindowViews : public content::OverlayWindow,
// Send the message that a custom control on |this| has been clicked.
void ClickCustomControl(const std::string& control_id);
views::View* play_pause_controls_view_for_testing() const;
views::ToggleImageButton* play_pause_controls_view_for_testing() const;
private:
// Gets the internal |ui::Layer| of the controls.
......
......@@ -111,6 +111,7 @@ void PictureInPictureWindowControllerImpl::EmbedSurface(
// |initiator_| enters Picture-in-Picture mode.
media_player_id_ =
media_web_contents_observer_->GetPictureInPictureVideoMediaPlayerId();
UpdatePlaybackState(IsPlayerActive(), !media_player_id_.has_value());
window_->UpdateVideoSize(natural_size);
......
......@@ -305,4 +305,8 @@ void ToggleImageButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
}
}
bool ToggleImageButton::toggled_for_testing() const {
return toggled_;
}
} // namespace views
......@@ -161,6 +161,8 @@ class VIEWS_EXPORT ToggleImageButton : public ImageButton {
base::string16* tooltip) const override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
bool toggled_for_testing() const;
private:
// The parent class's images_ member is used for the current images,
// and this array is used to hold the alternative images.
......
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