Commit f72852aa authored by Yulun Wu's avatar Yulun Wu Committed by Commit Bot

Add unit tests for drag handle nudge.

Other changes:

Add test methods to drag_handle class
Modified shelf_widget GetDragHandle() to return DragHandle* instead of View*
Modified DragHandle::ShowDragHandleNudge() to fetch timeout for current pref instead of taking it as an argument.
Fixed bug where ShowDraghandleNudge did not call handleNudgeShown.

Revert "Revert "Add unit tests for drag handle nudge.""

This reverts commit 4b6df1eb.

Bug: 1034168
Change-Id: I73258ce83cd681a936fec907b04ef065b6d10592
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2080558Reviewed-by: default avatarManu Cornet <manucornet@chromium.org>
Commit-Queue: Yulun Wu <yulunwu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745695}
parent 25abe360
...@@ -1896,6 +1896,7 @@ test("ash_unittests") { ...@@ -1896,6 +1896,7 @@ test("ash_unittests") {
"shelf/shelf_config_unittest.cc", "shelf/shelf_config_unittest.cc",
"shelf/shelf_context_menu_model_unittest.cc", "shelf/shelf_context_menu_model_unittest.cc",
"shelf/shelf_controller_unittest.cc", "shelf/shelf_controller_unittest.cc",
"shelf/shelf_drag_handle_unittest.cc",
"shelf/shelf_layout_manager_unittest.cc", "shelf/shelf_layout_manager_unittest.cc",
"shelf/shelf_locking_manager_unittest.cc", "shelf/shelf_locking_manager_unittest.cc",
"shelf/shelf_test_util.cc", "shelf/shelf_test_util.cc",
......
...@@ -89,11 +89,14 @@ bool DragHandle::DoesIntersectRect(const views::View* target, ...@@ -89,11 +89,14 @@ bool DragHandle::DoesIntersectRect(const views::View* target,
return drag_handle_bounds.Intersects(rect); return drag_handle_bounds.Intersects(rect);
} }
void DragHandle::ShowDragHandleNudge(base::TimeDelta nudge_duration) { void DragHandle::ShowDragHandleNudge() {
if (showing_nudge_) if (ShowingNudge())
return; return;
showing_nudge_ = true; showing_nudge_ = true;
PrefService* pref =
Shell::Get()->session_controller()->GetLastActiveUserPrefService();
base::TimeDelta nudge_duration = contextual_tooltip::GetNudgeTimeout(
pref, contextual_tooltip::TooltipType::kDragHandle);
AnimateDragHandleShow(); AnimateDragHandleShow();
ShowDragHandleTooltip(); ShowDragHandleTooltip();
...@@ -103,6 +106,8 @@ void DragHandle::ShowDragHandleNudge(base::TimeDelta nudge_duration) { ...@@ -103,6 +106,8 @@ void DragHandle::ShowDragHandleNudge(base::TimeDelta nudge_duration) {
base::BindOnce(&DragHandle::HideDragHandleNudge, base::BindOnce(&DragHandle::HideDragHandleNudge,
base::Unretained(this))); base::Unretained(this)));
} }
contextual_tooltip::HandleNudgeShown(
pref, contextual_tooltip::TooltipType::kDragHandle);
} }
void DragHandle::SetColorAndOpacity(SkColor color, float opacity) { void DragHandle::SetColorAndOpacity(SkColor color, float opacity) {
...@@ -111,7 +116,7 @@ void DragHandle::SetColorAndOpacity(SkColor color, float opacity) { ...@@ -111,7 +116,7 @@ void DragHandle::SetColorAndOpacity(SkColor color, float opacity) {
} }
void DragHandle::HideDragHandleNudge() { void DragHandle::HideDragHandleNudge() {
if (!showing_nudge_) if (!ShowingNudge())
return; return;
hide_drag_handle_nudge_timer_.Stop(); hide_drag_handle_nudge_timer_.Stop();
HideDragHandleNudgeHelper(); HideDragHandleNudgeHelper();
...@@ -123,7 +128,7 @@ void DragHandle::OnGestureEvent(ui::GestureEvent* event) { ...@@ -123,7 +128,7 @@ void DragHandle::OnGestureEvent(ui::GestureEvent* event) {
features::AreContextualNudgesEnabled()) { features::AreContextualNudgesEnabled()) {
// Drag handle always shows nudge when tapped and does not affect the next // Drag handle always shows nudge when tapped and does not affect the next
// time a session based nudge will be shown. // time a session based nudge will be shown.
ShowDragHandleNudge(contextual_tooltip::kNudgeShowDuration); ShowDragHandleNudge();
} }
} }
......
...@@ -32,7 +32,7 @@ class ASH_EXPORT DragHandle : public views::View, ...@@ -32,7 +32,7 @@ class ASH_EXPORT DragHandle : public views::View,
// Animates drag handle and tooltip for drag handle teaching users that // Animates drag handle and tooltip for drag handle teaching users that
// swiping up on will take the user back to the home screen. // swiping up on will take the user back to the home screen.
void ShowDragHandleNudge(base::TimeDelta nudge_duration); void ShowDragHandleNudge();
// Immediately begins the animation to return the drag handle back to its // Immediately begins the animation to return the drag handle back to its
// original position and hide the tooltip. // original position and hide the tooltip.
...@@ -41,6 +41,12 @@ class ASH_EXPORT DragHandle : public views::View, ...@@ -41,6 +41,12 @@ class ASH_EXPORT DragHandle : public views::View,
// views::View: // views::View:
void OnGestureEvent(ui::GestureEvent* event) override; void OnGestureEvent(ui::GestureEvent* event) override;
bool ShowingNudge() { return showing_nudge_; }
bool HasHideTimerForTesting() {
return hide_drag_handle_nudge_timer_.IsRunning();
}
private: private:
// Animates tooltip for drag handle gesture. // Animates tooltip for drag handle gesture.
void ShowDragHandleTooltip(); void ShowDragHandleTooltip();
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ash/shelf/hotseat_transition_animator.h" #include "ash/shelf/hotseat_transition_animator.h"
#include "ash/public/cpp/shelf_config.h" #include "ash/public/cpp/shelf_config.h"
#include "ash/shelf/drag_handle.h"
#include "ash/shelf/shelf_widget.h" #include "ash/shelf/shelf_widget.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h" #include "ash/wm/tablet_mode/tablet_mode_controller.h"
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define ASH_SHELF_LOGIN_SHELF_GESTURE_CONTROLLER_H_ #define ASH_SHELF_LOGIN_SHELF_GESTURE_CONTROLLER_H_
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/shelf/drag_handle.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "ui/views/widget/widget_observer.h" #include "ui/views/widget/widget_observer.h"
...@@ -17,7 +18,6 @@ class GestureEvent; ...@@ -17,7 +18,6 @@ class GestureEvent;
namespace ash { namespace ash {
class ContextualNudge; class ContextualNudge;
class DragHandle;
class Shelf; class Shelf;
// Handles the swipe up gesture on login shelf. The gesture is enabled only when // Handles the swipe up gesture on login shelf. The gesture is enabled only when
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/public/cpp/ash_features.h"
#include "ash/shelf/contextual_tooltip.h"
#include "ash/shelf/drag_handle.h"
#include "ash/shelf/test/shelf_layout_manager_test_base.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/tablet_mode/tablet_mode_controller_test_api.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h"
namespace ash {
namespace {
ShelfWidget* GetShelfWidget() {
return AshTestBase::GetPrimaryShelf()->shelf_widget();
}
} // namespace
// Test base for unit test related to drag handle contextual nudges.
class DragHandleContextualNudgeTest : public ShelfLayoutManagerTestBase {
public:
DragHandleContextualNudgeTest() {
scoped_feature_list_.InitAndEnableFeature(ash::features::kContextualNudges);
}
~DragHandleContextualNudgeTest() override = default;
DragHandleContextualNudgeTest(const DragHandleContextualNudgeTest& other) =
delete;
DragHandleContextualNudgeTest& operator=(
const DragHandleContextualNudgeTest& other) = delete;
// ShelfLayoutManagerTestBase:
void SetUp() override {
ShelfLayoutManagerTestBase::SetUp();
test_clock_.Advance(base::TimeDelta::FromHours(2));
contextual_tooltip::OverrideClockForTesting(&test_clock_);
}
void TearDown() override {
contextual_tooltip::ClearClockOverrideForTesting();
AshTestBase::TearDown();
}
base::SimpleTestClock test_clock_;
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
TEST_F(DragHandleContextualNudgeTest, DragHandleNudgeShownInAppShelf) {
// Creates a widget that will become maximized in tablet mode.
views::Widget* widget = CreateTestWidget();
widget->Maximize();
// Drag handle and nudge should not be shown in clamshell mode.
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->ShowingNudge());
TabletModeControllerTestApi().EnterTabletMode();
// Test that the first time a user transitioning into tablet mode a maximized
// window will show the drag handle nudge. This drag handle nudge should not
// have a timeout.
EXPECT_EQ(WorkspaceWindowState::kMaximized, GetWorkspaceWindowState());
EXPECT_EQ(ShelfBackgroundType::kInApp, GetShelfWidget()->GetBackgroundType());
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->GetVisible());
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->ShowingNudge());
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->HasHideTimerForTesting());
// The nudge should remain visible until the shelf state changes.
TabletModeControllerTestApi().LeaveTabletMode();
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->ShowingNudge());
// Reentering tablet mode should show the drag handle but not the nudge.
TabletModeControllerTestApi().EnterTabletMode();
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->GetVisible());
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->ShowingNudge());
// Advance time for more than a day (which should enable the nudge again).
test_clock_.Advance(base::TimeDelta::FromHours(25));
TabletModeControllerTestApi().LeaveTabletMode();
TabletModeControllerTestApi().EnterTabletMode();
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->GetVisible());
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->ShowingNudge());
// On subsequent shows, the nudge should be hidden after a timeout.
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->HasHideTimerForTesting());
}
TEST_F(DragHandleContextualNudgeTest, DragHandleNudgeShownOnTap) {
// Creates a widget that will become fullscreen in tablet mode.
views::Widget* widget = CreateTestWidget();
widget->Maximize();
TabletModeControllerTestApi().EnterTabletMode();
// The drag handle and nudge should be showing.
EXPECT_EQ(WorkspaceWindowState::kMaximized, GetWorkspaceWindowState());
EXPECT_EQ(ShelfBackgroundType::kInApp, GetShelfWidget()->GetBackgroundType());
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->GetVisible());
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->ShowingNudge());
// Exiting and re-entering tablet should hide the nudge and put the shelf into
// the default kInApp shelf state.
TabletModeControllerTestApi().LeaveTabletMode();
TabletModeControllerTestApi().EnterTabletMode();
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->GetVisible());
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->ShowingNudge());
// Tapping the drag handle should show the drag handle nudge.
GetEventGenerator()->GestureTapAt(
GetShelfWidget()->GetDragHandle()->GetBoundsInScreen().CenterPoint());
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->GetVisible());
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->ShowingNudge());
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->HasHideTimerForTesting());
}
TEST_F(DragHandleContextualNudgeTest, HideDragHandleNudge) {
// Creates a widget that will become fullscreen in tablet mode.
views::Widget* widget = CreateTestWidget();
widget->Maximize();
TabletModeControllerTestApi().EnterTabletMode();
// The drag handle and nudge should be showing.
EXPECT_EQ(WorkspaceWindowState::kMaximized, GetWorkspaceWindowState());
EXPECT_EQ(ShelfBackgroundType::kInApp, GetShelfWidget()->GetBackgroundType());
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->GetVisible());
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->ShowingNudge());
// Hiding the drag handle nudge should not affect the visibility of the drag
// handle.
GetShelfWidget()->GetDragHandle()->HideDragHandleNudge();
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->GetVisible());
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->ShowingNudge());
}
TEST_F(DragHandleContextualNudgeTest, HideDragHandleNudgeHiddenOnMinimize) {
// Creates a widget that will become fullscreen in tablet mode.
views::Widget* widget = CreateTestWidget();
widget->Maximize();
TabletModeControllerTestApi().EnterTabletMode();
// The drag handle and nudge should be showing.
EXPECT_EQ(WorkspaceWindowState::kMaximized, GetWorkspaceWindowState());
EXPECT_EQ(ShelfBackgroundType::kInApp, GetShelfWidget()->GetBackgroundType());
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->GetVisible());
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->ShowingNudge());
// Minimizing the widget should hide the drag handle and nudge.
widget->Minimize();
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->ShowingNudge());
}
} // namespace ash
...@@ -569,15 +569,12 @@ ui::Layer* ShelfWidget::GetAnimatingDragHandle() { ...@@ -569,15 +569,12 @@ ui::Layer* ShelfWidget::GetAnimatingDragHandle() {
return delegate_view_->animating_drag_handle(); return delegate_view_->animating_drag_handle();
} }
views::View* ShelfWidget::GetDragHandle() { DragHandle* ShelfWidget::GetDragHandle() {
return delegate_view_->drag_handle(); return delegate_view_->drag_handle();
} }
void ShelfWidget::ShowDragHandleNudge() { void ShelfWidget::ShowDragHandleNudge() {
delegate_view_->drag_handle()->ShowDragHandleNudge( delegate_view_->drag_handle()->ShowDragHandleNudge();
contextual_tooltip::GetNudgeTimeout(
Shell::Get()->session_controller()->GetLastActiveUserPrefService(),
contextual_tooltip::TooltipType::kDragHandle));
} }
void ShelfWidget::HideDragHandleNudge() { void ShelfWidget::HideDragHandleNudge() {
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
namespace ash { namespace ash {
enum class AnimationChangeType; enum class AnimationChangeType;
class ApplicationDragAndDropHost; class ApplicationDragAndDropHost;
class DragHandle;
class FocusCycler; class FocusCycler;
class HotseatWidget; class HotseatWidget;
class LoginShelfView; class LoginShelfView;
...@@ -167,7 +168,7 @@ class ASH_EXPORT ShelfWidget : public AccessibilityObserver, ...@@ -167,7 +168,7 @@ class ASH_EXPORT ShelfWidget : public AccessibilityObserver,
ui::Layer* GetAnimatingDragHandle(); ui::Layer* GetAnimatingDragHandle();
// Gets the view used to display the drag handle on the in-app shelf. // Gets the view used to display the drag handle on the in-app shelf.
views::View* GetDragHandle(); DragHandle* GetDragHandle();
// Starts the animation to show the drag handle nudge. // Starts the animation to show the drag handle nudge.
void ShowDragHandleNudge(); void ShowDragHandleNudge();
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ash/public/cpp/shelf_config.h" #include "ash/public/cpp/shelf_config.h"
#include "ash/root_window_controller.h" #include "ash/root_window_controller.h"
#include "ash/screen_util.h" #include "ash/screen_util.h"
#include "ash/shelf/drag_handle.h"
#include "ash/shelf/hotseat_transition_animator.h" #include "ash/shelf/hotseat_transition_animator.h"
#include "ash/shelf/login_shelf_view.h" #include "ash/shelf/login_shelf_view.h"
#include "ash/shelf/shelf.h" #include "ash/shelf/shelf.h"
......
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