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 "ui/aura/window.h" | 5 #include "ui/aura/window.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 1444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1455 // resulting in window12's layer being below window1's layer (though the | 1455 // resulting in window12's layer being below window1's layer (though the |
1456 // windows themselves would still be correctly stacked, so events would pass | 1456 // windows themselves would still be correctly stacked, so events would pass |
1457 // through.) | 1457 // through.) |
1458 RootWindow::GetInstance()->StackChildAbove(window1.get(), window12.get()); | 1458 RootWindow::GetInstance()->StackChildAbove(window1.get(), window12.get()); |
1459 | 1459 |
1460 // Both window12 and its layer should be stacked above window1. | 1460 // Both window12 and its layer should be stacked above window1. |
1461 EXPECT_TRUE(WindowIsAbove(window12.get(), window1.get())); | 1461 EXPECT_TRUE(WindowIsAbove(window12.get(), window1.get())); |
1462 EXPECT_TRUE(LayerIsAbove(window12.get(), window1.get())); | 1462 EXPECT_TRUE(LayerIsAbove(window12.get(), window1.get())); |
1463 } | 1463 } |
1464 | 1464 |
| 1465 class RootWindowAttachmentObserver : public WindowObserver { |
| 1466 public: |
| 1467 RootWindowAttachmentObserver() : added_count_(0), removed_count_(0) {} |
| 1468 virtual ~RootWindowAttachmentObserver() {} |
| 1469 |
| 1470 int added_count() const { return added_count_; } |
| 1471 int removed_count() const { return removed_count_; } |
| 1472 |
| 1473 void Clear() { |
| 1474 added_count_ = 0; |
| 1475 removed_count_ = 0; |
| 1476 } |
| 1477 |
| 1478 // Overridden from WindowObserver: |
| 1479 virtual void OnWindowAddedToRootWindow(Window* window) OVERRIDE { |
| 1480 ++added_count_; |
| 1481 } |
| 1482 virtual void OnWindowRemovingFromRootWindow(Window* window) OVERRIDE { |
| 1483 ++removed_count_; |
| 1484 } |
| 1485 |
| 1486 private: |
| 1487 int added_count_; |
| 1488 int removed_count_; |
| 1489 |
| 1490 DISALLOW_COPY_AND_ASSIGN(RootWindowAttachmentObserver); |
| 1491 }; |
| 1492 |
| 1493 TEST_F(WindowTest, RootWindowAttachment) { |
| 1494 RootWindowAttachmentObserver observer; |
| 1495 |
| 1496 // Test a direct add/remove from the RootWindow. |
| 1497 scoped_ptr<Window> w1(new Window(NULL)); |
| 1498 w1->Init(ui::Layer::LAYER_NOT_DRAWN); |
| 1499 w1->AddObserver(&observer); |
| 1500 |
| 1501 w1->SetParent(NULL); |
| 1502 EXPECT_EQ(1, observer.added_count()); |
| 1503 EXPECT_EQ(0, observer.removed_count()); |
| 1504 |
| 1505 w1.reset(); |
| 1506 EXPECT_EQ(1, observer.added_count()); |
| 1507 EXPECT_EQ(1, observer.removed_count()); |
| 1508 |
| 1509 observer.Clear(); |
| 1510 |
| 1511 // Test an indirect add/remove from the RootWindow. |
| 1512 w1.reset(new Window(NULL)); |
| 1513 w1->Init(ui::Layer::LAYER_NOT_DRAWN); |
| 1514 Window* w11 = new Window(NULL); |
| 1515 w11->Init(ui::Layer::LAYER_NOT_DRAWN); |
| 1516 w11->AddObserver(&observer); |
| 1517 w11->SetParent(w1.get()); |
| 1518 EXPECT_EQ(0, observer.added_count()); |
| 1519 EXPECT_EQ(0, observer.removed_count()); |
| 1520 |
| 1521 w1->SetParent(NULL); |
| 1522 EXPECT_EQ(1, observer.added_count()); |
| 1523 EXPECT_EQ(0, observer.removed_count()); |
| 1524 |
| 1525 w1.reset(); // Deletes w11. |
| 1526 w11 = NULL; |
| 1527 EXPECT_EQ(1, observer.added_count()); |
| 1528 EXPECT_EQ(1, observer.removed_count()); |
| 1529 |
| 1530 observer.Clear(); |
| 1531 |
| 1532 // Test an indirect add/remove with nested observers. |
| 1533 w1.reset(new Window(NULL)); |
| 1534 w1->Init(ui::Layer::LAYER_NOT_DRAWN); |
| 1535 w11 = new Window(NULL); |
| 1536 w11->Init(ui::Layer::LAYER_NOT_DRAWN); |
| 1537 w11->AddObserver(&observer); |
| 1538 w11->SetParent(w1.get()); |
| 1539 Window* w111 = new Window(NULL); |
| 1540 w111->Init(ui::Layer::LAYER_NOT_DRAWN); |
| 1541 w111->AddObserver(&observer); |
| 1542 w111->SetParent(w11); |
| 1543 |
| 1544 EXPECT_EQ(0, observer.added_count()); |
| 1545 EXPECT_EQ(0, observer.removed_count()); |
| 1546 |
| 1547 w1->SetParent(NULL); |
| 1548 EXPECT_EQ(2, observer.added_count()); |
| 1549 EXPECT_EQ(0, observer.removed_count()); |
| 1550 |
| 1551 w1.reset(); // Deletes w11 and w111. |
| 1552 w11 = NULL; |
| 1553 w111 = NULL; |
| 1554 EXPECT_EQ(2, observer.added_count()); |
| 1555 EXPECT_EQ(2, observer.removed_count()); |
| 1556 } |
| 1557 |
1465 } // namespace test | 1558 } // namespace test |
1466 } // namespace aura | 1559 } // namespace aura |
OLD | NEW |