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

Unified Diff: content/browser/site_per_process_browsertest.cc

Issue 156303004: With --site-per-process, avoid a crash when a subframe process goes away. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable on GTK, add test. Created 6 years, 10 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/site_per_process_browsertest.cc
diff --git a/content/browser/site_per_process_browsertest.cc b/content/browser/site_per_process_browsertest.cc
index 1523ec543d674def40af35ebff109ed8766a8ffc..a43dc6a3134b7fd38f68c330fac1d9239335fb94 100644
--- a/content/browser/site_per_process_browsertest.cc
+++ b/content/browser/site_per_process_browsertest.cc
@@ -161,16 +161,33 @@ void RedirectNotificationObserver::Observe(
class SitePerProcessBrowserTest : public ContentBrowserTest {
protected:
+ // Start at a data URL so each extra navigation creates a navigation entry.
+ // (The first navigation will silently be classified as AUTO_SUBFRAME.)
+ // TODO(creis): This won't be necessary when we can wait for LOAD_STOP.
+ void StartFrameAtDataURL() {
+ std::string data_url_script =
+ "var iframes = document.getElementById('test');iframes.src="
+ "'data:text/html,dataurl';";
+ ASSERT_TRUE(ExecuteScript(shell()->web_contents(), data_url_script));
+ }
+
bool NavigateIframeToURL(Shell* window,
const GURL& url,
std::string iframe_id) {
+ // TODO(creis): This should wait for LOAD_STOP, but cross-site subframe
+ // navigations generate extra DidStartLoading and DidStopLoading messages.
+ // Until we replace swappedout:// with frame proxies, we need to listen for
+ // something else. For now, we trigger NEW_SUBFRAME navigations and listen
+ // for commit.
std::string script = base::StringPrintf(
- "var iframes = document.getElementById('%s');iframes.src='%s';",
+ "setTimeout(\""
+ "var iframes = document.getElementById('%s');iframes.src='%s';"
+ "\",0)",
iframe_id.c_str(), url.spec().c_str());
WindowedNotificationObserver load_observer(
- NOTIFICATION_LOAD_STOP,
+ NOTIFICATION_NAV_ENTRY_COMMITTED,
Source<NavigationController>(
- &shell()->web_contents()->GetController()));
+ &window->web_contents()->GetController()));
bool result = ExecuteScript(window->web_contents(), script);
load_observer.Wait();
return result;
@@ -196,10 +213,15 @@ class SitePerProcessBrowserTest : public ContentBrowserTest {
};
// Ensure that we can complete a cross-process subframe navigation.
-// TODO(nasko): Disable this test for now, since enabling swapping out of
-// RenderFrameHosts causes this to break. Fix this test once
-// didFailProvisionalLoad is moved from RenderView to RenderFrame.
-IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_CrossSiteIframe) {
+// This is disabled on GTK due to a NOTREACHED in
+// RenderWidgetHostViewChildFrame::AllocBackingStore. GTK support will be
nasko 2014/02/11 04:49:16 This reminded me that I worked around this in my b
Charlie Reis 2014/02/12 00:27:57 I'll give it a try in SetUpCommandLine.
+// removed before we support site-per-process.
+#if defined(TOOLKIT_GTK)
+#define MAYBE_CrossSiteIframe DISABLED_CrossSiteIframe
+#else
+#define MAYBE_CrossSiteIframe CrossSiteIframe
+#endif
+IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, MAYBE_CrossSiteIframe) {
ASSERT_TRUE(test_server()->Start());
net::SpawnedTestServer https_server(
net::SpawnedTestServer::TYPE_HTTPS,
@@ -207,21 +229,22 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_CrossSiteIframe) {
base::FilePath(FILE_PATH_LITERAL("content/test/data")));
ASSERT_TRUE(https_server.Start());
GURL main_url(test_server()->GetURL("files/site_per_process_main.html"));
-
NavigateToURL(shell(), main_url);
+ StartFrameAtDataURL();
+
SitePerProcessWebContentsObserver observer(shell()->web_contents());
// Load same-site page into iframe.
GURL http_url(test_server()->GetURL("files/title1.html"));
EXPECT_TRUE(NavigateIframeToURL(shell(), http_url, "test"));
- EXPECT_EQ(observer.navigation_url(), http_url);
+ EXPECT_EQ(http_url, observer.navigation_url());
EXPECT_TRUE(observer.navigation_succeeded());
// Load cross-site page into iframe.
GURL https_url(https_server.GetURL("files/title1.html"));
EXPECT_TRUE(NavigateIframeToURL(shell(), https_url, "test"));
- EXPECT_EQ(observer.navigation_url(), https_url);
+ EXPECT_EQ(https_url, observer.navigation_url());
EXPECT_TRUE(observer.navigation_succeeded());
// Ensure that we have created a new process for the subframe.
@@ -238,6 +261,58 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_CrossSiteIframe) {
child->current_frame_host()->GetProcess());
}
+// Crash a subframe and ensures its children are cleared from the FrameTree.
+// See http://crbug.com/338508.
+#if defined(TOOLKIT_GTK)
+#define MAYBE_CrashSubframe DISABLED_CrashSubframe
+#else
+#define MAYBE_CrashSubframe CrashSubframe
+#endif
+IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, MAYBE_CrashSubframe) {
+ ASSERT_TRUE(test_server()->Start());
+ net::SpawnedTestServer https_server(
+ net::SpawnedTestServer::TYPE_HTTPS,
+ net::SpawnedTestServer::kLocalhost,
+ base::FilePath(FILE_PATH_LITERAL("content/test/data")));
+ ASSERT_TRUE(https_server.Start());
+ GURL main_url(test_server()->GetURL("files/site_per_process_main.html"));
+ NavigateToURL(shell(), main_url);
+
+ StartFrameAtDataURL();
+
+ // Load cross-site page into iframe.
+ GURL https_url(https_server.GetURL("files/title1.html"));
+ EXPECT_TRUE(NavigateIframeToURL(shell(), https_url, "test"));
nasko 2014/02/11 04:49:16 This reminds me that it soon might be the time to
Charlie Reis 2014/02/12 00:27:57 That will be great.
+
+ // Check the subframe process.
+ FrameTreeNode* root =
+ static_cast<WebContentsImpl*>(shell()->web_contents())->
+ GetFrameTree()->root();
+ ASSERT_EQ(1U, root->child_count());
+ FrameTreeNode* child = root->child_at(0);
+
+ // Crash the subframe process.
+ RenderProcessHost* root_process =
+ shell()->web_contents()->GetRenderProcessHost();
nasko 2014/02/11 04:49:16 nit: Why not keep it consistent with the next line
Charlie Reis 2014/02/12 00:27:57 Done.
+ RenderProcessHost* child_process = child->current_frame_host()->GetProcess();
+ RenderProcessHostWatcher crash_observer(
+ child_process,
+ RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
+ base::KillProcess(child_process->GetHandle(), 0, false);
+ crash_observer.Wait();
+
+ // Ensure that the child frame still exists but has been cleared.
nasko 2014/02/11 04:49:16 nit: How are we testing that it is cleared?
Charlie Reis 2014/02/12 00:27:57 Heh, I started with some lines to check that the U
+ EXPECT_EQ(1U, root->child_count());
+
+ // Now crash the top-level page to clear the child frame.
+ RenderProcessHostWatcher crash_observer2(
nasko 2014/02/11 04:49:16 nit: Why not add local scope to avoid having varia
Charlie Reis 2014/02/12 00:27:57 Done.
+ root_process,
+ RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
+ base::KillProcess(root_process->GetHandle(), 0, false);
+ crash_observer2.Wait();
+ EXPECT_EQ(0U, root->child_count());
+}
+
// TODO(nasko): Disable this test until out-of-process iframes is ready and the
// security checks are back in place.
IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,

Powered by Google App Engine
This is Rietveld 408576698