Chromium Code Reviews| Index: chrome/browser/ui/views/frame/browser_view_browsertest.cc |
| diff --git a/chrome/browser/ui/views/frame/browser_view_browsertest.cc b/chrome/browser/ui/views/frame/browser_view_browsertest.cc |
| index e573e1b2614b12dca8ce87080905df687187effd..55e0c1d5e3cec9a4fa0eb8fa3081d64c1f5cb114 100644 |
| --- a/chrome/browser/ui/views/frame/browser_view_browsertest.cc |
| +++ b/chrome/browser/ui/views/frame/browser_view_browsertest.cc |
| @@ -4,6 +4,7 @@ |
| #include "chrome/browser/ui/views/frame/browser_view.h" |
| +#include "base/run_loop.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_tabstrip.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| @@ -11,6 +12,7 @@ |
| #include "content/public/browser/invalidate_type.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/browser/web_contents_observer.h" |
| +#include "ui/base/ui_base_types.h" |
| typedef InProcessBrowserTest BrowserViewTest; |
| @@ -37,6 +39,35 @@ class TestWebContentsObserver : public content::WebContentsObserver { |
| DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver); |
| }; |
| +class WebContentsShowHideObserver : public content::WebContentsObserver { |
| + public: |
| + WebContentsShowHideObserver(content::WebContents* web_contents, |
| + const base::Closure& callback) |
| + : WebContentsObserver(web_contents), |
| + callback_(callback), |
| + show_state_(ui::SHOW_STATE_DEFAULT) {} |
| + |
| + // WebContentsObserver. |
| + virtual void WasHidden() OVERRIDE { |
| + show_state_ = ui::SHOW_STATE_INACTIVE; |
| + callback_.Run(); |
| + } |
| + |
| + virtual void WasShown() OVERRIDE { |
| + show_state_ = ui::SHOW_STATE_NORMAL; |
| + callback_.Run(); |
| + } |
| + |
| + bool shown() { return show_state_ == ui::SHOW_STATE_NORMAL; } |
| + bool hidden() { return show_state_ == ui::SHOW_STATE_INACTIVE; } |
| + |
| + private: |
| + base::Closure callback_; |
| + ui::WindowShowState show_state_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WebContentsShowHideObserver); |
| +}; |
| + |
| } // namespace |
| // Verifies don't crash when CloseNow() is invoked with two tabs in a browser. |
| @@ -68,3 +99,39 @@ IN_PROC_BROWSER_TEST_F(BrowserViewTest, CloseWithTabsStartWithActive) { |
| browser2->tab_strip_model()->GetWebContentsAt(1)); |
| BrowserView::GetBrowserViewForBrowser(browser2)->GetWidget()->CloseNow(); |
| } |
| + |
| +// Test that hiding a window by minimization will cause the web content to be |
| +// hidden as well (to save CPU cycles for rendering). |
| +IN_PROC_BROWSER_TEST_F(BrowserViewTest, MinimizeHidesWebContents) { |
|
sky
2014/05/20 19:46:27
Test coverage should be in content. The test here
Mr4D (OOO till 08-26)
2014/05/20 21:26:56
I prefer 1:1 tests and not tests which imply that
ncarter (slow)
2014/05/20 21:40:01
Fwiw, I think this test can move to a content_brow
|
| + // Minimizing the window should cause the active WebContents to be hidden. |
| + { |
| + base::RunLoop run_loop; |
| + WebContentsShowHideObserver observed( |
| + browser()->tab_strip_model()->GetActiveWebContents(), |
| + run_loop.QuitClosure()); |
| + |
| + ASSERT_FALSE(observed.hidden()); |
| + ASSERT_FALSE(observed.shown()); |
| + browser()->window()->Minimize(); |
| + if (!observed.hidden()) |
| + run_loop.RunUntilIdle(); |
| + ASSERT_TRUE(observed.hidden()); |
| + ASSERT_FALSE(observed.shown()); |
| + } |
| + |
| + // Restoring the window should cause the active WebContents to be shown. |
| + { |
| + base::RunLoop run_loop; |
| + WebContentsShowHideObserver observed( |
| + browser()->tab_strip_model()->GetActiveWebContents(), |
| + run_loop.QuitClosure()); |
| + |
| + ASSERT_FALSE(observed.hidden()); |
| + ASSERT_FALSE(observed.shown()); |
| + browser()->window()->Restore(); |
| + if (!observed.shown()) |
| + run_loop.RunUntilIdle(); |
| + ASSERT_TRUE(observed.shown()); |
| + ASSERT_FALSE(observed.hidden()); |
| + } |
| +} |