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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/command_line.h" 5 #include "base/command_line.h"
6 #include "chrome/browser/chrome_notification_types.h" 6 #include "chrome/browser/chrome_notification_types.h"
7 #include "chrome/browser/devtools/devtools_window.h" 7 #include "chrome/browser/devtools/devtools_window.h"
8 #include "chrome/browser/search/search.h" 8 #include "chrome/browser/search/search.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_commands.h" 10 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/singleton_tabs.h" 11 #include "chrome/browser/ui/singleton_tabs.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/test_switches.h" 16 #include "chrome/test/base/test_switches.h"
17 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/render_process_host.h" 19 #include "content/public/browser/render_process_host.h"
20 #include "content/public/browser/render_process_host_observer.h"
20 #include "content/public/browser/render_view_host.h" 21 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/render_widget_host_iterator.h" 22 #include "content/public/browser/render_widget_host_iterator.h"
22 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
23 #include "content/public/browser/web_contents_observer.h" 24 #include "content/public/browser/web_contents_observer.h"
25 #include "content/public/test/browser_test_utils.h"
24 26
25 using content::RenderViewHost; 27 using content::RenderViewHost;
26 using content::RenderWidgetHost; 28 using content::RenderWidgetHost;
27 using content::WebContents; 29 using content::WebContents;
28 30
29 namespace { 31 namespace {
30 32
31 int RenderProcessHostCount() { 33 int RenderProcessHostCount() {
32 content::RenderProcessHost::iterator hosts = 34 content::RenderProcessHost::iterator hosts =
33 content::RenderProcessHost::AllHostsIterator(); 35 content::RenderProcessHost::AllHostsIterator();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // in a process of that type, even if that means creating a new process. 106 // in a process of that type, even if that means creating a new process.
105 void TestProcessOverflow() { 107 void TestProcessOverflow() {
106 int tab_count = 1; 108 int tab_count = 1;
107 int host_count = 1; 109 int host_count = 1;
108 WebContents* tab1 = NULL; 110 WebContents* tab1 = NULL;
109 WebContents* tab2 = NULL; 111 WebContents* tab2 = NULL;
110 content::RenderProcessHost* rph1 = NULL; 112 content::RenderProcessHost* rph1 = NULL;
111 content::RenderProcessHost* rph2 = NULL; 113 content::RenderProcessHost* rph2 = NULL;
112 content::RenderProcessHost* rph3 = NULL; 114 content::RenderProcessHost* rph3 = NULL;
113 115
114 // Change the first tab to be the omnibox page (TYPE_WEBUI). 116 EXPECT_EQ(host_count, RenderProcessHostCount());
117 ASSERT_EQ(tab_count, browser()->tab_strip_model()->count());
118
119 tab1 = browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1);
120 content::RenderProcessHostWatcher process_watcher(
121 tab1->GetRenderProcessHost(),
122 content::RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION);
123
124 // Change the first tab to be the omnibox page (TYPE_WEBUI). The navigation
125 // should terminate the existing process.
115 GURL omnibox(chrome::kChromeUIOmniboxURL); 126 GURL omnibox(chrome::kChromeUIOmniboxURL);
116 ui_test_utils::NavigateToURL(browser(), omnibox); 127 ui_test_utils::NavigateToURL(browser(), omnibox);
128 // Wait for the RPH of the previous page (i.e. starting page) to be
129 // destroyed. The host does not get destroyed until the screenshot of the
130 // page is taken, which may happen after the navigation completes.
131 process_watcher.Wait();
117 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count()); 132 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count());
118 tab1 = browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1); 133 tab1 = browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1);
119 rph1 = tab1->GetRenderProcessHost(); 134 rph1 = tab1->GetRenderProcessHost();
120 EXPECT_EQ(omnibox, tab1->GetURL()); 135 EXPECT_EQ(omnibox, tab1->GetURL());
121 EXPECT_EQ(host_count, RenderProcessHostCount()); 136 EXPECT_EQ(host_count, RenderProcessHostCount());
122 137
123 // Create a new TYPE_TABBED tab. It should be in its own process. 138 // Create a new TYPE_TABBED tab. It should be in its own process.
124 GURL page1("data:text/html,hello world1"); 139 GURL page1("data:text/html,hello world1");
125 140
126 ui_test_utils::WindowedTabAddedNotificationObserver observer1( 141 ui_test_utils::WindowedTabAddedNotificationObserver observer1(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, ProcessPerTab) { 212 IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, ProcessPerTab) {
198 // Set max renderers to 1 to force running out of processes. 213 // Set max renderers to 1 to force running out of processes.
199 content::RenderProcessHost::SetMaxRendererProcessCount(1); 214 content::RenderProcessHost::SetMaxRendererProcessCount(1);
200 215
201 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 216 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
202 parsed_command_line.AppendSwitch(switches::kProcessPerTab); 217 parsed_command_line.AppendSwitch(switches::kProcessPerTab);
203 218
204 int tab_count = 1; 219 int tab_count = 1;
205 int host_count = 1; 220 int host_count = 1;
206 221
222 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count());
223 EXPECT_EQ(host_count, RenderProcessHostCount());
224
225 WebContents* tab1 =
226 browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1);
227 content::RenderProcessHostWatcher process_watcher(
228 tab1->GetRenderProcessHost(),
229 content::RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION);
230
207 // Change the first tab to be the new tab page (TYPE_WEBUI). 231 // Change the first tab to be the new tab page (TYPE_WEBUI).
208 GURL omnibox(chrome::kChromeUIOmniboxURL); 232 GURL omnibox(chrome::kChromeUIOmniboxURL);
209 ui_test_utils::NavigateToURL(browser(), omnibox); 233 ui_test_utils::NavigateToURL(browser(), omnibox);
234 // Wait for the RPH of the previous page (i.e. starting page) to be
235 // destroyed. The host does not get destroyed until the screenshot of the
236 // page is taken, which may happen after the navigation completes.
237 process_watcher.Wait();
210 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count()); 238 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count());
211 EXPECT_EQ(host_count, RenderProcessHostCount()); 239 EXPECT_EQ(host_count, RenderProcessHostCount());
212 240
213 // Create a new TYPE_TABBED tab. It should be in its own process. 241 // Create a new TYPE_TABBED tab. It should be in its own process.
214 GURL page1("data:text/html,hello world1"); 242 GURL page1("data:text/html,hello world1");
215 ui_test_utils::WindowedTabAddedNotificationObserver observer1( 243 ui_test_utils::WindowedTabAddedNotificationObserver observer1(
216 content::NotificationService::AllSources()); 244 content::NotificationService::AllSources());
217 chrome::ShowSingletonTab(browser(), page1); 245 chrome::ShowSingletonTab(browser(), page1);
218 observer1.Wait(); 246 observer1.Wait();
219 tab_count++; 247 tab_count++;
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 chrome::NOTIFICATION_BROWSER_CLOSED, 497 chrome::NOTIFICATION_BROWSER_CLOSED,
470 content::NotificationService::AllSources()); 498 content::NotificationService::AllSources());
471 499
472 // Kill the renderer process, simulating a crash. This should the ProcessDied 500 // Kill the renderer process, simulating a crash. This should the ProcessDied
473 // method to be called. Alternatively, RenderProcessHost::OnChannelError can 501 // method to be called. Alternatively, RenderProcessHost::OnChannelError can
474 // be called to directly force a call to ProcessDied. 502 // be called to directly force a call to ProcessDied.
475 base::KillProcess(wc1->GetRenderProcessHost()->GetHandle(), -1, true); 503 base::KillProcess(wc1->GetRenderProcessHost()->GetHandle(), -1, true);
476 504
477 observer.Wait(); 505 observer.Wait();
478 } 506 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698