| 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 <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "athena/common/container_priorities.h" | 10 #include "athena/common/container_priorities.h" |
| 11 #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" | 12 #include "ui/aura/test/test_window_delegate.h" |
| 14 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/events/test/event_generator.h" |
| 15 #include "ui/wm/core/window_util.h" | 15 #include "ui/wm/core/window_util.h" |
| 16 | 16 |
| 17 typedef athena::test::AthenaTestBase ScreenManagerTest; | 17 typedef athena::test::AthenaTestBase ScreenManagerTest; |
| 18 | 18 |
| 19 namespace athena { | 19 namespace athena { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 const int kTestZOrderPriority = 10; | 22 const int kTestZOrderPriority = 10; |
| 23 | 23 |
| 24 aura::Window* Create(const std::string& name, int z_order_priority) { | 24 aura::Window* Create(const std::string& name, int z_order_priority) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 normal_params.can_activate_children = true; | 117 normal_params.can_activate_children = true; |
| 118 aura::Window* normal_container = | 118 aura::Window* normal_container = |
| 119 ScreenManager::Get()->CreateContainer(normal_params); | 119 ScreenManager::Get()->CreateContainer(normal_params); |
| 120 | 120 |
| 121 aura::test::EventCountDelegate normal_delegate; | 121 aura::test::EventCountDelegate normal_delegate; |
| 122 scoped_ptr<aura::Window> normal_window(CreateTestWindow( | 122 scoped_ptr<aura::Window> normal_window(CreateTestWindow( |
| 123 normal_container, &normal_delegate, gfx::Rect(0, 0, 100, 100))); | 123 normal_container, &normal_delegate, gfx::Rect(0, 0, 100, 100))); |
| 124 | 124 |
| 125 EXPECT_TRUE(wm::CanActivateWindow(normal_window.get())); | 125 EXPECT_TRUE(wm::CanActivateWindow(normal_window.get())); |
| 126 wm::ActivateWindow(normal_window.get()); | 126 wm::ActivateWindow(normal_window.get()); |
| 127 aura::test::EventGenerator event_generator(root_window()); | 127 ui::test::EventGenerator event_generator(root_window()); |
| 128 event_generator.MoveMouseTo(0, 0); | 128 event_generator.MoveMouseTo(0, 0); |
| 129 event_generator.ClickLeftButton(); | 129 event_generator.ClickLeftButton(); |
| 130 EXPECT_EQ("1 1", normal_delegate.GetMouseButtonCountsAndReset()); | 130 EXPECT_EQ("1 1", normal_delegate.GetMouseButtonCountsAndReset()); |
| 131 event_generator.PressKey(ui::VKEY_A, ui::EF_NONE); | 131 event_generator.PressKey(ui::VKEY_A, ui::EF_NONE); |
| 132 event_generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); | 132 event_generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); |
| 133 EXPECT_EQ("1 1", normal_delegate.GetKeyCountsAndReset()); | 133 EXPECT_EQ("1 1", normal_delegate.GetKeyCountsAndReset()); |
| 134 | 134 |
| 135 ScreenManager::ContainerParams grab_params( | 135 ScreenManager::ContainerParams grab_params( |
| 136 "grabbing", kTestZOrderPriority + 1); | 136 "grabbing", kTestZOrderPriority + 1); |
| 137 grab_params.can_activate_children = true; | 137 grab_params.can_activate_children = true; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 ScreenManager::ContainerParams vk_params( | 182 ScreenManager::ContainerParams vk_params( |
| 183 "virtual keyboard", kTestZOrderPriority + 1); | 183 "virtual keyboard", kTestZOrderPriority + 1); |
| 184 vk_params.can_activate_children = true; | 184 vk_params.can_activate_children = true; |
| 185 aura::Window* vk_container = ScreenManager::Get()->CreateContainer(vk_params); | 185 aura::Window* vk_container = ScreenManager::Get()->CreateContainer(vk_params); |
| 186 | 186 |
| 187 aura::test::EventCountDelegate vk_delegate; | 187 aura::test::EventCountDelegate vk_delegate; |
| 188 scoped_ptr<aura::Window> vk_window(CreateTestWindow( | 188 scoped_ptr<aura::Window> vk_window(CreateTestWindow( |
| 189 vk_container, &vk_delegate, gfx::Rect(0, 20, 100, 80))); | 189 vk_container, &vk_delegate, gfx::Rect(0, 20, 100, 80))); |
| 190 EXPECT_TRUE(wm::CanActivateWindow(vk_window.get())); | 190 EXPECT_TRUE(wm::CanActivateWindow(vk_window.get())); |
| 191 | 191 |
| 192 aura::test::EventGenerator event_generator(root_window()); | 192 ui::test::EventGenerator event_generator(root_window()); |
| 193 event_generator.MoveMouseTo(10, 25); | 193 event_generator.MoveMouseTo(10, 25); |
| 194 event_generator.ClickLeftButton(); | 194 event_generator.ClickLeftButton(); |
| 195 EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); | 195 EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); |
| 196 EXPECT_EQ("1 1", vk_delegate.GetMouseButtonCountsAndReset()); | 196 EXPECT_EQ("1 1", vk_delegate.GetMouseButtonCountsAndReset()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 TEST_F(ScreenManagerTest, GrabAndMouseCapture) { | 199 TEST_F(ScreenManagerTest, GrabAndMouseCapture) { |
| 200 ScreenManager::ContainerParams normal_params( | 200 ScreenManager::ContainerParams normal_params( |
| 201 "normal", kTestZOrderPriority); | 201 "normal", kTestZOrderPriority); |
| 202 normal_params.can_activate_children = true; | 202 normal_params.can_activate_children = true; |
| 203 aura::Window* normal_container = | 203 aura::Window* normal_container = |
| 204 ScreenManager::Get()->CreateContainer(normal_params); | 204 ScreenManager::Get()->CreateContainer(normal_params); |
| 205 | 205 |
| 206 aura::test::EventCountDelegate normal_delegate; | 206 aura::test::EventCountDelegate normal_delegate; |
| 207 scoped_ptr<aura::Window> normal_window(CreateTestWindow( | 207 scoped_ptr<aura::Window> normal_window(CreateTestWindow( |
| 208 normal_container, &normal_delegate, gfx::Rect(0, 0, 100, 100))); | 208 normal_container, &normal_delegate, gfx::Rect(0, 0, 100, 100))); |
| 209 | 209 |
| 210 aura::test::EventGenerator event_generator(root_window()); | 210 ui::test::EventGenerator event_generator(root_window()); |
| 211 event_generator.MoveMouseTo(0, 0); | 211 event_generator.MoveMouseTo(0, 0); |
| 212 event_generator.PressLeftButton(); | 212 event_generator.PressLeftButton(); |
| 213 | 213 |
| 214 // Creating grabbing container while mouse pressing. | 214 // Creating grabbing container while mouse pressing. |
| 215 ScreenManager::ContainerParams grab_params( | 215 ScreenManager::ContainerParams grab_params( |
| 216 "grabbing", kTestZOrderPriority + 1); | 216 "grabbing", kTestZOrderPriority + 1); |
| 217 grab_params.can_activate_children = true; | 217 grab_params.can_activate_children = true; |
| 218 grab_params.grab_inputs = true; | 218 grab_params.grab_inputs = true; |
| 219 aura::Window* grab_container = | 219 aura::Window* grab_container = |
| 220 ScreenManager::Get()->CreateContainer(grab_params); | 220 ScreenManager::Get()->CreateContainer(grab_params); |
| 221 | 221 |
| 222 aura::test::EventCountDelegate grab_delegate; | 222 aura::test::EventCountDelegate grab_delegate; |
| 223 scoped_ptr<aura::Window> grab_window(CreateTestWindow( | 223 scoped_ptr<aura::Window> grab_window(CreateTestWindow( |
| 224 grab_container, &grab_delegate, gfx::Rect(10, 10, 100, 100))); | 224 grab_container, &grab_delegate, gfx::Rect(10, 10, 100, 100))); |
| 225 | 225 |
| 226 // 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 |
| 227 // mouse event. | 227 // mouse event. |
| 228 event_generator.ReleaseLeftButton(); | 228 event_generator.ReleaseLeftButton(); |
| 229 EXPECT_EQ("1 1", normal_delegate.GetMouseButtonCountsAndReset()); | 229 EXPECT_EQ("1 1", normal_delegate.GetMouseButtonCountsAndReset()); |
| 230 EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); | 230 EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); |
| 231 | 231 |
| 232 // 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| |
| 233 // because grab_container grabs the input. | 233 // because grab_container grabs the input. |
| 234 event_generator.ClickLeftButton(); | 234 event_generator.ClickLeftButton(); |
| 235 EXPECT_EQ("0 0", normal_delegate.GetMouseButtonCountsAndReset()); | 235 EXPECT_EQ("0 0", normal_delegate.GetMouseButtonCountsAndReset()); |
| 236 EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); | 236 EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); |
| 237 } | 237 } |
| 238 | 238 |
| 239 } // namespace athena | 239 } // namespace athena |
| OLD | NEW |