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.
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/browser/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"
19 class RenderProcessHostTest
: public ContentBrowserTest
{};
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());
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();
35 TestNotificationTracker termination_watcher
;
36 termination_watcher
.ListenFor(NOTIFICATION_RENDERER_PROCESS_CLOSED
,
37 Source
<RenderProcessHost
>(rph
));
38 ChildProcessHostMsg_ShutdownRequest msg
;
39 rph
->OnMessageReceived(msg
);
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
);
46 EXPECT_EQ(0U, termination_watcher
.size());
50 } // namespace content