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

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

Issue 293923002: Add a test that verifies that the active WebContents is shown Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update this old test I found lying around. Created 5 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
+ }
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698