| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/renderer_host/render_process_host_browsertest.h" | 5 #include "content/browser/renderer_host/render_process_host_browsertest.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/test/base/ui_test_utils.h" | 9 #include "chrome/test/base/ui_test_utils.h" |
| 10 #include "content/browser/renderer_host/render_process_host.h" | 10 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 11 #include "content/browser/tab_contents/tab_contents.h" | 11 #include "content/browser/tab_contents/tab_contents.h" |
| 12 #include "content/common/test_url_constants.h" | 12 #include "content/common/test_url_constants.h" |
| 13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 14 | 14 |
| 15 RenderProcessHostTest::RenderProcessHostTest() { | 15 RenderProcessHostTest::RenderProcessHostTest() { |
| 16 EnableDOMAutomation(); | 16 EnableDOMAutomation(); |
| 17 } | 17 } |
| 18 | 18 |
| 19 int RenderProcessHostTest::RenderProcessHostCount() { | 19 int RenderProcessHostTest::RenderProcessHostCount() { |
| 20 RenderProcessHost::iterator hosts = RenderProcessHost::AllHostsIterator(); | 20 content::RenderProcessHost::iterator hosts = |
| 21 content::RenderProcessHost::AllHostsIterator(); |
| 21 int count = 0; | 22 int count = 0; |
| 22 while (!hosts.IsAtEnd()) { | 23 while (!hosts.IsAtEnd()) { |
| 23 if (hosts.GetCurrentValue()->HasConnection()) | 24 if (hosts.GetCurrentValue()->HasConnection()) |
| 24 count++; | 25 count++; |
| 25 hosts.Advance(); | 26 hosts.Advance(); |
| 26 } | 27 } |
| 27 return count; | 28 return count; |
| 28 } | 29 } |
| 29 | 30 |
| 30 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) { | 31 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) { |
| 31 // Set max renderers to 1 to force running out of processes. | 32 // Set max renderers to 1 to force running out of processes. |
| 32 RenderProcessHost::SetMaxRendererProcessCountForTest(1); | 33 content::RenderProcessHost::SetMaxRendererProcessCountForTest(1); |
| 33 | 34 |
| 34 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 35 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| 35 parsed_command_line.AppendSwitch(switches::kProcessPerTab); | 36 parsed_command_line.AppendSwitch(switches::kProcessPerTab); |
| 36 | 37 |
| 37 int tab_count = 1; | 38 int tab_count = 1; |
| 38 int host_count = 1; | 39 int host_count = 1; |
| 39 | 40 |
| 40 #if defined(TOUCH_UI) | 41 #if defined(TOUCH_UI) |
| 41 ++host_count; // For the touch keyboard. | 42 ++host_count; // For the touch keyboard. |
| 42 #endif | 43 #endif |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 EXPECT_EQ(tab_count, browser()->tab_count()); | 83 EXPECT_EQ(tab_count, browser()->tab_count()); |
| 83 EXPECT_EQ(host_count, RenderProcessHostCount()); | 84 EXPECT_EQ(host_count, RenderProcessHostCount()); |
| 84 } | 85 } |
| 85 | 86 |
| 86 // When we hit the max number of renderers, verify that the way we do process | 87 // When we hit the max number of renderers, verify that the way we do process |
| 87 // sharing behaves correctly. In particular, this test is verifying that even | 88 // sharing behaves correctly. In particular, this test is verifying that even |
| 88 // when we hit the max process limit, that renderers of each type will wind up | 89 // when we hit the max process limit, that renderers of each type will wind up |
| 89 // in a process of that type, even if that means creating a new process. | 90 // in a process of that type, even if that means creating a new process. |
| 90 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessOverflow) { | 91 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessOverflow) { |
| 91 // Set max renderers to 1 to force running out of processes. | 92 // Set max renderers to 1 to force running out of processes. |
| 92 RenderProcessHost::SetMaxRendererProcessCountForTest(1); | 93 content::RenderProcessHost::SetMaxRendererProcessCountForTest(1); |
| 93 | 94 |
| 94 int tab_count = 1; | 95 int tab_count = 1; |
| 95 int host_count = 1; | 96 int host_count = 1; |
| 96 TabContents* tab1 = NULL; | 97 TabContents* tab1 = NULL; |
| 97 TabContents* tab2 = NULL; | 98 TabContents* tab2 = NULL; |
| 98 RenderProcessHost* rph1 = NULL; | 99 content::RenderProcessHost* rph1 = NULL; |
| 99 RenderProcessHost* rph2 = NULL; | 100 content::RenderProcessHost* rph2 = NULL; |
| 100 RenderProcessHost* rph3 = NULL; | 101 content::RenderProcessHost* rph3 = NULL; |
| 101 | 102 |
| 102 #if defined(TOUCH_UI) | 103 #if defined(TOUCH_UI) |
| 103 ++host_count; // For the touch keyboard. | 104 ++host_count; // For the touch keyboard. |
| 104 #endif | 105 #endif |
| 105 | 106 |
| 106 // Change the first tab to be the new tab page (TYPE_WEBUI). | 107 // Change the first tab to be the new tab page (TYPE_WEBUI). |
| 107 GURL newtab(chrome::kTestNewTabURL); | 108 GURL newtab(chrome::kTestNewTabURL); |
| 108 ui_test_utils::NavigateToURL(browser(), newtab); | 109 ui_test_utils::NavigateToURL(browser(), newtab); |
| 109 EXPECT_EQ(tab_count, browser()->tab_count()); | 110 EXPECT_EQ(tab_count, browser()->tab_count()); |
| 110 tab1 = browser()->GetTabContentsAt(tab_count - 1); | 111 tab1 = browser()->GetTabContentsAt(tab_count - 1); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 host_count++; | 167 host_count++; |
| 167 #endif | 168 #endif |
| 168 EXPECT_EQ(tab_count, browser()->tab_count()); | 169 EXPECT_EQ(tab_count, browser()->tab_count()); |
| 169 tab1 = browser()->GetTabContentsAt(tab_count - 1); | 170 tab1 = browser()->GetTabContentsAt(tab_count - 1); |
| 170 rph3 = tab1->GetRenderProcessHost(); | 171 rph3 = tab1->GetRenderProcessHost(); |
| 171 EXPECT_EQ(tab1->GetURL(), bookmarks); | 172 EXPECT_EQ(tab1->GetURL(), bookmarks); |
| 172 EXPECT_EQ(host_count, RenderProcessHostCount()); | 173 EXPECT_EQ(host_count, RenderProcessHostCount()); |
| 173 EXPECT_NE(rph1, rph3); | 174 EXPECT_NE(rph1, rph3); |
| 174 EXPECT_NE(rph2, rph3); | 175 EXPECT_NE(rph2, rph3); |
| 175 } | 176 } |
| OLD | NEW |