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

Side by Side Diff: chrome/browser/renderer_host/test/render_process_host_browsertest.cc

Issue 2928004: Add unit test and supporting code to test process overflow case. (Closed)
Patch Set: linux compile error Created 10 years, 5 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
« no previous file with comments | « chrome/browser/renderer_host/site_instance.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/browser.h"
6 #include "chrome/browser/profile.h"
7 #include "chrome/browser/renderer_host/site_instance.h"
8 #include "chrome/browser/tab_contents/tab_contents.h"
9 #include "chrome/browser/renderer_host/render_process_host.h"
10 #include "chrome/common/url_constants.h"
11 #include "chrome/test/in_process_browser_test.h"
12 #include "chrome/test/ui_test_utils.h"
13
14 class RenderProcessHostTest : public InProcessBrowserTest {
15 public:
16 RenderProcessHostTest() {
17 EnableDOMAutomation();
18 }
19
20 int RenderProcessHostCount() {
21 RenderProcessHost::iterator hosts = RenderProcessHost::AllHostsIterator();
22 int count = 0;
23 while (!hosts.IsAtEnd()) {
24 if (hosts.GetCurrentValue()->HasConnection())
25 count++;
26 hosts.Advance();
27 }
28 return count;
29 }
30 };
31
32 // When we hit the max number of renderers, verify that the way we do process
33 // sharing behaves correctly. In particular, this test is verifying that even
34 // when we hit the max process limit, that renderers of each type will wind up
35 // in a process of that type, even if that means creating a new process.
36 // TODO(erikkay) crbug.com/43448 - disabled for now until we can get a
37 // reasonable implementation in place.
38 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, DISABLED_ProcessOverflow) {
39 // Set max renderers to 1 to force running out of processes.
40 RenderProcessHost::SetMaxRendererProcessCount(1);
41
42 int tab_count = 1;
43 int host_count = 1;
44 TabContents* tab1 = NULL;
45 TabContents* tab2 = NULL;
46 RenderProcessHost* rph1 = NULL;
47 RenderProcessHost* rph2 = NULL;
48 RenderProcessHost* rph3 = NULL;
49
50 // Change the first tab to be the new tab page (TYPE_DOMUI).
51 GURL newtab(chrome::kChromeUINewTabURL);
52 ui_test_utils::NavigateToURL(browser(), newtab);
53 EXPECT_EQ(tab_count, browser()->tab_count());
54 tab1 = browser()->GetTabContentsAt(tab_count - 1);
55 rph1 = tab1->GetRenderProcessHost();
56 EXPECT_EQ(tab1->GetURL(), newtab);
57 EXPECT_EQ(host_count, RenderProcessHostCount());
58
59 // Create a new TYPE_NORMAL tab. It should be in its own process.
60 GURL page1("data:text/html,hello world1");
61 browser()->ShowSingletonTab(page1);
62 if (browser()->tab_count() == tab_count)
63 ui_test_utils::WaitForNewTab(browser());
64 tab_count++;
65 host_count++;
66 EXPECT_EQ(tab_count, browser()->tab_count());
67 tab1 = browser()->GetTabContentsAt(tab_count - 1);
68 rph2 = tab1->GetRenderProcessHost();
69 EXPECT_EQ(tab1->GetURL(), page1);
70 EXPECT_EQ(host_count, RenderProcessHostCount());
71 EXPECT_NE(rph1, rph2);
72
73 // Create another TYPE_NORMAL tab. It should share the previous process.
74 GURL page2("data:text/html,hello world2");
75 browser()->ShowSingletonTab(page2);
76 if (browser()->tab_count() == tab_count)
77 ui_test_utils::WaitForNewTab(browser());
78 tab_count++;
79 EXPECT_EQ(tab_count, browser()->tab_count());
80 tab2 = browser()->GetTabContentsAt(tab_count - 1);
81 EXPECT_EQ(tab2->GetURL(), page2);
82 EXPECT_EQ(host_count, RenderProcessHostCount());
83 EXPECT_EQ(tab2->GetRenderProcessHost(), rph2);
84
85 // Create another TYPE_DOMUI tab. It should share the process with newtab.
86 // Note: intentionally create this tab after the TYPE_NORMAL tabs to exercise
87 // bug 43448 where extension and DOMUI tabs could get combined into normal
88 // renderers.
89 GURL history(chrome::kChromeUIHistoryURL);
90 browser()->ShowSingletonTab(history);
91 if (browser()->tab_count() == tab_count)
92 ui_test_utils::WaitForNewTab(browser());
93 tab_count++;
94 EXPECT_EQ(tab_count, browser()->tab_count());
95 tab2 = browser()->GetTabContentsAt(tab_count - 1);
96 EXPECT_EQ(tab2->GetURL(), history);
97 EXPECT_EQ(host_count, RenderProcessHostCount());
98 EXPECT_EQ(tab2->GetRenderProcessHost(), rph1);
99
100 // Create a TYPE_EXTENSION tab. It should be in its own process.
101 // (the bookmark manager is implemented as an extension)
102 GURL bookmarks(chrome::kChromeUIBookmarksURL);
103 browser()->ShowSingletonTab(bookmarks);
104 if (browser()->tab_count() == tab_count)
105 ui_test_utils::WaitForNewTab(browser());
106 tab_count++;
107 host_count++;
108 EXPECT_EQ(tab_count, browser()->tab_count());
109 tab1 = browser()->GetTabContentsAt(tab_count - 1);
110 rph3 = tab1->GetRenderProcessHost();
111 EXPECT_EQ(tab1->GetURL(), bookmarks);
112 EXPECT_EQ(host_count, RenderProcessHostCount());
113 EXPECT_NE(rph1, rph3);
114 EXPECT_NE(rph2, rph3);
115 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/site_instance.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698