diff options
Diffstat (limited to 'athena/screen/screen_manager_unittest.cc')
-rw-r--r-- | athena/screen/screen_manager_unittest.cc | 180 |
1 files changed, 114 insertions, 66 deletions
diff --git a/athena/screen/screen_manager_unittest.cc b/athena/screen/screen_manager_unittest.cc index af91d51637..dd634ba44a 100644 --- a/athena/screen/screen_manager_unittest.cc +++ b/athena/screen/screen_manager_unittest.cc @@ -2,15 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "athena/screen/public/screen_manager.h" - #include <algorithm> #include <string> -#include "athena/test/athena_test_base.h" +#include "athena/screen/screen_manager_impl.h" +#include "athena/test/base/athena_test_base.h" +#include "athena/test/base/test_windows.h" #include "athena/util/container_priorities.h" #include "ui/aura/test/test_window_delegate.h" #include "ui/aura/window.h" +#include "ui/aura/window_targeter.h" #include "ui/events/test/event_generator.h" #include "ui/wm/core/window_util.h" @@ -103,20 +104,91 @@ TEST_F(ScreenManagerTest, NonActivatableContainer) { aura::Window* activatable_container = ScreenManager::Get()->CreateContainer(activatable); - scoped_ptr<aura::Window> window( - CreateWindow(no_activatable_container, NULL, gfx::Rect(0, 0, 100, 100))); + scoped_ptr<aura::Window> window(CreateWindow( + no_activatable_container, nullptr, 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) { +TEST_F(ScreenManagerTest, BlockInputsShouldNotBlockVirtualKeyboard) { + ScreenManager::ContainerParams block_params("blocking", kTestZOrderPriority); + block_params.can_activate_children = true; + block_params.block_events = true; + aura::Window* block_container = + ScreenManager::Get()->CreateContainer(block_params); + + aura::test::EventCountDelegate block_delegate; + scoped_ptr<aura::Window> block_window(CreateWindow( + block_container, &block_delegate, gfx::Rect(0, 0, 100, 100))); + EXPECT_TRUE(wm::CanActivateWindow(block_window.get())); + + // Create a normal container appearing over the |block_container|. This is + // essentially the case of virtual keyboard. + ScreenManager::ContainerParams vk_params("virtual keyboard", + kTestZOrderPriority + 1); + vk_params.can_activate_children = true; + aura::Window* vk_container = ScreenManager::Get()->CreateContainer(vk_params); + + aura::test::EventCountDelegate vk_delegate; + scoped_ptr<aura::Window> vk_window( + CreateWindow(vk_container, &vk_delegate, gfx::Rect(0, 20, 100, 80))); + EXPECT_TRUE(wm::CanActivateWindow(vk_window.get())); + + ui::test::EventGenerator event_generator(root_window()); + event_generator.MoveMouseTo(10, 25); + event_generator.ClickLeftButton(); + EXPECT_EQ("0 0", block_delegate.GetMouseButtonCountsAndReset()); + EXPECT_EQ("1 1", vk_delegate.GetMouseButtonCountsAndReset()); +} + +TEST_F(ScreenManagerTest, DefaultContainer) { + ScreenManagerImpl* impl = + static_cast<ScreenManagerImpl*>(ScreenManager::Get()); + aura::Window* original_default = impl->FindContainerByPriority(CP_DEFAULT); + aura::Window* parent = original_default->parent(); + // Temporarily remove the original default container from tree. + parent->RemoveChild(original_default); + + ScreenManager::ContainerParams params("new_default", CP_END + 1); + params.default_parent = true; + params.modal_container_priority = CP_END + 2; + aura::Window* new_default = ScreenManager::Get()->CreateContainer(params); + aura::Window* w = test::CreateNormalWindow(nullptr, nullptr).release(); + EXPECT_EQ(new_default, w->parent()); + delete new_default; + + // Add the original back to shutdown properly. + parent->AddChild(original_default); +} + +namespace { + +class ScreenManagerTargeterTest + : public athena::test::AthenaTestBase, + public testing::WithParamInterface<bool> { + public: + ScreenManagerTargeterTest() + : targeter_(GetParam() ? nullptr : new aura::WindowTargeter) {} + ~ScreenManagerTargeterTest() override {} + + protected: + scoped_ptr<ui::EventTargeter> targeter_; + + private: + DISALLOW_COPY_AND_ASSIGN(ScreenManagerTargeterTest); +}; + +} // namespace + +TEST_P(ScreenManagerTargeterTest, BlockContainer) { ScreenManager::ContainerParams normal_params( "normal", kTestZOrderPriority); normal_params.can_activate_children = true; aura::Window* normal_container = ScreenManager::Get()->CreateContainer(normal_params); + normal_container->SetEventTargeter(targeter_.Pass()); aura::test::EventCountDelegate normal_delegate; scoped_ptr<aura::Window> normal_window(CreateWindow( @@ -132,76 +204,48 @@ TEST_F(ScreenManagerTest, GrabInputContainer) { event_generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); EXPECT_EQ("1 1", normal_delegate.GetKeyCountsAndReset()); - ScreenManager::ContainerParams grab_params( - "grabbing", kTestZOrderPriority + 1); - grab_params.can_activate_children = true; - grab_params.grab_inputs = true; - aura::Window* grab_container = - ScreenManager::Get()->CreateContainer(grab_params); + ScreenManager::ContainerParams block_params("blocking", + kTestZOrderPriority + 1); + block_params.can_activate_children = true; + block_params.block_events = true; + aura::Window* block_container = + ScreenManager::Get()->CreateContainer(block_params); EXPECT_FALSE(wm::CanActivateWindow(normal_window.get())); - aura::test::EventCountDelegate grab_delegate; - scoped_ptr<aura::Window> grab_window(CreateWindow( - grab_container, &grab_delegate, gfx::Rect(10, 10, 100, 100))); - EXPECT_TRUE(wm::CanActivateWindow(grab_window.get())); + aura::test::EventCountDelegate block_delegate; + scoped_ptr<aura::Window> block_window(CreateWindow( + block_container, &block_delegate, gfx::Rect(10, 10, 100, 100))); + EXPECT_TRUE(wm::CanActivateWindow(block_window.get())); - wm::ActivateWindow(grab_window.get()); + wm::ActivateWindow(block_window.get()); // (0, 0) is still on normal_window, but the event should not go there - // because grabbing_container prevents it. + // because blockbing_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()); + EXPECT_EQ("0 0", block_delegate.GetMouseButtonCountsAndReset()); + event_generator.MoveMouseWheel(0, 10); + // EXPECT_EQ(0, normal_event_counter.num_scroll_events()); event_generator.MoveMouseTo(20, 20); event_generator.ClickLeftButton(); - EXPECT_EQ("1 1", grab_delegate.GetMouseButtonCountsAndReset()); + EXPECT_EQ("1 1", block_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", kTestZOrderPriority); - 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( - CreateWindow(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", kTestZOrderPriority + 1); - vk_params.can_activate_children = true; - aura::Window* vk_container = ScreenManager::Get()->CreateContainer(vk_params); - - aura::test::EventCountDelegate vk_delegate; - scoped_ptr<aura::Window> vk_window( - CreateWindow(vk_container, &vk_delegate, gfx::Rect(0, 20, 100, 80))); - EXPECT_TRUE(wm::CanActivateWindow(vk_window.get())); - - ui::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()); + EXPECT_EQ("1 1", block_delegate.GetKeyCountsAndReset()); } -TEST_F(ScreenManagerTest, GrabAndMouseCapture) { +TEST_P(ScreenManagerTargeterTest, BlockAndMouseCapture) { ScreenManager::ContainerParams normal_params( "normal", kTestZOrderPriority); normal_params.can_activate_children = true; aura::Window* normal_container = ScreenManager::Get()->CreateContainer(normal_params); + normal_container->SetEventTargeter(targeter_.Pass()); aura::test::EventCountDelegate normal_delegate; scoped_ptr<aura::Window> normal_window(CreateWindow( @@ -211,29 +255,33 @@ TEST_F(ScreenManagerTest, GrabAndMouseCapture) { event_generator.MoveMouseTo(0, 0); event_generator.PressLeftButton(); - // Creating grabbing container while mouse pressing. - ScreenManager::ContainerParams grab_params( - "grabbing", kTestZOrderPriority + 1); - grab_params.can_activate_children = true; - grab_params.grab_inputs = true; - aura::Window* grab_container = - ScreenManager::Get()->CreateContainer(grab_params); + // Creating blocking container while mouse pressing. + ScreenManager::ContainerParams block_params("blocking", + kTestZOrderPriority + 1); + block_params.can_activate_children = true; + block_params.block_events = true; + aura::Window* block_container = + ScreenManager::Get()->CreateContainer(block_params); - aura::test::EventCountDelegate grab_delegate; - scoped_ptr<aura::Window> grab_window(CreateWindow( - grab_container, &grab_delegate, gfx::Rect(10, 10, 100, 100))); + aura::test::EventCountDelegate block_delegate; + scoped_ptr<aura::Window> block_window(CreateWindow( + block_container, &block_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()); + EXPECT_EQ("0 0", block_delegate.GetMouseButtonCountsAndReset()); // After release, further mouse events should not be sent to |normal_window| - // because grab_container grabs the input. + // because block_container blocks the input. event_generator.ClickLeftButton(); EXPECT_EQ("0 0", normal_delegate.GetMouseButtonCountsAndReset()); - EXPECT_EQ("0 0", grab_delegate.GetMouseButtonCountsAndReset()); + EXPECT_EQ("0 0", block_delegate.GetMouseButtonCountsAndReset()); } +INSTANTIATE_TEST_CASE_P(WithOrWithoutTargeter, + ScreenManagerTargeterTest, + testing::Values(false, true)); + } // namespace athena |