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

Side by Side Diff: chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc

Issue 305373004: Fix renderer process host backgrounding test on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Wait for script. Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_view_host.h" 20 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/render_widget_host_iterator.h" 21 #include "content/public/browser/render_widget_host_iterator.h"
22 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "content/public/browser/web_contents_observer.h" 23 #include "content/public/browser/web_contents_observer.h"
24 #include "content/public/test/browser_test_utils.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
31 int RenderProcessHostCount() { 32 int RenderProcessHostCount() {
32 content::RenderProcessHost::iterator hosts = 33 content::RenderProcessHost::iterator hosts =
33 content::RenderProcessHost::AllHostsIterator(); 34 content::RenderProcessHost::AllHostsIterator();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 66
66 // Show a tab, activating the current one if there is one, and wait for 67 // Show a tab, activating the current one if there is one, and wait for
67 // the renderer process to be created or foregrounded, returning the process 68 // the renderer process to be created or foregrounded, returning the process
68 // handle. 69 // handle.
69 base::ProcessHandle ShowSingletonTab(const GURL& page) { 70 base::ProcessHandle ShowSingletonTab(const GURL& page) {
70 chrome::ShowSingletonTab(browser(), page); 71 chrome::ShowSingletonTab(browser(), page);
71 WebContents* wc = browser()->tab_strip_model()->GetActiveWebContents(); 72 WebContents* wc = browser()->tab_strip_model()->GetActiveWebContents();
72 CHECK(wc->GetURL() == page); 73 CHECK(wc->GetURL() == page);
73 74
74 WaitForLauncherThread(); 75 WaitForLauncherThread();
76 WaitForMessageProcessing(wc);
75 return wc->GetRenderProcessHost()->GetHandle(); 77 return wc->GetRenderProcessHost()->GetHandle();
76 } 78 }
77 79
78 // Loads the given url in a new background tab and returns the handle of its 80 // Loads the given url in a new background tab and returns the handle of its
79 // renderer. 81 // renderer.
80 base::ProcessHandle OpenBackgroundTab(const GURL& page) { 82 base::ProcessHandle OpenBackgroundTab(const GURL& page) {
81 ui_test_utils::NavigateToURLWithDisposition(browser(), page, 83 ui_test_utils::NavigateToURLWithDisposition(browser(), page,
82 NEW_BACKGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 84 NEW_BACKGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
83 85
84 TabStripModel* tab_strip = browser()->tab_strip_model(); 86 TabStripModel* tab_strip = browser()->tab_strip_model();
85 WebContents* wc = tab_strip->GetWebContentsAt( 87 WebContents* wc = tab_strip->GetWebContentsAt(
86 tab_strip->active_index() + 1); 88 tab_strip->active_index() + 1);
87 CHECK(wc->GetVisibleURL() == page); 89 CHECK(wc->GetVisibleURL() == page);
88 90
89 WaitForLauncherThread(); 91 WaitForLauncherThread();
92 WaitForMessageProcessing(wc);
90 return wc->GetRenderProcessHost()->GetHandle(); 93 return wc->GetRenderProcessHost()->GetHandle();
91 } 94 }
92 95
93 // Ensures that the backgrounding / foregrounding gets a chance to run. 96 // Ensures that the backgrounding / foregrounding gets a chance to run.
94 void WaitForLauncherThread() { 97 void WaitForLauncherThread() {
95 content::BrowserThread::PostTaskAndReply( 98 content::BrowserThread::PostTaskAndReply(
96 content::BrowserThread::PROCESS_LAUNCHER, FROM_HERE, 99 content::BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
97 base::Bind(&base::DoNothing), base::MessageLoop::QuitClosure()); 100 base::Bind(&base::DoNothing), base::MessageLoop::QuitClosure());
98 base::MessageLoop::current()->Run(); 101 base::MessageLoop::current()->Run();
99 } 102 }
100 103
104 // Implicitly waits for the given WebContents to process outstanding IPC
105 // messages by running some JavaScript and waiting for the result.
jam 2014/06/04 01:06:05 this comment is a bit misleading; afaik you're wai
DaleCurtis 2014/06/04 01:10:18 Done.
106 void WaitForMessageProcessing(WebContents* wc) {
107 bool result = false;
108 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
109 wc, "window.domAutomationController.send(true);", &result));
110 ASSERT_TRUE(result);
111 }
112
101 // When we hit the max number of renderers, verify that the way we do process 113 // When we hit the max number of renderers, verify that the way we do process
102 // sharing behaves correctly. In particular, this test is verifying that even 114 // sharing behaves correctly. In particular, this test is verifying that even
103 // when we hit the max process limit, that renderers of each type will wind up 115 // when we hit the max process limit, that renderers of each type will wind up
104 // in a process of that type, even if that means creating a new process. 116 // in a process of that type, even if that means creating a new process.
105 void TestProcessOverflow() { 117 void TestProcessOverflow() {
106 int tab_count = 1; 118 int tab_count = 1;
107 int host_count = 1; 119 int host_count = 1;
108 WebContents* tab1 = NULL; 120 WebContents* tab1 = NULL;
109 WebContents* tab2 = NULL; 121 WebContents* tab2 = NULL;
110 content::RenderProcessHost* rph1 = NULL; 122 content::RenderProcessHost* rph1 = NULL;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 ui_test_utils::NavigateToURLWithDisposition( 257 ui_test_utils::NavigateToURLWithDisposition(
246 browser(), omnibox, NEW_FOREGROUND_TAB, 258 browser(), omnibox, NEW_FOREGROUND_TAB,
247 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 259 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
248 tab_count++; 260 tab_count++;
249 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count()); 261 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count());
250 EXPECT_EQ(host_count, RenderProcessHostCount()); 262 EXPECT_EQ(host_count, RenderProcessHostCount());
251 } 263 }
252 264
253 // We don't change process priorities on Mac or Posix because the user lacks the 265 // We don't change process priorities on Mac or Posix because the user lacks the
254 // permission to raise a process' priority even after lowering it. 266 // permission to raise a process' priority even after lowering it.
255 // TODO(dalecurtis): Reenable this on Windows after figuring out how to reliably 267 #if defined(OS_WIN) || defined(OS_LINUX)
256 // wait for the renderer process to process IPC messages.
257 #if defined(OS_LINUX)
258 IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, Backgrounding) { 268 IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, Backgrounding) {
259 if (!base::Process::CanBackgroundProcesses()) { 269 if (!base::Process::CanBackgroundProcesses()) {
260 LOG(ERROR) << "Can't background processes"; 270 LOG(ERROR) << "Can't background processes";
261 return; 271 return;
262 } 272 }
263 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 273 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
264 parsed_command_line.AppendSwitch(switches::kProcessPerTab); 274 parsed_command_line.AppendSwitch(switches::kProcessPerTab);
265 275
266 // Change the first tab to be the omnibox page (TYPE_WEBUI). 276 // Change the first tab to be the omnibox page (TYPE_WEBUI).
267 GURL omnibox(chrome::kChromeUIOmniboxURL); 277 GURL omnibox(chrome::kChromeUIOmniboxURL);
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 chrome::NOTIFICATION_BROWSER_CLOSED, 481 chrome::NOTIFICATION_BROWSER_CLOSED,
472 content::NotificationService::AllSources()); 482 content::NotificationService::AllSources());
473 483
474 // Kill the renderer process, simulating a crash. This should the ProcessDied 484 // Kill the renderer process, simulating a crash. This should the ProcessDied
475 // method to be called. Alternatively, RenderProcessHost::OnChannelError can 485 // method to be called. Alternatively, RenderProcessHost::OnChannelError can
476 // be called to directly force a call to ProcessDied. 486 // be called to directly force a call to ProcessDied.
477 base::KillProcess(wc1->GetRenderProcessHost()->GetHandle(), -1, true); 487 base::KillProcess(wc1->GetRenderProcessHost()->GetHandle(), -1, true);
478 488
479 observer.Wait(); 489 observer.Wait();
480 } 490 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698