Chromium Code Reviews| Index: content/browser/web_contents/web_contents_impl_unittest.cc |
| diff --git a/content/browser/web_contents/web_contents_impl_unittest.cc b/content/browser/web_contents/web_contents_impl_unittest.cc |
| index 187f3c42b3e7d0eca942e47303532da9095a4b48..de571ba4a165441312d35b39a99437c7d4020913 100644 |
| --- a/content/browser/web_contents/web_contents_impl_unittest.cc |
| +++ b/content/browser/web_contents/web_contents_impl_unittest.cc |
| @@ -2879,6 +2879,70 @@ TEST_F(WebContentsImplTest, StartStopEventsBalance) { |
| EXPECT_FALSE(observer.is_loading()); |
| } |
| +// Ensure that WebContentsImpl does not stop loading too early when there still |
| +// is a pending renderer. This can happen if a same-process non user-initiated |
| +// navigation completes while there is an ongoing cross-process navigation. |
| +// TODO(fdegans): Rewrite the test for PlzNavigate when DidStartLoading and |
| +// DidStopLoading are properly called. |
| +TEST_F(WebContentsImplTest, NoEarlyStop) { |
| + const GURL kUrl1("http://www.chromium.org"); |
| + const GURL kUrl2("http://www.google.com"); |
| + const GURL kUrl3("http://www.wikipedia.org"); |
| + |
| + contents()->NavigateAndCommit(kUrl1); |
| + |
| + TestRenderFrameHost* current_rfh = contents()->GetMainFrame(); |
| + |
| + // Start a browser-initiated cross-process navigation to |kUrl2|. There should |
| + // be a pending RenderFrameHost and the WebContents should be loading. |
| + controller().LoadURL( |
| + kUrl2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| + EXPECT_TRUE(contents()->cross_navigation_pending()); |
| + TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame(); |
| + ASSERT_NE(pending_rfh, nullptr); |
| + EXPECT_TRUE(contents()->IsLoading()); |
| + |
| + // The current RenderFrameHost starts a non user-initiated render-initiated |
| + // navigation and sends a DidStartLoading IPC. The WebContents should still be |
| + // loading. |
| + current_rfh->OnMessageReceived( |
| + FrameHostMsg_DidStartLoading(current_rfh->GetRoutingID(), false)); |
|
Charlie Reis
2015/03/05 04:46:18
nit: Wrong indent.
Fabrice (no longer in Chrome)
2015/03/05 12:37:43
Done.
|
| + EXPECT_TRUE(contents()->IsLoading()); |
| + |
| + // Simulate the pending RenderFrameHost DidStartLoading. There should still be |
| + // a pending RenderFrameHost and the WebContents should still be loading. |
| + pending_rfh->PrepareForCommit(kUrl2); |
|
Charlie Reis
2015/03/05 04:46:18
Compile error here?
Fabrice (no longer in Chrome)
2015/03/05 12:37:43
I needed to rebase locally.
Done.
|
| + pending_rfh->OnMessageReceived( |
| + FrameHostMsg_DidStartLoading(pending_rfh->GetRoutingID(), false)); |
| + EXPECT_EQ(contents()->GetPendingMainFrame(), pending_rfh); |
| + EXPECT_TRUE(contents()->IsLoading()); |
| + |
| + // Simulate the commit and DidStopLoading from the renderer-initiated |
| + // navigation in the current RenderFrameHost. There should still be a pending |
| + // RenderFrameHost and the WebContents should still be loading. |
| + current_rfh->SendNavigate(1, kUrl3); |
| + current_rfh->OnMessageReceived( |
| + FrameHostMsg_DidStopLoading(current_rfh->GetRoutingID())); |
| + EXPECT_EQ(contents()->GetPendingMainFrame(), pending_rfh); |
| + EXPECT_TRUE(contents()->IsLoading()); |
| + |
| + // Commit the navigation, the formerly pending RenderFrameHost should now be |
|
Charlie Reis
2015/03/05 04:46:18
Run-on sentence. Use either a period or a semicol
Fabrice (no longer in Chrome)
2015/03/05 12:37:43
Done.
|
| + // the current RenderFrameHost and the WebContents should still be loading. |
| + contents()->TestDidNavigate(pending_rfh, 1, kUrl2, |
| + ui::PAGE_TRANSITION_TYPED); |
| + EXPECT_EQ(contents()->GetPendingMainFrame(), nullptr); |
| + TestRenderFrameHost* new_current_rfh = contents()->GetMainFrame(); |
| + ASSERT_EQ(new_current_rfh, pending_rfh); |
|
Charlie Reis
2015/03/05 04:46:19
EXPECT_EQ
(Save ASSERT_* for things that prevent
Fabrice (no longer in Chrome)
2015/03/05 12:37:43
Done.
|
| + EXPECT_TRUE(contents()->IsLoading()); |
| + |
| + // Simulate the new current RenderFrameHost DidStopLoading. The WebContents |
| + // should now have stopped loading. |
| + new_current_rfh->OnMessageReceived( |
| + FrameHostMsg_DidStopLoading(new_current_rfh->GetRoutingID())); |
| + EXPECT_EQ(contents()->GetMainFrame(), new_current_rfh); |
| + EXPECT_FALSE(contents()->IsLoading()); |
| +} |
| + |
| TEST_F(WebContentsImplTest, MediaPowerSaveBlocking) { |
| // PlayerIDs are actually pointers cast to int64, so verify that both negative |
| // and positive player ids don't blow up. |