Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 #endif | 224 #endif |
| 225 | 225 |
| 226 // Calls ShowInactive() on a Widget, and spins a run loop. The goal is to give | 226 // Calls ShowInactive() on a Widget, and spins a run loop. The goal is to give |
| 227 // the OS a chance to activate a widget. However, for this case, the test | 227 // the OS a chance to activate a widget. However, for this case, the test |
| 228 // doesn't expect that to happen, so there is nothing to wait for. | 228 // doesn't expect that to happen, so there is nothing to wait for. |
| 229 void ShowInactiveSync(Widget* widget) { | 229 void ShowInactiveSync(Widget* widget) { |
| 230 widget->ShowInactive(); | 230 widget->ShowInactive(); |
| 231 RunPendingMessagesForActiveStatusChange(); | 231 RunPendingMessagesForActiveStatusChange(); |
| 232 } | 232 } |
| 233 | 233 |
| 234 // Wait until |property| returns |expected_value|, but no longer than 1 second. | |
| 235 class PropertyWaiter { | |
| 236 public: | |
| 237 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.
| |
| 238 bool expected_value) | |
| 239 : property_(property), expected_value_(expected_value) {} | |
| 240 | |
| 241 bool Wait() { | |
| 242 if (property_.Run() == expected_value_) { | |
| 243 success_ = true; | |
| 244 return success_; | |
| 245 } | |
| 246 start_time_ = base::TimeTicks::Now(); | |
| 247 timer_.Start(FROM_HERE, base::TimeDelta(), this, &PropertyWaiter::Check); | |
| 248 run_loop_.Run(); | |
| 249 return success_; | |
| 250 } | |
| 251 | |
| 252 private: | |
| 253 void Check() { | |
| 254 DCHECK(!success_); | |
| 255 success_ = property_.Run() == expected_value_; | |
| 256 if (success_ || base::TimeTicks::Now() - start_time_ > kTimeout) { | |
| 257 timer_.Stop(); | |
| 258 run_loop_.Quit(); | |
| 259 } | |
| 260 } | |
| 261 | |
| 262 const base::TimeDelta kTimeout = base::TimeDelta::FromSeconds(1); | |
| 263 base::Callback<bool(void)> property_; | |
| 264 const bool expected_value_; | |
| 265 bool success_ = false; | |
| 266 base::TimeTicks start_time_; | |
| 267 base::RunLoop run_loop_; | |
| 268 base::RepeatingTimer timer_; | |
| 269 }; | |
| 270 | |
| 234 } // namespace | 271 } // namespace |
| 235 | 272 |
| 236 class WidgetTestInteractive : public WidgetTest { | 273 class WidgetTestInteractive : public WidgetTest { |
| 237 public: | 274 public: |
| 238 WidgetTestInteractive() {} | 275 WidgetTestInteractive() {} |
| 239 ~WidgetTestInteractive() override {} | 276 ~WidgetTestInteractive() override {} |
| 240 | 277 |
| 241 void SetUp() override { | 278 void SetUp() override { |
| 242 // On mus these tests run as part of views::ViewsTestSuite which already | 279 // On mus these tests run as part of views::ViewsTestSuite which already |
| 243 // does this initialization. | 280 // does this initialization. |
| (...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1208 // Testing a widget which specifies a initially focused view. | 1245 // Testing a widget which specifies a initially focused view. |
| 1209 TestInitialFocusWidgetDelegate delegate(GetContext()); | 1246 TestInitialFocusWidgetDelegate delegate(GetContext()); |
| 1210 | 1247 |
| 1211 Widget* widget = delegate.GetWidget(); | 1248 Widget* widget = delegate.GetWidget(); |
| 1212 ShowSync(widget); | 1249 ShowSync(widget); |
| 1213 widget->Show(); | 1250 widget->Show(); |
| 1214 EXPECT_TRUE(delegate.view()->HasFocus()); | 1251 EXPECT_TRUE(delegate.view()->HasFocus()); |
| 1215 EXPECT_EQ(delegate.view(), widget->GetFocusManager()->GetStoredFocusView()); | 1252 EXPECT_EQ(delegate.view(), widget->GetFocusManager()->GetStoredFocusView()); |
| 1216 } | 1253 } |
| 1217 | 1254 |
| 1255 TEST_F(WidgetTestInteractive, RestoreAfterMinimize) { | |
| 1256 Widget* widget = CreateWidget(); | |
| 1257 ShowSync(widget); | |
| 1258 ASSERT_FALSE(widget->IsMinimized()); | |
| 1259 | |
| 1260 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
| |
| 1261 base::Bind(&Widget::IsMinimized, base::Unretained(widget)), true); | |
| 1262 widget->Minimize(); | |
| 1263 EXPECT_TRUE(minimize_waiter.Wait()); | |
| 1264 | |
| 1265 PropertyWaiter restore_waiter( | |
| 1266 base::Bind(&Widget::IsMinimized, base::Unretained(widget)), false); | |
| 1267 widget->Restore(); | |
| 1268 EXPECT_TRUE(restore_waiter.Wait()); | |
| 1269 | |
| 1270 widget->CloseNow(); | |
| 1271 } | |
| 1272 | |
| 1218 namespace { | 1273 namespace { |
| 1219 | 1274 |
| 1220 // Helper class for CaptureLostTrackingWidget to store whether | 1275 // Helper class for CaptureLostTrackingWidget to store whether |
| 1221 // OnMouseCaptureLost has been invoked for a widget. | 1276 // OnMouseCaptureLost has been invoked for a widget. |
| 1222 class CaptureLostState { | 1277 class CaptureLostState { |
| 1223 public: | 1278 public: |
| 1224 CaptureLostState() : got_capture_lost_(false) {} | 1279 CaptureLostState() : got_capture_lost_(false) {} |
| 1225 | 1280 |
| 1226 bool GetAndClearGotCaptureLost() { | 1281 bool GetAndClearGotCaptureLost() { |
| 1227 bool value = got_capture_lost_; | 1282 bool value = got_capture_lost_; |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1807 | 1862 |
| 1808 ui::KeyEvent key_event2(key_event); | 1863 ui::KeyEvent key_event2(key_event); |
| 1809 widget->OnKeyEvent(&key_event2); | 1864 widget->OnKeyEvent(&key_event2); |
| 1810 EXPECT_FALSE(key_event2.stopped_propagation()); | 1865 EXPECT_FALSE(key_event2.stopped_propagation()); |
| 1811 | 1866 |
| 1812 widget->CloseNow(); | 1867 widget->CloseNow(); |
| 1813 } | 1868 } |
| 1814 | 1869 |
| 1815 } // namespace test | 1870 } // namespace test |
| 1816 } // namespace views | 1871 } // namespace views |
| OLD | NEW |