Index: athena/screen/screen_manager_unittest.cc |
diff --git a/athena/screen/screen_manager_unittest.cc b/athena/screen/screen_manager_unittest.cc |
index ed8b248a3b2ace8cfb4b95dacf9177521cf31b0b..c8787daad3f50c0c14986281fbd7b527ccecf988 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/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" |
@@ -111,12 +112,83 @@ TEST_F(ScreenManagerTest, NonActivatableContainer) { |
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(NULL, NULL).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() ? NULL : new aura::WindowTargeter) {} |
+ virtual ~ScreenManagerTargeterTest() {} |
+ |
+ 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 |