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 07ce7982dfbfd82f11b2450f58b6460309b5a359..888f8ba3bd208e18155d4e57eeed270cc11601c8 100644 |
--- a/chrome/browser/ui/views/frame/browser_view_browsertest.cc |
+++ b/chrome/browser/ui/views/frame/browser_view_browsertest.cc |
@@ -18,6 +18,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" |
class BrowserViewTest : public InProcessBrowserTest { |
public: |
@@ -78,6 +79,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. |
@@ -237,3 +267,37 @@ IN_PROC_BROWSER_TEST_F(BrowserViewTest, AvoidUnnecessaryVisibilityChanges) { |
browser_view()->bookmark_bar()->RemoveObserver(&observer); |
} |
+ |
+IN_PROC_BROWSER_TEST_F(BrowserViewTest, MinimizeHidesWebContents) { |
+ // 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.Run(); |
+ 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.Run(); |
+ ASSERT_TRUE(observed.shown()); |
+ ASSERT_FALSE(observed.hidden()); |
+ } |
+} |