Chromium Code Reviews| Index: chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc |
| diff --git a/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc b/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc |
| index 6d47d2b608808c7f73ffb7d3ef40b0532e2f5a38..ab78dc1bedf2bcb3a04a4ce45d79b12cbd126fe6 100644 |
| --- a/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc |
| +++ b/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc |
| @@ -17,6 +17,7 @@ |
| #include "chrome/test/base/ui_test_utils.h" |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/render_process_host.h" |
| +#include "content/public/browser/render_process_host_observer.h" |
| #include "content/public/browser/render_view_host.h" |
| #include "content/public/browser/render_widget_host_iterator.h" |
| #include "content/public/browser/web_contents.h" |
| @@ -28,6 +29,42 @@ using content::WebContents; |
| namespace { |
| +class RenderProcessHostAliveObserver |
|
nasko
2014/03/26 22:48:27
Why create a new class? Doesn't RenderProcessHostW
mfomitchev
2014/03/27 21:51:34
Done.
|
| + : public content::RenderProcessHostObserver { |
| + public: |
| + explicit RenderProcessHostAliveObserver(content::RenderProcessHost* host) |
| + : host_(host) { |
| + host_->AddObserver(this); |
| + } |
| + |
| + virtual ~RenderProcessHostAliveObserver() { |
| + CHECK(!host_); |
| + } |
| + |
| + void WaitUntilProcessDies() { |
| + if (!host_) |
| + return; |
| + base::RunLoop run_loop; |
| + quit_closure_ = run_loop.QuitClosure(); |
| + run_loop.Run(); |
| + } |
| + |
| + private: |
| + // content::RenderProcessHostObserver: |
| + virtual void RenderProcessHostDestroyed( |
| + content::RenderProcessHost* host) OVERRIDE { |
| + CHECK_EQ(host_, host); |
| + host_ = NULL; |
| + if (!quit_closure_.is_null()) |
| + quit_closure_.Run(); |
| + } |
| + |
| + content::RenderProcessHost* host_; |
| + base::Closure quit_closure_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(RenderProcessHostAliveObserver); |
| +}; |
| + |
| int RenderProcessHostCount() { |
| content::RenderProcessHost::iterator hosts = |
| content::RenderProcessHost::AllHostsIterator(); |
| @@ -111,9 +148,18 @@ class ChromeRenderProcessHostTest : public InProcessBrowserTest { |
| content::RenderProcessHost* rph2 = NULL; |
| content::RenderProcessHost* rph3 = NULL; |
| - // Change the first tab to be the omnibox page (TYPE_WEBUI). |
| + EXPECT_EQ(host_count, RenderProcessHostCount()); |
| + ASSERT_EQ(tab_count, browser()->tab_strip_model()->count()); |
| + |
| + tab1 = browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1); |
| + RenderProcessHostAliveObserver process_observer( |
| + tab1->GetRenderProcessHost()); |
| + |
| + // Change the first tab to be the omnibox page (TYPE_WEBUI). The navigation |
| + // should terminate the existing process. |
| GURL omnibox(chrome::kChromeUIOmniboxURL); |
| ui_test_utils::NavigateToURL(browser(), omnibox); |
| + process_observer.WaitUntilProcessDies(); |
|
nasko
2014/03/26 22:48:27
Please add a comment why we need to wait for the p
mfomitchev
2014/03/27 21:51:34
Done.
|
| EXPECT_EQ(tab_count, browser()->tab_strip_model()->count()); |
| tab1 = browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1); |
| rph1 = tab1->GetRenderProcessHost(); |
| @@ -204,9 +250,17 @@ IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, ProcessPerTab) { |
| int tab_count = 1; |
| int host_count = 1; |
| + EXPECT_EQ(tab_count, browser()->tab_strip_model()->count()); |
| + EXPECT_EQ(host_count, RenderProcessHostCount()); |
| + |
| + WebContents* tab1 = |
| + browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1); |
| + RenderProcessHostAliveObserver process_observer(tab1->GetRenderProcessHost()); |
| + |
| // Change the first tab to be the new tab page (TYPE_WEBUI). |
| GURL omnibox(chrome::kChromeUIOmniboxURL); |
| ui_test_utils::NavigateToURL(browser(), omnibox); |
| + process_observer.WaitUntilProcessDies(); |
|
nasko
2014/03/26 22:48:27
ditto on comment.
mfomitchev
2014/03/27 21:51:34
Done.
|
| EXPECT_EQ(tab_count, browser()->tab_strip_model()->count()); |
| EXPECT_EQ(host_count, RenderProcessHostCount()); |