android_webview
apps
ash
accelerators
accelerometer
accessibility
ambient
animation
annotator
api
app_list
app_menu
ash_strings_grd
assistant
auth
birch
booting
bubble
calendar
capture_mode
child_accounts
clipboard
color_enhancement
components
constants
controls
contextual_nudge.cc
contextual_nudge.h
contextual_tooltip.cc
contextual_tooltip.h
contextual_tooltip_unittest.cc
rounded_scroll_bar.cc
rounded_scroll_bar.h
rounded_scroll_bar_unittest.cc
scroll_view_gradient_helper.cc
scroll_view_gradient_helper.h
scroll_view_gradient_helper_unittest.cc
curtain
dbus
detachable_base
display
drag_drop
events
fast_ink
frame
frame_sink
frame_throttler
game_dashboard
glanceables
host
hud_display
ime
in_session_auth
keyboard
lock_screen_action
login
media
metrics
multi_capture
multi_device_setup
multi_user
perftests
picker
policy
power
projector
public
quick_pair
resources
rgb_keyboard
rotator
rounded_display
scalable_iph
search_box
sensor_info
session
shelf
strings
style
system
test
tooltips
touch
tray_action
user_education
utility
virtual_trackpad
wallpaper
webui
wm
wm_mode
BUILD.gn
DEPS
DIR_METADATA
OWNERS
README.md
ash_element_identifiers.cc
ash_element_identifiers.h
ash_export.h
ash_interfaces.cc
ash_prefs.cc
ash_strings.grd
autotest_private_api_utils.cc
bluetooth_devices_observer.cc
bluetooth_devices_observer.h
cancel_mode.cc
cancel_mode.h
debug.cc
debug.h
dip_unittest.cc
extended_desktop_unittest.cc
focus_cycler.cc
focus_cycler.h
focus_cycler_unittest.cc
fullscreen_pixeltest.cc
login_status.h
root_window_controller.cc
root_window_controller.h
root_window_controller_unittest.cc
root_window_settings.cc
root_window_settings.h
screen_util.cc
screen_util.h
screen_util_unittest.cc
shell.cc
shell.h
shell_delegate.cc
shell_delegate.h
shell_init_params.cc
shell_init_params.h
shell_observer.h
shell_tab_handler.cc
shell_tab_handler.h
shell_test_api.cc
shell_unittest.cc
shutdown_controller_impl.cc
shutdown_controller_impl.h
shutdown_reason.cc
shutdown_reason.h
test_media_client.cc
test_media_client.h
test_shell_delegate.cc
test_shell_delegate.h
window_tree_host_lookup.cc
window_user_data.h
window_user_data_unittest.cc
base
build
build_overrides
buildtools
cc
chrome
chromecast
chromeos
clank
codelabs
components
content
courgette
crypto
dbus
device
docs
extensions
fuchsia_web
gin
google_apis
google_update
gpu
headless
infra
internal
ios
ios_internal
ipc
media
mojo
native_client
native_client_sdk
net
pdf
ppapi
printing
remoting
rlz
sandbox
services
signing_keys
skia
sql
storage
styleguide
testing
third_party
tools
ui
url
v8
webkit
.clang-format
.clang-tidy
.clangd
.eslintrc.js
.git-blame-ignore-revs
.gitallowed
.gitattributes
.gitignore
.gitmodules
.gn
.mailmap
.rustfmt.toml
.vpython3
.yapfignore
ATL_OWNERS
AUTHORS
BUILD.gn
CODE_OF_CONDUCT.md
CPPLINT.cfg
DEPS
DIR_METADATA
LICENSE
LICENSE.chromium_os
OWNERS
PRESUBMIT.py
PRESUBMIT_test.py
PRESUBMIT_test_mocks.py
README.md
WATCHLISTS
codereview.settings

