| Index: ash/shelf/shelf_widget_unittest.cc
|
| diff --git a/ash/shelf/shelf_widget_unittest.cc b/ash/shelf/shelf_widget_unittest.cc
|
| index 9f365565d79061e8f98db2d592606ee91a414b15..50fce9de90874aa62adff6f183a6b4161ba3f9c0 100644
|
| --- a/ash/shelf/shelf_widget_unittest.cc
|
| +++ b/ash/shelf/shelf_widget_unittest.cc
|
| @@ -16,6 +16,7 @@
|
| #include "ash/test/shelf_view_test_api.h"
|
| #include "ash/wm/window_util.h"
|
| #include "ui/aura/root_window.h"
|
| +#include "ui/events/event_utils.h"
|
| #include "ui/gfx/display.h"
|
| #include "ui/gfx/screen.h"
|
| #include "ui/views/corewm/corewm_switches.h"
|
| @@ -189,6 +190,120 @@ TEST_F(ShelfWidgetTest, ShelfInitiallySizedAfterLogin) {
|
| shelf_widget->GetContentsView()->width() -
|
| test::ShelfTestAPI(shelf).shelf_view()->width());
|
| }
|
| -#endif
|
| +#endif // defined(OS_CHROMEOS)
|
| +
|
| +// Tests that the shelf lets mouse-events close to the edge fall through to the
|
| +// window underneath.
|
| +TEST_F(ShelfWidgetTest, ShelfEdgeOverlappingWindowHitTestMouse) {
|
| + ShelfWidget* shelf_widget = GetShelfWidget();
|
| + gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
|
| + EXPECT_TRUE(!shelf_bounds.IsEmpty());
|
| + internal::ShelfLayoutManager* shelf_layout_manager =
|
| + shelf_widget->shelf_layout_manager();
|
| + ASSERT_TRUE(shelf_layout_manager);
|
| + EXPECT_EQ(SHELF_VISIBLE, shelf_layout_manager->visibility_state());
|
| +
|
| + // Create a Widget which overlaps with the shelf in the top edge.
|
| + const int kOverlapSize = 15;
|
| + const int kWindowHeight = 200;
|
| + views::Widget* widget = new views::Widget;
|
| + views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
|
| + params.bounds = gfx::Rect(0, shelf_bounds.y() - kWindowHeight + kOverlapSize,
|
| + 200, kWindowHeight);
|
| + params.context = CurrentContext();
|
| + // Widget is now owned by the parent window.
|
| + widget->Init(params);
|
| + widget->Show();
|
| + gfx::Rect widget_bounds = widget->GetWindowBoundsInScreen();
|
| + EXPECT_TRUE(widget_bounds.Intersects(shelf_bounds));
|
| +
|
| +
|
| + ui::EventTarget* root = widget->GetNativeWindow()->GetRootWindow();
|
| + ui::EventTargeter* targeter = root->GetEventTargeter();
|
| + {
|
| + // Create a mouse-event targetting the top of the shelf widget. The
|
| + // window-targeter should find |widget| as the target (instead of the
|
| + // shelf).
|
| + gfx::Point event_location(20, shelf_bounds.y() + 1);
|
| + ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location,
|
| + ui::EF_NONE, ui::EF_NONE);
|
| + ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse);
|
| + EXPECT_EQ(widget->GetNativeWindow(), target);
|
| + }
|
| +
|
| + // Now auto-hide (hidden) the shelf.
|
| + shelf_layout_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
|
| + shelf_layout_manager->LayoutShelf();
|
| + EXPECT_EQ(SHELF_AUTO_HIDE, shelf_layout_manager->visibility_state());
|
| + EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_layout_manager->auto_hide_state());
|
| + shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
|
| + EXPECT_TRUE(!shelf_bounds.IsEmpty());
|
| +
|
| + // Move |widget| so it still overlaps the shelf.
|
| + widget->SetBounds(gfx::Rect(0, shelf_bounds.y() - kWindowHeight +
|
| + kOverlapSize, 200, kWindowHeight));
|
| + widget_bounds = widget->GetWindowBoundsInScreen();
|
| + EXPECT_TRUE(widget_bounds.Intersects(shelf_bounds));
|
| + {
|
| + // Create a mouse-event targetting the top of the shelf widget. This time,
|
| + // window-target should find the shelf as the target.
|
| + gfx::Point event_location(20, shelf_bounds.y() + 1);
|
| + ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location,
|
| + ui::EF_NONE, ui::EF_NONE);
|
| + ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse);
|
| + EXPECT_EQ(shelf_widget->GetNativeWindow(), target);
|
| + }
|
| +}
|
| +
|
| +// Tests that the shelf has a slightly larger hit-region for touch-events when
|
| +// it's in the auto-hidden state.
|
| +TEST_F(ShelfWidgetTest, HiddenShelfHitTestTouch) {
|
| + ShelfWidget* shelf_widget = GetShelfWidget();
|
| + gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
|
| + EXPECT_TRUE(!shelf_bounds.IsEmpty());
|
| + internal::ShelfLayoutManager* shelf_layout_manager =
|
| + shelf_widget->shelf_layout_manager();
|
| + ASSERT_TRUE(shelf_layout_manager);
|
| + EXPECT_EQ(SHELF_VISIBLE, shelf_layout_manager->visibility_state());
|
| +
|
| + // Create a widget to make sure that the shelf does auto-hide.
|
| + views::Widget* widget = new views::Widget;
|
| + views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
|
| + params.bounds = gfx::Rect(0, 0, 200, 200);
|
| + params.context = CurrentContext();
|
| + // Widget is now owned by the parent window.
|
| + widget->Init(params);
|
| + widget->Show();
|
| +
|
| + ui::EventTarget* root = shelf_widget->GetNativeWindow()->GetRootWindow();
|
| + ui::EventTargeter* targeter = root->GetEventTargeter();
|
| + // Touch just over the shelf. Since the shelf is visible, the window-targeter
|
| + // should not find the shelf as the target.
|
| + {
|
| + gfx::Point event_location(20, shelf_bounds.y() - 1);
|
| + ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, event_location, 0,
|
| + ui::EventTimeForNow());
|
| + EXPECT_NE(shelf_widget->GetNativeWindow(),
|
| + targeter->FindTargetForEvent(root, &touch));
|
| + }
|
| +
|
| + // Now auto-hide (hidden) the shelf.
|
| + shelf_layout_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
|
| + shelf_layout_manager->LayoutShelf();
|
| + EXPECT_EQ(SHELF_AUTO_HIDE, shelf_layout_manager->visibility_state());
|
| + EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_layout_manager->auto_hide_state());
|
| + shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
|
| + EXPECT_TRUE(!shelf_bounds.IsEmpty());
|
| +
|
| + // Touch just over the shelf again. This time, the targeter should find the
|
| + // shelf as the target.
|
| + {
|
| + gfx::Point event_location(20, shelf_bounds.y() - 1);
|
| + ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, event_location, 0,
|
| + ui::EventTimeForNow());
|
| + EXPECT_EQ(shelf_widget->GetNativeWindow(),
|
| + targeter->FindTargetForEvent(root, &touch));
|
| + }
|
| +}
|
|
|
| } // namespace ash
|
|
|