Commit e40eb0c5 authored by Jiawei Li's avatar Jiawei Li Committed by Commit Bot

[chromecast] Notify page is loading on ReadyToCommitNavigation

In certain cases, second DidStartNavigation event will occur prior to
prior navigation's DidFinishLoad, leading to that CastWebContentsImpl
would drop second main frame loading event.

DidStartNavigation -> DidStartNavigation -> DidFinishLoad ->
DidFinishLoad. (LOADING->ignore same LOADING -> LOADED -> IGNORE SAME
LOADED event). Ignored event won't be broadcasted to
CastWebContents::Observer. BindingsManagerCast might not work as
intended under this specific circumstance.

To resolve that, another page loading notification should be added on
ReadyToCommitNavigation.

Bug: Internal b/149898650
Test: Verified with manually build.
Change-Id: Ie119b21495fde6db7b4dd24515ceac3a080c5166
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2067870Reviewed-by: default avatarSean Topping <seantopping@chromium.org>
Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Commit-Queue: Jiawei Li <lijiawei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744058}
parent 674608ad
...@@ -676,6 +676,48 @@ IN_PROC_BROWSER_TEST_F(CastWebContentsBrowserTest, LoadCanceledByApp) { ...@@ -676,6 +676,48 @@ IN_PROC_BROWSER_TEST_F(CastWebContentsBrowserTest, LoadCanceledByApp) {
run_loop->Run(); run_loop->Run();
} }
IN_PROC_BROWSER_TEST_F(CastWebContentsBrowserTest, LocationRedirectLifecycle) {
auto run_loop = std::make_unique<base::RunLoop>();
auto quit_closure = [&run_loop]() {
if (run_loop->running()) {
run_loop->QuitWhenIdle();
}
};
// ===========================================================================
// Test: When the app redirects to another url via window.location. Another
// navigation will be committed. LOADING -> LOADED -> LOADING -> LOADED state
// trasition is expected.
// ===========================================================================
embedded_test_server()->ServeFilesFromSourceDirectory(GetTestDataPath());
StartTestServer();
{
InSequence seq;
EXPECT_CALL(
mock_cast_wc_observer_,
OnPageStateChanged(CheckPageState(
cast_web_contents_.get(), CastWebContents::PageState::LOADING)));
EXPECT_CALL(
mock_cast_wc_observer_,
OnPageStateChanged(CheckPageState(cast_web_contents_.get(),
CastWebContents::PageState::LOADED)));
EXPECT_CALL(
mock_cast_wc_observer_,
OnPageStateChanged(CheckPageState(
cast_web_contents_.get(), CastWebContents::PageState::LOADING)));
EXPECT_CALL(
mock_cast_wc_observer_,
OnPageStateChanged(CheckPageState(cast_web_contents_.get(),
CastWebContents::PageState::LOADED)))
.WillOnce(InvokeWithoutArgs(quit_closure));
}
cast_web_contents_->LoadUrl(
embedded_test_server()->GetURL("/location_redirect.html"));
run_loop->Run();
}
IN_PROC_BROWSER_TEST_F(CastWebContentsBrowserTest, NotifyMissingResource) { IN_PROC_BROWSER_TEST_F(CastWebContentsBrowserTest, NotifyMissingResource) {
auto run_loop = std::make_unique<base::RunLoop>(); auto run_loop = std::make_unique<base::RunLoop>();
auto quit_closure = [&run_loop]() { auto quit_closure = [&run_loop]() {
......
...@@ -598,6 +598,26 @@ void CastWebContentsImpl::DidStartNavigation( ...@@ -598,6 +598,26 @@ void CastWebContentsImpl::DidStartNavigation(
void CastWebContentsImpl::ReadyToCommitNavigation( void CastWebContentsImpl::ReadyToCommitNavigation(
content::NavigationHandle* navigation_handle) { content::NavigationHandle* navigation_handle) {
DCHECK(navigation_handle);
if (!web_contents_ || closing_ || stopped_)
return;
if (!navigation_handle->IsInMainFrame())
return;
// Main frame has begun navigating/loading.
OnPageLoading();
start_loading_ticks_ = base::TimeTicks::Now();
GURL loading_url;
content::NavigationEntry* nav_entry =
web_contents()->GetController().GetVisibleEntry();
if (nav_entry) {
loading_url = nav_entry->GetVirtualURL();
}
TracePageLoadBegin(loading_url);
UpdatePageState();
DCHECK_EQ(page_state_, PageState::LOADING);
NotifyPageState();
if (before_load_scripts_.empty()) if (before_load_scripts_.empty())
return; return;
......
<!DOCTYPE html>
<head>
</head>
<body>
<script type="text/javascript">
window.location = "about:blank";
</script>
</body>
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