OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
6 #include <memory> | 6 #include <memory> |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/environment.h" | 10 #include "base/environment.h" |
(...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 } | 1319 } |
1320 #endif | 1320 #endif |
1321 | 1321 |
1322 // Desktop native widget Aura tests are for non Chrome OS platforms. | 1322 // Desktop native widget Aura tests are for non Chrome OS platforms. |
1323 #if !defined(OS_CHROMEOS) | 1323 #if !defined(OS_CHROMEOS) |
1324 // This class validates whether paints are received for a visible Widget. | 1324 // This class validates whether paints are received for a visible Widget. |
1325 // To achieve this it overrides the Show and Close methods on the Widget class | 1325 // To achieve this it overrides the Show and Close methods on the Widget class |
1326 // and sets state whether subsequent paints are expected. | 1326 // and sets state whether subsequent paints are expected. |
1327 class DesktopAuraTestValidPaintWidget : public views::Widget { | 1327 class DesktopAuraTestValidPaintWidget : public views::Widget { |
1328 public: | 1328 public: |
1329 DesktopAuraTestValidPaintWidget() | 1329 DesktopAuraTestValidPaintWidget() {} |
1330 : received_paint_(false), | |
1331 expect_paint_(true), | |
1332 received_paint_while_hidden_(false) {} | |
1333 | |
1334 ~DesktopAuraTestValidPaintWidget() override {} | 1330 ~DesktopAuraTestValidPaintWidget() override {} |
1335 | 1331 |
1336 void InitForTest(Widget::InitParams create_params); | 1332 void InitForTest(Widget::InitParams create_params); |
1337 | 1333 |
1338 bool ReadReceivedPaintAndReset() { | 1334 bool ReadReceivedPaintAndReset() { |
1339 bool result = received_paint_; | 1335 bool result = received_paint_; |
1340 received_paint_ = false; | 1336 received_paint_ = false; |
1341 return result; | 1337 return result; |
1342 } | 1338 } |
1343 | 1339 |
1344 bool received_paint_while_hidden() const { | 1340 bool received_paint_while_hidden() const { |
1345 return received_paint_while_hidden_; | 1341 return received_paint_while_hidden_; |
1346 } | 1342 } |
1347 | 1343 |
| 1344 int visibility_change_count() const { return visibility_change_count_; } |
| 1345 |
| 1346 bool visible_at_last_change() const { return visible_at_last_change_; } |
| 1347 |
1348 void WaitUntilPaint() { | 1348 void WaitUntilPaint() { |
1349 if (received_paint_) | 1349 if (received_paint_) |
1350 return; | 1350 return; |
1351 base::RunLoop runloop; | 1351 base::RunLoop runloop; |
1352 quit_closure_ = runloop.QuitClosure(); | 1352 quit_closure_ = runloop.QuitClosure(); |
1353 runloop.Run(); | 1353 runloop.Run(); |
1354 quit_closure_ = base::Closure(); | 1354 quit_closure_ = base::Closure(); |
1355 } | 1355 } |
1356 | 1356 |
1357 // views::Widget: | 1357 // views::Widget: |
(...skipping 15 matching lines...) Expand all Loading... |
1373 void OnNativeWidgetPaint(const ui::PaintContext& context) override { | 1373 void OnNativeWidgetPaint(const ui::PaintContext& context) override { |
1374 received_paint_ = true; | 1374 received_paint_ = true; |
1375 EXPECT_TRUE(expect_paint_); | 1375 EXPECT_TRUE(expect_paint_); |
1376 if (!expect_paint_) | 1376 if (!expect_paint_) |
1377 received_paint_while_hidden_ = true; | 1377 received_paint_while_hidden_ = true; |
1378 views::Widget::OnNativeWidgetPaint(context); | 1378 views::Widget::OnNativeWidgetPaint(context); |
1379 if (!quit_closure_.is_null()) | 1379 if (!quit_closure_.is_null()) |
1380 quit_closure_.Run(); | 1380 quit_closure_.Run(); |
1381 } | 1381 } |
1382 | 1382 |
| 1383 void OnNativeWidgetVisibilityChanged(bool visible) override { |
| 1384 ++visibility_change_count_; |
| 1385 visible_at_last_change_ = visible; |
| 1386 views::Widget::OnNativeWidgetVisibilityChanged(visible); |
| 1387 } |
| 1388 |
1383 private: | 1389 private: |
1384 bool received_paint_; | 1390 int visibility_change_count_ = 0; |
1385 bool expect_paint_; | 1391 bool visible_at_last_change_ = false; |
1386 bool received_paint_while_hidden_; | 1392 |
| 1393 bool received_paint_ = false; |
| 1394 bool expect_paint_ = true; |
| 1395 bool received_paint_while_hidden_ = false; |
| 1396 |
1387 base::Closure quit_closure_; | 1397 base::Closure quit_closure_; |
1388 | 1398 |
1389 DISALLOW_COPY_AND_ASSIGN(DesktopAuraTestValidPaintWidget); | 1399 DISALLOW_COPY_AND_ASSIGN(DesktopAuraTestValidPaintWidget); |
1390 }; | 1400 }; |
1391 | 1401 |
1392 void DesktopAuraTestValidPaintWidget::InitForTest(InitParams init_params) { | 1402 void DesktopAuraTestValidPaintWidget::InitForTest(InitParams init_params) { |
1393 init_params.bounds = gfx::Rect(0, 0, 200, 200); | 1403 init_params.bounds = gfx::Rect(0, 0, 200, 200); |
1394 init_params.ownership = InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 1404 init_params.ownership = InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
1395 init_params.native_widget = | 1405 init_params.native_widget = |
1396 CreatePlatformDesktopNativeWidgetImpl(init_params, this, nullptr); | 1406 CreatePlatformDesktopNativeWidgetImpl(init_params, this, nullptr); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1428 widget.WaitUntilPaint(); | 1438 widget.WaitUntilPaint(); |
1429 EXPECT_TRUE(widget.ReadReceivedPaintAndReset()); | 1439 EXPECT_TRUE(widget.ReadReceivedPaintAndReset()); |
1430 widget.SchedulePaintInRect(widget.GetRestoredBounds()); | 1440 widget.SchedulePaintInRect(widget.GetRestoredBounds()); |
1431 widget.Hide(); | 1441 widget.Hide(); |
1432 RunPendingMessages(); | 1442 RunPendingMessages(); |
1433 EXPECT_FALSE(widget.ReadReceivedPaintAndReset()); | 1443 EXPECT_FALSE(widget.ReadReceivedPaintAndReset()); |
1434 EXPECT_FALSE(widget.received_paint_while_hidden()); | 1444 EXPECT_FALSE(widget.received_paint_while_hidden()); |
1435 widget.Close(); | 1445 widget.Close(); |
1436 } | 1446 } |
1437 | 1447 |
| 1448 // Tests that visibility changes after scheduling an asynchronous Close() are |
| 1449 // sane and consistent across platforms. |
| 1450 TEST_F(WidgetTest, DesktopNativeWidgetVisibilityAfterCloseTest) { |
| 1451 // TODO(sad): Desktop widgets do not work well in mus https://crbug.com/616551 |
| 1452 if (IsMus()) |
| 1453 return; |
| 1454 |
| 1455 DesktopAuraTestValidPaintWidget widget; |
| 1456 widget.InitForTest(CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS)); |
| 1457 widget.WaitUntilPaint(); |
| 1458 EXPECT_TRUE(widget.ReadReceivedPaintAndReset()); |
| 1459 EXPECT_EQ(1, widget.visibility_change_count()); |
| 1460 EXPECT_TRUE(widget.visible_at_last_change()); |
| 1461 |
| 1462 // Hide before close should behave normally. Hide and show are synchronous. |
| 1463 widget.Hide(); |
| 1464 EXPECT_EQ(2, widget.visibility_change_count()); |
| 1465 EXPECT_FALSE(widget.visible_at_last_change()); |
| 1466 widget.Show(); |
| 1467 EXPECT_EQ(3, widget.visibility_change_count()); |
| 1468 EXPECT_TRUE(widget.visible_at_last_change()); |
| 1469 |
| 1470 RunPendingMessages(); |
| 1471 EXPECT_EQ(3, widget.visibility_change_count()); // No change. |
| 1472 |
| 1473 EXPECT_FALSE(widget.ReadReceivedPaintAndReset()); |
| 1474 widget.WaitUntilPaint(); |
| 1475 EXPECT_TRUE(widget.ReadReceivedPaintAndReset()); |
| 1476 |
| 1477 // After a Close, there should be no changes. |
| 1478 widget.Close(); |
| 1479 EXPECT_EQ(3, widget.visibility_change_count()); // No change. |
| 1480 widget.Hide(); |
| 1481 EXPECT_EQ(3, widget.visibility_change_count()); // No change. |
| 1482 widget.Show(); |
| 1483 EXPECT_EQ(3, widget.visibility_change_count()); // No change. |
| 1484 RunPendingMessages(); |
| 1485 EXPECT_EQ(3, widget.visibility_change_count()); // No change. |
| 1486 } |
| 1487 |
1438 // Test to ensure that the aura Window's visiblity state is set to visible if | 1488 // Test to ensure that the aura Window's visiblity state is set to visible if |
1439 // the underlying widget is hidden and then shown. | 1489 // the underlying widget is hidden and then shown. |
1440 TEST_F(WidgetTest, TestWindowVisibilityAfterHide) { | 1490 TEST_F(WidgetTest, TestWindowVisibilityAfterHide) { |
1441 // Create a widget. | 1491 // Create a widget. |
1442 Widget widget; | 1492 Widget widget; |
1443 Widget::InitParams init_params = | 1493 Widget::InitParams init_params = |
1444 CreateParams(Widget::InitParams::TYPE_WINDOW); | 1494 CreateParams(Widget::InitParams::TYPE_WINDOW); |
1445 init_params.show_state = ui::SHOW_STATE_NORMAL; | 1495 init_params.show_state = ui::SHOW_STATE_NORMAL; |
1446 gfx::Rect initial_bounds(0, 0, 300, 400); | 1496 gfx::Rect initial_bounds(0, 0, 300, 400); |
1447 init_params.bounds = initial_bounds; | 1497 init_params.bounds = initial_bounds; |
(...skipping 2355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3803 CreateParams(Widget::InitParams::TYPE_WINDOW), | 3853 CreateParams(Widget::InitParams::TYPE_WINDOW), |
3804 Widget::InitParams::TRANSLUCENT_WINDOW); | 3854 Widget::InitParams::TRANSLUCENT_WINDOW); |
3805 EXPECT_EQ(IsNativeWindowTransparent(widget.GetNativeWindow()), | 3855 EXPECT_EQ(IsNativeWindowTransparent(widget.GetNativeWindow()), |
3806 widget.ShouldWindowContentsBeTransparent()); | 3856 widget.ShouldWindowContentsBeTransparent()); |
3807 } | 3857 } |
3808 | 3858 |
3809 #endif // !defined(OS_CHROMEOS) | 3859 #endif // !defined(OS_CHROMEOS) |
3810 | 3860 |
3811 } // namespace test | 3861 } // namespace test |
3812 } // namespace views | 3862 } // namespace views |
OLD | NEW |