Chromium Code Reviews| 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/public/screen_manager.h" | 5 #include "athena/screen/public/screen_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 7 #include <string> | 8 #include <string> |
| 8 | 9 |
| 10 #include "athena/common/container_priorities.h" | |
| 9 #include "athena/test/athena_test_base.h" | 11 #include "athena/test/athena_test_base.h" |
| 12 #include "ui/aura/test/event_generator.h" | |
| 13 #include "ui/aura/test/test_window_delegate.h" | |
| 10 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/wm/core/window_util.h" | |
| 11 | 16 |
| 12 typedef athena::test::AthenaTestBase ScreenManagerTest; | 17 typedef athena::test::AthenaTestBase ScreenManagerTest; |
| 13 | 18 |
| 14 namespace athena { | 19 namespace athena { |
| 15 namespace { | 20 namespace { |
| 16 | 21 |
| 17 aura::Window* Create(const std::string& name, int z_order_priority) { | 22 aura::Window* Create(const std::string& name, int z_order_priority) { |
| 18 ScreenManager::ContainerParams params(name, z_order_priority); | 23 ScreenManager::ContainerParams params(name, z_order_priority); |
| 19 return ScreenManager::Get()->CreateContainer(params); | 24 return ScreenManager::Get()->CreateContainer(params); |
| 20 } | 25 } |
| 21 | 26 |
| 27 aura::Window* CreateTestWindow(aura::Window* container, | |
| 28 aura::WindowDelegate* delegate, | |
| 29 const gfx::Rect& bounds) { | |
| 30 aura::Window* window = new aura::Window(delegate); | |
| 31 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); | |
| 32 window->Init(aura::WINDOW_LAYER_TEXTURED); | |
| 33 container->AddChild(window); | |
| 34 window->Show(); | |
| 35 window->SetBounds(bounds); | |
| 36 return window; | |
| 37 } | |
| 38 | |
| 22 void CheckZOrder(aura::Window* w1, aura::Window* w2) { | 39 void CheckZOrder(aura::Window* w1, aura::Window* w2) { |
| 23 aura::Window* parent = w1->parent(); | 40 aura::Window* parent = w1->parent(); |
| 24 const aura::Window::Windows& children = parent->children(); | 41 const aura::Window::Windows& children = parent->children(); |
| 25 aura::Window::Windows::const_iterator begin_iter = children.begin(); | 42 aura::Window::Windows::const_iterator begin_iter = children.begin(); |
| 26 aura::Window::Windows::const_iterator end_iter = children.end(); | 43 aura::Window::Windows::const_iterator end_iter = children.end(); |
| 27 | 44 |
| 28 aura::Window::Windows::const_iterator w1_iter = | 45 aura::Window::Windows::const_iterator w1_iter = |
| 29 std::find(begin_iter, end_iter, w1); | 46 std::find(begin_iter, end_iter, w1); |
| 30 aura::Window::Windows::const_iterator w2_iter = | 47 aura::Window::Windows::const_iterator w2_iter = |
| 31 std::find(begin_iter, end_iter, w2); | 48 std::find(begin_iter, end_iter, w2); |
| 32 EXPECT_NE(end_iter, w1_iter); | 49 EXPECT_NE(end_iter, w1_iter); |
| 33 EXPECT_NE(end_iter, w2_iter); | 50 EXPECT_NE(end_iter, w2_iter); |
| 34 EXPECT_TRUE(w1_iter < w2_iter); | 51 EXPECT_TRUE(w1_iter < w2_iter); |
| 35 } | 52 } |
| 36 | 53 |
| 37 } // namespace | 54 } // namespace |
| 38 | 55 |
| 56 TEST_F(ScreenManagerTest, CreateContainer) { | |
| 57 size_t num_containers = root_window()->children().size(); | |
| 58 | |
| 59 aura::Window* container = ScreenManager::Get()->CreateContainer( | |
| 60 ScreenManager::ContainerParams("test", CP_DEBUG)); | |
|
oshima
2014/07/24 18:12:48
can you define your own priorities ?
Jun Mukai
2014/07/24 18:57:26
Done.
| |
| 61 EXPECT_EQ("test", container->name()); | |
| 62 | |
| 63 const aura::Window::Windows& containers = root_window()->children(); | |
| 64 EXPECT_EQ(num_containers + 1, containers.size()); | |
| 65 EXPECT_NE(containers.end(), | |
| 66 std::find(containers.begin(), containers.end(), container)); | |
| 67 } | |
| 68 | |
| 39 TEST_F(ScreenManagerTest, Zorder) { | 69 TEST_F(ScreenManagerTest, Zorder) { |
| 40 aura::Window* window_10 = Create("test10", 10); | 70 aura::Window* window_10 = Create("test10", 10); |
| 41 aura::Window* window_11 = Create("test11", 11); | 71 aura::Window* window_11 = Create("test11", 11); |
| 42 aura::Window* window_12 = Create("test12", 12); | 72 aura::Window* window_12 = Create("test12", 12); |
| 43 | 73 |
| 44 { | 74 { |
| 45 SCOPED_TRACE("Init"); | 75 SCOPED_TRACE("Init"); |
| 46 CheckZOrder(window_10, window_11); | 76 CheckZOrder(window_10, window_11); |
| 47 CheckZOrder(window_11, window_12); | 77 CheckZOrder(window_11, window_12); |
| 48 } | 78 } |
| 49 { | 79 { |
| 50 SCOPED_TRACE("Delete"); | 80 SCOPED_TRACE("Delete"); |
| 51 delete window_11; | 81 delete window_11; |
| 52 CheckZOrder(window_10, window_12); | 82 CheckZOrder(window_10, window_12); |
| 53 } | 83 } |
| 54 { | 84 { |
| 55 SCOPED_TRACE("Insert"); | 85 SCOPED_TRACE("Insert"); |
| 56 window_11 = Create("test11", 11); | 86 window_11 = Create("test11", 11); |
| 57 CheckZOrder(window_10, window_11); | 87 CheckZOrder(window_10, window_11); |
| 58 CheckZOrder(window_11, window_12); | 88 CheckZOrder(window_11, window_12); |
| 59 } | 89 } |
| 60 } | 90 } |
| 61 | 91 |
| 92 TEST_F(ScreenManagerTest, NonActivatableContainer) { | |
| 93 ScreenManager::ContainerParams non_activatable( | |
| 94 "non_activatable", CP_DEBUG); | |
| 95 non_activatable.can_activate_children = false; | |
| 96 aura::Window* no_activatable_container = | |
| 97 ScreenManager::Get()->CreateContainer(non_activatable); | |
| 98 | |
| 99 ScreenManager::ContainerParams activatable( | |
| 100 "activatable", CP_DEBUG + 1); | |
| 101 activatable.can_activate_children = true; | |
| 102 aura::Window* activatable_container = | |
| 103 ScreenManager::Get()->CreateContainer(activatable); | |
| 104 | |
| 105 scoped_ptr<aura::Window> window(CreateTestWindow( | |
| 106 no_activatable_container, NULL, gfx::Rect(0, 0, 100, 100))); | |
| 107 EXPECT_FALSE(wm::CanActivateWindow(window.get())); | |
| 108 | |
| 109 activatable_container->AddChild(window.get()); | |
| 110 EXPECT_TRUE(wm::CanActivateWindow(window.get())); | |
| 111 } | |
| 112 | |
| 113 TEST_F(ScreenManagerTest, GrabInputContainer) { | |
| 114 ScreenManager::ContainerParams normal_params( | |
| 115 "normal", CP_DEBUG); | |
| 116 normal_params.can_activate_children = true; | |
| 117 aura::Window* normal_container = | |
| 118 ScreenManager::Get()->CreateContainer(normal_params); | |
| 119 | |
| 120 aura::test::EventCountDelegate normal_delegate; | |
| 121 scoped_ptr<aura::Window> normal_window(CreateTestWindow( | |
| 122 normal_container, &normal_delegate, gfx::Rect(0, 0, 100, 100))); | |
| 123 | |
| 124 EXPECT_TRUE(wm::CanActivateWindow(normal_window.get())); | |
| 125 wm::ActivateWindow(normal_window.get()); | |
| 126 aura::test::EventGenerator event_generator(root_window()); | |
| 127 event_generator.MoveMouseTo(0, 0); | |
| 128 event_generator.ClickLeftButton(); | |
| 129 EXPECT_EQ("1 1", normal_delegate.GetMouseButtonCountsAndReset()); | |
| 130 event_generator.PressKey(ui::VKEY_A, ui::EF_NONE); | |
| 131 event_generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); | |
| 132 EXPECT_EQ("1 1", normal_delegate.GetKeyCountsAndReset()); | |
| 133 | |
| 134 ScreenManager::ContainerParams grab_params( | |
| 135 "grabbing", CP_DEBUG + 1); | |
| 136 grab_params.can_activate_children = true; | |
| 137 grab_params.grab_inputs = true; | |
| 138 aura::Window* grab_container = | |
| 139 ScreenManager::Get()->CreateContainer(grab_params); | |
| 140 | |
| 141 EXPECT_FALSE(wm::CanActivateWindow(normal_window.get())); | |
| 142 | |
| 143 aura::test::EventCountDelegate grab_delegate; | |
| 144 scoped_ptr<aura::Window> grab_window(CreateTestWindow( | |
| 145 grab_container, &grab_delegate, gfx::Rect(10, 10, 100, 100))); | |
| 146 EXPECT_TRUE(wm::CanActivateWindow(grab_window.get())); | |
| 147 | |
| 148 wm::ActivateWindow(grab_window.get()); | |
| 149 | |
| 150 // (0, 0) is still on normal_window, but the event should not go there | |
| 151 // because grabbing_container prevents it. | |
| 152 event_generator.MoveMouseTo(0, 0); | |
| 153 event_generator.ClickLeftButton(); | |
| 154 EXPECT_EQ("0 0", normal_delegate.GetMouseButtonCountsAndReset()); | |
| 155 EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); | |
| 156 | |
| 157 event_generator.MoveMouseTo(20, 20); | |
| 158 event_generator.ClickLeftButton(); | |
| 159 EXPECT_EQ("1 1", grab_delegate.GetMouseButtonCountsAndReset()); | |
| 160 | |
| 161 event_generator.PressKey(ui::VKEY_A, ui::EF_NONE); | |
| 162 event_generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); | |
| 163 EXPECT_EQ("0 0", normal_delegate.GetKeyCountsAndReset()); | |
| 164 EXPECT_EQ("1 1", grab_delegate.GetKeyCountsAndReset()); | |
| 165 } | |
| 166 | |
| 167 TEST_F(ScreenManagerTest, GrabShouldNotBlockVirtualKeyboard) { | |
| 168 ScreenManager::ContainerParams grab_params("grabbing", CP_DEBUG); | |
| 169 grab_params.can_activate_children = true; | |
| 170 grab_params.grab_inputs = true; | |
| 171 aura::Window* grab_container = | |
| 172 ScreenManager::Get()->CreateContainer(grab_params); | |
| 173 | |
| 174 aura::test::EventCountDelegate grab_delegate; | |
| 175 scoped_ptr<aura::Window> grab_window(CreateTestWindow( | |
| 176 grab_container, &grab_delegate, gfx::Rect(0, 0, 100, 100))); | |
| 177 EXPECT_TRUE(wm::CanActivateWindow(grab_window.get())); | |
| 178 | |
| 179 // Create a normal container appearing over the |grab_container|. This is | |
| 180 // essentially the case of virtual keyboard. | |
| 181 ScreenManager::ContainerParams vk_params("virtual keyboard", CP_DEBUG + 1); | |
| 182 aura::Window* vk_container = ScreenManager::Get()->CreateContainer(vk_params); | |
| 183 | |
| 184 aura::test::EventCountDelegate vk_delegate; | |
| 185 scoped_ptr<aura::Window> vk_window(CreateTestWindow( | |
| 186 vk_container, &vk_delegate, gfx::Rect(0, 20, 100, 80))); | |
| 187 | |
| 188 aura::test::EventGenerator event_generator(root_window()); | |
| 189 event_generator.MoveMouseTo(10, 25); | |
| 190 event_generator.ClickLeftButton(); | |
| 191 EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); | |
| 192 EXPECT_EQ("1 1", vk_delegate.GetMouseButtonCountsAndReset()); | |
| 193 } | |
| 194 | |
| 195 TEST_F(ScreenManagerTest, GrabAndMouseCapture) { | |
| 196 ScreenManager::ContainerParams normal_params( | |
| 197 "normal", CP_DEBUG); | |
| 198 normal_params.can_activate_children = true; | |
| 199 aura::Window* normal_container = | |
| 200 ScreenManager::Get()->CreateContainer(normal_params); | |
| 201 | |
| 202 aura::test::EventCountDelegate normal_delegate; | |
| 203 scoped_ptr<aura::Window> normal_window(CreateTestWindow( | |
| 204 normal_container, &normal_delegate, gfx::Rect(0, 0, 100, 100))); | |
| 205 | |
| 206 aura::test::EventGenerator event_generator(root_window()); | |
| 207 event_generator.MoveMouseTo(0, 0); | |
| 208 event_generator.PressLeftButton(); | |
| 209 | |
| 210 // Creating grabbing container while mouse pressing. | |
| 211 ScreenManager::ContainerParams grab_params( | |
| 212 "grabbing", CP_DEBUG + 1); | |
| 213 grab_params.can_activate_children = true; | |
| 214 grab_params.grab_inputs = true; | |
| 215 aura::Window* grab_container = | |
| 216 ScreenManager::Get()->CreateContainer(grab_params); | |
| 217 | |
| 218 aura::test::EventCountDelegate grab_delegate; | |
| 219 scoped_ptr<aura::Window> grab_window(CreateTestWindow( | |
| 220 grab_container, &grab_delegate, gfx::Rect(10, 10, 100, 100))); | |
| 221 | |
| 222 // Release event should be sent to |normal_window| because it captures the | |
| 223 // mouse event. | |
| 224 event_generator.ReleaseLeftButton(); | |
| 225 EXPECT_EQ("1 1", normal_delegate.GetMouseButtonCountsAndReset()); | |
| 226 EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); | |
| 227 | |
| 228 // After release, further mouse events should not be sent to |normal_window| | |
| 229 // because grab_container grabs the input. | |
| 230 event_generator.ClickLeftButton(); | |
| 231 EXPECT_EQ("0 0", normal_delegate.GetMouseButtonCountsAndReset()); | |
| 232 EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); | |
| 233 } | |
| 234 | |
| 62 } // namespace athena | 235 } // namespace athena |
| OLD | NEW |