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