Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/run_loop.h" | |
| 6 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 7 #include "content/browser/renderer_host/render_process_host_impl.h" | 8 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 8 #include "content/common/child_process_messages.h" | 9 #include "content/common/child_process_messages.h" |
| 9 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
| 10 #include "content/public/browser/render_process_host_observer.h" | 11 #include "content/public/browser/render_process_host_observer.h" |
| 11 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
| 12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
| 15 #include "content/public/common/service_registry.h" | |
| 14 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
| 15 #include "content/public/test/content_browser_test.h" | 17 #include "content/public/test/content_browser_test.h" |
| 16 #include "content/public/test/content_browser_test_utils.h" | 18 #include "content/public/test/content_browser_test_utils.h" |
| 19 #include "content/public/test/test_mojo_service.mojom.h" | |
| 17 #include "content/shell/browser/shell.h" | 20 #include "content/shell/browser/shell.h" |
| 18 #include "net/test/embedded_test_server/embedded_test_server.h" | 21 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 19 | 22 |
| 20 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 21 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
| 22 #endif | 25 #endif |
| 23 | 26 |
| 24 namespace content { | 27 namespace content { |
| 25 namespace { | 28 namespace { |
| 26 | 29 |
| 27 int RenderProcessHostCount() { | 30 int RenderProcessHostCount() { |
| 28 content::RenderProcessHost::iterator hosts = | 31 content::RenderProcessHost::iterator hosts = |
| 29 content::RenderProcessHost::AllHostsIterator(); | 32 content::RenderProcessHost::AllHostsIterator(); |
| 30 int count = 0; | 33 int count = 0; |
| 31 while (!hosts.IsAtEnd()) { | 34 while (!hosts.IsAtEnd()) { |
| 32 if (hosts.GetCurrentValue()->HasConnection()) | 35 if (hosts.GetCurrentValue()->HasConnection()) |
| 33 count++; | 36 count++; |
| 34 hosts.Advance(); | 37 hosts.Advance(); |
| 35 } | 38 } |
| 36 return count; | 39 return count; |
| 37 } | 40 } |
| 38 | 41 |
| 39 class RenderProcessHostTest : public ContentBrowserTest, | 42 class RenderProcessHostTest : public ContentBrowserTest, |
| 40 public RenderProcessHostObserver { | 43 public RenderProcessHostObserver { |
| 41 public: | 44 public: |
| 42 RenderProcessHostTest() : process_exits_(0), host_destructions_(0) {} | 45 RenderProcessHostTest() : process_exits_(0), host_destructions_(0) {} |
| 43 | 46 |
| 44 protected: | 47 protected: |
| 48 void set_process_exit_callback(const base::Closure& callback) { | |
| 49 process_exit_callback_ = callback; | |
| 50 } | |
| 51 | |
| 45 // RenderProcessHostObserver: | 52 // RenderProcessHostObserver: |
| 46 void RenderProcessExited(RenderProcessHost* host, | 53 void RenderProcessExited(RenderProcessHost* host, |
| 47 base::TerminationStatus status, | 54 base::TerminationStatus status, |
| 48 int exit_code) override { | 55 int exit_code) override { |
| 49 ++process_exits_; | 56 ++process_exits_; |
| 57 if (!process_exit_callback_.is_null()) | |
| 58 process_exit_callback_.Run(); | |
| 50 } | 59 } |
| 51 void RenderProcessHostDestroyed(RenderProcessHost* host) override { | 60 void RenderProcessHostDestroyed(RenderProcessHost* host) override { |
| 52 ++host_destructions_; | 61 ++host_destructions_; |
| 53 } | 62 } |
| 54 | 63 |
| 55 int process_exits_; | 64 int process_exits_; |
| 56 int host_destructions_; | 65 int host_destructions_; |
| 66 base::Closure process_exit_callback_; | |
| 57 }; | 67 }; |
| 58 | 68 |
| 59 // Sometimes the renderer process's ShutdownRequest (corresponding to the | 69 // Sometimes the renderer process's ShutdownRequest (corresponding to the |
| 60 // ViewMsg_WasSwappedOut from a previous navigation) doesn't arrive until after | 70 // ViewMsg_WasSwappedOut from a previous navigation) doesn't arrive until after |
| 61 // the browser process decides to re-use the renderer for a new purpose. This | 71 // the browser process decides to re-use the renderer for a new purpose. This |
| 62 // test makes sure the browser doesn't let the renderer die in that case. See | 72 // test makes sure the browser doesn't let the renderer die in that case. See |
| 63 // http://crbug.com/87176. | 73 // http://crbug.com/87176. |
| 64 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, | 74 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, |
| 65 ShutdownRequestFromActiveTabIgnored) { | 75 ShutdownRequestFromActiveTabIgnored) { |
| 66 ASSERT_TRUE(embedded_test_server()->Start()); | 76 ASSERT_TRUE(embedded_test_server()->Start()); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 "ObserverLogger::RenderProcessHostDestroyed ", logging_string); | 201 "ObserverLogger::RenderProcessHostDestroyed ", logging_string); |
| 192 | 202 |
| 193 // If the test fails, and somehow the RPH is still alive somehow, at least | 203 // If the test fails, and somehow the RPH is still alive somehow, at least |
| 194 // deregister the observers so that the test fails and doesn't also crash. | 204 // deregister the observers so that the test fails and doesn't also crash. |
| 195 if (!observer_logger.host_destroyed()) { | 205 if (!observer_logger.host_destroyed()) { |
| 196 rph->RemoveObserver(&shell_closer); | 206 rph->RemoveObserver(&shell_closer); |
| 197 rph->RemoveObserver(&observer_logger); | 207 rph->RemoveObserver(&observer_logger); |
| 198 } | 208 } |
| 199 } | 209 } |
| 200 | 210 |
| 211 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, KillProcessOnBadMojoMessage) { | |
| 212 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 213 | |
| 214 GURL test_url = embedded_test_server()->GetURL("/simple_page.html"); | |
| 215 NavigateToURL(shell(), test_url); | |
| 216 RenderProcessHost* rph = | |
| 217 shell()->web_contents()->GetRenderViewHost()->GetProcess(); | |
| 218 | |
| 219 host_destructions_ = 0; | |
| 220 process_exits_ = 0; | |
| 221 rph->AddObserver(this); | |
| 222 | |
| 223 mojom::TestMojoServicePtr service; | |
| 224 rph->GetServiceRegistry()->ConnectToRemoteService(mojo::GetProxy(&service)); | |
| 225 | |
| 226 base::RunLoop run_loop; | |
| 227 set_process_exit_callback(run_loop.QuitClosure()); | |
| 228 | |
| 229 // Should reply with a bad message and cause process death. | |
| 230 service->DoSomething([]{}); | |
| 231 | |
| 232 run_loop.Run(); | |
| 233 | |
| 234 EXPECT_EQ(1, process_exits_); | |
| 235 EXPECT_EQ(0, host_destructions_); | |
| 236 if (!host_destructions_) | |
| 237 rph->RemoveObserver(this); | |
| 238 } | |
| 239 | |
| 240 | |
|
jam
2016/06/13 18:30:39
nit: extra line
Ken Rockot(use gerrit already)
2016/06/13 22:36:40
done
| |
| 201 } // namespace | 241 } // namespace |
| 202 } // namespace content | 242 } // namespace content |
| OLD | NEW |