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

Side by Side Diff: content/browser/renderer_host/render_process_host_browsertest.cc

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
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/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/process.h" 8 #include "base/process.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/browser_tabstrip.h"
11 #include "chrome/browser/ui/singleton_tabs.h" 12 #include "chrome/browser/ui/singleton_tabs.h"
12 #include "chrome/test/base/in_process_browser_test.h" 13 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/ui_test_utils.h" 14 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/browser/renderer_host/render_process_host_impl.h" 15 #include "content/browser/renderer_host/render_process_host_impl.h"
15 #include "content/browser/web_contents/web_contents_impl.h" 16 #include "content/browser/web_contents/web_contents_impl.h"
16 #include "content/common/test_url_constants.h" 17 #include "content/common/test_url_constants.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "content/public/common/content_switches.h" 19 #include "content/public/common/content_switches.h"
19 20
20 using content::WebContents; 21 using content::WebContents;
(...skipping 18 matching lines...) Expand all
39 hosts.Advance(); 40 hosts.Advance();
40 } 41 }
41 return count; 42 return count;
42 } 43 }
43 44
44 // Show a tab, activating the current one if there is one, and wait for 45 // Show a tab, activating the current one if there is one, and wait for
45 // the renderer process to be created or foregrounded, returning the process 46 // the renderer process to be created or foregrounded, returning the process
46 // handle. 47 // handle.
47 base::ProcessHandle ShowSingletonTab(const GURL& page) { 48 base::ProcessHandle ShowSingletonTab(const GURL& page) {
48 chrome::ShowSingletonTab(browser(), page); 49 chrome::ShowSingletonTab(browser(), page);
49 WebContents* wc = browser()->GetActiveWebContents(); 50 WebContents* wc = chrome::GetActiveWebContents(browser());
50 CHECK(wc->GetURL() == page); 51 CHECK(wc->GetURL() == page);
51 52
52 // Ensure that the backgrounding / foregrounding gets a chance to run. 53 // Ensure that the backgrounding / foregrounding gets a chance to run.
53 content::BrowserThread::PostTaskAndReply( 54 content::BrowserThread::PostTaskAndReply(
54 content::BrowserThread::PROCESS_LAUNCHER, FROM_HERE, 55 content::BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
55 base::Bind(&base::DoNothing), MessageLoop::QuitClosure()); 56 base::Bind(&base::DoNothing), MessageLoop::QuitClosure());
56 MessageLoop::current()->Run(); 57 MessageLoop::current()->Run();
57 58
58 return wc->GetRenderProcessHost()->GetHandle(); 59 return wc->GetRenderProcessHost()->GetHandle();
59 } 60 }
60 61
61 // When we hit the max number of renderers, verify that the way we do process 62 // When we hit the max number of renderers, verify that the way we do process
62 // sharing behaves correctly. In particular, this test is verifying that even 63 // sharing behaves correctly. In particular, this test is verifying that even
63 // when we hit the max process limit, that renderers of each type will wind up 64 // when we hit the max process limit, that renderers of each type will wind up
64 // in a process of that type, even if that means creating a new process. 65 // in a process of that type, even if that means creating a new process.
65 void TestProcessOverflow() { 66 void TestProcessOverflow() {
66 int tab_count = 1; 67 int tab_count = 1;
67 int host_count = 1; 68 int host_count = 1;
68 WebContents* tab1 = NULL; 69 WebContents* tab1 = NULL;
69 WebContents* tab2 = NULL; 70 WebContents* tab2 = NULL;
70 content::RenderProcessHost* rph1 = NULL; 71 content::RenderProcessHost* rph1 = NULL;
71 content::RenderProcessHost* rph2 = NULL; 72 content::RenderProcessHost* rph2 = NULL;
72 content::RenderProcessHost* rph3 = NULL; 73 content::RenderProcessHost* rph3 = NULL;
73 74
74 // Change the first tab to be the new tab page (TYPE_WEBUI). 75 // Change the first tab to be the new tab page (TYPE_WEBUI).
75 GURL newtab(chrome::kTestNewTabURL); 76 GURL newtab(chrome::kTestNewTabURL);
76 ui_test_utils::NavigateToURL(browser(), newtab); 77 ui_test_utils::NavigateToURL(browser(), newtab);
77 EXPECT_EQ(tab_count, browser()->tab_count()); 78 EXPECT_EQ(tab_count, browser()->tab_count());
78 tab1 = browser()->GetWebContentsAt(tab_count - 1); 79 tab1 = chrome::GetWebContentsAt(browser(), tab_count - 1);
79 rph1 = tab1->GetRenderProcessHost(); 80 rph1 = tab1->GetRenderProcessHost();
80 EXPECT_EQ(tab1->GetURL(), newtab); 81 EXPECT_EQ(tab1->GetURL(), newtab);
81 EXPECT_EQ(host_count, RenderProcessHostCount()); 82 EXPECT_EQ(host_count, RenderProcessHostCount());
82 83
83 // Create a new TYPE_TABBED tab. It should be in its own process. 84 // Create a new TYPE_TABBED tab. It should be in its own process.
84 GURL page1("data:text/html,hello world1"); 85 GURL page1("data:text/html,hello world1");
85 chrome::ShowSingletonTab(browser(), page1); 86 chrome::ShowSingletonTab(browser(), page1);
86 if (browser()->tab_count() == tab_count) 87 if (browser()->tab_count() == tab_count)
87 ui_test_utils::WaitForNewTab(browser()); 88 ui_test_utils::WaitForNewTab(browser());
88 tab_count++; 89 tab_count++;
89 host_count++; 90 host_count++;
90 EXPECT_EQ(tab_count, browser()->tab_count()); 91 EXPECT_EQ(tab_count, browser()->tab_count());
91 tab1 = browser()->GetWebContentsAt(tab_count - 1); 92 tab1 = chrome::GetWebContentsAt(browser(), tab_count - 1);
92 rph2 = tab1->GetRenderProcessHost(); 93 rph2 = tab1->GetRenderProcessHost();
93 EXPECT_EQ(tab1->GetURL(), page1); 94 EXPECT_EQ(tab1->GetURL(), page1);
94 EXPECT_EQ(host_count, RenderProcessHostCount()); 95 EXPECT_EQ(host_count, RenderProcessHostCount());
95 EXPECT_NE(rph1, rph2); 96 EXPECT_NE(rph1, rph2);
96 97
97 // Create another TYPE_TABBED tab. It should share the previous process. 98 // Create another TYPE_TABBED tab. It should share the previous process.
98 GURL page2("data:text/html,hello world2"); 99 GURL page2("data:text/html,hello world2");
99 chrome::ShowSingletonTab(browser(), page2); 100 chrome::ShowSingletonTab(browser(), page2);
100 if (browser()->tab_count() == tab_count) 101 if (browser()->tab_count() == tab_count)
101 ui_test_utils::WaitForNewTab(browser()); 102 ui_test_utils::WaitForNewTab(browser());
102 tab_count++; 103 tab_count++;
103 EXPECT_EQ(tab_count, browser()->tab_count()); 104 EXPECT_EQ(tab_count, browser()->tab_count());
104 tab2 = browser()->GetWebContentsAt(tab_count - 1); 105 tab2 = chrome::GetWebContentsAt(browser(), tab_count - 1);
105 EXPECT_EQ(tab2->GetURL(), page2); 106 EXPECT_EQ(tab2->GetURL(), page2);
106 EXPECT_EQ(host_count, RenderProcessHostCount()); 107 EXPECT_EQ(host_count, RenderProcessHostCount());
107 EXPECT_EQ(tab2->GetRenderProcessHost(), rph2); 108 EXPECT_EQ(tab2->GetRenderProcessHost(), rph2);
108 109
109 // Create another TYPE_WEBUI tab. It should share the process with newtab. 110 // Create another TYPE_WEBUI tab. It should share the process with newtab.
110 // Note: intentionally create this tab after the TYPE_TABBED tabs to 111 // Note: intentionally create this tab after the TYPE_TABBED tabs to
111 // exercise bug 43448 where extension and WebUI tabs could get combined into 112 // exercise bug 43448 where extension and WebUI tabs could get combined into
112 // normal renderers. 113 // normal renderers.
113 GURL history(chrome::kTestHistoryURL); 114 GURL history(chrome::kTestHistoryURL);
114 chrome::ShowSingletonTab(browser(), history); 115 chrome::ShowSingletonTab(browser(), history);
115 if (browser()->tab_count() == tab_count) 116 if (browser()->tab_count() == tab_count)
116 ui_test_utils::WaitForNewTab(browser()); 117 ui_test_utils::WaitForNewTab(browser());
117 tab_count++; 118 tab_count++;
118 EXPECT_EQ(tab_count, browser()->tab_count()); 119 EXPECT_EQ(tab_count, browser()->tab_count());
119 tab2 = browser()->GetWebContentsAt(tab_count - 1); 120 tab2 = chrome::GetWebContentsAt(browser(), tab_count - 1);
120 EXPECT_EQ(tab2->GetURL(), history); 121 EXPECT_EQ(tab2->GetURL(), history);
121 EXPECT_EQ(host_count, RenderProcessHostCount()); 122 EXPECT_EQ(host_count, RenderProcessHostCount());
122 EXPECT_EQ(tab2->GetRenderProcessHost(), rph1); 123 EXPECT_EQ(tab2->GetRenderProcessHost(), rph1);
123 124
124 // Create a TYPE_EXTENSION tab. It should be in its own process. 125 // Create a TYPE_EXTENSION tab. It should be in its own process.
125 // (the bookmark manager is implemented as an extension) 126 // (the bookmark manager is implemented as an extension)
126 GURL bookmarks(chrome::kTestBookmarksURL); 127 GURL bookmarks(chrome::kTestBookmarksURL);
127 chrome::ShowSingletonTab(browser(), bookmarks); 128 chrome::ShowSingletonTab(browser(), bookmarks);
128 if (browser()->tab_count() == tab_count) 129 if (browser()->tab_count() == tab_count)
129 ui_test_utils::WaitForNewTab(browser()); 130 ui_test_utils::WaitForNewTab(browser());
130 tab_count++; 131 tab_count++;
131 host_count++; 132 host_count++;
132 EXPECT_EQ(tab_count, browser()->tab_count()); 133 EXPECT_EQ(tab_count, browser()->tab_count());
133 tab1 = browser()->GetWebContentsAt(tab_count - 1); 134 tab1 = chrome::GetWebContentsAt(browser(), tab_count - 1);
134 rph3 = tab1->GetRenderProcessHost(); 135 rph3 = tab1->GetRenderProcessHost();
135 EXPECT_EQ(tab1->GetURL(), bookmarks); 136 EXPECT_EQ(tab1->GetURL(), bookmarks);
136 EXPECT_EQ(host_count, RenderProcessHostCount()); 137 EXPECT_EQ(host_count, RenderProcessHostCount());
137 EXPECT_NE(rph1, rph3); 138 EXPECT_NE(rph1, rph3);
138 EXPECT_NE(rph2, rph3); 139 EXPECT_NE(rph2, rph3);
139 } 140 }
140 }; 141 };
141 142
142 143
143 class RenderProcessHostTestWithCommandLine : public RenderProcessHostTest { 144 class RenderProcessHostTestWithCommandLine : public RenderProcessHostTest {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // Set max renderers to 1 to force running out of processes. 241 // Set max renderers to 1 to force running out of processes.
241 content::RenderProcessHost::SetMaxRendererProcessCount(1); 242 content::RenderProcessHost::SetMaxRendererProcessCount(1);
242 TestProcessOverflow(); 243 TestProcessOverflow();
243 } 244 }
244 245
245 // Variation of the ProcessOverflow test, which is driven through command line 246 // Variation of the ProcessOverflow test, which is driven through command line
246 // parameter instead of direct function call into the class. 247 // parameter instead of direct function call into the class.
247 IN_PROC_BROWSER_TEST_F(RenderProcessHostTestWithCommandLine, ProcessOverflow) { 248 IN_PROC_BROWSER_TEST_F(RenderProcessHostTestWithCommandLine, ProcessOverflow) {
248 TestProcessOverflow(); 249 TestProcessOverflow();
249 } 250 }
OLDNEW
« no previous file with comments | « content/browser/plugin_browsertest.cc ('k') | content/browser/renderer_host/render_view_host_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698