Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/frame_host/render_frame_host_impl.h" | 5 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "content/browser/web_contents/web_contents_impl.h" | 8 #include "content/browser/web_contents/web_contents_impl.h" |
| 9 #include "content/common/frame_messages.h" | 9 #include "content/common/frame_messages.h" |
| 10 #include "content/public/browser/javascript_dialog_manager.h" | 10 #include "content/public/browser/javascript_dialog_manager.h" |
| 11 #include "content/public/browser/render_frame_host.h" | 11 #include "content/public/browser/render_frame_host.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/common/browser_side_navigation_policy.h" | |
| 13 #include "content/public/common/content_client.h" | 14 #include "content/public/common/content_client.h" |
| 14 #include "content/public/test/browser_test_utils.h" | 15 #include "content/public/test/browser_test_utils.h" |
| 15 #include "content/public/test/content_browser_test.h" | 16 #include "content/public/test/content_browser_test.h" |
| 16 #include "content/public/test/content_browser_test_utils.h" | 17 #include "content/public/test/content_browser_test_utils.h" |
| 17 #include "content/public/test/test_utils.h" | 18 #include "content/public/test/test_utils.h" |
| 18 #include "content/shell/browser/shell.h" | 19 #include "content/shell/browser/shell.h" |
| 19 #include "content/test/test_content_browser_client.h" | 20 #include "content/test/test_content_browser_client.h" |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 | 23 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 RenderFrameDeletedObserver deleted_observer( | 347 RenderFrameDeletedObserver deleted_observer( |
| 347 new_shell->web_contents()->GetMainFrame()); | 348 new_shell->web_contents()->GetMainFrame()); |
| 348 deleted_observer.WaitUntilDeleted(); | 349 deleted_observer.WaitUntilDeleted(); |
| 349 | 350 |
| 350 bool is_closed = false; | 351 bool is_closed = false; |
| 351 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 352 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 352 shell(), "domAutomationController.send(popup.closed)", &is_closed)); | 353 shell(), "domAutomationController.send(popup.closed)", &is_closed)); |
| 353 EXPECT_TRUE(is_closed); | 354 EXPECT_TRUE(is_closed); |
| 354 } | 355 } |
| 355 | 356 |
| 357 // After a navigation, the StreamHandle must be released. | |
| 358 IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, StreamHandleReleased) { | |
| 359 EXPECT_TRUE(NavigateToURL(shell(), GetTestUrl("", "title1.html"))); | |
| 360 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); | |
| 361 RenderFrameHostImpl* main_frame = | |
| 362 static_cast<RenderFrameHostImpl*>(wc->GetMainFrame()); | |
| 363 EXPECT_EQ(nullptr, main_frame->stream_handle_for_testing()); | |
| 364 } | |
| 365 | |
| 366 namespace { | |
| 367 class DropStreamHandleConsumedFilter : public BrowserMessageFilter { | |
| 368 public: | |
| 369 DropStreamHandleConsumedFilter() : BrowserMessageFilter(FrameMsgStart) {} | |
| 370 | |
| 371 protected: | |
| 372 ~DropStreamHandleConsumedFilter() override {} | |
| 373 | |
| 374 private: | |
| 375 // BrowserMessageFilter: | |
| 376 bool OnMessageReceived(const IPC::Message& message) override { | |
| 377 return message.type() == FrameHostMsg_StreamHandleConsumed::ID; | |
| 378 } | |
| 379 | |
| 380 DISALLOW_COPY_AND_ASSIGN(DropStreamHandleConsumedFilter); | |
| 381 }; | |
| 382 } // namespace | |
| 383 | |
| 384 // After a renderer crash, the StreamHandle must be released. | |
| 385 IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBrowserTest, | |
| 386 StreamHandleReleasedOnRendererCrash) { | |
| 387 // |stream_handle_| is only used with PlzNavigate. | |
| 388 if (!IsBrowserSideNavigationEnabled()) | |
| 389 return; | |
| 390 | |
| 391 EXPECT_TRUE(NavigateToURL(shell(), GURL("about:blank"))); | |
|
nasko
2017/06/13 16:53:43
Why not navigate to a real URL, such as GetURL("/t
arthursonzogni
2017/06/14 10:30:53
It was because the embedded_test_server was not st
| |
| 392 | |
| 393 // Set up a filter to make sure that the browser is not notified that its | |
| 394 // |stream_handle_| has been consumed. | |
| 395 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); | |
| 396 RenderFrameHostImpl* main_frame = | |
| 397 static_cast<RenderFrameHostImpl*>(wc->GetMainFrame()); | |
| 398 scoped_refptr<DropStreamHandleConsumedFilter> filter = | |
| 399 new DropStreamHandleConsumedFilter(); | |
| 400 main_frame->GetProcess()->AddFilter(filter.get()); | |
| 401 | |
| 402 EXPECT_TRUE(NavigateToURL(shell(), GURL("data:text/html,hello"))); | |
|
nasko
2017/06/13 16:53:43
Same here, I think we are better off using an http
arthursonzogni
2017/06/14 10:30:53
Done.
| |
| 403 | |
| 404 // Check that the |stream_handle_| hasn't been released yet. | |
| 405 EXPECT_NE(nullptr, main_frame->stream_handle_for_testing()); | |
| 406 | |
| 407 // Make the renderer crash. | |
| 408 RenderProcessHost* renderer_process = main_frame->GetProcess(); | |
| 409 RenderProcessHostWatcher crash_observer( | |
| 410 renderer_process, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | |
| 411 renderer_process->Shutdown(0, false); | |
| 412 crash_observer.Wait(); | |
| 413 | |
| 414 // The |stream_handle_| must have been released now. | |
| 415 EXPECT_EQ(nullptr, main_frame->stream_handle_for_testing()); | |
| 416 } | |
| 417 | |
| 356 } // namespace content | 418 } // namespace content |
| OLD | NEW |