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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "content/browser/renderer_host/render_process_host_impl.h" | 9 #include "content/browser/renderer_host/render_process_host_impl.h" |
10 #include "content/common/child_process_messages.h" | 10 #include "content/common/child_process_messages.h" |
| 11 #include "content/public/browser/render_frame_host.h" |
11 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
12 #include "content/public/browser/render_process_host_observer.h" | 13 #include "content/public/browser/render_process_host_observer.h" |
13 #include "content/public/browser/render_view_host.h" | |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
16 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
17 #include "content/public/test/content_browser_test.h" | 17 #include "content/public/test/content_browser_test.h" |
18 #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_service.mojom.h" | 19 #include "content/public/test/test_service.mojom.h" |
20 #include "content/shell/browser/shell.h" | 20 #include "content/shell/browser/shell.h" |
21 #include "net/test/embedded_test_server/embedded_test_server.h" | 21 #include "net/test/embedded_test_server/embedded_test_server.h" |
22 #include "services/service_manager/public/cpp/interface_provider.h" | 22 #include "services/service_manager/public/cpp/interface_provider.h" |
23 #include "services/service_manager/public/cpp/interface_registry.h" | 23 #include "services/service_manager/public/cpp/interface_registry.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // the browser process decides to re-use the renderer for a new purpose. This | 73 // the browser process decides to re-use the renderer for a new purpose. This |
74 // test makes sure the browser doesn't let the renderer die in that case. See | 74 // test makes sure the browser doesn't let the renderer die in that case. See |
75 // http://crbug.com/87176. | 75 // http://crbug.com/87176. |
76 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, | 76 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, |
77 ShutdownRequestFromActiveTabIgnored) { | 77 ShutdownRequestFromActiveTabIgnored) { |
78 ASSERT_TRUE(embedded_test_server()->Start()); | 78 ASSERT_TRUE(embedded_test_server()->Start()); |
79 | 79 |
80 GURL test_url = embedded_test_server()->GetURL("/simple_page.html"); | 80 GURL test_url = embedded_test_server()->GetURL("/simple_page.html"); |
81 NavigateToURL(shell(), test_url); | 81 NavigateToURL(shell(), test_url); |
82 RenderProcessHost* rph = | 82 RenderProcessHost* rph = |
83 shell()->web_contents()->GetRenderViewHost()->GetProcess(); | 83 shell()->web_contents()->GetMainFrame()->GetProcess(); |
84 | 84 |
85 host_destructions_ = 0; | 85 host_destructions_ = 0; |
86 process_exits_ = 0; | 86 process_exits_ = 0; |
87 rph->AddObserver(this); | 87 rph->AddObserver(this); |
88 ChildProcessHostMsg_ShutdownRequest msg; | 88 ChildProcessHostMsg_ShutdownRequest msg; |
89 rph->OnMessageReceived(msg); | 89 rph->OnMessageReceived(msg); |
90 | 90 |
91 // If the RPH sends a mistaken ChildProcessMsg_Shutdown, the renderer process | 91 // If the RPH sends a mistaken ChildProcessMsg_Shutdown, the renderer process |
92 // will take some time to die. Wait for a second tab to load in order to give | 92 // will take some time to die. Wait for a second tab to load in order to give |
93 // that time to happen. | 93 // that time to happen. |
94 NavigateToURL(CreateBrowser(), test_url); | 94 NavigateToURL(CreateBrowser(), test_url); |
95 | 95 |
96 EXPECT_EQ(0, process_exits_); | 96 EXPECT_EQ(0, process_exits_); |
97 if (!host_destructions_) | 97 if (!host_destructions_) |
98 rph->RemoveObserver(this); | 98 rph->RemoveObserver(this); |
99 } | 99 } |
100 | 100 |
101 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, | 101 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, |
102 GuestsAreNotSuitableHosts) { | 102 GuestsAreNotSuitableHosts) { |
103 // Set max renderers to 1 to force running out of processes. | 103 // Set max renderers to 1 to force running out of processes. |
104 content::RenderProcessHost::SetMaxRendererProcessCount(1); | 104 content::RenderProcessHost::SetMaxRendererProcessCount(1); |
105 | 105 |
106 ASSERT_TRUE(embedded_test_server()->Start()); | 106 ASSERT_TRUE(embedded_test_server()->Start()); |
107 | 107 |
108 GURL test_url = embedded_test_server()->GetURL("/simple_page.html"); | 108 GURL test_url = embedded_test_server()->GetURL("/simple_page.html"); |
109 NavigateToURL(shell(), test_url); | 109 NavigateToURL(shell(), test_url); |
110 RenderProcessHost* rph = | 110 RenderProcessHost* rph = |
111 shell()->web_contents()->GetRenderViewHost()->GetProcess(); | 111 shell()->web_contents()->GetMainFrame()->GetProcess(); |
112 // Make it believe it's a guest. | 112 // Make it believe it's a guest. |
113 reinterpret_cast<RenderProcessHostImpl*>(rph)-> | 113 reinterpret_cast<RenderProcessHostImpl*>(rph)-> |
114 set_is_for_guests_only_for_testing(true); | 114 set_is_for_guests_only_for_testing(true); |
115 EXPECT_EQ(1, RenderProcessHostCount()); | 115 EXPECT_EQ(1, RenderProcessHostCount()); |
116 | 116 |
117 // Navigate to a different page. | 117 // Navigate to a different page. |
118 GURL::Replacements replace_host; | 118 GURL::Replacements replace_host; |
119 replace_host.SetHostStr("localhost"); | 119 replace_host.SetHostStr("localhost"); |
120 GURL another_url = embedded_test_server()->GetURL("/simple_page.html"); | 120 GURL another_url = embedded_test_server()->GetURL("/simple_page.html"); |
121 another_url = another_url.ReplaceComponents(replace_host); | 121 another_url = another_url.ReplaceComponents(replace_host); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 AllProcessExitedCallsBeforeAnyHostDestroyedCalls) { | 175 AllProcessExitedCallsBeforeAnyHostDestroyedCalls) { |
176 ASSERT_TRUE(embedded_test_server()->Start()); | 176 ASSERT_TRUE(embedded_test_server()->Start()); |
177 | 177 |
178 GURL test_url = embedded_test_server()->GetURL("/simple_page.html"); | 178 GURL test_url = embedded_test_server()->GetURL("/simple_page.html"); |
179 NavigateToURL(shell(), test_url); | 179 NavigateToURL(shell(), test_url); |
180 | 180 |
181 std::string logging_string; | 181 std::string logging_string; |
182 ShellCloser shell_closer(shell(), &logging_string); | 182 ShellCloser shell_closer(shell(), &logging_string); |
183 ObserverLogger observer_logger(&logging_string); | 183 ObserverLogger observer_logger(&logging_string); |
184 RenderProcessHost* rph = | 184 RenderProcessHost* rph = |
185 shell()->web_contents()->GetRenderViewHost()->GetProcess(); | 185 shell()->web_contents()->GetMainFrame()->GetProcess(); |
186 | 186 |
187 // Ensure that the ShellCloser observer is first, so that it will have first | 187 // Ensure that the ShellCloser observer is first, so that it will have first |
188 // dibs on the ProcessExited callback. | 188 // dibs on the ProcessExited callback. |
189 rph->AddObserver(&shell_closer); | 189 rph->AddObserver(&shell_closer); |
190 rph->AddObserver(&observer_logger); | 190 rph->AddObserver(&observer_logger); |
191 | 191 |
192 // This will crash the render process, and start all the callbacks. | 192 // This will crash the render process, and start all the callbacks. |
193 // We can't use NavigateToURL here since it accesses the shell() after | 193 // We can't use NavigateToURL here since it accesses the shell() after |
194 // navigating, which the shell_closer deletes. | 194 // navigating, which the shell_closer deletes. |
195 NavigateToURLBlockUntilNavigationsComplete( | 195 NavigateToURLBlockUntilNavigationsComplete( |
(...skipping 13 matching lines...) Expand all Loading... |
209 rph->RemoveObserver(&observer_logger); | 209 rph->RemoveObserver(&observer_logger); |
210 } | 210 } |
211 } | 211 } |
212 | 212 |
213 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, KillProcessOnBadMojoMessage) { | 213 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, KillProcessOnBadMojoMessage) { |
214 ASSERT_TRUE(embedded_test_server()->Start()); | 214 ASSERT_TRUE(embedded_test_server()->Start()); |
215 | 215 |
216 GURL test_url = embedded_test_server()->GetURL("/simple_page.html"); | 216 GURL test_url = embedded_test_server()->GetURL("/simple_page.html"); |
217 NavigateToURL(shell(), test_url); | 217 NavigateToURL(shell(), test_url); |
218 RenderProcessHost* rph = | 218 RenderProcessHost* rph = |
219 shell()->web_contents()->GetRenderViewHost()->GetProcess(); | 219 shell()->web_contents()->GetMainFrame()->GetProcess(); |
220 | 220 |
221 host_destructions_ = 0; | 221 host_destructions_ = 0; |
222 process_exits_ = 0; | 222 process_exits_ = 0; |
223 rph->AddObserver(this); | 223 rph->AddObserver(this); |
224 | 224 |
225 mojom::TestServicePtr service; | 225 mojom::TestServicePtr service; |
226 rph->GetRemoteInterfaces()->GetInterface(&service); | 226 rph->GetRemoteInterfaces()->GetInterface(&service); |
227 | 227 |
228 base::RunLoop run_loop; | 228 base::RunLoop run_loop; |
229 set_process_exit_callback(run_loop.QuitClosure()); | 229 set_process_exit_callback(run_loop.QuitClosure()); |
230 | 230 |
231 // Should reply with a bad message and cause process death. | 231 // Should reply with a bad message and cause process death. |
232 service->DoSomething(base::Bind(&base::DoNothing)); | 232 service->DoSomething(base::Bind(&base::DoNothing)); |
233 | 233 |
234 run_loop.Run(); | 234 run_loop.Run(); |
235 | 235 |
236 EXPECT_EQ(1, process_exits_); | 236 EXPECT_EQ(1, process_exits_); |
237 EXPECT_EQ(0, host_destructions_); | 237 EXPECT_EQ(0, host_destructions_); |
238 if (!host_destructions_) | 238 if (!host_destructions_) |
239 rph->RemoveObserver(this); | 239 rph->RemoveObserver(this); |
240 } | 240 } |
241 | 241 |
242 } // namespace | 242 } // namespace |
243 } // namespace content | 243 } // namespace content |
OLD | NEW |