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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
|
// Copyright 2023 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/capture_mode/capture_mode_education_controller.h"
#include "ash/accelerators/accelerator_tracker.h"
#include "ash/capture_mode/capture_mode_controller.h"
#include "ash/constants/ash_features.h"
#include "ash/constants/ash_pref_names.h"
#include "ash/constants/notifier_catalogs.h"
#include "ash/public/cpp/ash_view_ids.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/style/keyboard_shortcut_view.h"
#include "ash/system/toast/anchored_nudge.h"
#include "ash/system/toast/anchored_nudge_manager_impl.h"
#include "ash/test/ash_test_base.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/keyboard_codes_posix.h"
namespace ash {
namespace {
constexpr char kCaptureModeNudgeId[] = "kCaptureModeNudge";
constexpr char kNudgeTimeToActionWithin1m[] =
"Ash.NotifierFramework.Nudge.TimeToAction.Within1m";
constexpr char kNudgeTimeToActionWithin1h[] =
"Ash.NotifierFramework.Nudge.TimeToAction.Within1h";
constexpr char kNudgeTimeToActionWithinSession[] =
"Ash.NotifierFramework.Nudge.TimeToAction.WithinSession";
constexpr float kKeyboardImageWidth = 448;
constexpr int kNudgeWorkAreaSpacing = 8;
PrefService* GetPrefService() {
return Shell::Get()->session_controller()->GetActivePrefService();
}
void CancelNudge(const std::string& id) {
Shell::Get()->anchored_nudge_manager()->Cancel(id);
}
} // namespace
class CaptureModeEducationControllerTest : public AshTestBase {
public:
CaptureModeEducationControllerTest(const std::string& arm_name = "")
: AshTestBase(base::test::TaskEnvironment::TimeSource::MOCK_TIME) {
scoped_feature_list_.InitWithFeaturesAndParameters(
/*enabled_features=*/
{{features::kCaptureModeEducation,
{{"CaptureModeEducationParam", arm_name}}}},
/*disabled_features=*/{});
}
CaptureModeEducationControllerTest(
const CaptureModeEducationControllerTest&) = delete;
CaptureModeEducationControllerTest& operator=(
const CaptureModeEducationControllerTest&) = delete;
~CaptureModeEducationControllerTest() override = default;
static void SetOverrideClock(base::Clock* test_clock) {
CaptureModeEducationController::SetOverrideClockForTesting(test_clock);
}
// By default, attempts to use the Windows Snipping Tool (capture bar)
// shortcut to activate the nudge.
void ActivateNudgeAndCheckVisibility(ui::KeyboardCode key_code = ui::VKEY_S,
int flags = ui::EF_COMMAND_DOWN |
ui::EF_SHIFT_DOWN) {
// Attempt to use the Windows Snipping Tool (capture bar) shortcut.
PressAndReleaseKey(key_code, flags);
// Get the list of visible nudges from the nudge manager and make sure our
// education nudge is in the list and visible.
const AnchoredNudge* nudge =
Shell::Get()->anchored_nudge_manager()->GetNudgeIfShown(
kCaptureModeNudgeId);
ASSERT_TRUE(nudge);
EXPECT_TRUE(nudge->GetVisible());
}
// Starts a capture session using the screenshot shortcut, and verifies that
// the nudge and tutorial are both closed. Stops the session afterwards.
void StartSessionAndCheckEducationClosed() {
// Use the screenshot shortcut to start a capture session.
PressAndReleaseKey(ui::VKEY_MEDIA_LAUNCH_APP1,
ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN);
auto* capture_mode_controller = CaptureModeController::Get();
ASSERT_TRUE(capture_mode_controller->IsActive());
// Get the list of visible nudges from the nudge manager and make sure our
// education nudge is no longer in the list.
const AnchoredNudge* nudge =
Shell::Get()->anchored_nudge_manager()->GetNudgeIfShown(
kCaptureModeNudgeId);
EXPECT_FALSE(nudge);
// The tutorial should also be closed.
EXPECT_FALSE(capture_mode_controller->education_controller()
->tutorial_widget_for_test());
// Stop the session in case we start a new one later.
capture_mode_controller->Stop();
ASSERT_FALSE(capture_mode_controller->IsActive());
}
// Skip the 3 times/24 hours show limit for testing.
void SkipNudgePrefs() {
CaptureModeController::Get()->education_controller()->skip_prefs_for_test_ =
true;
}
protected:
base::test::ScopedFeatureList scoped_feature_list_;
};
TEST_F(CaptureModeEducationControllerTest, Exists) {
// Check that the default arm is enabled.
ASSERT_EQ(features::kCaptureModeEducationParam.Get(),
features::CaptureModeEducationParam::kShortcutNudge);
ASSERT_TRUE(CaptureModeController::Get()->education_controller());
}
TEST_F(CaptureModeEducationControllerTest, NudgeAppearsOnAcceleratorPressed) {
base::SimpleTestClock test_clock;
CaptureModeEducationControllerTest::SetOverrideClock(&test_clock);
// We will need to show the nudge more than three times, so ignore pref
// limits.
SkipNudgePrefs();
for (auto [tracker_data, metadata] : kAcceleratorTrackerList) {
// We only want to test capture mode related misinputs.
if (metadata.type != TrackerType::kCaptureMode) {
continue;
}
ActivateNudgeAndCheckVisibility(tracker_data.key_code, tracker_data.flags);
// Close nudge to get ready for the next input.
CancelNudge(kCaptureModeNudgeId);
}
}
// Test fixture to verify the behaviour of Arm 1, the shortcut nudge.
class CaptureModeEducationShortcutNudgeTest
: public CaptureModeEducationControllerTest {
public:
CaptureModeEducationShortcutNudgeTest()
: CaptureModeEducationControllerTest("ShortcutNudge") {}
CaptureModeEducationShortcutNudgeTest(
const CaptureModeEducationShortcutNudgeTest&) = delete;
CaptureModeEducationShortcutNudgeTest& operator=(
const CaptureModeEducationShortcutNudgeTest&) = delete;
~CaptureModeEducationShortcutNudgeTest() override = default;
};
TEST_F(CaptureModeEducationShortcutNudgeTest, KeyboardShortcutVisible) {
base::SimpleTestClock test_clock;
CaptureModeEducationControllerTest::SetOverrideClock(&test_clock);
// Advance clock so we aren't at zero time.
test_clock.Advance(base::Hours(25));
// Attempt to use the Windows Snipping Tool (capture bar) shortcut.
PressAndReleaseKey(ui::VKEY_S, ui::EF_COMMAND_DOWN | ui::EF_SHIFT_DOWN);
// Get the list of visible nudges from the nudge manager and make sure our
// education nudge is in the list and visible.
AnchoredNudge* nudge =
Shell::Get()->anchored_nudge_manager()->GetNudgeIfShown(
kCaptureModeNudgeId);
ASSERT_TRUE(nudge);
EXPECT_TRUE(nudge->GetVisible());
// The keyboard shortcut view should be visible.
auto* shortcut_view = views::AsViewClass<KeyboardShortcutView>(
nudge->GetContentsView()->GetViewByID(
VIEW_ID_SYSTEM_NUDGE_SHORTCUT_VIEW));
ASSERT_TRUE(shortcut_view);
EXPECT_TRUE(shortcut_view->GetVisible());
StartSessionAndCheckEducationClosed();
CaptureModeEducationControllerTest::SetOverrideClock(nullptr);
}
TEST_F(CaptureModeEducationShortcutNudgeTest, EducationPreferencesShowLimit) {
base::SimpleTestClock test_clock;
CaptureModeEducationControllerTest::SetOverrideClock(&test_clock);
// Advance clock so we aren't at zero time.
test_clock.Advance(base::Hours(25));
AnchoredNudgeManagerImpl* nudge_manager =
Shell::Get()->anchored_nudge_manager();
for (int i = 0; i < 3; i++) {
ActivateNudgeAndCheckVisibility();
// Showing the nudge should also update the preferences.
EXPECT_EQ(
GetPrefService()->GetInteger(prefs::kCaptureModeEducationShownCount),
i + 1);
// Close the nudge.
CancelNudge(kCaptureModeNudgeId);
// Advance the clock so we can show the nudge again.
test_clock.Advance(base::Hours(25));
}
// Activate the nudge once more.
PressAndReleaseKey(ui::VKEY_S, ui::EF_COMMAND_DOWN | ui::EF_SHIFT_DOWN);
// The nudge should not be visible.
const AnchoredNudge* nudge =
nudge_manager->GetNudgeIfShown(kCaptureModeNudgeId);
ASSERT_FALSE(nudge);
// The nudge count should not increment as the nudge was not shown.
EXPECT_EQ(
GetPrefService()->GetInteger(prefs::kCaptureModeEducationShownCount), 3);
CaptureModeEducationControllerTest::SetOverrideClock(nullptr);
}
TEST_F(CaptureModeEducationShortcutNudgeTest, EducationPreferencesTimeLimit) {
base::SimpleTestClock test_clock;
CaptureModeEducationControllerTest::SetOverrideClock(&test_clock);
// Advance clock so we aren't at zero time.
test_clock.Advance(base::Hours(25));
ActivateNudgeAndCheckVisibility();
// Showing the nudge should also update the preferences.
EXPECT_EQ(
GetPrefService()->GetInteger(prefs::kCaptureModeEducationShownCount), 1);
// Close the nudge.
CancelNudge(kCaptureModeNudgeId);
// Advance the clock, but not more than 24 hours.
test_clock.Advance(base::Hours(20));
// Activate the nudge once more.
PressAndReleaseKey(ui::VKEY_S, ui::EF_COMMAND_DOWN | ui::EF_SHIFT_DOWN);
// The nudge should not be visible.
const AnchoredNudge* null_nudge =
Shell::Get()->anchored_nudge_manager()->GetNudgeIfShown(
kCaptureModeNudgeId);
ASSERT_FALSE(null_nudge);
// The nudge count should not increment as the nudge was not shown.
EXPECT_EQ(
GetPrefService()->GetInteger(prefs::kCaptureModeEducationShownCount), 1);
CaptureModeEducationControllerTest::SetOverrideClock(nullptr);
}
// Tests that metrics relating to the shortcut nudge (Arm 1) are properly
// recorded.
TEST_F(CaptureModeEducationShortcutNudgeTest, ShortcutNudgeMetrics) {
base::HistogramTester histogram_tester;
// For this test, we do not care about pref limits.
SkipNudgePrefs();
// The nudge has not been activated, so all related buckets should be at 0.
Shell::Get()->anchored_nudge_manager()->ResetNudgeRegistryForTesting();
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationShortcutNudge, 0);
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1h,
NudgeCatalogName::kCaptureModeEducationShortcutNudge, 0);
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithinSession,
NudgeCatalogName::kCaptureModeEducationShortcutNudge, 0);
// The other nudge buckets should be empty as well.
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationShortcutTutorial, 0);
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationQuickSettingsNudge, 0);
ActivateNudgeAndCheckVisibility();
// Attempt to use the screenshot shortcut as soon as possible.
PressAndReleaseKey(ui::VKEY_MEDIA_LAUNCH_APP1,
ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN);
auto* capture_mode_controller = CaptureModeController::Get();
ASSERT_TRUE(capture_mode_controller->IsActive());
capture_mode_controller->Stop();
// The buckets do not cascade, so a nudge that has been activated within 1m
// will not show up in the `kNudgeTimeToActionWithin1h` bucket or session
// bucket.
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationShortcutNudge, 1);
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1h,
NudgeCatalogName::kCaptureModeEducationShortcutNudge, 0);
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithinSession,
NudgeCatalogName::kCaptureModeEducationShortcutNudge, 0);
// The other nudge buckets should still be empty.
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationShortcutTutorial, 0);
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationQuickSettingsNudge, 0);
ActivateNudgeAndCheckVisibility();
// Attempt to use the screenshot shortcut after more than 1 minute, but less
// than 1 hour.
task_environment()->FastForwardBy(base::Minutes(30));
PressAndReleaseKey(ui::VKEY_MEDIA_LAUNCH_APP1,
ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN);
ASSERT_TRUE(capture_mode_controller->IsActive());
capture_mode_controller->Stop();
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationShortcutNudge, 1);
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1h,
NudgeCatalogName::kCaptureModeEducationShortcutNudge, 1);
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithinSession,
NudgeCatalogName::kCaptureModeEducationShortcutNudge, 0);
ActivateNudgeAndCheckVisibility();
// Attempt to use the screenshot shortcut after more than 1 hour.
task_environment()->FastForwardBy(base::Hours(2));
PressAndReleaseKey(ui::VKEY_MEDIA_LAUNCH_APP1,
ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN);
ASSERT_TRUE(capture_mode_controller->IsActive());
capture_mode_controller->Stop();
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationShortcutNudge, 1);
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1h,
NudgeCatalogName::kCaptureModeEducationShortcutNudge, 1);
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithinSession,
NudgeCatalogName::kCaptureModeEducationShortcutNudge, 1);
}
// Test fixture to verify the behaviour of Arm 2, the shortcut tutorial.
class CaptureModeEducationShortcutTutorialTest
: public CaptureModeEducationControllerTest {
public:
CaptureModeEducationShortcutTutorialTest()
: CaptureModeEducationControllerTest("ShortcutTutorial") {}
CaptureModeEducationShortcutTutorialTest(
const CaptureModeEducationShortcutTutorialTest&) = delete;
CaptureModeEducationShortcutTutorialTest& operator=(
const CaptureModeEducationShortcutTutorialTest&) = delete;
~CaptureModeEducationShortcutTutorialTest() override = default;
};
TEST_F(CaptureModeEducationShortcutTutorialTest, DialogOpensAndCloses) {
base::SimpleTestClock test_clock;
CaptureModeEducationControllerTest::SetOverrideClock(&test_clock);
// Advance clock so we aren't at zero time.
test_clock.Advance(base::Hours(25));
// Attempt to use the Windows Snipping Tool (capture bar) shortcut.
PressAndReleaseKey(ui::VKEY_S, ui::EF_COMMAND_DOWN | ui::EF_SHIFT_DOWN);
// Click the "Show me how" button on the nudge.
AnchoredNudgeManagerImpl* nudge_manager =
Shell::Get()->anchored_nudge_manager();
LeftClickOn(nudge_manager->GetNudgePrimaryButtonForTest(kCaptureModeNudgeId));
// The nudge should not be visible.
EXPECT_FALSE(nudge_manager->GetNudgeIfShown(kCaptureModeNudgeId));
// The tutorial widget should be visible.
auto* tutorial_widget = CaptureModeController::Get()
->education_controller()
->tutorial_widget_for_test();
ASSERT_TRUE(tutorial_widget);
// The keyboard image should be scaled to the the correct width.
auto* image_view = tutorial_widget->GetContentsView()->GetViewByID(
VIEW_ID_SCREEN_CAPTURE_EDUCATION_KEYBOARD_IMAGE);
ASSERT_TRUE(image_view);
EXPECT_EQ(kKeyboardImageWidth, image_view->width());
StartSessionAndCheckEducationClosed();
}
// Tests that metrics relating to the shortcut tutorial (Arm 2) are properly
// recorded.
TEST_F(CaptureModeEducationShortcutTutorialTest, ShortcutTutorialMetrics) {
base::HistogramTester histogram_tester;
// For this test, we do not care about pref limits.
SkipNudgePrefs();
// The nudge has not been activated, so all related buckets should be at 0.
Shell::Get()->anchored_nudge_manager()->ResetNudgeRegistryForTesting();
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationShortcutTutorial, 0);
// The other nudge buckets should be empty as well.
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationShortcutNudge, 0);
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationQuickSettingsNudge, 0);
ActivateNudgeAndCheckVisibility();
// Attempt to use the screenshot shortcut as soon as possible.
PressAndReleaseKey(ui::VKEY_MEDIA_LAUNCH_APP1,
ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN);
// The nudge bucket should now show a user action.
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationShortcutTutorial, 1);
// The other nudge buckets should still be empty.
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationShortcutNudge, 0);
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationQuickSettingsNudge, 0);
}
// Test fixture to verify the behaviour of Arm 3, the settings nudge.
class CaptureModeEducationQuickSettingsNudgeTest
: public CaptureModeEducationControllerTest {
public:
CaptureModeEducationQuickSettingsNudgeTest()
: CaptureModeEducationControllerTest("QuickSettingsNudge") {}
CaptureModeEducationQuickSettingsNudgeTest(
const CaptureModeEducationQuickSettingsNudgeTest&) = delete;
CaptureModeEducationQuickSettingsNudgeTest& operator=(
const CaptureModeEducationQuickSettingsNudgeTest&) = delete;
~CaptureModeEducationQuickSettingsNudgeTest() override = default;
};
TEST_F(CaptureModeEducationQuickSettingsNudgeTest, NudgeLocation) {
UpdateDisplay("800x600");
base::SimpleTestClock test_clock;
CaptureModeEducationControllerTest::SetOverrideClock(&test_clock);
// Advance clock so we aren't at zero time.
test_clock.Advance(base::Hours(25));
// Attempt to use the Windows Snipping Tool (capture bar) shortcut.
PressAndReleaseKey(ui::VKEY_S, ui::EF_COMMAND_DOWN | ui::EF_SHIFT_DOWN);
// Get the list of visible nudges from the nudge manager and make sure our
// education nudge is in the list and visible.
AnchoredNudge* nudge =
Shell::Get()->anchored_nudge_manager()->GetNudgeIfShown(
kCaptureModeNudgeId);
ASSERT_TRUE(nudge);
EXPECT_TRUE(nudge->GetVisible());
// Test the shelf in horizontal (bottom) alignment.
ASSERT_TRUE(Shell::GetPrimaryRootWindowController()
->shelf()
->IsHorizontalAlignment());
// The nudge should appear on the bottom right side of the screen. Compare the
// positions of the bottom right corners of the nudge and the work area.
const auto nudge_corner = nudge->GetBoundsInScreen().bottom_right();
auto work_area_corner =
nudge->GetWidget()->GetWorkAreaBoundsInScreen().bottom_right();
EXPECT_EQ(work_area_corner.x() - kNudgeWorkAreaSpacing, nudge_corner.x());
EXPECT_EQ(work_area_corner.y() - kNudgeWorkAreaSpacing, nudge_corner.y());
StartSessionAndCheckEducationClosed();
// TODO(hewer): Test shelf in vertical positions.
CaptureModeEducationControllerTest::SetOverrideClock(nullptr);
}
// Tests that metrics relating to the settings nudge (Arm 3) are properly
// recorded.
TEST_F(CaptureModeEducationQuickSettingsNudgeTest, SettingsNudgeMetrics) {
base::HistogramTester histogram_tester;
// For this test, we do not care about pref limits.
SkipNudgePrefs();
// The nudge has not been activated, so all related buckets should be at 0.
Shell::Get()->anchored_nudge_manager()->ResetNudgeRegistryForTesting();
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationQuickSettingsNudge, 0);
// The other nudge buckets should be empty as well.
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationShortcutNudge, 0);
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationShortcutTutorial, 0);
ActivateNudgeAndCheckVisibility();
// Attempt to use the screenshot shortcut as soon as possible.
PressAndReleaseKey(ui::VKEY_MEDIA_LAUNCH_APP1,
ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN);
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationQuickSettingsNudge, 1);
// The other nudge buckets should still be empty.
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationShortcutNudge, 0);
histogram_tester.ExpectBucketCount(
kNudgeTimeToActionWithin1m,
NudgeCatalogName::kCaptureModeEducationShortcutTutorial, 0);
}
class CaptureModeEducationControllerBypassLimitsFlagTest
: public CaptureModeEducationControllerTest {
public:
CaptureModeEducationControllerBypassLimitsFlagTest() {
scoped_feature_list_.InitWithFeaturesAndParameters(
/*enabled_features=*/
{{features::kCaptureModeEducation,
{{"CaptureModeEducationParam", "ShortcutNudge"}}},
{features::kCaptureModeEducationBypassLimits, {}}},
/*disabled_features=*/{});
}
CaptureModeEducationControllerBypassLimitsFlagTest(
const CaptureModeEducationControllerBypassLimitsFlagTest&) = delete;
CaptureModeEducationControllerBypassLimitsFlagTest& operator=(
const CaptureModeEducationControllerBypassLimitsFlagTest&) = delete;
~CaptureModeEducationControllerBypassLimitsFlagTest() override = default;
protected:
base::test::ScopedFeatureList scoped_feature_list_;
};
TEST_F(CaptureModeEducationControllerBypassLimitsFlagTest, NoShowLimits) {
// Show the nudge more than three times without advancing the clock,
// it should be visible each time.
for (int i = 0; i < 4; i++) {
ActivateNudgeAndCheckVisibility();
CancelNudge(kCaptureModeNudgeId);
}
}
} // namespace ash
|