OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/views/corewm/transient_window_manager.h" | 5 #include "ui/views/corewm/transient_window_manager.h" |
6 | 6 |
7 #include "ui/aura/client/visibility_client.h" | 7 #include "ui/aura/client/visibility_client.h" |
8 #include "ui/aura/client/window_tree_client.h" | 8 #include "ui/aura/client/window_tree_client.h" |
9 #include "ui/aura/layout_manager.h" | 9 #include "ui/aura/layout_manager.h" |
10 #include "ui/aura/test/test_windows.h" | 10 #include "ui/aura/test/test_windows.h" |
11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 12 #include "ui/views/corewm/transient_window_observer.h" |
12 #include "ui/views/corewm/window_util.h" | 13 #include "ui/views/corewm/window_util.h" |
13 #include "ui/views/test/views_test_base.h" | 14 #include "ui/views/test/views_test_base.h" |
14 | 15 |
15 using aura::Window; | 16 using aura::Window; |
16 | 17 |
17 using aura::test::ChildWindowIDsAsString; | 18 using aura::test::ChildWindowIDsAsString; |
18 using aura::test::CreateTestWindowWithId; | 19 using aura::test::CreateTestWindowWithId; |
19 | 20 |
20 namespace views { | 21 namespace views { |
21 namespace corewm { | 22 namespace corewm { |
22 | 23 |
| 24 class TestTransientWindowObserver : public TransientWindowObserver { |
| 25 public: |
| 26 TestTransientWindowObserver() : add_count_(0), remove_count_(0) { |
| 27 } |
| 28 |
| 29 virtual ~TestTransientWindowObserver() { |
| 30 } |
| 31 |
| 32 int add_count() const { return add_count_; } |
| 33 int remove_count() const { return remove_count_; } |
| 34 |
| 35 // TransientWindowObserver overrides: |
| 36 virtual void OnTransientChildAdded(Window* window, |
| 37 Window* transient) OVERRIDE { |
| 38 add_count_++; |
| 39 } |
| 40 virtual void OnTransientChildRemoved(Window* window, |
| 41 Window* transient) OVERRIDE { |
| 42 remove_count_++; |
| 43 } |
| 44 |
| 45 private: |
| 46 int add_count_; |
| 47 int remove_count_; |
| 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(TestTransientWindowObserver); |
| 50 }; |
| 51 |
23 class TransientWindowManagerTest : public views::ViewsTestBase { | 52 class TransientWindowManagerTest : public views::ViewsTestBase { |
24 public: | 53 public: |
25 TransientWindowManagerTest() {} | 54 TransientWindowManagerTest() {} |
26 virtual ~TransientWindowManagerTest() {} | 55 virtual ~TransientWindowManagerTest() {} |
27 | 56 |
28 protected: | 57 protected: |
29 // Creates a transient window that is transient to |parent|. | 58 // Creates a transient window that is transient to |parent|. |
30 Window* CreateTransientChild(int id, Window* parent) { | 59 Window* CreateTransientChild(int id, Window* parent) { |
31 Window* window = new Window(NULL); | 60 Window* window = new Window(NULL); |
32 window->set_id(id); | 61 window->set_id(id); |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 EXPECT_EQ(root->children()[1], transient2.get()); | 595 EXPECT_EQ(root->children()[1], transient2.get()); |
567 EXPECT_EQ(root->children()[2], window1.get()); | 596 EXPECT_EQ(root->children()[2], window1.get()); |
568 EXPECT_EQ(root->children()[3], window3.get()); | 597 EXPECT_EQ(root->children()[3], window3.get()); |
569 ASSERT_EQ(4u, root->layer()->children().size()); | 598 ASSERT_EQ(4u, root->layer()->children().size()); |
570 EXPECT_EQ(root->layer()->children()[0], window2->layer()); | 599 EXPECT_EQ(root->layer()->children()[0], window2->layer()); |
571 EXPECT_EQ(root->layer()->children()[1], transient2->layer()); | 600 EXPECT_EQ(root->layer()->children()[1], transient2->layer()); |
572 EXPECT_EQ(root->layer()->children()[2], window1->layer()); | 601 EXPECT_EQ(root->layer()->children()[2], window1->layer()); |
573 EXPECT_EQ(root->layer()->children()[3], window3->layer()); | 602 EXPECT_EQ(root->layer()->children()[3], window3->layer()); |
574 } | 603 } |
575 | 604 |
| 605 // Verifies TransientWindowObserver is notified appropriately. |
| 606 TEST_F(TransientWindowManagerTest, TransientWindowObserverNotified) { |
| 607 scoped_ptr<Window> parent(CreateTestWindowWithId(0, GetContext())); |
| 608 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); |
| 609 |
| 610 TestTransientWindowObserver test_observer; |
| 611 TransientWindowManager::Get(parent.get())->AddObserver(&test_observer); |
| 612 |
| 613 AddTransientChild(parent.get(), w1.get()); |
| 614 EXPECT_EQ(1, test_observer.add_count()); |
| 615 EXPECT_EQ(0, test_observer.remove_count()); |
| 616 |
| 617 RemoveTransientChild(parent.get(), w1.get()); |
| 618 EXPECT_EQ(1, test_observer.add_count()); |
| 619 EXPECT_EQ(1, test_observer.remove_count()); |
| 620 |
| 621 TransientWindowManager::Get(parent.get())->RemoveObserver(&test_observer); |
| 622 } |
| 623 |
576 } // namespace corewm | 624 } // namespace corewm |
577 } // namespace views | 625 } // namespace views |
OLD | NEW |