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

Unified Diff: chrome/browser/ui/views/frame/browser_view_browsertest.cc

Issue 286943005: Reducing CPU cycles of hidden/minimized browser windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
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());
+ }
+}
« no previous file with comments | « no previous file | content/browser/web_contents/web_contents_impl.h » ('j') | content/browser/web_contents/web_contents_view_aura.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698