OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_shell/modal_container_layout_manager.h" | 5 #include "ui/aura_shell/modal_container_layout_manager.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "ui/aura/root_window.h" | 8 #include "ui/aura/root_window.h" |
9 #include "ui/aura/test/event_generator.h" | 9 #include "ui/aura/test/event_generator.h" |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
11 #include "ui/aura_shell/shell.h" | 11 #include "ui/aura_shell/shell.h" |
12 #include "ui/aura_shell/shell_window_ids.h" | 12 #include "ui/aura_shell/shell_window_ids.h" |
13 #include "ui/aura_shell/test/aura_shell_test_base.h" | 13 #include "ui/aura_shell/test/aura_shell_test_base.h" |
| 14 #include "ui/aura_shell/window_util.h" |
14 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
15 #include "ui/views/widget/widget_delegate.h" | 16 #include "ui/views/widget/widget_delegate.h" |
16 | 17 |
17 namespace aura_shell { | 18 namespace aura_shell { |
18 namespace test { | 19 namespace test { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 aura::Window* GetModalContainer() { | 23 aura::Window* GetModalContainer() { |
23 return Shell::GetInstance()->GetContainer( | 24 return Shell::GetInstance()->GetContainer( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 75 } |
75 | 76 |
76 private: | 77 private: |
77 bool destroyed_; | 78 bool destroyed_; |
78 | 79 |
79 DISALLOW_COPY_AND_ASSIGN(TransientWindowObserver); | 80 DISALLOW_COPY_AND_ASSIGN(TransientWindowObserver); |
80 }; | 81 }; |
81 | 82 |
82 } // namespace | 83 } // namespace |
83 | 84 |
84 typedef aura_shell::test::AuraShellTestBase ModalContainerLayoutManagerTest; | 85 typedef AuraShellTestBase ModalContainerLayoutManagerTest; |
85 | 86 |
86 TEST_F(ModalContainerLayoutManagerTest, NonModalTransient) { | 87 TEST_F(ModalContainerLayoutManagerTest, NonModalTransient) { |
87 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); | 88 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); |
88 aura::Window* transient = TestWindow::OpenTestWindow(parent.get(), false); | 89 aura::Window* transient = TestWindow::OpenTestWindow(parent.get(), false); |
89 TransientWindowObserver destruction_observer; | 90 TransientWindowObserver destruction_observer; |
90 transient->AddObserver(&destruction_observer); | 91 transient->AddObserver(&destruction_observer); |
91 | 92 |
92 EXPECT_EQ(parent.get(), transient->transient_parent()); | 93 EXPECT_EQ(parent.get(), transient->transient_parent()); |
93 EXPECT_EQ(GetDefaultContainer(), transient->parent()); | 94 EXPECT_EQ(GetDefaultContainer(), transient->parent()); |
94 | 95 |
95 // The transient should be destroyed with its parent. | 96 // The transient should be destroyed with its parent. |
96 parent.reset(); | 97 parent.reset(); |
97 EXPECT_TRUE(destruction_observer.destroyed()); | 98 EXPECT_TRUE(destruction_observer.destroyed()); |
98 } | 99 } |
99 | 100 |
100 TEST_F(ModalContainerLayoutManagerTest, ModalTransient) { | 101 TEST_F(ModalContainerLayoutManagerTest, ModalTransient) { |
101 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); | 102 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); |
102 // parent should be active. | 103 // parent should be active. |
103 EXPECT_EQ(parent.get(), aura::RootWindow::GetInstance()->active_window()); | 104 EXPECT_TRUE(IsActiveWindow(parent.get())); |
104 | 105 |
105 aura::Window* t1 = TestWindow::OpenTestWindow(parent.get(), true); | 106 aura::Window* t1 = TestWindow::OpenTestWindow(parent.get(), true); |
106 TransientWindowObserver do1; | 107 TransientWindowObserver do1; |
107 t1->AddObserver(&do1); | 108 t1->AddObserver(&do1); |
108 | 109 |
109 EXPECT_EQ(parent.get(), t1->transient_parent()); | 110 EXPECT_EQ(parent.get(), t1->transient_parent()); |
110 EXPECT_EQ(GetModalContainer(), t1->parent()); | 111 EXPECT_EQ(GetModalContainer(), t1->parent()); |
111 | 112 |
112 // t1 should now be active. | 113 // t1 should now be active. |
113 EXPECT_EQ(t1, aura::RootWindow::GetInstance()->active_window()); | 114 EXPECT_TRUE(IsActiveWindow(t1)); |
114 | 115 |
115 // Attempting to click the parent should result in no activation change. | 116 // Attempting to click the parent should result in no activation change. |
116 aura::test::EventGenerator e1(parent.get()); | 117 aura::test::EventGenerator e1(parent.get()); |
117 e1.ClickLeftButton(); | 118 e1.ClickLeftButton(); |
118 EXPECT_EQ(t1, aura::RootWindow::GetInstance()->active_window()); | 119 EXPECT_TRUE(IsActiveWindow(t1)); |
119 | 120 |
120 // Now open another modal transient parented to the original modal transient. | 121 // Now open another modal transient parented to the original modal transient. |
121 aura::Window* t2 = TestWindow::OpenTestWindow(t1, true); | 122 aura::Window* t2 = TestWindow::OpenTestWindow(t1, true); |
122 TransientWindowObserver do2; | 123 TransientWindowObserver do2; |
123 t2->AddObserver(&do2); | 124 t2->AddObserver(&do2); |
124 | 125 |
125 EXPECT_EQ(t2, aura::RootWindow::GetInstance()->active_window()); | 126 EXPECT_TRUE(IsActiveWindow(t2)); |
126 | 127 |
127 EXPECT_EQ(t1, t2->transient_parent()); | 128 EXPECT_EQ(t1, t2->transient_parent()); |
128 EXPECT_EQ(GetModalContainer(), t2->parent()); | 129 EXPECT_EQ(GetModalContainer(), t2->parent()); |
129 | 130 |
130 // t2 should still be active, even after clicking on t1. | 131 // t2 should still be active, even after clicking on t1. |
131 aura::test::EventGenerator e2(t1); | 132 aura::test::EventGenerator e2(t1); |
132 e2.ClickLeftButton(); | 133 e2.ClickLeftButton(); |
133 EXPECT_EQ(t2, aura::RootWindow::GetInstance()->active_window()); | 134 EXPECT_TRUE(IsActiveWindow(t2)); |
134 | 135 |
135 // Both transients should be destroyed with parent. | 136 // Both transients should be destroyed with parent. |
136 parent.reset(); | 137 parent.reset(); |
137 EXPECT_TRUE(do1.destroyed()); | 138 EXPECT_TRUE(do1.destroyed()); |
138 EXPECT_TRUE(do2.destroyed()); | 139 EXPECT_TRUE(do2.destroyed()); |
139 } | 140 } |
140 | 141 |
141 // Tests that we can activate an unrelated window after a modal window is closed | 142 // Tests that we can activate an unrelated window after a modal window is closed |
142 // for a window. | 143 // for a window. |
143 TEST_F(ModalContainerLayoutManagerTest, CanActivateAfterEndModalSession) { | 144 TEST_F(ModalContainerLayoutManagerTest, CanActivateAfterEndModalSession) { |
144 scoped_ptr<aura::Window> unrelated(TestWindow::OpenTestWindow(NULL, false)); | 145 scoped_ptr<aura::Window> unrelated(TestWindow::OpenTestWindow(NULL, false)); |
145 unrelated->SetBounds(gfx::Rect(100, 100, 50, 50)); | 146 unrelated->SetBounds(gfx::Rect(100, 100, 50, 50)); |
146 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); | 147 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); |
147 // parent should be active. | 148 // parent should be active. |
148 EXPECT_EQ(parent.get(), aura::RootWindow::GetInstance()->active_window()); | 149 EXPECT_TRUE(IsActiveWindow(parent.get())); |
149 | 150 |
150 scoped_ptr<aura::Window> transient( | 151 scoped_ptr<aura::Window> transient( |
151 TestWindow::OpenTestWindow(parent.get(), true)); | 152 TestWindow::OpenTestWindow(parent.get(), true)); |
152 // t1 should now be active. | 153 // t1 should now be active. |
153 EXPECT_EQ(transient.get(), aura::RootWindow::GetInstance()->active_window()); | 154 EXPECT_TRUE(IsActiveWindow(transient.get())); |
154 | 155 |
155 // Attempting to click the parent should result in no activation change. | 156 // Attempting to click the parent should result in no activation change. |
156 aura::test::EventGenerator e1(parent.get()); | 157 aura::test::EventGenerator e1(parent.get()); |
157 e1.ClickLeftButton(); | 158 e1.ClickLeftButton(); |
158 EXPECT_EQ(transient.get(), aura::RootWindow::GetInstance()->active_window()); | 159 EXPECT_TRUE(IsActiveWindow(transient.get())); |
159 | 160 |
160 // Now close the transient. | 161 // Now close the transient. |
161 transient.reset(); | 162 transient.reset(); |
162 | 163 |
163 // parent should now be active again. | 164 // parent should now be active again. |
164 EXPECT_EQ(parent.get(), aura::RootWindow::GetInstance()->active_window()); | 165 EXPECT_TRUE(IsActiveWindow(parent.get())); |
165 | 166 |
166 // Attempting to click unrelated should activate it. | 167 // Attempting to click unrelated should activate it. |
167 aura::test::EventGenerator e2(unrelated.get()); | 168 aura::test::EventGenerator e2(unrelated.get()); |
168 e2.ClickLeftButton(); | 169 e2.ClickLeftButton(); |
169 EXPECT_EQ(unrelated.get(), aura::RootWindow::GetInstance()->active_window()); | 170 EXPECT_TRUE(IsActiveWindow(unrelated.get())); |
170 } | 171 } |
171 | 172 |
172 } // namespace test | 173 } // namespace test |
173 } // namespace aura_shell | 174 } // namespace aura_shell |
OLD | NEW |