| 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" |
| 6 |
| 5 #include <algorithm> | 7 #include <algorithm> |
| 6 #include <string> | 8 #include <string> |
| 7 | 9 |
| 8 #include "athena/screen/screen_manager_impl.h" | |
| 9 #include "athena/test/base/athena_test_base.h" | 10 #include "athena/test/base/athena_test_base.h" |
| 10 #include "athena/test/base/test_windows.h" | |
| 11 #include "athena/util/container_priorities.h" | 11 #include "athena/util/container_priorities.h" |
| 12 #include "ui/aura/test/test_window_delegate.h" | 12 #include "ui/aura/test/test_window_delegate.h" |
| 13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_targeter.h" | |
| 15 #include "ui/events/test/event_generator.h" | 14 #include "ui/events/test/event_generator.h" |
| 16 #include "ui/wm/core/window_util.h" | 15 #include "ui/wm/core/window_util.h" |
| 17 | 16 |
| 18 typedef athena::test::AthenaTestBase ScreenManagerTest; | 17 typedef athena::test::AthenaTestBase ScreenManagerTest; |
| 19 | 18 |
| 20 namespace athena { | 19 namespace athena { |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 const int kTestZOrderPriority = 10; | 22 const int kTestZOrderPriority = 10; |
| 24 | 23 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 ScreenManager::Get()->CreateContainer(activatable); | 104 ScreenManager::Get()->CreateContainer(activatable); |
| 106 | 105 |
| 107 scoped_ptr<aura::Window> window( | 106 scoped_ptr<aura::Window> window( |
| 108 CreateWindow(no_activatable_container, NULL, gfx::Rect(0, 0, 100, 100))); | 107 CreateWindow(no_activatable_container, NULL, gfx::Rect(0, 0, 100, 100))); |
| 109 EXPECT_FALSE(wm::CanActivateWindow(window.get())); | 108 EXPECT_FALSE(wm::CanActivateWindow(window.get())); |
| 110 | 109 |
| 111 activatable_container->AddChild(window.get()); | 110 activatable_container->AddChild(window.get()); |
| 112 EXPECT_TRUE(wm::CanActivateWindow(window.get())); | 111 EXPECT_TRUE(wm::CanActivateWindow(window.get())); |
| 113 } | 112 } |
| 114 | 113 |
| 115 TEST_F(ScreenManagerTest, BlockInputsShouldNotBlockVirtualKeyboard) { | 114 TEST_F(ScreenManagerTest, GrabInputContainer) { |
| 116 ScreenManager::ContainerParams block_params("blocking", kTestZOrderPriority); | |
| 117 block_params.can_activate_children = true; | |
| 118 block_params.block_events = true; | |
| 119 aura::Window* block_container = | |
| 120 ScreenManager::Get()->CreateContainer(block_params); | |
| 121 | |
| 122 aura::test::EventCountDelegate block_delegate; | |
| 123 scoped_ptr<aura::Window> block_window(CreateWindow( | |
| 124 block_container, &block_delegate, gfx::Rect(0, 0, 100, 100))); | |
| 125 EXPECT_TRUE(wm::CanActivateWindow(block_window.get())); | |
| 126 | |
| 127 // Create a normal container appearing over the |block_container|. This is | |
| 128 // essentially the case of virtual keyboard. | |
| 129 ScreenManager::ContainerParams vk_params("virtual keyboard", | |
| 130 kTestZOrderPriority + 1); | |
| 131 vk_params.can_activate_children = true; | |
| 132 aura::Window* vk_container = ScreenManager::Get()->CreateContainer(vk_params); | |
| 133 | |
| 134 aura::test::EventCountDelegate vk_delegate; | |
| 135 scoped_ptr<aura::Window> vk_window( | |
| 136 CreateWindow(vk_container, &vk_delegate, gfx::Rect(0, 20, 100, 80))); | |
| 137 EXPECT_TRUE(wm::CanActivateWindow(vk_window.get())); | |
| 138 | |
| 139 ui::test::EventGenerator event_generator(root_window()); | |
| 140 event_generator.MoveMouseTo(10, 25); | |
| 141 event_generator.ClickLeftButton(); | |
| 142 EXPECT_EQ("0 0", block_delegate.GetMouseButtonCountsAndReset()); | |
| 143 EXPECT_EQ("1 1", vk_delegate.GetMouseButtonCountsAndReset()); | |
| 144 } | |
| 145 | |
| 146 TEST_F(ScreenManagerTest, DefaultContainer) { | |
| 147 ScreenManagerImpl* impl = | |
| 148 static_cast<ScreenManagerImpl*>(ScreenManager::Get()); | |
| 149 aura::Window* original_default = impl->FindContainerByPriority(CP_DEFAULT); | |
| 150 aura::Window* parent = original_default->parent(); | |
| 151 // Temporarily remove the original default container from tree. | |
| 152 parent->RemoveChild(original_default); | |
| 153 | |
| 154 ScreenManager::ContainerParams params("new_default", CP_END + 1); | |
| 155 params.default_parent = true; | |
| 156 params.modal_container_priority = CP_END + 2; | |
| 157 aura::Window* new_default = ScreenManager::Get()->CreateContainer(params); | |
| 158 aura::Window* w = test::CreateNormalWindow(NULL, NULL).release(); | |
| 159 EXPECT_EQ(new_default, w->parent()); | |
| 160 delete new_default; | |
| 161 | |
| 162 // Add the original back to shutdown properly. | |
| 163 parent->AddChild(original_default); | |
| 164 } | |
| 165 | |
| 166 namespace { | |
| 167 | |
| 168 class ScreenManagerTargeterTest | |
| 169 : public athena::test::AthenaTestBase, | |
| 170 public testing::WithParamInterface<ui::EventTargeter*> { | |
| 171 public: | |
| 172 ScreenManagerTargeterTest() : targeter_(GetParam()) {} | |
| 173 virtual ~ScreenManagerTargeterTest() {} | |
| 174 | |
| 175 protected: | |
| 176 scoped_ptr<ui::EventTargeter> targeter_; | |
| 177 | |
| 178 private: | |
| 179 DISALLOW_COPY_AND_ASSIGN(ScreenManagerTargeterTest); | |
| 180 }; | |
| 181 | |
| 182 } // namespace | |
| 183 | |
| 184 TEST_P(ScreenManagerTargeterTest, BlockContainer) { | |
| 185 ScreenManager::ContainerParams normal_params( | 115 ScreenManager::ContainerParams normal_params( |
| 186 "normal", kTestZOrderPriority); | 116 "normal", kTestZOrderPriority); |
| 187 normal_params.can_activate_children = true; | 117 normal_params.can_activate_children = true; |
| 188 aura::Window* normal_container = | 118 aura::Window* normal_container = |
| 189 ScreenManager::Get()->CreateContainer(normal_params); | 119 ScreenManager::Get()->CreateContainer(normal_params); |
| 190 normal_container->SetEventTargeter(targeter_.Pass()); | |
| 191 | 120 |
| 192 aura::test::EventCountDelegate normal_delegate; | 121 aura::test::EventCountDelegate normal_delegate; |
| 193 scoped_ptr<aura::Window> normal_window(CreateWindow( | 122 scoped_ptr<aura::Window> normal_window(CreateWindow( |
| 194 normal_container, &normal_delegate, gfx::Rect(0, 0, 100, 100))); | 123 normal_container, &normal_delegate, gfx::Rect(0, 0, 100, 100))); |
| 195 | 124 |
| 196 EXPECT_TRUE(wm::CanActivateWindow(normal_window.get())); | 125 EXPECT_TRUE(wm::CanActivateWindow(normal_window.get())); |
| 197 wm::ActivateWindow(normal_window.get()); | 126 wm::ActivateWindow(normal_window.get()); |
| 198 ui::test::EventGenerator event_generator(root_window()); | 127 ui::test::EventGenerator event_generator(root_window()); |
| 199 event_generator.MoveMouseTo(0, 0); | 128 event_generator.MoveMouseTo(0, 0); |
| 200 event_generator.ClickLeftButton(); | 129 event_generator.ClickLeftButton(); |
| 201 EXPECT_EQ("1 1", normal_delegate.GetMouseButtonCountsAndReset()); | 130 EXPECT_EQ("1 1", normal_delegate.GetMouseButtonCountsAndReset()); |
| 202 event_generator.PressKey(ui::VKEY_A, ui::EF_NONE); | 131 event_generator.PressKey(ui::VKEY_A, ui::EF_NONE); |
| 203 event_generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); | 132 event_generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); |
| 204 EXPECT_EQ("1 1", normal_delegate.GetKeyCountsAndReset()); | 133 EXPECT_EQ("1 1", normal_delegate.GetKeyCountsAndReset()); |
| 205 | 134 |
| 206 ScreenManager::ContainerParams block_params("blocking", | 135 ScreenManager::ContainerParams grab_params( |
| 207 kTestZOrderPriority + 1); | 136 "grabbing", kTestZOrderPriority + 1); |
| 208 block_params.can_activate_children = true; | 137 grab_params.can_activate_children = true; |
| 209 block_params.block_events = true; | 138 grab_params.grab_inputs = true; |
| 210 aura::Window* block_container = | 139 aura::Window* grab_container = |
| 211 ScreenManager::Get()->CreateContainer(block_params); | 140 ScreenManager::Get()->CreateContainer(grab_params); |
| 212 | 141 |
| 213 EXPECT_FALSE(wm::CanActivateWindow(normal_window.get())); | 142 EXPECT_FALSE(wm::CanActivateWindow(normal_window.get())); |
| 214 | 143 |
| 215 aura::test::EventCountDelegate block_delegate; | 144 aura::test::EventCountDelegate grab_delegate; |
| 216 scoped_ptr<aura::Window> block_window(CreateWindow( | 145 scoped_ptr<aura::Window> grab_window(CreateWindow( |
| 217 block_container, &block_delegate, gfx::Rect(10, 10, 100, 100))); | 146 grab_container, &grab_delegate, gfx::Rect(10, 10, 100, 100))); |
| 218 EXPECT_TRUE(wm::CanActivateWindow(block_window.get())); | 147 EXPECT_TRUE(wm::CanActivateWindow(grab_window.get())); |
| 219 | 148 |
| 220 wm::ActivateWindow(block_window.get()); | 149 wm::ActivateWindow(grab_window.get()); |
| 221 | 150 |
| 222 // (0, 0) is still on normal_window, but the event should not go there | 151 // (0, 0) is still on normal_window, but the event should not go there |
| 223 // because blockbing_container prevents it. | 152 // because grabbing_container prevents it. |
| 224 event_generator.MoveMouseTo(0, 0); | 153 event_generator.MoveMouseTo(0, 0); |
| 225 event_generator.ClickLeftButton(); | 154 event_generator.ClickLeftButton(); |
| 226 EXPECT_EQ("0 0", normal_delegate.GetMouseButtonCountsAndReset()); | 155 EXPECT_EQ("0 0", normal_delegate.GetMouseButtonCountsAndReset()); |
| 227 EXPECT_EQ("0 0", block_delegate.GetMouseButtonCountsAndReset()); | 156 EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); |
| 228 event_generator.MoveMouseWheel(0, 10); | |
| 229 // EXPECT_EQ(0, normal_event_counter.num_scroll_events()); | |
| 230 | 157 |
| 231 event_generator.MoveMouseTo(20, 20); | 158 event_generator.MoveMouseTo(20, 20); |
| 232 event_generator.ClickLeftButton(); | 159 event_generator.ClickLeftButton(); |
| 233 EXPECT_EQ("1 1", block_delegate.GetMouseButtonCountsAndReset()); | 160 EXPECT_EQ("1 1", grab_delegate.GetMouseButtonCountsAndReset()); |
| 234 | 161 |
| 235 event_generator.PressKey(ui::VKEY_A, ui::EF_NONE); | 162 event_generator.PressKey(ui::VKEY_A, ui::EF_NONE); |
| 236 event_generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); | 163 event_generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); |
| 237 EXPECT_EQ("0 0", normal_delegate.GetKeyCountsAndReset()); | 164 EXPECT_EQ("0 0", normal_delegate.GetKeyCountsAndReset()); |
| 238 EXPECT_EQ("1 1", block_delegate.GetKeyCountsAndReset()); | 165 EXPECT_EQ("1 1", grab_delegate.GetKeyCountsAndReset()); |
| 239 } | 166 } |
| 240 | 167 |
| 241 TEST_P(ScreenManagerTargeterTest, BlockAndMouseCapture) { | 168 TEST_F(ScreenManagerTest, GrabShouldNotBlockVirtualKeyboard) { |
| 169 ScreenManager::ContainerParams grab_params("grabbing", kTestZOrderPriority); |
| 170 grab_params.can_activate_children = true; |
| 171 grab_params.grab_inputs = true; |
| 172 aura::Window* grab_container = |
| 173 ScreenManager::Get()->CreateContainer(grab_params); |
| 174 |
| 175 aura::test::EventCountDelegate grab_delegate; |
| 176 scoped_ptr<aura::Window> grab_window( |
| 177 CreateWindow(grab_container, &grab_delegate, gfx::Rect(0, 0, 100, 100))); |
| 178 EXPECT_TRUE(wm::CanActivateWindow(grab_window.get())); |
| 179 |
| 180 // Create a normal container appearing over the |grab_container|. This is |
| 181 // essentially the case of virtual keyboard. |
| 182 ScreenManager::ContainerParams vk_params( |
| 183 "virtual keyboard", kTestZOrderPriority + 1); |
| 184 vk_params.can_activate_children = true; |
| 185 aura::Window* vk_container = ScreenManager::Get()->CreateContainer(vk_params); |
| 186 |
| 187 aura::test::EventCountDelegate vk_delegate; |
| 188 scoped_ptr<aura::Window> vk_window( |
| 189 CreateWindow(vk_container, &vk_delegate, gfx::Rect(0, 20, 100, 80))); |
| 190 EXPECT_TRUE(wm::CanActivateWindow(vk_window.get())); |
| 191 |
| 192 ui::test::EventGenerator event_generator(root_window()); |
| 193 event_generator.MoveMouseTo(10, 25); |
| 194 event_generator.ClickLeftButton(); |
| 195 EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); |
| 196 EXPECT_EQ("1 1", vk_delegate.GetMouseButtonCountsAndReset()); |
| 197 } |
| 198 |
| 199 TEST_F(ScreenManagerTest, GrabAndMouseCapture) { |
| 242 ScreenManager::ContainerParams normal_params( | 200 ScreenManager::ContainerParams normal_params( |
| 243 "normal", kTestZOrderPriority); | 201 "normal", kTestZOrderPriority); |
| 244 normal_params.can_activate_children = true; | 202 normal_params.can_activate_children = true; |
| 245 aura::Window* normal_container = | 203 aura::Window* normal_container = |
| 246 ScreenManager::Get()->CreateContainer(normal_params); | 204 ScreenManager::Get()->CreateContainer(normal_params); |
| 247 normal_container->SetEventTargeter(targeter_.Pass()); | |
| 248 | 205 |
| 249 aura::test::EventCountDelegate normal_delegate; | 206 aura::test::EventCountDelegate normal_delegate; |
| 250 scoped_ptr<aura::Window> normal_window(CreateWindow( | 207 scoped_ptr<aura::Window> normal_window(CreateWindow( |
| 251 normal_container, &normal_delegate, gfx::Rect(0, 0, 100, 100))); | 208 normal_container, &normal_delegate, gfx::Rect(0, 0, 100, 100))); |
| 252 | 209 |
| 253 ui::test::EventGenerator event_generator(root_window()); | 210 ui::test::EventGenerator event_generator(root_window()); |
| 254 event_generator.MoveMouseTo(0, 0); | 211 event_generator.MoveMouseTo(0, 0); |
| 255 event_generator.PressLeftButton(); | 212 event_generator.PressLeftButton(); |
| 256 | 213 |
| 257 // Creating blocking container while mouse pressing. | 214 // Creating grabbing container while mouse pressing. |
| 258 ScreenManager::ContainerParams block_params("blocking", | 215 ScreenManager::ContainerParams grab_params( |
| 259 kTestZOrderPriority + 1); | 216 "grabbing", kTestZOrderPriority + 1); |
| 260 block_params.can_activate_children = true; | 217 grab_params.can_activate_children = true; |
| 261 block_params.block_events = true; | 218 grab_params.grab_inputs = true; |
| 262 aura::Window* block_container = | 219 aura::Window* grab_container = |
| 263 ScreenManager::Get()->CreateContainer(block_params); | 220 ScreenManager::Get()->CreateContainer(grab_params); |
| 264 | 221 |
| 265 aura::test::EventCountDelegate block_delegate; | 222 aura::test::EventCountDelegate grab_delegate; |
| 266 scoped_ptr<aura::Window> block_window(CreateWindow( | 223 scoped_ptr<aura::Window> grab_window(CreateWindow( |
| 267 block_container, &block_delegate, gfx::Rect(10, 10, 100, 100))); | 224 grab_container, &grab_delegate, gfx::Rect(10, 10, 100, 100))); |
| 268 | 225 |
| 269 // Release event should be sent to |normal_window| because it captures the | 226 // Release event should be sent to |normal_window| because it captures the |
| 270 // mouse event. | 227 // mouse event. |
| 271 event_generator.ReleaseLeftButton(); | 228 event_generator.ReleaseLeftButton(); |
| 272 EXPECT_EQ("1 1", normal_delegate.GetMouseButtonCountsAndReset()); | 229 EXPECT_EQ("1 1", normal_delegate.GetMouseButtonCountsAndReset()); |
| 273 EXPECT_EQ("0 0", block_delegate.GetMouseButtonCountsAndReset()); | 230 EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); |
| 274 | 231 |
| 275 // After release, further mouse events should not be sent to |normal_window| | 232 // After release, further mouse events should not be sent to |normal_window| |
| 276 // because block_container blocks the input. | 233 // because grab_container grabs the input. |
| 277 event_generator.ClickLeftButton(); | 234 event_generator.ClickLeftButton(); |
| 278 EXPECT_EQ("0 0", normal_delegate.GetMouseButtonCountsAndReset()); | 235 EXPECT_EQ("0 0", normal_delegate.GetMouseButtonCountsAndReset()); |
| 279 EXPECT_EQ("0 0", block_delegate.GetMouseButtonCountsAndReset()); | 236 EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); |
| 280 } | 237 } |
| 281 | 238 |
| 282 INSTANTIATE_TEST_CASE_P(WithOrWithoutTargeter, | |
| 283 ScreenManagerTargeterTest, | |
| 284 testing::Values(static_cast<ui::EventTargeter*>(NULL), | |
| 285 new aura::WindowTargeter)); | |
| 286 | |
| 287 } // namespace athena | 239 } // namespace athena |
| OLD | NEW |