OLD | NEW |
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 Loading... |
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 renderer process associated with the specified |
| 105 // WebContents to process outstanding IPC messages by running some JavaScript |
| 106 // and waiting for the result. |
| 107 void WaitForMessageProcessing(WebContents* wc) { |
| 108 bool result = false; |
| 109 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 110 wc, "window.domAutomationController.send(true);", &result)); |
| 111 ASSERT_TRUE(result); |
| 112 } |
| 113 |
101 // When we hit the max number of renderers, verify that the way we do process | 114 // 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 | 115 // 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 | 116 // 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. | 117 // in a process of that type, even if that means creating a new process. |
105 void TestProcessOverflow() { | 118 void TestProcessOverflow() { |
106 int tab_count = 1; | 119 int tab_count = 1; |
107 int host_count = 1; | 120 int host_count = 1; |
108 WebContents* tab1 = NULL; | 121 WebContents* tab1 = NULL; |
109 WebContents* tab2 = NULL; | 122 WebContents* tab2 = NULL; |
110 content::RenderProcessHost* rph1 = NULL; | 123 content::RenderProcessHost* rph1 = NULL; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 ui_test_utils::NavigateToURLWithDisposition( | 258 ui_test_utils::NavigateToURLWithDisposition( |
246 browser(), omnibox, NEW_FOREGROUND_TAB, | 259 browser(), omnibox, NEW_FOREGROUND_TAB, |
247 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 260 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
248 tab_count++; | 261 tab_count++; |
249 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count()); | 262 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count()); |
250 EXPECT_EQ(host_count, RenderProcessHostCount()); | 263 EXPECT_EQ(host_count, RenderProcessHostCount()); |
251 } | 264 } |
252 | 265 |
253 // We don't change process priorities on Mac or Posix because the user lacks the | 266 // 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. | 267 // permission to raise a process' priority even after lowering it. |
255 // TODO(dalecurtis): Reenable this on Windows after figuring out how to reliably | 268 #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) { | 269 IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, Backgrounding) { |
259 if (!base::Process::CanBackgroundProcesses()) { | 270 if (!base::Process::CanBackgroundProcesses()) { |
260 LOG(ERROR) << "Can't background processes"; | 271 LOG(ERROR) << "Can't background processes"; |
261 return; | 272 return; |
262 } | 273 } |
263 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 274 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
264 parsed_command_line.AppendSwitch(switches::kProcessPerTab); | 275 parsed_command_line.AppendSwitch(switches::kProcessPerTab); |
265 | 276 |
266 // Change the first tab to be the omnibox page (TYPE_WEBUI). | 277 // Change the first tab to be the omnibox page (TYPE_WEBUI). |
267 GURL omnibox(chrome::kChromeUIOmniboxURL); | 278 GURL omnibox(chrome::kChromeUIOmniboxURL); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 chrome::NOTIFICATION_BROWSER_CLOSED, | 482 chrome::NOTIFICATION_BROWSER_CLOSED, |
472 content::NotificationService::AllSources()); | 483 content::NotificationService::AllSources()); |
473 | 484 |
474 // Kill the renderer process, simulating a crash. This should the ProcessDied | 485 // Kill the renderer process, simulating a crash. This should the ProcessDied |
475 // method to be called. Alternatively, RenderProcessHost::OnChannelError can | 486 // method to be called. Alternatively, RenderProcessHost::OnChannelError can |
476 // be called to directly force a call to ProcessDied. | 487 // be called to directly force a call to ProcessDied. |
477 base::KillProcess(wc1->GetRenderProcessHost()->GetHandle(), -1, true); | 488 base::KillProcess(wc1->GetRenderProcessHost()->GetHandle(), -1, true); |
478 | 489 |
479 observer.Wait(); | 490 observer.Wait(); |
480 } | 491 } |
OLD | NEW |