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_process_host_observer.h" |
20 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
21 #include "content/public/browser/render_widget_host_iterator.h" | 22 #include "content/public/browser/render_widget_host_iterator.h" |
22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
23 #include "content/public/browser/web_contents_observer.h" | 24 #include "content/public/browser/web_contents_observer.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 |
| 32 class RenderProcessHostAliveObserver |
| 33 : public content::RenderProcessHostObserver { |
| 34 public: |
| 35 explicit RenderProcessHostAliveObserver(content::RenderProcessHost* host) |
| 36 : host_(host) { |
| 37 host_->AddObserver(this); |
| 38 } |
| 39 |
| 40 virtual ~RenderProcessHostAliveObserver() { |
| 41 CHECK(!host_); |
| 42 } |
| 43 |
| 44 void WaitUntilProcessDies() { |
| 45 if (!host_) |
| 46 return; |
| 47 base::RunLoop run_loop; |
| 48 quit_closure_ = run_loop.QuitClosure(); |
| 49 run_loop.Run(); |
| 50 } |
| 51 |
| 52 private: |
| 53 // content::RenderProcessHostObserver: |
| 54 virtual void RenderProcessHostDestroyed( |
| 55 content::RenderProcessHost* host) OVERRIDE { |
| 56 CHECK_EQ(host_, host); |
| 57 host_ = NULL; |
| 58 if (!quit_closure_.is_null()) |
| 59 quit_closure_.Run(); |
| 60 } |
| 61 |
| 62 content::RenderProcessHost* host_; |
| 63 base::Closure quit_closure_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostAliveObserver); |
| 66 }; |
| 67 |
31 int RenderProcessHostCount() { | 68 int RenderProcessHostCount() { |
32 content::RenderProcessHost::iterator hosts = | 69 content::RenderProcessHost::iterator hosts = |
33 content::RenderProcessHost::AllHostsIterator(); | 70 content::RenderProcessHost::AllHostsIterator(); |
34 int count = 0; | 71 int count = 0; |
35 while (!hosts.IsAtEnd()) { | 72 while (!hosts.IsAtEnd()) { |
36 if (hosts.GetCurrentValue()->HasConnection()) | 73 if (hosts.GetCurrentValue()->HasConnection()) |
37 count++; | 74 count++; |
38 hosts.Advance(); | 75 hosts.Advance(); |
39 } | 76 } |
40 return count; | 77 return count; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // in a process of that type, even if that means creating a new process. | 141 // in a process of that type, even if that means creating a new process. |
105 void TestProcessOverflow() { | 142 void TestProcessOverflow() { |
106 int tab_count = 1; | 143 int tab_count = 1; |
107 int host_count = 1; | 144 int host_count = 1; |
108 WebContents* tab1 = NULL; | 145 WebContents* tab1 = NULL; |
109 WebContents* tab2 = NULL; | 146 WebContents* tab2 = NULL; |
110 content::RenderProcessHost* rph1 = NULL; | 147 content::RenderProcessHost* rph1 = NULL; |
111 content::RenderProcessHost* rph2 = NULL; | 148 content::RenderProcessHost* rph2 = NULL; |
112 content::RenderProcessHost* rph3 = NULL; | 149 content::RenderProcessHost* rph3 = NULL; |
113 | 150 |
114 // Change the first tab to be the omnibox page (TYPE_WEBUI). | 151 EXPECT_EQ(host_count, RenderProcessHostCount()); |
| 152 ASSERT_EQ(tab_count, browser()->tab_strip_model()->count()); |
| 153 |
| 154 tab1 = browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1); |
| 155 RenderProcessHostAliveObserver process_observer( |
| 156 tab1->GetRenderProcessHost()); |
| 157 |
| 158 // Change the first tab to be the omnibox page (TYPE_WEBUI). The navigation |
| 159 // should terminate the existing process. |
115 GURL omnibox(chrome::kChromeUIOmniboxURL); | 160 GURL omnibox(chrome::kChromeUIOmniboxURL); |
116 ui_test_utils::NavigateToURL(browser(), omnibox); | 161 ui_test_utils::NavigateToURL(browser(), omnibox); |
| 162 process_observer.WaitUntilProcessDies(); |
117 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count()); | 163 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count()); |
118 tab1 = browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1); | 164 tab1 = browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1); |
119 rph1 = tab1->GetRenderProcessHost(); | 165 rph1 = tab1->GetRenderProcessHost(); |
120 EXPECT_EQ(omnibox, tab1->GetURL()); | 166 EXPECT_EQ(omnibox, tab1->GetURL()); |
121 EXPECT_EQ(host_count, RenderProcessHostCount()); | 167 EXPECT_EQ(host_count, RenderProcessHostCount()); |
122 | 168 |
123 // Create a new TYPE_TABBED tab. It should be in its own process. | 169 // Create a new TYPE_TABBED tab. It should be in its own process. |
124 GURL page1("data:text/html,hello world1"); | 170 GURL page1("data:text/html,hello world1"); |
125 | 171 |
126 ui_test_utils::WindowedTabAddedNotificationObserver observer1( | 172 ui_test_utils::WindowedTabAddedNotificationObserver observer1( |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 chrome::NOTIFICATION_BROWSER_CLOSED, | 515 chrome::NOTIFICATION_BROWSER_CLOSED, |
470 content::NotificationService::AllSources()); | 516 content::NotificationService::AllSources()); |
471 | 517 |
472 // Kill the renderer process, simulating a crash. This should the ProcessDied | 518 // Kill the renderer process, simulating a crash. This should the ProcessDied |
473 // method to be called. Alternatively, RenderProcessHost::OnChannelError can | 519 // method to be called. Alternatively, RenderProcessHost::OnChannelError can |
474 // be called to directly force a call to ProcessDied. | 520 // be called to directly force a call to ProcessDied. |
475 base::KillProcess(wc1->GetRenderProcessHost()->GetHandle(), -1, true); | 521 base::KillProcess(wc1->GetRenderProcessHost()->GetHandle(), -1, true); |
476 | 522 |
477 observer.Wait(); | 523 observer.Wait(); |
478 } | 524 } |
OLD | NEW |