| 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 "ash/wm/system_modal_container_layout_manager.h" | 5 #include "ash/wm/system_modal_container_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/session_state_delegate.h" | 8 #include "ash/session_state_delegate.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| 11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
| 16 #include "ui/aura/test/event_generator.h" | 16 #include "ui/aura/test/event_generator.h" |
| 17 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 18 #include "ui/compositor/layer.h" | 18 #include "ui/compositor/layer.h" |
| 19 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
| 20 #include "ui/views/corewm/transient_window_manager.h" |
| 20 #include "ui/views/test/capture_tracking_view.h" | 21 #include "ui/views/test/capture_tracking_view.h" |
| 21 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 22 #include "ui/views/widget/widget_delegate.h" | 23 #include "ui/views/widget/widget_delegate.h" |
| 23 | 24 |
| 24 namespace ash { | 25 namespace ash { |
| 25 namespace test { | 26 namespace test { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 aura::Window* GetModalContainer() { | 30 aura::Window* GetModalContainer() { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 return widget->GetNativeView(); | 155 return widget->GetNativeView(); |
| 155 } | 156 } |
| 156 }; | 157 }; |
| 157 | 158 |
| 158 TEST_F(SystemModalContainerLayoutManagerTest, NonModalTransient) { | 159 TEST_F(SystemModalContainerLayoutManagerTest, NonModalTransient) { |
| 159 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); | 160 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 160 aura::Window* transient = OpenTestWindowWithParent(parent.get(), false); | 161 aura::Window* transient = OpenTestWindowWithParent(parent.get(), false); |
| 161 TransientWindowObserver destruction_observer; | 162 TransientWindowObserver destruction_observer; |
| 162 transient->AddObserver(&destruction_observer); | 163 transient->AddObserver(&destruction_observer); |
| 163 | 164 |
| 164 EXPECT_EQ(parent.get(), transient->transient_parent()); | 165 EXPECT_EQ(parent.get(), views::corewm::GetTransientParent(transient)); |
| 165 EXPECT_EQ(parent->parent(), transient->parent()); | 166 EXPECT_EQ(parent->parent(), transient->parent()); |
| 166 | 167 |
| 167 // The transient should be destroyed with its parent. | 168 // The transient should be destroyed with its parent. |
| 168 parent.reset(); | 169 parent.reset(); |
| 169 EXPECT_TRUE(destruction_observer.destroyed()); | 170 EXPECT_TRUE(destruction_observer.destroyed()); |
| 170 } | 171 } |
| 171 | 172 |
| 172 TEST_F(SystemModalContainerLayoutManagerTest, ModalTransient) { | 173 TEST_F(SystemModalContainerLayoutManagerTest, ModalTransient) { |
| 173 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); | 174 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 174 // parent should be active. | 175 // parent should be active. |
| 175 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); | 176 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); |
| 176 aura::Window* t1 = OpenTestWindowWithParent(parent.get(), true); | 177 aura::Window* t1 = OpenTestWindowWithParent(parent.get(), true); |
| 177 | 178 |
| 178 TransientWindowObserver do1; | 179 TransientWindowObserver do1; |
| 179 t1->AddObserver(&do1); | 180 t1->AddObserver(&do1); |
| 180 | 181 |
| 181 EXPECT_EQ(parent.get(), t1->transient_parent()); | 182 EXPECT_EQ(parent.get(), views::corewm::GetTransientParent(t1)); |
| 182 EXPECT_EQ(GetModalContainer(), t1->parent()); | 183 EXPECT_EQ(GetModalContainer(), t1->parent()); |
| 183 | 184 |
| 184 // t1 should now be active. | 185 // t1 should now be active. |
| 185 EXPECT_TRUE(wm::IsActiveWindow(t1)); | 186 EXPECT_TRUE(wm::IsActiveWindow(t1)); |
| 186 | 187 |
| 187 // Attempting to click the parent should result in no activation change. | 188 // Attempting to click the parent should result in no activation change. |
| 188 aura::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), parent.get()); | 189 aura::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), parent.get()); |
| 189 e1.ClickLeftButton(); | 190 e1.ClickLeftButton(); |
| 190 EXPECT_TRUE(wm::IsActiveWindow(t1)); | 191 EXPECT_TRUE(wm::IsActiveWindow(t1)); |
| 191 | 192 |
| 192 // Now open another modal transient parented to the original modal transient. | 193 // Now open another modal transient parented to the original modal transient. |
| 193 aura::Window* t2 = OpenTestWindowWithParent(t1, true); | 194 aura::Window* t2 = OpenTestWindowWithParent(t1, true); |
| 194 TransientWindowObserver do2; | 195 TransientWindowObserver do2; |
| 195 t2->AddObserver(&do2); | 196 t2->AddObserver(&do2); |
| 196 | 197 |
| 197 EXPECT_TRUE(wm::IsActiveWindow(t2)); | 198 EXPECT_TRUE(wm::IsActiveWindow(t2)); |
| 198 | 199 |
| 199 EXPECT_EQ(t1, t2->transient_parent()); | 200 EXPECT_EQ(t1, views::corewm::GetTransientParent(t2)); |
| 200 EXPECT_EQ(GetModalContainer(), t2->parent()); | 201 EXPECT_EQ(GetModalContainer(), t2->parent()); |
| 201 | 202 |
| 202 // t2 should still be active, even after clicking on t1. | 203 // t2 should still be active, even after clicking on t1. |
| 203 aura::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), t1); | 204 aura::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), t1); |
| 204 e2.ClickLeftButton(); | 205 e2.ClickLeftButton(); |
| 205 EXPECT_TRUE(wm::IsActiveWindow(t2)); | 206 EXPECT_TRUE(wm::IsActiveWindow(t2)); |
| 206 | 207 |
| 207 // Both transients should be destroyed with parent. | 208 // Both transients should be destroyed with parent. |
| 208 parent.reset(); | 209 parent.reset(); |
| 209 EXPECT_TRUE(do1.destroyed()); | 210 EXPECT_TRUE(do1.destroyed()); |
| 210 EXPECT_TRUE(do2.destroyed()); | 211 EXPECT_TRUE(do2.destroyed()); |
| 211 } | 212 } |
| 212 | 213 |
| 213 TEST_F(SystemModalContainerLayoutManagerTest, ModalNonTransient) { | 214 TEST_F(SystemModalContainerLayoutManagerTest, ModalNonTransient) { |
| 214 scoped_ptr<aura::Window> t1(OpenToplevelTestWindow(true)); | 215 scoped_ptr<aura::Window> t1(OpenToplevelTestWindow(true)); |
| 215 // parent should be active. | 216 // parent should be active. |
| 216 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); | 217 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); |
| 217 TransientWindowObserver do1; | 218 TransientWindowObserver do1; |
| 218 t1->AddObserver(&do1); | 219 t1->AddObserver(&do1); |
| 219 | 220 |
| 220 EXPECT_EQ(NULL, t1->transient_parent()); | 221 EXPECT_EQ(NULL, views::corewm::GetTransientParent(t1.get())); |
| 221 EXPECT_EQ(GetModalContainer(), t1->parent()); | 222 EXPECT_EQ(GetModalContainer(), t1->parent()); |
| 222 | 223 |
| 223 // t1 should now be active. | 224 // t1 should now be active. |
| 224 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); | 225 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); |
| 225 | 226 |
| 226 // Attempting to click the parent should result in no activation change. | 227 // Attempting to click the parent should result in no activation change. |
| 227 aura::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), | 228 aura::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), |
| 228 Shell::GetPrimaryRootWindow()); | 229 Shell::GetPrimaryRootWindow()); |
| 229 e1.ClickLeftButton(); | 230 e1.ClickLeftButton(); |
| 230 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); | 231 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); |
| 231 | 232 |
| 232 // Now open another modal transient parented to the original modal transient. | 233 // Now open another modal transient parented to the original modal transient. |
| 233 aura::Window* t2 = OpenTestWindowWithParent(t1.get(), true); | 234 aura::Window* t2 = OpenTestWindowWithParent(t1.get(), true); |
| 234 TransientWindowObserver do2; | 235 TransientWindowObserver do2; |
| 235 t2->AddObserver(&do2); | 236 t2->AddObserver(&do2); |
| 236 | 237 |
| 237 EXPECT_TRUE(wm::IsActiveWindow(t2)); | 238 EXPECT_TRUE(wm::IsActiveWindow(t2)); |
| 238 | 239 |
| 239 EXPECT_EQ(t1, t2->transient_parent()); | 240 EXPECT_EQ(t1, views::corewm::GetTransientParent(t2)); |
| 240 EXPECT_EQ(GetModalContainer(), t2->parent()); | 241 EXPECT_EQ(GetModalContainer(), t2->parent()); |
| 241 | 242 |
| 242 // t2 should still be active, even after clicking on t1. | 243 // t2 should still be active, even after clicking on t1. |
| 243 aura::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), t1.get()); | 244 aura::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), t1.get()); |
| 244 e2.ClickLeftButton(); | 245 e2.ClickLeftButton(); |
| 245 EXPECT_TRUE(wm::IsActiveWindow(t2)); | 246 EXPECT_TRUE(wm::IsActiveWindow(t2)); |
| 246 | 247 |
| 247 // Both transients should be destroyed with parent. | 248 // Both transients should be destroyed with parent. |
| 248 t1.reset(); | 249 t1.reset(); |
| 249 EXPECT_TRUE(do1.destroyed()); | 250 EXPECT_TRUE(do1.destroyed()); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 | 487 |
| 487 // No more modal screen. | 488 // No more modal screen. |
| 488 modal1->Hide(); | 489 modal1->Hide(); |
| 489 TestWindow::CloseTestWindow(modal1.release()); | 490 TestWindow::CloseTestWindow(modal1.release()); |
| 490 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); | 491 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); |
| 491 EXPECT_TRUE(wm::IsActiveWindow(normal.get())); | 492 EXPECT_TRUE(wm::IsActiveWindow(normal.get())); |
| 492 } | 493 } |
| 493 | 494 |
| 494 } // namespace test | 495 } // namespace test |
| 495 } // namespace ash | 496 } // namespace ash |
| OLD | NEW |