Index: athena/screen/screen_manager_unittest.cc |
diff --git a/athena/screen/screen_manager_unittest.cc b/athena/screen/screen_manager_unittest.cc |
index 1a04ae8447d52052a49077c741f68c8ac531ed23..a0316b06d7746774fcb19c4118854aaab1253fbe 100644 |
--- a/athena/screen/screen_manager_unittest.cc |
+++ b/athena/screen/screen_manager_unittest.cc |
@@ -4,10 +4,15 @@ |
#include "athena/screen/public/screen_manager.h" |
+#include <algorithm> |
#include <string> |
+#include "athena/common/container_priorities.h" |
#include "athena/test/athena_test_base.h" |
+#include "ui/aura/test/event_generator.h" |
+#include "ui/aura/test/test_window_delegate.h" |
#include "ui/aura/window.h" |
+#include "ui/wm/core/window_util.h" |
typedef athena::test::AthenaTestBase ScreenManagerTest; |
@@ -19,6 +24,18 @@ aura::Window* Create(const std::string& name, int z_order_priority) { |
return ScreenManager::Get()->CreateContainer(params); |
} |
+aura::Window* CreateTestWindow(aura::Window* container, |
+ aura::WindowDelegate* delegate, |
+ const gfx::Rect& bounds) { |
+ aura::Window* window = new aura::Window(delegate); |
+ window->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
+ window->Init(aura::WINDOW_LAYER_TEXTURED); |
+ container->AddChild(window); |
+ window->Show(); |
+ window->SetBounds(bounds); |
+ return window; |
+} |
+ |
void CheckZOrder(aura::Window* w1, aura::Window* w2) { |
aura::Window* parent = w1->parent(); |
const aura::Window::Windows& children = parent->children(); |
@@ -36,6 +53,19 @@ void CheckZOrder(aura::Window* w1, aura::Window* w2) { |
} // namespace |
+TEST_F(ScreenManagerTest, CreateContainer) { |
+ size_t num_containers = root_window()->children().size(); |
+ |
+ aura::Window* container = ScreenManager::Get()->CreateContainer( |
+ 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.
|
+ EXPECT_EQ("test", container->name()); |
+ |
+ const aura::Window::Windows& containers = root_window()->children(); |
+ EXPECT_EQ(num_containers + 1, containers.size()); |
+ EXPECT_NE(containers.end(), |
+ std::find(containers.begin(), containers.end(), container)); |
+} |
+ |
TEST_F(ScreenManagerTest, Zorder) { |
aura::Window* window_10 = Create("test10", 10); |
aura::Window* window_11 = Create("test11", 11); |
@@ -59,4 +89,147 @@ TEST_F(ScreenManagerTest, Zorder) { |
} |
} |
+TEST_F(ScreenManagerTest, NonActivatableContainer) { |
+ ScreenManager::ContainerParams non_activatable( |
+ "non_activatable", CP_DEBUG); |
+ non_activatable.can_activate_children = false; |
+ aura::Window* no_activatable_container = |
+ ScreenManager::Get()->CreateContainer(non_activatable); |
+ |
+ ScreenManager::ContainerParams activatable( |
+ "activatable", CP_DEBUG + 1); |
+ activatable.can_activate_children = true; |
+ aura::Window* activatable_container = |
+ ScreenManager::Get()->CreateContainer(activatable); |
+ |
+ scoped_ptr<aura::Window> window(CreateTestWindow( |
+ no_activatable_container, NULL, gfx::Rect(0, 0, 100, 100))); |
+ EXPECT_FALSE(wm::CanActivateWindow(window.get())); |
+ |
+ activatable_container->AddChild(window.get()); |
+ EXPECT_TRUE(wm::CanActivateWindow(window.get())); |
+} |
+ |
+TEST_F(ScreenManagerTest, GrabInputContainer) { |
+ ScreenManager::ContainerParams normal_params( |
+ "normal", CP_DEBUG); |
+ normal_params.can_activate_children = true; |
+ aura::Window* normal_container = |
+ ScreenManager::Get()->CreateContainer(normal_params); |
+ |
+ aura::test::EventCountDelegate normal_delegate; |
+ scoped_ptr<aura::Window> normal_window(CreateTestWindow( |
+ normal_container, &normal_delegate, gfx::Rect(0, 0, 100, 100))); |
+ |
+ EXPECT_TRUE(wm::CanActivateWindow(normal_window.get())); |
+ wm::ActivateWindow(normal_window.get()); |
+ aura::test::EventGenerator event_generator(root_window()); |
+ event_generator.MoveMouseTo(0, 0); |
+ event_generator.ClickLeftButton(); |
+ EXPECT_EQ("1 1", normal_delegate.GetMouseButtonCountsAndReset()); |
+ event_generator.PressKey(ui::VKEY_A, ui::EF_NONE); |
+ event_generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); |
+ EXPECT_EQ("1 1", normal_delegate.GetKeyCountsAndReset()); |
+ |
+ ScreenManager::ContainerParams grab_params( |
+ "grabbing", CP_DEBUG + 1); |
+ grab_params.can_activate_children = true; |
+ grab_params.grab_inputs = true; |
+ aura::Window* grab_container = |
+ ScreenManager::Get()->CreateContainer(grab_params); |
+ |
+ EXPECT_FALSE(wm::CanActivateWindow(normal_window.get())); |
+ |
+ aura::test::EventCountDelegate grab_delegate; |
+ scoped_ptr<aura::Window> grab_window(CreateTestWindow( |
+ grab_container, &grab_delegate, gfx::Rect(10, 10, 100, 100))); |
+ EXPECT_TRUE(wm::CanActivateWindow(grab_window.get())); |
+ |
+ wm::ActivateWindow(grab_window.get()); |
+ |
+ // (0, 0) is still on normal_window, but the event should not go there |
+ // because grabbing_container prevents it. |
+ event_generator.MoveMouseTo(0, 0); |
+ event_generator.ClickLeftButton(); |
+ EXPECT_EQ("0 0", normal_delegate.GetMouseButtonCountsAndReset()); |
+ EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); |
+ |
+ event_generator.MoveMouseTo(20, 20); |
+ event_generator.ClickLeftButton(); |
+ EXPECT_EQ("1 1", grab_delegate.GetMouseButtonCountsAndReset()); |
+ |
+ event_generator.PressKey(ui::VKEY_A, ui::EF_NONE); |
+ event_generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); |
+ EXPECT_EQ("0 0", normal_delegate.GetKeyCountsAndReset()); |
+ EXPECT_EQ("1 1", grab_delegate.GetKeyCountsAndReset()); |
+} |
+ |
+TEST_F(ScreenManagerTest, GrabShouldNotBlockVirtualKeyboard) { |
+ ScreenManager::ContainerParams grab_params("grabbing", CP_DEBUG); |
+ grab_params.can_activate_children = true; |
+ grab_params.grab_inputs = true; |
+ aura::Window* grab_container = |
+ ScreenManager::Get()->CreateContainer(grab_params); |
+ |
+ aura::test::EventCountDelegate grab_delegate; |
+ scoped_ptr<aura::Window> grab_window(CreateTestWindow( |
+ grab_container, &grab_delegate, gfx::Rect(0, 0, 100, 100))); |
+ EXPECT_TRUE(wm::CanActivateWindow(grab_window.get())); |
+ |
+ // Create a normal container appearing over the |grab_container|. This is |
+ // essentially the case of virtual keyboard. |
+ ScreenManager::ContainerParams vk_params("virtual keyboard", CP_DEBUG + 1); |
+ aura::Window* vk_container = ScreenManager::Get()->CreateContainer(vk_params); |
+ |
+ aura::test::EventCountDelegate vk_delegate; |
+ scoped_ptr<aura::Window> vk_window(CreateTestWindow( |
+ vk_container, &vk_delegate, gfx::Rect(0, 20, 100, 80))); |
+ |
+ aura::test::EventGenerator event_generator(root_window()); |
+ event_generator.MoveMouseTo(10, 25); |
+ event_generator.ClickLeftButton(); |
+ EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); |
+ EXPECT_EQ("1 1", vk_delegate.GetMouseButtonCountsAndReset()); |
+} |
+ |
+TEST_F(ScreenManagerTest, GrabAndMouseCapture) { |
+ ScreenManager::ContainerParams normal_params( |
+ "normal", CP_DEBUG); |
+ normal_params.can_activate_children = true; |
+ aura::Window* normal_container = |
+ ScreenManager::Get()->CreateContainer(normal_params); |
+ |
+ aura::test::EventCountDelegate normal_delegate; |
+ scoped_ptr<aura::Window> normal_window(CreateTestWindow( |
+ normal_container, &normal_delegate, gfx::Rect(0, 0, 100, 100))); |
+ |
+ aura::test::EventGenerator event_generator(root_window()); |
+ event_generator.MoveMouseTo(0, 0); |
+ event_generator.PressLeftButton(); |
+ |
+ // Creating grabbing container while mouse pressing. |
+ ScreenManager::ContainerParams grab_params( |
+ "grabbing", CP_DEBUG + 1); |
+ grab_params.can_activate_children = true; |
+ grab_params.grab_inputs = true; |
+ aura::Window* grab_container = |
+ ScreenManager::Get()->CreateContainer(grab_params); |
+ |
+ aura::test::EventCountDelegate grab_delegate; |
+ scoped_ptr<aura::Window> grab_window(CreateTestWindow( |
+ grab_container, &grab_delegate, gfx::Rect(10, 10, 100, 100))); |
+ |
+ // Release event should be sent to |normal_window| because it captures the |
+ // mouse event. |
+ event_generator.ReleaseLeftButton(); |
+ EXPECT_EQ("1 1", normal_delegate.GetMouseButtonCountsAndReset()); |
+ EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); |
+ |
+ // After release, further mouse events should not be sent to |normal_window| |
+ // because grab_container grabs the input. |
+ event_generator.ClickLeftButton(); |
+ EXPECT_EQ("0 0", normal_delegate.GetMouseButtonCountsAndReset()); |
+ EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); |
+} |
+ |
} // namespace athena |