OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "athena/screen/modal_window_controller.h" |
| 6 #include "athena/screen/screen_manager_impl.h" |
| 7 #include "athena/test/base/athena_test_base.h" |
| 8 #include "athena/test/base/test_windows.h" |
| 9 #include "athena/util/container_priorities.h" |
| 10 #include "ui/aura/test/test_window_delegate.h" |
| 11 #include "ui/aura/window.h" |
| 12 |
| 13 namespace athena { |
| 14 |
| 15 typedef test::AthenaTestBase ModalWindowControllerTest; |
| 16 |
| 17 aura::Window* FindContainerByPriority(int priority) { |
| 18 ScreenManagerImpl* screen_manager = |
| 19 static_cast<ScreenManagerImpl*>(ScreenManager::Get()); |
| 20 return screen_manager->FindContainerByPriority(priority); |
| 21 } |
| 22 |
| 23 TEST_F(ModalWindowControllerTest, ModalContainer) { |
| 24 aura::test::EventCountDelegate delegate; |
| 25 scoped_ptr<aura::Window> modal(test::CreateTransientWindow( |
| 26 &delegate, NULL, ui::MODAL_TYPE_SYSTEM, false)); |
| 27 |
| 28 aura::Window* modal_container = FindContainerByPriority(CP_SYSTEM_MODAL); |
| 29 EXPECT_TRUE(modal_container); |
| 30 |
| 31 ModalWindowController* modal_controller = |
| 32 ModalWindowController::Get(modal_container); |
| 33 ASSERT_TRUE(modal_controller); |
| 34 EXPECT_EQ(modal_container, modal->parent()); |
| 35 EXPECT_FALSE(modal_controller->dimmed()); |
| 36 modal->Show(); |
| 37 EXPECT_TRUE(modal_controller->dimmed()); |
| 38 |
| 39 modal->Hide(); |
| 40 EXPECT_TRUE(FindContainerByPriority(CP_SYSTEM_MODAL)); |
| 41 EXPECT_FALSE(modal_controller->dimmed()); |
| 42 |
| 43 modal->Show(); |
| 44 EXPECT_TRUE(FindContainerByPriority(CP_SYSTEM_MODAL)); |
| 45 EXPECT_TRUE(modal_controller->dimmed()); |
| 46 |
| 47 modal.reset(); |
| 48 EXPECT_FALSE(FindContainerByPriority(CP_SYSTEM_MODAL)); |
| 49 |
| 50 // Create two. |
| 51 modal = test::CreateTransientWindow( |
| 52 &delegate, NULL, ui::MODAL_TYPE_SYSTEM, false).Pass(); |
| 53 scoped_ptr<aura::Window> modal2(test::CreateTransientWindow( |
| 54 &delegate, NULL, ui::MODAL_TYPE_SYSTEM, false)); |
| 55 |
| 56 modal_container = FindContainerByPriority(CP_SYSTEM_MODAL); |
| 57 EXPECT_TRUE(modal_container); |
| 58 modal_controller = ModalWindowController::Get(modal_container); |
| 59 ASSERT_TRUE(modal_controller); |
| 60 EXPECT_EQ(modal_container, modal->parent()); |
| 61 EXPECT_EQ(modal_container, modal2->parent()); |
| 62 |
| 63 EXPECT_FALSE(modal_controller->dimmed()); |
| 64 modal->Show(); |
| 65 EXPECT_TRUE(modal_controller->dimmed()); |
| 66 modal2->Show(); |
| 67 EXPECT_TRUE(modal_controller->dimmed()); |
| 68 |
| 69 modal->Hide(); |
| 70 EXPECT_TRUE(modal_controller->dimmed()); |
| 71 modal2->Hide(); |
| 72 EXPECT_FALSE(modal_controller->dimmed()); |
| 73 EXPECT_TRUE(FindContainerByPriority(CP_SYSTEM_MODAL)); |
| 74 |
| 75 modal2.reset(); |
| 76 EXPECT_TRUE(FindContainerByPriority(CP_SYSTEM_MODAL)); |
| 77 EXPECT_FALSE(modal_controller->dimmed()); |
| 78 |
| 79 modal.reset(); |
| 80 EXPECT_FALSE(FindContainerByPriority(CP_SYSTEM_MODAL)); |
| 81 } |
| 82 |
| 83 TEST_F(ModalWindowControllerTest, NestedModalWindows) { |
| 84 ScreenManager::ContainerParams params("top", CP_END); |
| 85 params.can_activate_children = true; |
| 86 params.modal_container_priority = CP_END + 1; |
| 87 aura::Window* top_container = ScreenManager::Get()->CreateContainer(params); |
| 88 |
| 89 aura::test::TestWindowDelegate delegate; |
| 90 scoped_ptr<aura::Window> top_w1( |
| 91 test::CreateNormalWindow(&delegate, top_container)); |
| 92 EXPECT_EQ(top_container, top_w1->parent()); |
| 93 |
| 94 aura::Window* default_container = FindContainerByPriority(CP_DEFAULT); |
| 95 EXPECT_TRUE(default_container); |
| 96 |
| 97 scoped_ptr<aura::Window> normal_w1(test::CreateNormalWindow(&delegate, NULL)); |
| 98 EXPECT_EQ(default_container, normal_w1->parent()); |
| 99 |
| 100 scoped_ptr<aura::Window> normal_m1(test::CreateTransientWindow( |
| 101 &delegate, normal_w1.get(), ui::MODAL_TYPE_SYSTEM, false)); |
| 102 aura::Window* default_modal_container = |
| 103 FindContainerByPriority(CP_SYSTEM_MODAL); |
| 104 EXPECT_EQ(default_modal_container, normal_m1->parent()); |
| 105 |
| 106 // A modal window with the transient parent which doesn't specify |
| 107 // the modal container should fallback the default container's modal |
| 108 // container. |
| 109 aura::Window* home_container = FindContainerByPriority(CP_DEFAULT); |
| 110 EXPECT_TRUE(home_container); |
| 111 |
| 112 scoped_ptr<aura::Window> normal_m2(test::CreateTransientWindow( |
| 113 &delegate, home_container, ui::MODAL_TYPE_SYSTEM, false)); |
| 114 EXPECT_EQ(default_modal_container, normal_m2->parent()); |
| 115 |
| 116 // No modal container for top container yet. |
| 117 EXPECT_FALSE(FindContainerByPriority(CP_END + 1)); |
| 118 |
| 119 // Creating a modal with always on top creates the modal dialog on top |
| 120 // most dialog container. |
| 121 scoped_ptr<aura::Window> top_m0(test::CreateTransientWindow( |
| 122 &delegate, NULL, ui::MODAL_TYPE_SYSTEM, true)); |
| 123 |
| 124 aura::Window* top_modal_container = FindContainerByPriority(CP_END + 1); |
| 125 EXPECT_EQ(top_modal_container, top_m0->parent()); |
| 126 |
| 127 // Creating a modal dialog with transient parent on the top container |
| 128 // creates the winodw on the top container's modal container. |
| 129 scoped_ptr<aura::Window> top_m1(test::CreateTransientWindow( |
| 130 &delegate, top_w1.get(), ui::MODAL_TYPE_SYSTEM, true)); |
| 131 EXPECT_EQ(top_modal_container, top_m1->parent()); |
| 132 |
| 133 normal_m1.reset(); |
| 134 EXPECT_TRUE(FindContainerByPriority(CP_SYSTEM_MODAL)); |
| 135 normal_m2.reset(); |
| 136 EXPECT_FALSE(FindContainerByPriority(CP_SYSTEM_MODAL)); |
| 137 |
| 138 top_m0.reset(); |
| 139 EXPECT_TRUE(FindContainerByPriority(CP_END + 1)); |
| 140 top_m1.reset(); |
| 141 EXPECT_FALSE(FindContainerByPriority(CP_END + 1)); |
| 142 } |
| 143 |
| 144 } // namespace athena |
OLD | NEW |