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

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: Fixing some unit tests. 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"
24 25
25 using content::RenderViewHost; 26 using content::RenderViewHost;
26 using content::RenderWidgetHost; 27 using content::RenderWidgetHost;
27 using content::WebContents; 28 using content::WebContents;
28 29
29 namespace { 30 namespace {
30 31
32 class RenderProcessHostAliveObserver
nasko 2014/03/26 22:48:27 Why create a new class? Doesn't RenderProcessHostW
mfomitchev 2014/03/27 21:51:34 Done.
33 : public content::RenderProcessHostObserver {
34 public:
35 explicit RenderProcessHostAliveObserver(content::RenderProcessHost* host)
36 : host_(host) {
37 host_->AddObserver(this);
38 }
39
40 virtual ~RenderProcessHostAliveObserver() {
41 CHECK(!host_);
42 }
43
44 void WaitUntilProcessDies() {
45 if (!host_)
46 return;
47 base::RunLoop run_loop;
48 quit_closure_ = run_loop.QuitClosure();
49 run_loop.Run();
50 }
51
52 private:
53 // content::RenderProcessHostObserver:
54 virtual void RenderProcessHostDestroyed(
55 content::RenderProcessHost* host) OVERRIDE {
56 CHECK_EQ(host_, host);
57 host_ = NULL;
58 if (!quit_closure_.is_null())
59 quit_closure_.Run();
60 }
61
62 content::RenderProcessHost* host_;
63 base::Closure quit_closure_;
64
65 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostAliveObserver);
66 };
67
31 int RenderProcessHostCount() { 68 int RenderProcessHostCount() {
32 content::RenderProcessHost::iterator hosts = 69 content::RenderProcessHost::iterator hosts =
33 content::RenderProcessHost::AllHostsIterator(); 70 content::RenderProcessHost::AllHostsIterator();
34 int count = 0; 71 int count = 0;
35 while (!hosts.IsAtEnd()) { 72 while (!hosts.IsAtEnd()) {
36 if (hosts.GetCurrentValue()->HasConnection()) 73 if (hosts.GetCurrentValue()->HasConnection())
37 count++; 74 count++;
38 hosts.Advance(); 75 hosts.Advance();
39 } 76 }
40 return count; 77 return count;
(...skipping 63 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. 141 // in a process of that type, even if that means creating a new process.
105 void TestProcessOverflow() { 142 void TestProcessOverflow() {
106 int tab_count = 1; 143 int tab_count = 1;
107 int host_count = 1; 144 int host_count = 1;
108 WebContents* tab1 = NULL; 145 WebContents* tab1 = NULL;
109 WebContents* tab2 = NULL; 146 WebContents* tab2 = NULL;
110 content::RenderProcessHost* rph1 = NULL; 147 content::RenderProcessHost* rph1 = NULL;
111 content::RenderProcessHost* rph2 = NULL; 148 content::RenderProcessHost* rph2 = NULL;
112 content::RenderProcessHost* rph3 = NULL; 149 content::RenderProcessHost* rph3 = NULL;
113 150
114 // Change the first tab to be the omnibox page (TYPE_WEBUI). 151 EXPECT_EQ(host_count, RenderProcessHostCount());
152 ASSERT_EQ(tab_count, browser()->tab_strip_model()->count());
153
154 tab1 = browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1);
155 RenderProcessHostAliveObserver process_observer(
156 tab1->GetRenderProcessHost());
157
158 // Change the first tab to be the omnibox page (TYPE_WEBUI). The navigation
159 // should terminate the existing process.
115 GURL omnibox(chrome::kChromeUIOmniboxURL); 160 GURL omnibox(chrome::kChromeUIOmniboxURL);
116 ui_test_utils::NavigateToURL(browser(), omnibox); 161 ui_test_utils::NavigateToURL(browser(), omnibox);
162 process_observer.WaitUntilProcessDies();
nasko 2014/03/26 22:48:27 Please add a comment why we need to wait for the p
mfomitchev 2014/03/27 21:51:34 Done.
117 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count()); 163 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count());
118 tab1 = browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1); 164 tab1 = browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1);
119 rph1 = tab1->GetRenderProcessHost(); 165 rph1 = tab1->GetRenderProcessHost();
120 EXPECT_EQ(omnibox, tab1->GetURL()); 166 EXPECT_EQ(omnibox, tab1->GetURL());
121 EXPECT_EQ(host_count, RenderProcessHostCount()); 167 EXPECT_EQ(host_count, RenderProcessHostCount());
122 168
123 // Create a new TYPE_TABBED tab. It should be in its own process. 169 // Create a new TYPE_TABBED tab. It should be in its own process.
124 GURL page1("data:text/html,hello world1"); 170 GURL page1("data:text/html,hello world1");
125 171
126 ui_test_utils::WindowedTabAddedNotificationObserver observer1( 172 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) { 243 IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, ProcessPerTab) {
198 // Set max renderers to 1 to force running out of processes. 244 // Set max renderers to 1 to force running out of processes.
199 content::RenderProcessHost::SetMaxRendererProcessCount(1); 245 content::RenderProcessHost::SetMaxRendererProcessCount(1);
200 246
201 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 247 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
202 parsed_command_line.AppendSwitch(switches::kProcessPerTab); 248 parsed_command_line.AppendSwitch(switches::kProcessPerTab);
203 249
204 int tab_count = 1; 250 int tab_count = 1;
205 int host_count = 1; 251 int host_count = 1;
206 252
253 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count());
254 EXPECT_EQ(host_count, RenderProcessHostCount());
255
256 WebContents* tab1 =
257 browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1);
258 RenderProcessHostAliveObserver process_observer(tab1->GetRenderProcessHost());
259
207 // Change the first tab to be the new tab page (TYPE_WEBUI). 260 // Change the first tab to be the new tab page (TYPE_WEBUI).
208 GURL omnibox(chrome::kChromeUIOmniboxURL); 261 GURL omnibox(chrome::kChromeUIOmniboxURL);
209 ui_test_utils::NavigateToURL(browser(), omnibox); 262 ui_test_utils::NavigateToURL(browser(), omnibox);
263 process_observer.WaitUntilProcessDies();
nasko 2014/03/26 22:48:27 ditto on comment.
mfomitchev 2014/03/27 21:51:34 Done.
210 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count()); 264 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count());
211 EXPECT_EQ(host_count, RenderProcessHostCount()); 265 EXPECT_EQ(host_count, RenderProcessHostCount());
212 266
213 // Create a new TYPE_TABBED tab. It should be in its own process. 267 // Create a new TYPE_TABBED tab. It should be in its own process.
214 GURL page1("data:text/html,hello world1"); 268 GURL page1("data:text/html,hello world1");
215 ui_test_utils::WindowedTabAddedNotificationObserver observer1( 269 ui_test_utils::WindowedTabAddedNotificationObserver observer1(
216 content::NotificationService::AllSources()); 270 content::NotificationService::AllSources());
217 chrome::ShowSingletonTab(browser(), page1); 271 chrome::ShowSingletonTab(browser(), page1);
218 observer1.Wait(); 272 observer1.Wait();
219 tab_count++; 273 tab_count++;
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 chrome::NOTIFICATION_BROWSER_CLOSED, 523 chrome::NOTIFICATION_BROWSER_CLOSED,
470 content::NotificationService::AllSources()); 524 content::NotificationService::AllSources());
471 525
472 // Kill the renderer process, simulating a crash. This should the ProcessDied 526 // Kill the renderer process, simulating a crash. This should the ProcessDied
473 // method to be called. Alternatively, RenderProcessHost::OnChannelError can 527 // method to be called. Alternatively, RenderProcessHost::OnChannelError can
474 // be called to directly force a call to ProcessDied. 528 // be called to directly force a call to ProcessDied.
475 base::KillProcess(wc1->GetRenderProcessHost()->GetHandle(), -1, true); 529 base::KillProcess(wc1->GetRenderProcessHost()->GetHandle(), -1, true);
476 530
477 observer.Wait(); 531 observer.Wait();
478 } 532 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698