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