1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "content/common/child_process_messages.h" 6 #include "content/public/browser/notification_types.h" 7 #include "content/public/browser/render_process_host.h" 8 #include "content/public/browser/render_view_host.h" 9 #include "content/public/browser/web_contents.h" 10 #include "content/public/test/test_notification_tracker.h" 11 #include "content/shell/shell.h" 12 #include "content/test/content_browser_test.h" 13 #include "content/test/content_browser_test_utils.h" 14 #include "net/test/embedded_test_server/embedded_test_server.h" 15 16 namespace content { 17 namespace { 18 19 class RenderProcessHostTest : public ContentBrowserTest {}; 20 21 // Sometimes the renderer process's ShutdownRequest (corresponding to the 22 // ViewMsg_WasSwappedOut from a previous navigation) doesn't arrive until after 23 // the browser process decides to re-use the renderer for a new purpose. This 24 // test makes sure the browser doesn't let the renderer die in that case. See 25 // http://crbug.com/87176. 26 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, 27 ShutdownRequestFromActiveTabIgnored) { 28 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 29 30 GURL test_url = embedded_test_server()->GetURL("/simple_page.html"); 31 NavigateToURL(shell(), test_url); 32 RenderProcessHost* rph = 33 shell()->web_contents()->GetRenderViewHost()->GetProcess(); 34 35 TestNotificationTracker termination_watcher; 36 termination_watcher.ListenFor(NOTIFICATION_RENDERER_PROCESS_CLOSED, 37 Source<RenderProcessHost>(rph)); 38 ChildProcessHostMsg_ShutdownRequest msg; 39 rph->OnMessageReceived(msg); 40 41 // If the RPH sends a mistaken ChildProcessMsg_Shutdown, the renderer process 42 // will take some time to die. Wait for a second tab to load in order to give 43 // that time to happen. 44 NavigateToURL(CreateBrowser(), test_url); 45 46 EXPECT_EQ(0U, termination_watcher.size()); 47 } 48 49 } // namespace 50 } // namespace content 51