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

Unified Diff: content/browser/renderer_host/render_process_host_browsertest.cc

Issue 2929113002: Enable spare RenderProcessHost to be preinitialized. (Closed)
Patch Set: comments Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_process_host_browsertest.cc
diff --git a/content/browser/renderer_host/render_process_host_browsertest.cc b/content/browser/renderer_host/render_process_host_browsertest.cc
index 866e829d1b74c93dad22fc5b77ee71e84cf19598..c643a4618ece91b415b7b32fe8232d1027011b62 100644
--- a/content/browser/renderer_host/render_process_host_browsertest.cc
+++ b/content/browser/renderer_host/render_process_host_browsertest.cc
@@ -17,6 +17,8 @@
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_service.mojom.h"
#include "content/shell/browser/shell.h"
+#include "content/shell/browser/shell_browser_context.h"
+#include "content/shell/browser/shell_content_browser_client.h"
#include "media/base/bind_to_current_loop.h"
#include "media/base/media_switches.h"
#include "media/base/test_data_util.h"
@@ -42,6 +44,15 @@ int RenderProcessHostCount() {
return count;
}
+RenderProcessHost* FirstRenderProcessHost() {
+ content::RenderProcessHost::iterator hosts =
+ content::RenderProcessHost::AllHostsIterator();
+ if (!hosts.IsAtEnd()) {
+ return hosts.GetCurrentValue();
+ }
+ return nullptr;
+}
+
class RenderProcessHostTest : public ContentBrowserTest,
public RenderProcessHostObserver {
public:
@@ -126,10 +137,90 @@ IN_PROC_BROWSER_TEST_F(RenderProcessHostTest,
another_url = another_url.ReplaceComponents(replace_host);
NavigateToURL(CreateBrowser(), another_url);
- // Expect that we got another process (the guest renderer was not reused).
+ // Expect that we got another process (the guest RenderProcessHost was not
+ // reused).
EXPECT_EQ(2, RenderProcessHostCount());
}
+IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, SpareRenderProcessHostTaken) {
+ ASSERT_TRUE(embedded_test_server()->Start());
+
+ RenderProcessHost::WarmupSpareRenderProcessHost(
+ ShellContentBrowserClient::Get()->browser_context());
+ RenderProcessHost* spare_renderer = FirstRenderProcessHost();
+ EXPECT_NE(nullptr, spare_renderer);
+ EXPECT_EQ(RenderProcessHostImpl::GetSpareRenderProcessHostForTesting(),
+ spare_renderer);
Charlie Reis 2017/06/26 21:22:50 We might not need this line, if we can just use Ge
mattcary 2017/06/28 13:14:38 Done.
+
+ GURL test_url = embedded_test_server()->GetURL("/simple_page.html");
+ NavigateToURL(CreateBrowser(), test_url);
+
+ EXPECT_EQ(spare_renderer, FirstRenderProcessHost());
Charlie Reis 2017/06/26 21:22:50 I would suggest checking shell()->web_contents()->
mattcary 2017/06/28 13:14:38 Done, that's a good idea, thanks. This is what I w
+
+ // The spare render process host should no longer be available.
+ EXPECT_EQ(nullptr,
+ RenderProcessHostImpl::GetSpareRenderProcessHostForTesting());
+}
+
+IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, SpareRenderProcessHostNotTaken) {
+ ASSERT_TRUE(embedded_test_server()->Start());
+
+ RenderProcessHost::WarmupSpareRenderProcessHost(
+ ShellContentBrowserClient::Get()->off_the_record_browser_context());
+ RenderProcessHost* spare_renderer = FirstRenderProcessHost();
+ GURL test_url = embedded_test_server()->GetURL("/simple_page.html");
+ NavigateToURL(CreateBrowser(), test_url);
+
+ // There should have been another process created for the navigation.
+ EXPECT_NE(spare_renderer, FirstRenderProcessHost());
Charlie Reis 2017/06/26 21:22:50 Same here.
mattcary 2017/06/28 13:14:38 Done.
+
+ // The spare RenderProcessHost should have been cleaned up. Note this
+ // behavior is identical to what would have happened if the RenderProcessHost
+ // were taken.
+ EXPECT_EQ(nullptr,
+ RenderProcessHostImpl::GetSpareRenderProcessHostForTesting());
+}
+
+IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, SpareRenderProcessHostKilled) {
+ RenderProcessHost::WarmupSpareRenderProcessHost(
+ ShellContentBrowserClient::Get()->browser_context());
+
+ RenderProcessHost* spare =
+ RenderProcessHostImpl::GetSpareRenderProcessHostForTesting();
+ mojom::TestServicePtr service;
+ ASSERT_NE(nullptr, spare);
+ BindInterface(spare, &service);
+
+ base::RunLoop run_loop;
+ set_process_exit_callback(run_loop.QuitClosure());
+ spare->AddObserver(this); // For process_exit_callback.
+
+ // Should reply with a bad message and cause process death.
+ service->DoSomething(base::Bind(&base::DoNothing));
+ run_loop.Run();
+
+ // The spare RenderProcessHost should disappear when its process dies.
+ EXPECT_EQ(nullptr,
+ RenderProcessHostImpl::GetSpareRenderProcessHostForTesting());
+}
+
+IN_PROC_BROWSER_TEST_F(RenderProcessHostTest,
+ SpareRenderProcessHostStoragePartitionKilled) {
+ RenderProcessHost::WarmupSpareRenderProcessHost(
+ ShellContentBrowserClient::Get()->browser_context());
+ EXPECT_NE(nullptr,
+ RenderProcessHostImpl::GetSpareRenderProcessHostForTesting());
+
+ ShellContentBrowserClient::Get()
+ ->browser_context()
+ ->ShutdownStoragePartitions();
+
+ // The spare RenderProcessHost should disappear along with the
+ // StoragePartitions.
+ EXPECT_EQ(nullptr,
+ RenderProcessHostImpl::GetSpareRenderProcessHostForTesting());
+}
+
class ShellCloser : public RenderProcessHostObserver {
public:
ShellCloser(Shell* shell, std::string* logging_string)

Powered by Google App Engine
This is Rietveld 408576698