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

Unified Diff: ui/views/widget/widget_interactive_uitest.cc

Issue 2891893002: Fix Restore after Minimize on X11. (Closed)
Patch Set: Created 3 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: ui/views/widget/widget_interactive_uitest.cc
diff --git a/ui/views/widget/widget_interactive_uitest.cc b/ui/views/widget/widget_interactive_uitest.cc
index a2f699d45992fbaf15338c7e02252a414e3c3b54..6985ca17a7cb9f96a09e4934d71426160809d2bc 100644
--- a/ui/views/widget/widget_interactive_uitest.cc
+++ b/ui/views/widget/widget_interactive_uitest.cc
@@ -231,6 +231,43 @@ void ShowInactiveSync(Widget* widget) {
RunPendingMessagesForActiveStatusChange();
}
+// Wait until |property| returns |expected_value|, but no longer than 1 second.
+class PropertyWaiter {
+ public:
+ PropertyWaiter(const base::Callback<bool(void)>& property,
msw 2017/05/18 18:37:44 nit: rename |callback| here and in class and comme
alshabalin 2017/05/23 06:48:18 Done.
+ bool expected_value)
+ : property_(property), expected_value_(expected_value) {}
+
+ bool Wait() {
+ if (property_.Run() == expected_value_) {
+ success_ = true;
+ return success_;
+ }
+ start_time_ = base::TimeTicks::Now();
+ timer_.Start(FROM_HERE, base::TimeDelta(), this, &PropertyWaiter::Check);
+ run_loop_.Run();
+ return success_;
+ }
+
+ private:
+ void Check() {
+ DCHECK(!success_);
+ success_ = property_.Run() == expected_value_;
+ if (success_ || base::TimeTicks::Now() - start_time_ > kTimeout) {
+ timer_.Stop();
+ run_loop_.Quit();
+ }
+ }
+
+ const base::TimeDelta kTimeout = base::TimeDelta::FromSeconds(1);
+ base::Callback<bool(void)> property_;
+ const bool expected_value_;
+ bool success_ = false;
+ base::TimeTicks start_time_;
+ base::RunLoop run_loop_;
+ base::RepeatingTimer timer_;
+};
+
} // namespace
class WidgetTestInteractive : public WidgetTest {
@@ -1215,6 +1252,24 @@ TEST_F(WidgetTestInteractive, InitialFocus) {
EXPECT_EQ(delegate.view(), widget->GetFocusManager()->GetStoredFocusView());
}
+TEST_F(WidgetTestInteractive, RestoreAfterMinimize) {
+ Widget* widget = CreateWidget();
+ ShowSync(widget);
+ ASSERT_FALSE(widget->IsMinimized());
+
+ PropertyWaiter minimize_waiter(
msw 2017/05/18 18:37:44 Could a single base::RunLoop().RunUntilIdle(); han
alshabalin 2017/05/23 06:48:18 I tried that initially and it seemed to work, but
+ base::Bind(&Widget::IsMinimized, base::Unretained(widget)), true);
+ widget->Minimize();
+ EXPECT_TRUE(minimize_waiter.Wait());
+
+ PropertyWaiter restore_waiter(
+ base::Bind(&Widget::IsMinimized, base::Unretained(widget)), false);
+ widget->Restore();
+ EXPECT_TRUE(restore_waiter.Wait());
+
+ widget->CloseNow();
+}
+
namespace {
// Helper class for CaptureLostTrackingWidget to store whether

Powered by Google App Engine
This is Rietveld 408576698