1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
// 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_.InitWithFeatures(
{ash::features::kContextualNudges,
ash::features::kHideShelfControlsInTabletMode},
{});
} else {
scoped_feature_list_.InitAndDisableFeature(
ash::features::kContextualNudges);
}
}
~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
|