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.
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"
15 typedef test::AthenaTestBase ModalWindowControllerTest
;
17 aura::Window
* FindContainerByPriority(int priority
) {
18 ScreenManagerImpl
* screen_manager
=
19 static_cast<ScreenManagerImpl
*>(ScreenManager::Get());
20 return screen_manager
->FindContainerByPriority(priority
);
23 TEST_F(ModalWindowControllerTest
, ModalContainer
) {
24 aura::test::EventCountDelegate delegate
;
25 scoped_ptr
<aura::Window
> modal(test::CreateTransientWindow(
26 &delegate
, nullptr, ui::MODAL_TYPE_SYSTEM
, false));
28 aura::Window
* modal_container
= FindContainerByPriority(CP_SYSTEM_MODAL
);
29 EXPECT_TRUE(modal_container
);
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());
37 EXPECT_TRUE(modal_controller
->dimmed());
40 EXPECT_TRUE(FindContainerByPriority(CP_SYSTEM_MODAL
));
41 EXPECT_FALSE(modal_controller
->dimmed());
44 EXPECT_TRUE(FindContainerByPriority(CP_SYSTEM_MODAL
));
45 EXPECT_TRUE(modal_controller
->dimmed());
48 EXPECT_FALSE(FindContainerByPriority(CP_SYSTEM_MODAL
));
51 modal
= test::CreateTransientWindow(
52 &delegate
, nullptr, ui::MODAL_TYPE_SYSTEM
, false).Pass();
53 scoped_ptr
<aura::Window
> modal2(test::CreateTransientWindow(
54 &delegate
, nullptr, ui::MODAL_TYPE_SYSTEM
, false));
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());
63 EXPECT_FALSE(modal_controller
->dimmed());
65 EXPECT_TRUE(modal_controller
->dimmed());
67 EXPECT_TRUE(modal_controller
->dimmed());
70 EXPECT_TRUE(modal_controller
->dimmed());
72 EXPECT_FALSE(modal_controller
->dimmed());
73 EXPECT_TRUE(FindContainerByPriority(CP_SYSTEM_MODAL
));
76 EXPECT_TRUE(FindContainerByPriority(CP_SYSTEM_MODAL
));
77 EXPECT_FALSE(modal_controller
->dimmed());
80 EXPECT_FALSE(FindContainerByPriority(CP_SYSTEM_MODAL
));
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
);
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());
94 aura::Window
* default_container
= FindContainerByPriority(CP_DEFAULT
);
95 EXPECT_TRUE(default_container
);
97 scoped_ptr
<aura::Window
> normal_w1(
98 test::CreateNormalWindow(&delegate
, nullptr));
99 EXPECT_EQ(default_container
, normal_w1
->parent());
101 scoped_ptr
<aura::Window
> normal_m1(test::CreateTransientWindow(
102 &delegate
, normal_w1
.get(), ui::MODAL_TYPE_SYSTEM
, false));
103 aura::Window
* default_modal_container
=
104 FindContainerByPriority(CP_SYSTEM_MODAL
);
105 EXPECT_EQ(default_modal_container
, normal_m1
->parent());
107 // A modal window with the transient parent which doesn't specify
108 // the modal container should fallback the default container's modal
110 aura::Window
* home_container
= FindContainerByPriority(CP_DEFAULT
);
111 EXPECT_TRUE(home_container
);
113 scoped_ptr
<aura::Window
> normal_m2(test::CreateTransientWindow(
114 &delegate
, home_container
, ui::MODAL_TYPE_SYSTEM
, false));
115 EXPECT_EQ(default_modal_container
, normal_m2
->parent());
117 // No modal container for top container yet.
118 EXPECT_FALSE(FindContainerByPriority(CP_END
+ 1));
120 // Creating a modal with always on top creates the modal dialog on top
121 // most dialog container.
122 scoped_ptr
<aura::Window
> top_m0(test::CreateTransientWindow(
123 &delegate
, nullptr, ui::MODAL_TYPE_SYSTEM
, true));
125 aura::Window
* top_modal_container
= FindContainerByPriority(CP_END
+ 1);
126 EXPECT_EQ(top_modal_container
, top_m0
->parent());
128 // Creating a modal dialog with transient parent on the top container
129 // creates the winodw on the top container's modal container.
130 scoped_ptr
<aura::Window
> top_m1(test::CreateTransientWindow(
131 &delegate
, top_w1
.get(), ui::MODAL_TYPE_SYSTEM
, true));
132 EXPECT_EQ(top_modal_container
, top_m1
->parent());
135 EXPECT_TRUE(FindContainerByPriority(CP_SYSTEM_MODAL
));
137 EXPECT_FALSE(FindContainerByPriority(CP_SYSTEM_MODAL
));
140 EXPECT_TRUE(FindContainerByPriority(CP_END
+ 1));
142 EXPECT_FALSE(FindContainerByPriority(CP_END
+ 1));
145 } // namespace athena