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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/ui/views/frame/browser_view.h" 5 #include "chrome/browser/ui/views/frame/browser_view.h"
6 6
7 #include "base/run_loop.h"
7 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_tabstrip.h" 9 #include "chrome/browser/ui/browser_tabstrip.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" 10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/test/base/in_process_browser_test.h" 11 #include "chrome/test/base/in_process_browser_test.h"
11 #include "content/public/browser/invalidate_type.h" 12 #include "content/public/browser/invalidate_type.h"
12 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_contents_observer.h" 14 #include "content/public/browser/web_contents_observer.h"
15 #include "ui/base/ui_base_types.h"
14 16
15 typedef InProcessBrowserTest BrowserViewTest; 17 typedef InProcessBrowserTest BrowserViewTest;
16 18
17 namespace { 19 namespace {
18 20
19 // Used to simulate scenario in a crash. When WebContentsDestroyed() is invoked 21 // Used to simulate scenario in a crash. When WebContentsDestroyed() is invoked
20 // updates the navigation state of another tab. 22 // updates the navigation state of another tab.
21 class TestWebContentsObserver : public content::WebContentsObserver { 23 class TestWebContentsObserver : public content::WebContentsObserver {
22 public: 24 public:
23 TestWebContentsObserver(content::WebContents* source, 25 TestWebContentsObserver(content::WebContents* source,
24 content::WebContents* other) 26 content::WebContents* other)
25 : content::WebContentsObserver(source), 27 : content::WebContentsObserver(source),
26 other_(other) {} 28 other_(other) {}
27 virtual ~TestWebContentsObserver() {} 29 virtual ~TestWebContentsObserver() {}
28 30
29 virtual void WebContentsDestroyed() OVERRIDE { 31 virtual void WebContentsDestroyed() OVERRIDE {
30 other_->NotifyNavigationStateChanged( 32 other_->NotifyNavigationStateChanged(
31 content::INVALIDATE_TYPE_URL | content::INVALIDATE_TYPE_LOAD); 33 content::INVALIDATE_TYPE_URL | content::INVALIDATE_TYPE_LOAD);
32 } 34 }
33 35
34 private: 36 private:
35 content::WebContents* other_; 37 content::WebContents* other_;
36 38
37 DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver); 39 DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver);
38 }; 40 };
39 41
42 class WebContentsShowHideObserver : public content::WebContentsObserver {
43 public:
44 WebContentsShowHideObserver(content::WebContents* web_contents,
45 const base::Closure& callback)
46 : WebContentsObserver(web_contents),
47 callback_(callback),
48 show_state_(ui::SHOW_STATE_DEFAULT) {}
49
50 // WebContentsObserver.
51 virtual void WasHidden() OVERRIDE {
52 show_state_ = ui::SHOW_STATE_INACTIVE;
53 callback_.Run();
54 }
55
56 virtual void WasShown() OVERRIDE {
57 show_state_ = ui::SHOW_STATE_NORMAL;
58 callback_.Run();
59 }
60
61 bool shown() { return show_state_ == ui::SHOW_STATE_NORMAL; }
62 bool hidden() { return show_state_ == ui::SHOW_STATE_INACTIVE; }
63
64 private:
65 base::Closure callback_;
66 ui::WindowShowState show_state_;
67
68 DISALLOW_COPY_AND_ASSIGN(WebContentsShowHideObserver);
69 };
70
40 } // namespace 71 } // namespace
41 72
42 // Verifies don't crash when CloseNow() is invoked with two tabs in a browser. 73 // Verifies don't crash when CloseNow() is invoked with two tabs in a browser.
43 // Additionally when one of the tabs is destroyed NotifyNavigationStateChanged() 74 // Additionally when one of the tabs is destroyed NotifyNavigationStateChanged()
44 // is invoked on the other. 75 // is invoked on the other.
45 IN_PROC_BROWSER_TEST_F(BrowserViewTest, CloseWithTabs) { 76 IN_PROC_BROWSER_TEST_F(BrowserViewTest, CloseWithTabs) {
46 Browser* browser2 = 77 Browser* browser2 =
47 new Browser(Browser::CreateParams(browser()->profile(), 78 new Browser(Browser::CreateParams(browser()->profile(),
48 browser()->host_desktop_type())); 79 browser()->host_desktop_type()));
49 chrome::AddTabAt(browser2, GURL(), -1, true); 80 chrome::AddTabAt(browser2, GURL(), -1, true);
(...skipping 11 matching lines...) Expand all
61 new Browser(Browser::CreateParams(browser()->profile(), 92 new Browser(Browser::CreateParams(browser()->profile(),
62 browser()->host_desktop_type())); 93 browser()->host_desktop_type()));
63 chrome::AddTabAt(browser2, GURL(), -1, true); 94 chrome::AddTabAt(browser2, GURL(), -1, true);
64 chrome::AddTabAt(browser2, GURL(), -1, true); 95 chrome::AddTabAt(browser2, GURL(), -1, true);
65 browser2->tab_strip_model()->ActivateTabAt(0, true); 96 browser2->tab_strip_model()->ActivateTabAt(0, true);
66 TestWebContentsObserver observer( 97 TestWebContentsObserver observer(
67 browser2->tab_strip_model()->GetWebContentsAt(0), 98 browser2->tab_strip_model()->GetWebContentsAt(0),
68 browser2->tab_strip_model()->GetWebContentsAt(1)); 99 browser2->tab_strip_model()->GetWebContentsAt(1));
69 BrowserView::GetBrowserViewForBrowser(browser2)->GetWidget()->CloseNow(); 100 BrowserView::GetBrowserViewForBrowser(browser2)->GetWidget()->CloseNow();
70 } 101 }
102
103 // Test that hiding a window by minimization will cause the web content to be
104 // hidden as well (to save CPU cycles for rendering).
105 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
106 // Minimizing the window should cause the active WebContents to be hidden.
107 {
108 base::RunLoop run_loop;
109 WebContentsShowHideObserver observed(
110 browser()->tab_strip_model()->GetActiveWebContents(),
111 run_loop.QuitClosure());
112
113 ASSERT_FALSE(observed.hidden());
114 ASSERT_FALSE(observed.shown());
115 browser()->window()->Minimize();
116 if (!observed.hidden())
117 run_loop.RunUntilIdle();
118 ASSERT_TRUE(observed.hidden());
119 ASSERT_FALSE(observed.shown());
120 }
121
122 // Restoring the window should cause the active WebContents to be shown.
123 {
124 base::RunLoop run_loop;
125 WebContentsShowHideObserver observed(
126 browser()->tab_strip_model()->GetActiveWebContents(),
127 run_loop.QuitClosure());
128
129 ASSERT_FALSE(observed.hidden());
130 ASSERT_FALSE(observed.shown());
131 browser()->window()->Restore();
132 if (!observed.shown())
133 run_loop.RunUntilIdle();
134 ASSERT_TRUE(observed.shown());
135 ASSERT_FALSE(observed.hidden());
136 }
137 }
OLDNEW
« 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