Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / athena / screen / modal_window_controller_unittest.cc
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, nullptr, 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, nullptr, ui::MODAL_TYPE_SYSTEM, false).Pass();
53   scoped_ptr<aura::Window> modal2(test::CreateTransientWindow(
54       &delegate, nullptr, 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(
98       test::CreateNormalWindow(&delegate, nullptr));
99   EXPECT_EQ(default_container, normal_w1->parent());
100
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());
106
107   // A modal window with the transient parent which doesn't specify
108   // the modal container should fallback the default container's modal
109   // container.
110   aura::Window* home_container = FindContainerByPriority(CP_DEFAULT);
111   EXPECT_TRUE(home_container);
112
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());
116
117   // No modal container for top container yet.
118   EXPECT_FALSE(FindContainerByPriority(CP_END + 1));
119
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));
124
125   aura::Window* top_modal_container = FindContainerByPriority(CP_END + 1);
126   EXPECT_EQ(top_modal_container, top_m0->parent());
127
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());
133
134   normal_m1.reset();
135   EXPECT_TRUE(FindContainerByPriority(CP_SYSTEM_MODAL));
136   normal_m2.reset();
137   EXPECT_FALSE(FindContainerByPriority(CP_SYSTEM_MODAL));
138
139   top_m0.reset();
140   EXPECT_TRUE(FindContainerByPriority(CP_END + 1));
141   top_m1.reset();
142   EXPECT_FALSE(FindContainerByPriority(CP_END + 1));
143 }
144
145 }  // namespace athena