This flag has been on-by-default since March 2020. Cleanup is slightly complicated because the primary AreContextNudgesEnabled() function also tested the HideShelfControlsInTabletMode flag. That flag is referenced in the Tast test HotseatAnimation and hence cannot be removed. Convert checks for AreContextNudgesEnabled() to IsHideShelfControlsInTabletModeEnabled() to preserve the existing behavior. Remove the contextual nudges entry from about:flags. Bug: none Test: ash_unittests and browser_tests Change-Id: Ia66c7b6f8001aefd4c2ac54c97530806959ec642 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5274483 Reviewed-by: Toni Barzic <tbarzic@chromium.org> Commit-Queue: James Cook <jamescook@chromium.org> Cr-Commit-Position: refs/heads/main@{#1257642}
270 lines
11 KiB
C++
270 lines
11 KiB
C++
// Copyright 2020 The Chromium Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "ash/controls/contextual_tooltip.h"
|
|
|
|
#include "ash/constants/ash_features.h"
|
|
#include "ash/session/session_controller_impl.h"
|
|
#include "ash/shell.h"
|
|
#include "ash/test/ash_test_base.h"
|
|
#include "base/json/values_util.h"
|
|
#include "base/strings/string_util.h"
|
|
#include "base/test/scoped_feature_list.h"
|
|
#include "base/test/simple_test_clock.h"
|
|
#include "base/time/time.h"
|
|
#include "base/values.h"
|
|
#include "components/prefs/scoped_user_pref_update.h"
|
|
#include "ui/aura/window.h"
|
|
#include "ui/wm/core/window_util.h"
|
|
|
|
namespace ash {
|
|
|
|
namespace contextual_tooltip {
|
|
|
|
class ContextualTooltipTest : public AshTestBase,
|
|
public testing::WithParamInterface<bool> {
|
|
public:
|
|
ContextualTooltipTest() {
|
|
if (GetParam()) {
|
|
scoped_feature_list_.InitAndEnableFeature(
|
|
features::kHideShelfControlsInTabletMode);
|
|
|
|
} else {
|
|
scoped_feature_list_.InitAndDisableFeature(
|
|
features::kHideShelfControlsInTabletMode);
|
|
}
|
|
}
|
|
~ContextualTooltipTest() override = default;
|
|
|
|
base::SimpleTestClock* clock() { return &test_clock_; }
|
|
|
|
// AshTestBase:
|
|
void SetUp() override {
|
|
AshTestBase::SetUp();
|
|
contextual_tooltip::OverrideClockForTesting(&test_clock_);
|
|
test_clock_.Advance(base::Seconds(360));
|
|
}
|
|
void TearDown() override {
|
|
contextual_tooltip::ClearClockOverrideForTesting();
|
|
AshTestBase::TearDown();
|
|
}
|
|
|
|
PrefService* GetPrefService() {
|
|
return Shell::Get()->session_controller()->GetLastActiveUserPrefService();
|
|
}
|
|
|
|
private:
|
|
base::test::ScopedFeatureList scoped_feature_list_;
|
|
base::SimpleTestClock test_clock_;
|
|
};
|
|
|
|
using ContextualTooltipDisabledTest = ContextualTooltipTest;
|
|
|
|
INSTANTIATE_TEST_SUITE_P(All,
|
|
ContextualTooltipDisabledTest,
|
|
testing::Values(false));
|
|
INSTANTIATE_TEST_SUITE_P(All, ContextualTooltipTest, testing::Values(true));
|
|
|
|
// Checks that nudges are not shown when the feature flag is disabled.
|
|
TEST_P(ContextualTooltipDisabledTest, FeatureFlagDisabled) {
|
|
EXPECT_FALSE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, nullptr));
|
|
}
|
|
|
|
TEST_P(ContextualTooltipTest, ShouldShowPersistentDragHandleNudge) {
|
|
base::TimeDelta recheck_delay;
|
|
EXPECT_TRUE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, &recheck_delay));
|
|
EXPECT_TRUE(recheck_delay.is_zero());
|
|
EXPECT_TRUE(contextual_tooltip::GetNudgeTimeout(GetPrefService(),
|
|
TooltipType::kInAppToHome)
|
|
.is_zero());
|
|
}
|
|
|
|
// Checks that drag handle nudge has a timeout if it is not the first time it is
|
|
// being shown.
|
|
TEST_P(ContextualTooltipTest, NonPersistentDragHandleNudgeTimeout) {
|
|
for (int shown_count = 1;
|
|
shown_count < contextual_tooltip::kNotificationLimit; shown_count++) {
|
|
contextual_tooltip::HandleNudgeShown(GetPrefService(),
|
|
TooltipType::kInAppToHome);
|
|
clock()->Advance(contextual_tooltip::kMinInterval);
|
|
EXPECT_TRUE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, nullptr));
|
|
EXPECT_EQ(contextual_tooltip::GetNudgeTimeout(GetPrefService(),
|
|
TooltipType::kInAppToHome),
|
|
contextual_tooltip::kNudgeShowDuration);
|
|
}
|
|
}
|
|
|
|
// Checks that drag handle nudge should be shown after kMinInterval has passed
|
|
// since the last time it was shown but not before the time interval has passed.
|
|
TEST_P(ContextualTooltipTest, ShouldShowTimedDragHandleNudge) {
|
|
contextual_tooltip::HandleNudgeShown(GetPrefService(),
|
|
TooltipType::kInAppToHome);
|
|
base::TimeDelta recheck_delay;
|
|
for (int shown_count = 1;
|
|
shown_count < contextual_tooltip::kNotificationLimit; shown_count++) {
|
|
EXPECT_FALSE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, &recheck_delay));
|
|
EXPECT_EQ(contextual_tooltip::kMinInterval, recheck_delay);
|
|
clock()->Advance(contextual_tooltip::kMinInterval / 2);
|
|
EXPECT_FALSE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, &recheck_delay));
|
|
EXPECT_EQ(
|
|
contextual_tooltip::kMinInterval - contextual_tooltip::kMinInterval / 2,
|
|
recheck_delay);
|
|
clock()->Advance(contextual_tooltip::kMinInterval / 2);
|
|
EXPECT_TRUE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, nullptr));
|
|
contextual_tooltip::HandleNudgeShown(GetPrefService(),
|
|
TooltipType::kInAppToHome);
|
|
}
|
|
clock()->Advance(contextual_tooltip::kMinInterval);
|
|
EXPECT_FALSE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, &recheck_delay));
|
|
EXPECT_TRUE(recheck_delay.is_zero());
|
|
|
|
EXPECT_EQ(contextual_tooltip::GetNudgeTimeout(GetPrefService(),
|
|
TooltipType::kInAppToHome),
|
|
contextual_tooltip::kNudgeShowDuration);
|
|
}
|
|
|
|
// Tests that if the user has successfully performed the gesture for at least
|
|
// |kSuccessLimit|, the corresponding nudge should not be shown.
|
|
TEST_P(ContextualTooltipTest, ShouldNotShowNudgeAfterSuccessLimit) {
|
|
EXPECT_TRUE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, nullptr));
|
|
for (int success_count = 0;
|
|
success_count < contextual_tooltip::kSuccessLimitInAppToHome;
|
|
success_count++) {
|
|
contextual_tooltip::HandleGesturePerformed(GetPrefService(),
|
|
TooltipType::kInAppToHome);
|
|
}
|
|
|
|
base::TimeDelta recheck_delay;
|
|
EXPECT_FALSE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, &recheck_delay));
|
|
EXPECT_TRUE(recheck_delay.is_zero());
|
|
}
|
|
|
|
// Should not show back gesture nudge if drag handle nudge is expected to be
|
|
// shown.
|
|
TEST_P(ContextualTooltipTest,
|
|
DoNotShowBackGestureNudgeIfDragHandleNudgeIsExpected) {
|
|
EXPECT_TRUE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, nullptr));
|
|
|
|
// The drag handle nudge is expected to show, so back gesture nudge should not
|
|
// be shown at the same time.
|
|
base::TimeDelta recheck_delay;
|
|
EXPECT_FALSE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kBackGesture, &recheck_delay));
|
|
EXPECT_EQ(contextual_tooltip::kMinIntervalBetweenBackAndDragHandleNudge,
|
|
recheck_delay);
|
|
|
|
// After the nudge is shown, back gesture should remain hidden until
|
|
// sufficient amount of time passes.
|
|
contextual_tooltip::HandleNudgeShown(GetPrefService(),
|
|
TooltipType::kInAppToHome);
|
|
EXPECT_FALSE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kBackGesture, &recheck_delay));
|
|
|
|
EXPECT_EQ(contextual_tooltip::kMinIntervalBetweenBackAndDragHandleNudge,
|
|
recheck_delay);
|
|
|
|
clock()->Advance(
|
|
contextual_tooltip::kMinIntervalBetweenBackAndDragHandleNudge / 2);
|
|
EXPECT_FALSE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kBackGesture, &recheck_delay));
|
|
EXPECT_EQ(
|
|
contextual_tooltip::kMinIntervalBetweenBackAndDragHandleNudge -
|
|
contextual_tooltip::kMinIntervalBetweenBackAndDragHandleNudge / 2,
|
|
recheck_delay);
|
|
|
|
clock()->Advance(recheck_delay);
|
|
EXPECT_TRUE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kBackGesture, nullptr));
|
|
|
|
// After the drag handle becomes eligible to show again, the back gesture
|
|
// should be disabled.
|
|
clock()->Advance(contextual_tooltip::kMinInterval);
|
|
EXPECT_FALSE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kBackGesture, &recheck_delay));
|
|
EXPECT_EQ(contextual_tooltip::kMinIntervalBetweenBackAndDragHandleNudge,
|
|
recheck_delay);
|
|
}
|
|
|
|
// Tests that back gesture is allowed if the shelf is hidden, even if drag
|
|
// handle would normally be available.
|
|
TEST_P(ContextualTooltipTest, AllowBackGestureForHiddenShelf) {
|
|
EXPECT_TRUE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, nullptr));
|
|
|
|
// The drag handle nudge is expected to show, so back gesture nudge should not
|
|
// be shown at the same time.
|
|
EXPECT_FALSE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kBackGesture, nullptr));
|
|
|
|
// If drag handle nudge is disabled because the shelf is hidden, the back
|
|
// gesture nudge should be allowed.
|
|
contextual_tooltip::SetDragHandleNudgeDisabledForHiddenShelf(true);
|
|
EXPECT_FALSE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, nullptr));
|
|
EXPECT_TRUE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kBackGesture, nullptr));
|
|
|
|
// Disallow back gesture nudge if the shelf becomes visible.
|
|
contextual_tooltip::SetDragHandleNudgeDisabledForHiddenShelf(false);
|
|
EXPECT_TRUE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, nullptr));
|
|
EXPECT_FALSE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kBackGesture, nullptr));
|
|
}
|
|
|
|
// Tests that the drag handle nudge should not be shown while back gesture is
|
|
// showing, or soon after it's been shown.
|
|
TEST_P(ContextualTooltipTest,
|
|
DoNotShowDragHandleNudgeIfBackGestureNudgeIsShown) {
|
|
EXPECT_TRUE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, nullptr));
|
|
|
|
// Drag handle nudge not allowed if back gesture is showing.
|
|
contextual_tooltip::SetDragHandleNudgeDisabledForHiddenShelf(true);
|
|
contextual_tooltip::SetBackGestureNudgeShowing(true);
|
|
contextual_tooltip::SetDragHandleNudgeDisabledForHiddenShelf(false);
|
|
|
|
base::TimeDelta recheck_delay;
|
|
EXPECT_FALSE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, &recheck_delay));
|
|
EXPECT_EQ(contextual_tooltip::kMinIntervalBetweenBackAndDragHandleNudge,
|
|
recheck_delay);
|
|
|
|
// Allow drag handle only if sufficient amount of time passes since showing
|
|
// the back gesture nudge.
|
|
contextual_tooltip::SetBackGestureNudgeShowing(false);
|
|
contextual_tooltip::HandleNudgeShown(GetPrefService(),
|
|
TooltipType::kBackGesture);
|
|
|
|
recheck_delay = base::TimeDelta();
|
|
EXPECT_FALSE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, &recheck_delay));
|
|
|
|
EXPECT_EQ(contextual_tooltip::kMinIntervalBetweenBackAndDragHandleNudge,
|
|
recheck_delay);
|
|
|
|
clock()->Advance(
|
|
contextual_tooltip::kMinIntervalBetweenBackAndDragHandleNudge / 2);
|
|
EXPECT_FALSE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, &recheck_delay));
|
|
|
|
clock()->Advance(recheck_delay);
|
|
EXPECT_TRUE(contextual_tooltip::ShouldShowNudge(
|
|
GetPrefService(), TooltipType::kInAppToHome, nullptr));
|
|
}
|
|
|
|
} // namespace contextual_tooltip
|
|
|
|
} // namespace ash
|