Commit 69df5765 authored by Matthew Mourgos's avatar Matthew Mourgos Committed by Commit Bot

Prepare to enable Hotseat flag in M-81 - Part 3

ShelfWidgetTest::ShelfEdgeOverlappingWindowHitTestMouse is broken when
enabling the hotseat. It is caused by the CL
(https://crrev.com/c/1966428) which fails to set window insets for
hotseat widget. To accelerate the process of enabling the hotseat flag,
only run this test with hotseat disabled.

TBR=xiyuan@chromium.org

Bug: 1032702
Change-Id: I0a6ee824f23ea8ae948f4b6db2f0f9b27d828fb5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1981113Reviewed-by: default avatarMatthew Mourgos <mmourgos@chromium.org>
Commit-Queue: Matthew Mourgos <mmourgos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727487}
parent a1297fc3
......@@ -27,6 +27,7 @@
#include "ash/wm/window_util.h"
#include "base/bind_helpers.h"
#include "base/test/scoped_feature_list.h"
#include "chromeos/constants/chromeos_features.h"
#include "components/session_manager/session_manager_types.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/display/display.h"
......@@ -225,9 +226,82 @@ TEST_F(ShelfWidgetTest, ShelfInitiallySizedAfterLogin) {
nav_width2 + hotseat_width2 + margins + status_width2);
}
// 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) {
Shelf* shelf = GetPrimaryShelf();
ShelfWidget* shelf_widget = GetShelfWidget();
gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
EXPECT_TRUE(!shelf_bounds.IsEmpty());
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(std::move(params));
widget->Show();
aura::Window* root = shelf_widget->GetNativeWindow()->GetRootWindow();
ui::EventTargeter* targeter =
root->GetHost()->dispatcher()->GetDefaultEventTargeter();
// 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, ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
EXPECT_NE(shelf_widget->GetNativeWindow(),
targeter->FindTargetForEvent(root, &touch));
}
// Now auto-hide (hidden) the shelf.
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
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, ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
EXPECT_EQ(shelf_widget->GetNativeWindow(),
targeter->FindTargetForEvent(root, &touch));
}
}
class ShelfWidgetTestWithoutHotseat : public ShelfWidgetTest {
public:
ShelfWidgetTestWithoutHotseat() = default;
~ShelfWidgetTestWithoutHotseat() override = default;
void SetUp() override {
scoped_features_.InitAndDisableFeature(chromeos::features::kShelfHotseat);
ShelfWidgetTest::SetUp();
}
private:
base::test::ScopedFeatureList scoped_features_;
DISALLOW_COPY_AND_ASSIGN(ShelfWidgetTestWithoutHotseat);
};
// Tests that the shelf lets mouse-events close to the edge fall through to the
// window underneath.
TEST_F(ShelfWidgetTest, ShelfEdgeOverlappingWindowHitTestMouse) {
// TODO(andrewxu|mmourgos): Fix this test with hotseat feature enabled.
// crbug.com/1037927
TEST_F(ShelfWidgetTestWithoutHotseat, ShelfEdgeOverlappingWindowHitTestMouse) {
UpdateDisplay("400x400");
ShelfWidget* shelf_widget = GetShelfWidget();
gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
......@@ -313,61 +387,6 @@ TEST_F(ShelfWidgetTest, ShelfEdgeOverlappingWindowHitTestMouse) {
}
}
// 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) {
Shelf* shelf = GetPrimaryShelf();
ShelfWidget* shelf_widget = GetShelfWidget();
gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
EXPECT_TRUE(!shelf_bounds.IsEmpty());
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(std::move(params));
widget->Show();
aura::Window* root = shelf_widget->GetNativeWindow()->GetRootWindow();
ui::EventTargeter* targeter =
root->GetHost()->dispatcher()->GetDefaultEventTargeter();
// 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, ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
EXPECT_NE(shelf_widget->GetNativeWindow(),
targeter->FindTargetForEvent(root, &touch));
}
// Now auto-hide (hidden) the shelf.
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
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, ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
EXPECT_EQ(shelf_widget->GetNativeWindow(),
targeter->FindTargetForEvent(root, &touch));
}
}
class ShelfWidgetAfterLoginTest : public AshTestBase {
public:
ShelfWidgetAfterLoginTest() { set_start_session(false); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment