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

Unified Diff: chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc

Issue 213413005: Ensure RenderViewHost is not shut down until a screenshot of the page is taken. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implementing review feedback. Created 6 years, 9 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: chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc
diff --git a/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc b/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc
index 6d47d2b608808c7f73ffb7d3ef40b0532e2f5a38..6aa1ab125e6e1ac8f2f446ba114188c35b600053 100644
--- a/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc
+++ b/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc
@@ -17,10 +17,12 @@
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/render_process_host_observer.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_iterator.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
+#include "content/public/test/browser_test_utils.h"
using content::RenderViewHost;
using content::RenderWidgetHost;
@@ -111,9 +113,22 @@ class ChromeRenderProcessHostTest : public InProcessBrowserTest {
content::RenderProcessHost* rph2 = NULL;
content::RenderProcessHost* rph3 = NULL;
- // Change the first tab to be the omnibox page (TYPE_WEBUI).
+ EXPECT_EQ(host_count, RenderProcessHostCount());
+ ASSERT_EQ(tab_count, browser()->tab_strip_model()->count());
+
+ tab1 = browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1);
+ content::RenderProcessHostWatcher process_watcher(
+ tab1->GetRenderProcessHost(),
+ content::RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION);
+
+ // Change the first tab to be the omnibox page (TYPE_WEBUI). The navigation
+ // should terminate the existing process.
GURL omnibox(chrome::kChromeUIOmniboxURL);
ui_test_utils::NavigateToURL(browser(), omnibox);
+ // Wait for the RPH of the previous page (i.e. starting page) to be
+ // destroyed. The host does not get destroyed until the screenshot of the
+ // page is taken, which may happen after the navigation completes.
+ process_watcher.Wait();
EXPECT_EQ(tab_count, browser()->tab_strip_model()->count());
tab1 = browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1);
rph1 = tab1->GetRenderProcessHost();
@@ -204,9 +219,22 @@ IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, ProcessPerTab) {
int tab_count = 1;
int host_count = 1;
+ EXPECT_EQ(tab_count, browser()->tab_strip_model()->count());
+ EXPECT_EQ(host_count, RenderProcessHostCount());
+
+ WebContents* tab1 =
+ browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1);
+ content::RenderProcessHostWatcher process_watcher(
+ tab1->GetRenderProcessHost(),
+ content::RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION);
+
// Change the first tab to be the new tab page (TYPE_WEBUI).
GURL omnibox(chrome::kChromeUIOmniboxURL);
ui_test_utils::NavigateToURL(browser(), omnibox);
+ // Wait for the RPH of the previous page (i.e. starting page) to be
+ // destroyed. The host does not get destroyed until the screenshot of the
+ // page is taken, which may happen after the navigation completes.
+ process_watcher.Wait();
EXPECT_EQ(tab_count, browser()->tab_strip_model()->count());
EXPECT_EQ(host_count, RenderProcessHostCount());

Powered by Google App Engine
This is Rietveld 408576698