Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: content/browser/renderer_host/render_process_host_browsertest.cc

Issue 2929113002: Enable spare RenderProcessHost to be preinitialized. (Closed)
Patch Set: remove unneeded include Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_frame_host.h"
12 #include "content/public/browser/render_process_host.h" 12 #include "content/public/browser/render_process_host.h"
13 #include "content/public/browser/render_process_host_observer.h" 13 #include "content/public/browser/render_process_host_observer.h"
14 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/url_constants.h" 15 #include "content/public/common/url_constants.h"
16 #include "content/public/test/content_browser_test.h" 16 #include "content/public/test/content_browser_test.h"
17 #include "content/public/test/content_browser_test_utils.h" 17 #include "content/public/test/content_browser_test_utils.h"
18 #include "content/public/test/test_service.mojom.h" 18 #include "content/public/test/test_service.mojom.h"
19 #include "content/shell/browser/shell.h" 19 #include "content/shell/browser/shell.h"
20 #include "content/shell/browser/shell_browser_context.h"
21 #include "content/shell/browser/shell_browser_main_parts.h"
22 #include "content/shell/browser/shell_content_browser_client.h"
20 #include "media/base/bind_to_current_loop.h" 23 #include "media/base/bind_to_current_loop.h"
21 #include "media/base/media_switches.h" 24 #include "media/base/media_switches.h"
22 #include "media/base/test_data_util.h" 25 #include "media/base/test_data_util.h"
23 #include "media/mojo/features.h" 26 #include "media/mojo/features.h"
24 #include "net/test/embedded_test_server/embedded_test_server.h" 27 #include "net/test/embedded_test_server/embedded_test_server.h"
25 28
26 #if defined(OS_WIN) 29 #if defined(OS_WIN)
27 #include "base/win/windows_version.h" 30 #include "base/win/windows_version.h"
28 #endif 31 #endif
29 32
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 set_is_for_guests_only_for_testing(true); 122 set_is_for_guests_only_for_testing(true);
120 EXPECT_EQ(1, RenderProcessHostCount()); 123 EXPECT_EQ(1, RenderProcessHostCount());
121 124
122 // Navigate to a different page. 125 // Navigate to a different page.
123 GURL::Replacements replace_host; 126 GURL::Replacements replace_host;
124 replace_host.SetHostStr("localhost"); 127 replace_host.SetHostStr("localhost");
125 GURL another_url = embedded_test_server()->GetURL("/simple_page.html"); 128 GURL another_url = embedded_test_server()->GetURL("/simple_page.html");
126 another_url = another_url.ReplaceComponents(replace_host); 129 another_url = another_url.ReplaceComponents(replace_host);
127 NavigateToURL(CreateBrowser(), another_url); 130 NavigateToURL(CreateBrowser(), another_url);
128 131
129 // Expect that we got another process (the guest renderer was not reused). 132 // Expect that we got another process (the guest RenderProcessHost was not
133 // reused).
130 EXPECT_EQ(2, RenderProcessHostCount()); 134 EXPECT_EQ(2, RenderProcessHostCount());
131 } 135 }
132 136
137 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, SpareRenderProcessHostTaken) {
138 ASSERT_TRUE(embedded_test_server()->Start());
139
140 RenderProcessHost::WarmupSpareRenderProcessHost(
141 ShellContentBrowserClient::Get()->browser_context());
142 RenderProcessHost* spare_renderer =
143 RenderProcessHostImpl::GetSpareRenderProcessHostForTesting();
144 EXPECT_NE(nullptr, spare_renderer);
145
146 GURL test_url = embedded_test_server()->GetURL("/simple_page.html");
147 Shell* window = CreateBrowser();
148 NavigateToURL(window, test_url);
149
150 EXPECT_EQ(spare_renderer,
151 window->web_contents()->GetMainFrame()->GetProcess());
152
153 // The spare render process host should no longer be available.
154 EXPECT_EQ(nullptr,
155 RenderProcessHostImpl::GetSpareRenderProcessHostForTesting());
156 }
157
158 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, SpareRenderProcessHostNotTaken) {
159 ASSERT_TRUE(embedded_test_server()->Start());
160
161 RenderProcessHost::WarmupSpareRenderProcessHost(
162 ShellContentBrowserClient::Get()->off_the_record_browser_context());
163 RenderProcessHost* spare_renderer =
164 RenderProcessHostImpl::GetSpareRenderProcessHostForTesting();
165 GURL test_url = embedded_test_server()->GetURL("/simple_page.html");
166 Shell* window = CreateBrowser();
167 NavigateToURL(window, test_url);
168
169 // There should have been another process created for the navigation.
170 EXPECT_NE(spare_renderer,
171 window->web_contents()->GetMainFrame()->GetProcess());
172
173 // The spare RenderProcessHost should have been cleaned up. Note this
174 // behavior is identical to what would have happened if the RenderProcessHost
175 // were taken.
176 EXPECT_EQ(nullptr,
177 RenderProcessHostImpl::GetSpareRenderProcessHostForTesting());
178 }
179
180 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, SpareRenderProcessHostKilled) {
181 RenderProcessHost::WarmupSpareRenderProcessHost(
182 ShellContentBrowserClient::Get()->browser_context());
183
184 RenderProcessHost* spare_renderer =
185 RenderProcessHostImpl::GetSpareRenderProcessHostForTesting();
186 mojom::TestServicePtr service;
187 ASSERT_NE(nullptr, spare_renderer);
188 BindInterface(spare_renderer, &service);
189
190 base::RunLoop run_loop;
191 set_process_exit_callback(run_loop.QuitClosure());
192 spare_renderer->AddObserver(this); // For process_exit_callback.
193
194 // Should reply with a bad message and cause process death.
195 service->DoSomething(base::Bind(&base::DoNothing));
196 run_loop.Run();
197
198 // The spare RenderProcessHost should disappear when its process dies.
199 EXPECT_EQ(nullptr,
200 RenderProcessHostImpl::GetSpareRenderProcessHostForTesting());
201 }
202
133 class ShellCloser : public RenderProcessHostObserver { 203 class ShellCloser : public RenderProcessHostObserver {
134 public: 204 public:
135 ShellCloser(Shell* shell, std::string* logging_string) 205 ShellCloser(Shell* shell, std::string* logging_string)
136 : shell_(shell), logging_string_(logging_string) {} 206 : shell_(shell), logging_string_(logging_string) {}
137 207
138 protected: 208 protected:
139 // RenderProcessHostObserver: 209 // RenderProcessHostObserver:
140 void RenderProcessExited(RenderProcessHost* host, 210 void RenderProcessExited(RenderProcessHost* host,
141 base::TerminationStatus status, 211 base::TerminationStatus status,
142 int exit_code) override { 212 int exit_code) override {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 // Verify shutdown went as expected. 392 // Verify shutdown went as expected.
323 EXPECT_EQ(0, rph->get_audio_stream_count_for_testing()); 393 EXPECT_EQ(0, rph->get_audio_stream_count_for_testing());
324 EXPECT_EQ(1, process_exits_); 394 EXPECT_EQ(1, process_exits_);
325 EXPECT_EQ(0, host_destructions_); 395 EXPECT_EQ(0, host_destructions_);
326 if (!host_destructions_) 396 if (!host_destructions_)
327 rph->RemoveObserver(this); 397 rph->RemoveObserver(this);
328 } 398 }
329 399
330 } // namespace 400 } // namespace
331 } // namespace content 401 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698