Commit 4b6df1eb authored by Yi Xu's avatar Yi Xu Committed by Commit Bot

Revert "Add unit tests for drag handle nudge."

This reverts commit 5854b63f.

Reason for revert: failed to build on bot linux-chromeos-rel
details: https://ci.chromium.org/p/chromium/builders/ci/linux-chromeos-rel/35381?

Original change's description:
> 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.
> 
> Bug: 1034168
> Change-Id: Ifde73e31b1e35b630ab61b7ab43d49c9796dce20
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2076015
> Auto-Submit: Yulun Wu <yulunwu@chromium.org>
> Reviewed-by: Manu Cornet <manucornet@chromium.org>
> Reviewed-by: Toni Baržić <tbarzic@chromium.org>
> Commit-Queue: Yulun Wu <yulunwu@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#745583}

TBR=tbarzic@chromium.org,manucornet@chromium.org,yulunwu@chromium.org

Change-Id: Iee2da855a7f8ca0c0cba9689a4319607edbdd108
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1034168
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2079204Reviewed-by: default avatarYi Xu <yiyix@chromium.org>
Commit-Queue: Yi Xu <yiyix@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745599}
parent 2d103814
......@@ -1896,7 +1896,6 @@ test("ash_unittests") {
"shelf/shelf_config_unittest.cc",
"shelf/shelf_context_menu_model_unittest.cc",
"shelf/shelf_controller_unittest.cc",
"shelf/shelf_drag_handle_unittest.cc",
"shelf/shelf_layout_manager_unittest.cc",
"shelf/shelf_locking_manager_unittest.cc",
"shelf/shelf_test_util.cc",
......
......@@ -89,14 +89,11 @@ bool DragHandle::DoesIntersectRect(const views::View* target,
return drag_handle_bounds.Intersects(rect);
}
void DragHandle::ShowDragHandleNudge() {
if (ShowingNudge())
void DragHandle::ShowDragHandleNudge(base::TimeDelta nudge_duration) {
if (showing_nudge_)
return;
showing_nudge_ = true;
PrefService* pref =
Shell::Get()->session_controller()->GetLastActiveUserPrefService();
base::TimeDelta nudge_duration = contextual_tooltip::GetNudgeTimeout(
pref, contextual_tooltip::TooltipType::kDragHandle);
AnimateDragHandleShow();
ShowDragHandleTooltip();
......@@ -106,8 +103,6 @@ void DragHandle::ShowDragHandleNudge() {
base::BindOnce(&DragHandle::HideDragHandleNudge,
base::Unretained(this)));
}
contextual_tooltip::HandleNudgeShown(
pref, contextual_tooltip::TooltipType::kDragHandle);
}
void DragHandle::SetColorAndOpacity(SkColor color, float opacity) {
......@@ -116,7 +111,7 @@ void DragHandle::SetColorAndOpacity(SkColor color, float opacity) {
}
void DragHandle::HideDragHandleNudge() {
if (!ShowingNudge())
if (!showing_nudge_)
return;
hide_drag_handle_nudge_timer_.Stop();
HideDragHandleNudgeHelper();
......@@ -128,7 +123,7 @@ void DragHandle::OnGestureEvent(ui::GestureEvent* event) {
features::AreContextualNudgesEnabled()) {
// Drag handle always shows nudge when tapped and does not affect the next
// time a session based nudge will be shown.
ShowDragHandleNudge();
ShowDragHandleNudge(contextual_tooltip::kNudgeShowDuration);
}
}
......
......@@ -32,7 +32,7 @@ class ASH_EXPORT DragHandle : public views::View,
// Animates drag handle and tooltip for drag handle teaching users that
// swiping up on will take the user back to the home screen.
void ShowDragHandleNudge();
void ShowDragHandleNudge(base::TimeDelta nudge_duration);
// Immediately begins the animation to return the drag handle back to its
// original position and hide the tooltip.
......@@ -41,12 +41,6 @@ class ASH_EXPORT DragHandle : public views::View,
// views::View:
void OnGestureEvent(ui::GestureEvent* event) override;
bool ShowingNudge() { return showing_nudge_; }
bool HasHideTimerForTesting() {
return hide_drag_handle_nudge_timer_.IsRunning();
}
private:
// Animates tooltip for drag handle gesture.
void ShowDragHandleTooltip();
......
......@@ -5,7 +5,6 @@
#include "ash/shelf/hotseat_transition_animator.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/shelf/drag_handle.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
......
// 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,12 +569,15 @@ ui::Layer* ShelfWidget::GetAnimatingDragHandle() {
return delegate_view_->animating_drag_handle();
}
DragHandle* ShelfWidget::GetDragHandle() {
views::View* ShelfWidget::GetDragHandle() {
return delegate_view_->drag_handle();
}
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() {
......
......@@ -24,7 +24,6 @@
namespace ash {
enum class AnimationChangeType;
class ApplicationDragAndDropHost;
class DragHandle;
class FocusCycler;
class HotseatWidget;
class LoginShelfView;
......@@ -168,7 +167,7 @@ class ASH_EXPORT ShelfWidget : public AccessibilityObserver,
ui::Layer* GetAnimatingDragHandle();
// Gets the view used to display the drag handle on the in-app shelf.
DragHandle* GetDragHandle();
views::View* GetDragHandle();
// Starts the animation to show the drag handle nudge.
void ShowDragHandleNudge();
......
......@@ -13,7 +13,6 @@
#include "ash/public/cpp/shelf_config.h"
#include "ash/root_window_controller.h"
#include "ash/screen_util.h"
#include "ash/shelf/drag_handle.h"
#include "ash/shelf/hotseat_transition_animator.h"
#include "ash/shelf/login_shelf_view.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