Commit e530beb0 authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

[Autoplay] Persist user gesture before nav

In some cases we have a gesture on a previous navigation
but the `has_received_user_gesture` flag is not set so
we should also check the `has_received_user_gesture_before_nav`
flag too and allow propagation on the same eTLD+1.

BUG=884777

Change-Id: Iaabf03816bc4638f534321b1e9236bfa41d29938
Reviewed-on: https://chromium-review.googlesource.com/1255150Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595551}
parent 4ecc56fd
......@@ -71,6 +71,17 @@ class UnifiedAutoplayBrowserTest : public InProcessBrowserTest {
return played;
}
bool NavigateInRenderer(content::WebContents* web_contents, const GURL& url) {
content::TestNavigationObserver observer(web_contents);
bool result = content::ExecuteScriptWithoutUserGesture(
web_contents, "window.location = '" + url.spec() + "';");
if (result)
observer.Wait();
return result;
}
void SetAutoplayForceAllowFlag(const GURL& url) {
blink::mojom::AutoplayConfigurationClientAssociatedPtr client;
GetWebContents()
......@@ -253,6 +264,66 @@ IN_PROC_BROWSER_TEST_F(UnifiedAutoplayBrowserTest, ForceWasActivated_Yes) {
EXPECT_TRUE(AttemptPlay(GetWebContents()));
}
IN_PROC_BROWSER_TEST_F(UnifiedAutoplayBrowserTest,
Redirect_SameOrigin_WithGesture) {
const GURL kRedirectPageUrl =
embedded_test_server()->GetURL(kFramedTestPagePath);
const GURL kTestPageUrl = embedded_test_server()->GetURL(kTestPagePath);
NavigateParams params(browser(), kRedirectPageUrl, ui::PAGE_TRANSITION_LINK);
params.was_activated = content::WasActivatedOption::kYes;
ui_test_utils::NavigateToURL(&params);
EXPECT_TRUE(NavigateInRenderer(GetWebContents(), kTestPageUrl));
EXPECT_EQ(kTestPageUrl, GetWebContents()->GetLastCommittedURL());
EXPECT_TRUE(AttemptPlay(GetWebContents()));
}
IN_PROC_BROWSER_TEST_F(UnifiedAutoplayBrowserTest,
Redirect_SameOrigin_WithoutGesture) {
const GURL kRedirectPageUrl =
embedded_test_server()->GetURL(kFramedTestPagePath);
const GURL kTestPageUrl = embedded_test_server()->GetURL(kTestPagePath);
NavigateParams params(browser(), kRedirectPageUrl, ui::PAGE_TRANSITION_LINK);
ui_test_utils::NavigateToURL(&params);
EXPECT_TRUE(NavigateInRenderer(GetWebContents(), kTestPageUrl));
EXPECT_EQ(kTestPageUrl, GetWebContents()->GetLastCommittedURL());
EXPECT_FALSE(AttemptPlay(GetWebContents()));
}
IN_PROC_BROWSER_TEST_F(UnifiedAutoplayBrowserTest,
Redirect_CrossOrigin_WithGesture) {
const GURL kRedirectPageUrl =
embedded_test_server()->GetURL(kFramedTestPagePath);
const GURL kTestPageUrl =
embedded_test_server()->GetURL("foo.example.com", kTestPagePath);
NavigateParams params(browser(), kRedirectPageUrl, ui::PAGE_TRANSITION_LINK);
params.was_activated = content::WasActivatedOption::kYes;
ui_test_utils::NavigateToURL(&params);
EXPECT_TRUE(NavigateInRenderer(GetWebContents(), kTestPageUrl));
EXPECT_EQ(kTestPageUrl, GetWebContents()->GetLastCommittedURL());
EXPECT_FALSE(AttemptPlay(GetWebContents()));
}
IN_PROC_BROWSER_TEST_F(UnifiedAutoplayBrowserTest,
Redirect_CrossOrigin_WithoutGesture) {
const GURL kRedirectPageUrl =
embedded_test_server()->GetURL(kFramedTestPagePath);
const GURL kTestPageUrl =
embedded_test_server()->GetURL("foo.example.com", kTestPagePath);
NavigateParams params(browser(), kRedirectPageUrl, ui::PAGE_TRANSITION_LINK);
ui_test_utils::NavigateToURL(&params);
EXPECT_TRUE(NavigateInRenderer(GetWebContents(), kTestPageUrl));
EXPECT_EQ(kTestPageUrl, GetWebContents()->GetLastCommittedURL());
EXPECT_FALSE(AttemptPlay(GetWebContents()));
}
// Integration tests for the new unified autoplay sound settings UI.
class UnifiedAutoplaySettingBrowserTest : public UnifiedAutoplayBrowserTest {
......
......@@ -377,6 +377,12 @@ class CONTENT_EXPORT FrameTreeNode {
return replication_state_.has_received_user_gesture;
}
// Returns whether the frame received a user gesture on a previous navigation
// on the same eTLD+1.
bool has_received_user_gesture_before_nav() const {
return replication_state_.has_received_user_gesture_before_nav;
}
// When a tab is discarded, WebContents sets was_discarded on its
// root FrameTreeNode.
// In addition, when a child frame is created, this bit is passed on from
......
......@@ -982,7 +982,7 @@ void NavigationRequest::OnResponseStarted(
// `ShouldPropagateUserActivation` requirements (same eTLD+1).
// There are two different checks:
// 1. if the `frame_tree_node_` has an origin and is following the rules above
// with the target URL, it is used and the bit is set iif the navigation is
// with the target URL, it is used and the bit is set if the navigation is
// renderer initiated and the `frame_tree_node_` had a gesture. This should
// apply to same page navigations and is preferred over using the referrer
// as it can be changed.
......@@ -996,7 +996,8 @@ void NavigationRequest::OnResponseStarted(
request_params_.was_activated = WasActivatedOption::kNo;
if (navigation_handle_->IsRendererInitiated() &&
frame_tree_node_->has_received_user_gesture() &&
(frame_tree_node_->has_received_user_gesture() ||
frame_tree_node_->has_received_user_gesture_before_nav()) &&
ShouldPropagateUserActivation(
frame_tree_node_->current_origin(),
url::Origin::Create(navigation_handle_->GetURL()))) {
......
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