Index: ash/root_window_controller_unittest.cc |
diff --git a/ash/root_window_controller_unittest.cc b/ash/root_window_controller_unittest.cc |
index a6927224e07d71ca6404f47d5e38bc957026c573..58ed6bf7796f71fe41501b1721dff49e044fdd8e 100644 |
--- a/ash/root_window_controller_unittest.cc |
+++ b/ash/root_window_controller_unittest.cc |
@@ -647,6 +647,20 @@ class MockTextInputClient : public ui::DummyTextInputClient { |
DISALLOW_COPY_AND_ASSIGN(MockTextInputClient); |
}; |
+class TargetHitTestEventHandler : public ui::test::TestEventHandler { |
+ public: |
+ TargetHitTestEventHandler() : ui::test::TestEventHandler() {} |
James Cook
2014/09/12 22:01:52
nit: "ui::test::TestEventHandler" not needed
kevers
2014/09/15 17:23:46
Done.
|
+ |
+ virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { |
James Cook
2014/09/12 22:01:52
nit: "// ui::test::TestEventHandler overrides:" or
kevers
2014/09/15 17:23:45
Done.
|
+ if (event->type() == ui::ET_MOUSE_PRESSED) |
James Cook
2014/09/12 22:01:52
nit: one space after ==
kevers
2014/09/15 17:23:45
Done.
|
+ ui::test::TestEventHandler::OnMouseEvent(event); |
+ event->StopPropagation(); |
+ } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(TargetHitTestEventHandler); |
+}; |
+ |
// Test for http://crbug.com/297858. Virtual keyboard container should only show |
// on primary root window. |
TEST_F(VirtualKeyboardRootWindowControllerTest, |
@@ -841,5 +855,76 @@ TEST_F(VirtualKeyboardRootWindowControllerTest, EnsureCaretInWorkArea) { |
} |
} |
+TEST_F(VirtualKeyboardRootWindowControllerTest, ZOrderTest) { |
James Cook
2014/09/12 22:01:52
Add a brief comment about what this test is testin
kevers
2014/09/15 17:23:45
Done.
|
+ UpdateDisplay("800x600"); |
+ keyboard::KeyboardController* keyboard_controller = |
+ keyboard::KeyboardController::GetInstance(); |
+ keyboard::KeyboardControllerProxy* proxy = keyboard_controller->proxy(); |
+ |
+ aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
+ aura::Window* keyboard_container = |
+ Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer); |
+ ASSERT_TRUE(keyboard_container); |
+ keyboard_container->Show(); |
+ |
+ const int keyboard_height = 200; |
+ aura::Window* keyboard_window =proxy->GetKeyboardWindow(); |
James Cook
2014/09/12 22:01:52
nit: space after =
Or just run "git cl format"
kevers
2014/09/15 17:23:45
Whoops...done.
|
+ keyboard_container->AddChild(keyboard_window); |
+ keyboard_window->set_owned_by_parent(false); |
+ gfx::Rect keyboard_bounds = keyboard::KeyboardBoundsFromWindowBounds( |
+ keyboard_container->bounds(), keyboard_height); |
+ keyboard_window->SetBounds(keyboard_bounds); |
+ keyboard_window->Show(); |
+ |
+ ui::test::EventGenerator generator(root_window); |
+ |
+ int window_height = keyboard_bounds.bottom(); |
+ int window_width = keyboard_bounds.width() / 2; |
+ |
+ // Normal window is should be partially occluded by the virtual keyboard. |
James Cook
2014/09/12 22:01:52
nit: "is should be"?
kevers
2014/09/15 17:23:45
Fixed wording.
|
+ aura::test::TestWindowDelegate delegate; |
+ aura::Window* normal = CreateTestWindowInShellWithDelegateAndType( |
+ &delegate, ui::wm::WINDOW_TYPE_NORMAL, 0, |
+ gfx::Rect(0, 0, window_width, window_height)); |
+ normal->set_owned_by_parent(false); |
+ normal->Show(); |
+ TargetHitTestEventHandler normal_handler; |
+ normal->AddPreTargetHandler(&normal_handler); |
+ |
+ // Menu overlaps virtual keyboard. |
+ aura::test::TestWindowDelegate delegate2; |
+ aura::Window* menu = CreateTestWindowInShellWithDelegateAndType( |
+ &delegate2, ui::wm::WINDOW_TYPE_MENU, 0, |
+ gfx::Rect(window_width, 0, window_width, window_height)); |
+ menu->set_owned_by_parent(false); |
+ menu->Show(); |
+ TargetHitTestEventHandler menu_handler; |
+ menu->AddPreTargetHandler(&menu_handler); |
+ |
+ int left = window_width / 2; |
James Cook
2014/09/12 22:01:52
I'm having a hard time visualizing the coordinates
kevers
2014/09/15 17:23:45
Added comment block. I do feel that numbers are mo
|
+ int right = 3 * window_width / 2; |
+ int top = keyboard_bounds.y() / 2; |
+ int bottom = window_height - keyboard_height / 2; |
+ |
+ // Test that only the click on the top portion of the window is pickd up. |
James Cook
2014/09/12 22:01:52
This block might be clearer if it was moved up to
kevers
2014/09/15 17:23:45
Done.
|
+ generator.MoveMouseTo(left, top); |
+ generator.ClickLeftButton(); |
+ EXPECT_EQ(1, normal_handler.num_mouse_events()); |
+ generator.MoveMouseTo(left, bottom); |
+ generator.ClickLeftButton(); |
+ EXPECT_EQ(1, normal_handler.num_mouse_events()); |
+ |
+ // Test that both clicks register. |
+ generator.MoveMouseTo(right, top); |
+ generator.ClickLeftButton(); |
+ EXPECT_EQ(1, menu_handler.num_mouse_events()); |
+ generator.MoveMouseTo(right, bottom); |
+ generator.ClickLeftButton(); |
+ EXPECT_EQ(2, menu_handler.num_mouse_events()); |
+ |
+ delete normal; |
James Cook
2014/09/12 22:01:53
Can you use scoped_ptr<> for these?
|
+ delete menu; |
+} |
James Cook
2014/09/12 22:01:53
Thanks for writing a nice test for this! It's alw
|
+ |
} // namespace test |
} // namespace ash |