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 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <utility>
#include "ash/accessibility/accessibility_controller.h"
#include "ash/accessibility/drag_event_rewriter.h"
#include "ash/accessibility/ui/accessibility_confirmation_dialog.h"
#include "ash/constants/ash_pref_names.h"
#include "ash/shell.h"
#include "ash/system/accessibility/accessibility_feature_disable_dialog.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/ash/accessibility/accessibility_feature_browsertest.h"
#include "chrome/browser/ash/accessibility/accessibility_manager.h"
#include "chrome/browser/ash/accessibility/accessibility_test_utils.h"
#include "chrome/browser/ash/accessibility/facegaze_bubble_test_helper.h"
#include "chrome/browser/ash/accessibility/facegaze_test_utils.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h"
#include "content/public/test/browser_test.h"
#include "ui/accessibility/accessibility_features.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_handler.h"
#include "ui/events/keycodes/keyboard_codes_posix.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/geometry/point.h"
namespace ash {
using Config = FaceGazeTestUtils::Config;
using FaceGazeGesture = FaceGazeTestUtils::FaceGazeGesture;
using MacroName = FaceGazeTestUtils::MacroName;
using MediapipeGesture = FaceGazeTestUtils::MediapipeGesture;
using MockFaceLandmarkerResult = FaceGazeTestUtils::MockFaceLandmarkerResult;
namespace {
// Default forehead location.
constexpr std::pair<double, double> kDefaultForeheadLocation =
std::make_pair(0.11, 0.21);
// Expected cursor location when the above forehead location is used.
constexpr gfx::Point kDefaultCursorLocation = gfx::Point(360, 560);
// The center of the screen.
constexpr gfx::Point kCenter = gfx::Point(600, 400);
PrefService* GetPrefs() {
return AccessibilityManager::Get()->profile()->GetPrefs();
}
aura::Window* GetRootWindow() {
auto* root_window = Shell::GetRootWindowForNewWindows();
if (!root_window) {
root_window = Shell::GetPrimaryRootWindow();
}
return root_window;
}
// A class that records mouse and key events.
class MockEventHandler : public ui::EventHandler {
public:
MockEventHandler() = default;
~MockEventHandler() override = default;
MockEventHandler(const MockEventHandler&) = delete;
MockEventHandler& operator=(const MockEventHandler&) = delete;
void OnKeyEvent(ui::KeyEvent* event) override {
key_events_.push_back(*event);
}
void OnMouseEvent(ui::MouseEvent* event) override {
if (event->source_device_id() != ui::EventDeviceId::ED_UNKNOWN_DEVICE) {
return;
}
ui::EventType type = event->type();
if (type == ui::EventType::kMousePressed ||
type == ui::EventType::kMouseReleased ||
type == ui::EventType::kMouseMoved ||
type == ui::EventType::kMousewheel ||
type == ui::EventType::kMouseDragged) {
mouse_events_.push_back(*event);
}
}
void ClearEvents() {
key_events_.clear();
mouse_events_.clear();
}
const std::vector<ui::KeyEvent>& key_events() const { return key_events_; }
const std::vector<ui::MouseEvent>& mouse_events() const {
return mouse_events_;
}
std::vector<ui::MouseEvent> mouse_events(ui::EventType type) const {
std::vector<ui::MouseEvent> events;
for (const auto& event : mouse_events_) {
if (event.type() == type) {
events.push_back(event);
}
}
return events;
}
private:
std::vector<ui::KeyEvent> key_events_;
std::vector<ui::MouseEvent> mouse_events_;
};
} // namespace
class FaceGazeIntegrationTest
: public AccessibilityFeatureBrowserTest,
public ::testing::WithParamInterface<ManifestVersion> {
public:
FaceGazeIntegrationTest() = default;
~FaceGazeIntegrationTest() override = default;
FaceGazeIntegrationTest(const FaceGazeIntegrationTest&) = delete;
FaceGazeIntegrationTest& operator=(const FaceGazeIntegrationTest&) = delete;
protected:
// InProcessBrowserTest:
void SetUpCommandLine(base::CommandLine* command_line) override {
std::vector<base::test::FeatureRef> enabled_features;
std::vector<base::test::FeatureRef> disabled_features;
enabled_features.push_back(::features::kAccessibilityFaceGaze);
if (GetParam() == ManifestVersion::kTwo) {
disabled_features.push_back(
::features::kAccessibilityManifestV3AccessibilityCommon);
} else if (GetParam() == ManifestVersion::kThree) {
enabled_features.push_back(
::features::kAccessibilityManifestV3AccessibilityCommon);
}
scoped_feature_list_.InitWithFeatures(enabled_features, disabled_features);
AccessibilityFeatureBrowserTest::SetUpCommandLine(command_line);
}
void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();
utils_ = std::make_unique<FaceGazeTestUtils>();
bubble_helper_ = std::make_unique<FaceGazeBubbleTestHelper>();
GetRootWindow()->AddPreTargetHandler(&event_handler_);
}
void TearDownOnMainThread() override {
GetRootWindow()->RemovePreTargetHandler(&event_handler_);
InProcessBrowserTest::TearDownOnMainThread();
}
void AssertLatestMouseEvent(size_t num_events,
ui::EventType type,
const gfx::Point& root_location) {
std::vector<ui::MouseEvent> mouse_events = event_handler().mouse_events();
ASSERT_GT(mouse_events.size(), 0u);
ASSERT_EQ(num_events, mouse_events.size());
ASSERT_EQ(type, mouse_events[0].type());
ASSERT_EQ(root_location, mouse_events[0].root_location());
}
MockEventHandler& event_handler() { return event_handler_; }
FaceGazeTestUtils* utils() { return utils_.get(); }
FaceGazeBubbleTestHelper* bubble_helper() { return bubble_helper_.get(); }
private:
std::unique_ptr<FaceGazeTestUtils> utils_;
std::unique_ptr<FaceGazeBubbleTestHelper> bubble_helper_;
MockEventHandler event_handler_;
base::test::ScopedFeatureList scoped_feature_list_;
};
// TODO(crbug.com/388867838): Add manifest v3 variant when migration is
// complete.
INSTANTIATE_TEST_SUITE_P(ManifestV2,
FaceGazeIntegrationTest,
::testing::Values(ManifestVersion::kTwo));
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, UpdateCursorLocation) {
utils()->EnableFaceGaze(Config().Default());
event_handler().ClearEvents();
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult().WithNormalizedForeheadLocation(
kDefaultForeheadLocation));
utils()->TriggerMouseControllerInterval();
utils()->AssertCursorAt(kDefaultCursorLocation);
// We expect two mouse move events to be received because the FaceGaze
// extension calls two APIs to update the cursor position.
// EventGenerator generates a non-synthetic event. 'setCursorPosition'
// generates a synthetic event.
const std::vector<ui::MouseEvent> mouse_events =
event_handler().mouse_events();
ASSERT_EQ(2u, mouse_events.size());
ASSERT_EQ(ui::EventType::kMouseMoved, mouse_events[0].type());
ASSERT_EQ(kDefaultCursorLocation, mouse_events[0].root_location());
ASSERT_FALSE(mouse_events[0].IsSynthesized());
ASSERT_EQ(ui::EventType::kMouseMoved, mouse_events[1].type());
ASSERT_EQ(kDefaultCursorLocation, mouse_events[1].root_location());
ASSERT_TRUE(mouse_events[1].IsSynthesized());
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, ResetCursor) {
const base::flat_map<FaceGazeGesture, MacroName> gestures_to_macros = {
{FaceGazeGesture::JAW_OPEN, MacroName::RESET_CURSOR}};
const base::flat_map<FaceGazeGesture, int> gestures_to_confidences = {
{FaceGazeGesture::JAW_OPEN, 70}};
utils()->EnableFaceGaze(Config().Default().WithBindings(
gestures_to_macros, gestures_to_confidences));
// Move cursor.
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult().WithNormalizedForeheadLocation(
kDefaultForeheadLocation));
utils()->TriggerMouseControllerInterval();
utils()->AssertCursorAt(kDefaultCursorLocation);
event_handler().ClearEvents();
// Reset the cursor to the center of the screen using a gesture.
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult().WithGesture(MediapipeGesture::JAW_OPEN, 90));
utils()->AssertCursorAt(kCenter);
// We expect one mouse move event to be received because the FaceGaze
// extension only calls one API to reset the cursor position, which sends a
// synthesized event.
const std::vector<ui::MouseEvent> mouse_events =
event_handler().mouse_events();
ASSERT_EQ(1u, mouse_events.size());
ASSERT_EQ(ui::EventType::kMouseMoved, mouse_events[0].type());
ASSERT_EQ(kCenter, mouse_events[0].root_location());
ASSERT_TRUE(mouse_events[0].IsSynthesized());
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest,
IgnoreGesturesWithLowConfidence) {
const base::flat_map<FaceGazeGesture, MacroName> gestures_to_macros = {
{FaceGazeGesture::JAW_OPEN, MacroName::RESET_CURSOR}};
const base::flat_map<FaceGazeGesture, int> gestures_to_confidences = {
{FaceGazeGesture::JAW_OPEN, 100}};
utils()->EnableFaceGaze(Config().Default().WithBindings(
gestures_to_macros, gestures_to_confidences));
// Move cursor.
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult().WithNormalizedForeheadLocation(
kDefaultForeheadLocation));
utils()->TriggerMouseControllerInterval();
utils()->AssertCursorAt(kDefaultCursorLocation);
// Attempt to reset the cursor to the center of the screen using a gesture.
// This gesture will be ignored because the gesture doesn't have high enough
// confidence.
event_handler().ClearEvents();
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult().WithGesture(MediapipeGesture::JAW_OPEN, 90));
utils()->AssertCursorAt(kDefaultCursorLocation);
ASSERT_EQ(0u, event_handler().mouse_events().size());
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest,
UpdateCursorLocationWithSpeed1) {
utils()->EnableFaceGaze(Config().Default().WithCursorSpeeds(
{/*up=*/1, /*down=*/1, /*left=*/1, /*right=*/1}));
// With cursor acceleration off and buffer size 1, one-pixel head movements
// correspond to one-pixel changes on screen.
double px = 1.0 / 1200;
double py = 1.0 / 800;
for (int i = 1; i < 10; ++i) {
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult().WithNormalizedForeheadLocation(
std::make_pair(0.1 + px * i, 0.2 + py * i)));
utils()->TriggerMouseControllerInterval();
utils()->AssertCursorAt(gfx::Point(600 - i, 400 + i));
}
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, SpaceKeyEvents) {
const base::flat_map<FaceGazeGesture, MacroName> gestures_to_macros = {
{FaceGazeGesture::MOUTH_LEFT, MacroName::KEY_PRESS_SPACE}};
const base::flat_map<FaceGazeGesture, int> gestures_to_confidences = {
{FaceGazeGesture::MOUTH_LEFT, 70}};
utils()->EnableFaceGaze(Config().Default().WithBindings(
gestures_to_macros, gestures_to_confidences));
// Open jaw for space key press.
event_handler().ClearEvents();
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult().WithGesture(MediapipeGesture::MOUTH_LEFT, 90));
ASSERT_EQ(0u, event_handler().mouse_events().size());
std::vector<ui::KeyEvent> key_events = event_handler().key_events();
ASSERT_EQ(1u, key_events.size());
ASSERT_EQ(ui::KeyboardCode::VKEY_SPACE, key_events[0].key_code());
ASSERT_EQ(ui::EventType::kKeyPressed, key_events[0].type());
// Release gesture for space key release.
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult().WithGesture(MediapipeGesture::MOUTH_LEFT, 10));
ASSERT_EQ(0u, event_handler().mouse_events().size());
key_events = event_handler().key_events();
ASSERT_EQ(2u, event_handler().key_events().size());
ASSERT_EQ(ui::KeyboardCode::VKEY_SPACE, key_events[1].key_code());
ASSERT_EQ(ui::EventType::kKeyReleased, key_events[1].type());
}
// The BrowsDown gesture is special because it is the combination of two
// separate facial gestures (BROW_DOWN_LEFT and BROW_DOWN_RIGHT). This test
// ensures that the associated action is performed if either of the gestures is
// detected.
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, BrowsDownGesture) {
const base::flat_map<FaceGazeGesture, MacroName> gestures_to_macros = {
{FaceGazeGesture::BROWS_DOWN, MacroName::RESET_CURSOR}};
const base::flat_map<FaceGazeGesture, int> gestures_to_confidences = {
{FaceGazeGesture::BROWS_DOWN, 40}};
utils()->EnableFaceGaze(
Config()
.Default()
.WithCursorLocation(gfx::Point(0, 0))
.WithBindings(gestures_to_macros, gestures_to_confidences)
.WithGestureRepeatDelayMs(0));
// If neither gesture is detected, then don't perform the associated action.
event_handler().ClearEvents();
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult()
.WithGesture(MediapipeGesture::BROW_DOWN_LEFT, 30)
.WithGesture(MediapipeGesture::BROW_DOWN_RIGHT, 30));
ASSERT_EQ(0u, event_handler().mouse_events().size());
// If BROW_DOWN_LEFT is recognized, then perform the action.
event_handler().ClearEvents();
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult()
.WithGesture(MediapipeGesture::BROW_DOWN_LEFT, 50)
.WithGesture(MediapipeGesture::BROW_DOWN_RIGHT, 30));
utils()->AssertCursorAt(kCenter);
AssertLatestMouseEvent(1, ui::EventType::kMouseMoved, kCenter);
// Reset the mouse cursor away from the center.
utils()->MoveMouseTo(gfx::Point(0, 0));
utils()->AssertCursorAt(gfx::Point(0, 0));
// If BROW_DOWN_RIGHT is recognized, then perform the action.
event_handler().ClearEvents();
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult()
.WithGesture(MediapipeGesture::BROW_DOWN_LEFT, 30)
.WithGesture(MediapipeGesture::BROW_DOWN_RIGHT, 50));
utils()->AssertCursorAt(kCenter);
AssertLatestMouseEvent(1, ui::EventType::kMouseMoved, kCenter);
// Reset the mouse cursor away from the center.
utils()->MoveMouseTo(gfx::Point(0, 0));
utils()->AssertCursorAt(gfx::Point(0, 0));
// If both of the gestures are recognized, then perform the action.
event_handler().ClearEvents();
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult()
.WithGesture(MediapipeGesture::BROW_DOWN_LEFT, 50)
.WithGesture(MediapipeGesture::BROW_DOWN_RIGHT, 50));
utils()->AssertCursorAt(kCenter);
AssertLatestMouseEvent(1, ui::EventType::kMouseMoved, kCenter);
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, MousePressAndReleaseEvents) {
const base::flat_map<FaceGazeGesture, MacroName> gestures_to_macros = {
{FaceGazeGesture::MOUTH_PUCKER, MacroName::MOUSE_CLICK_LEFT}};
const base::flat_map<FaceGazeGesture, int> gestures_to_confidences = {
{FaceGazeGesture::MOUTH_PUCKER, 50}};
utils()->EnableFaceGaze(Config().Default().WithBindings(
gestures_to_macros, gestures_to_confidences));
event_handler().ClearEvents();
// Move mouth right to trigger mouse press event.
utils()->ProcessFaceLandmarkerResult(MockFaceLandmarkerResult().WithGesture(
MediapipeGesture::MOUTH_PUCKER, 60));
auto press_events =
event_handler().mouse_events(ui::EventType::kMousePressed);
auto release_events =
event_handler().mouse_events(ui::EventType::kMouseReleased);
ASSERT_EQ(1u, press_events.size());
ASSERT_EQ(1u, release_events.size());
ASSERT_TRUE(press_events.back().IsOnlyLeftMouseButton());
ASSERT_EQ(kCenter, press_events[0].root_location());
ASSERT_TRUE(release_events.back().IsOnlyLeftMouseButton());
ASSERT_EQ(kCenter, release_events[0].root_location());
// Release doesn't trigger anything else.
event_handler().ClearEvents();
utils()->ProcessFaceLandmarkerResult(MockFaceLandmarkerResult().WithGesture(
MediapipeGesture::MOUTH_PUCKER, 30));
ASSERT_EQ(0u, event_handler().mouse_events().size());
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, MouseLongClick) {
const base::flat_map<FaceGazeGesture, MacroName> gestures_to_macros = {
{FaceGazeGesture::MOUTH_RIGHT, MacroName::MOUSE_LONG_CLICK_LEFT}};
const base::flat_map<FaceGazeGesture, int> gestures_to_confidences = {
{FaceGazeGesture::MOUTH_RIGHT, 30}};
utils()->EnableFaceGaze(
Config()
.Default()
.WithBindings(gestures_to_macros, gestures_to_confidences)
.WithGestureRepeatDelayMs(0));
event_handler().ClearEvents();
auto* drag_event_rewriter = ash::Shell::Get()
->accessibility_controller()
->GetDragEventRewriterForTest();
ASSERT_NE(drag_event_rewriter, nullptr);
ASSERT_FALSE(drag_event_rewriter->IsEnabled());
// Move mouth right to trigger mouse press event.
utils()->ProcessFaceLandmarkerResult(MockFaceLandmarkerResult().WithGesture(
MediapipeGesture::MOUTH_RIGHT, 40));
std::vector<ui::MouseEvent> mouse_events =
event_handler().mouse_events(ui::EventType::kMousePressed);
ASSERT_EQ(1u, mouse_events.size());
ASSERT_EQ(ui::EventType::kMousePressed, mouse_events.back().type());
ASSERT_TRUE(mouse_events.back().IsOnlyLeftMouseButton());
ASSERT_EQ(kCenter, mouse_events.back().root_location());
ASSERT_FALSE(mouse_events.back().IsSynthesized());
ASSERT_TRUE(drag_event_rewriter->IsEnabled());
// Move forehead to trigger a kMouseDragged event.
event_handler().ClearEvents();
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult().WithNormalizedForeheadLocation(
std::make_pair(0.9, 0.9)));
utils()->TriggerMouseControllerInterval();
mouse_events = event_handler().mouse_events(ui::EventType::kMouseDragged);
ASSERT_EQ(1u, mouse_events.size());
ASSERT_EQ(ui::EventType::kMouseDragged, mouse_events.back().type());
ASSERT_TRUE(mouse_events.back().IsOnlyLeftMouseButton());
ASSERT_NE(kCenter, mouse_events.back().root_location());
ASSERT_FALSE(mouse_events.back().IsSynthesized());
ASSERT_TRUE(drag_event_rewriter->IsEnabled());
// Move mouth right again to trigger mouse release event.
event_handler().ClearEvents();
utils()->ProcessFaceLandmarkerResult(MockFaceLandmarkerResult().WithGesture(
MediapipeGesture::MOUTH_RIGHT, 40));
mouse_events = event_handler().mouse_events(ui::EventType::kMouseReleased);
ASSERT_EQ(1u, mouse_events.size());
ASSERT_EQ(ui::EventType::kMouseReleased, mouse_events.back().type());
ASSERT_TRUE(mouse_events.back().IsOnlyLeftMouseButton());
ASSERT_NE(kCenter, mouse_events.back().root_location());
ASSERT_FALSE(mouse_events.back().IsSynthesized());
ASSERT_FALSE(drag_event_rewriter->IsEnabled());
}
// TODO(crbug.com/367758998): Re-enable this test.
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, DISABLED_PerformanceHistogram) {
const base::flat_map<FaceGazeGesture, MacroName> gestures_to_macros = {
{FaceGazeGesture::MOUTH_PUCKER, MacroName::MOUSE_CLICK_LEFT}};
const base::flat_map<FaceGazeGesture, int> gestures_to_confidences = {
{FaceGazeGesture::MOUTH_PUCKER, 50}};
utils()->EnableFaceGaze(Config().Default().WithBindings(
gestures_to_macros, gestures_to_confidences));
HistogramWaiter waiter("Accessibility.FaceGaze.AverageFaceLandmarkerLatency");
for (int i = 0; i < 100; ++i) {
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult().WithLatency(i));
}
waiter.Wait();
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, OpenSettingsPage) {
const base::flat_map<FaceGazeGesture, MacroName> gestures_to_macros = {
{FaceGazeGesture::MOUTH_RIGHT, MacroName::OPEN_FACEGAZE_SETTINGS}};
const base::flat_map<FaceGazeGesture, int> gestures_to_confidences = {
{FaceGazeGesture::MOUTH_RIGHT, 30}};
utils()->EnableFaceGaze(Config().Default().WithBindings(
gestures_to_macros, gestures_to_confidences));
base::RunLoop waiter;
AccessibilityManager::Get()->SetOpenSettingsSubpageObserverForTest(
base::BindLambdaForTesting([&waiter]() { waiter.Quit(); }));
// Move mouth right to open the FaceGaze settings page.
utils()->ProcessFaceLandmarkerResult(MockFaceLandmarkerResult().WithGesture(
MediapipeGesture::MOUTH_RIGHT, 40));
waiter.Run();
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, ToggleVirtualKeyboard) {
const base::flat_map<FaceGazeGesture, MacroName> gestures_to_macros = {
{FaceGazeGesture::JAW_OPEN, MacroName::TOGGLE_VIRTUAL_KEYBOARD}};
const base::flat_map<FaceGazeGesture, int> gestures_to_confidences = {
{FaceGazeGesture::JAW_OPEN, 30}};
utils()->EnableFaceGaze(Config().Default().WithBindings(
gestures_to_macros, gestures_to_confidences));
base::RunLoop waiter;
ash::Shell::Get()
->accessibility_controller()
->SetVirtualKeyboardVisibleCallbackForTesting(
base::BindLambdaForTesting([&waiter]() { waiter.Quit(); }));
// Open jaw to toggle the virtual keyboard.
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult().WithGesture(MediapipeGesture::JAW_OPEN, 40));
waiter.Run();
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, DoubleClick) {
const base::flat_map<FaceGazeGesture, MacroName> gestures_to_macros = {
{FaceGazeGesture::MOUTH_FUNNEL, MacroName::MOUSE_CLICK_LEFT_DOUBLE}};
const base::flat_map<FaceGazeGesture, int> gestures_to_confidences = {
{FaceGazeGesture::MOUTH_FUNNEL, 50}};
utils()->EnableFaceGaze(Config().Default().WithBindings(
gestures_to_macros, gestures_to_confidences));
event_handler().ClearEvents();
// Mouth funnel to trigger double click event.
utils()->ProcessFaceLandmarkerResult(MockFaceLandmarkerResult().WithGesture(
MediapipeGesture::MOUTH_FUNNEL, 60));
auto press_events =
event_handler().mouse_events(ui::EventType::kMousePressed);
auto release_events =
event_handler().mouse_events(ui::EventType::kMouseReleased);
ASSERT_EQ(1u, press_events.size());
ASSERT_EQ(1u, release_events.size());
const auto& press_event = press_events.back();
const auto& release_event = release_events.back();
ASSERT_TRUE(press_event.IsOnlyLeftMouseButton());
ASSERT_EQ(kCenter, press_event.root_location());
// Assert that the press event is for a double click.
ASSERT_TRUE(ui::EF_IS_DOUBLE_CLICK & press_event.flags());
ASSERT_TRUE(release_event.IsOnlyLeftMouseButton());
ASSERT_EQ(kCenter, release_event.root_location());
// Assert that the release event is for a double click.
ASSERT_TRUE(ui::EF_IS_DOUBLE_CLICK & release_event.flags());
// Release doesn't trigger anything else.
event_handler().ClearEvents();
utils()->ProcessFaceLandmarkerResult(MockFaceLandmarkerResult().WithGesture(
MediapipeGesture::MOUTH_FUNNEL, 30));
ASSERT_EQ(0u, event_handler().mouse_events().size());
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, TripleClick) {
const base::flat_map<FaceGazeGesture, MacroName> gestures_to_macros = {
{FaceGazeGesture::MOUTH_FUNNEL, MacroName::MOUSE_CLICK_LEFT_TRIPLE}};
const base::flat_map<FaceGazeGesture, int> gestures_to_confidences = {
{FaceGazeGesture::MOUTH_FUNNEL, 50}};
utils()->EnableFaceGaze(Config().Default().WithBindings(
gestures_to_macros, gestures_to_confidences));
event_handler().ClearEvents();
// Mouth funnel to trigger triple click event.
utils()->ProcessFaceLandmarkerResult(MockFaceLandmarkerResult().WithGesture(
MediapipeGesture::MOUTH_FUNNEL, 60));
auto press_events =
event_handler().mouse_events(ui::EventType::kMousePressed);
auto release_events =
event_handler().mouse_events(ui::EventType::kMouseReleased);
ASSERT_EQ(1u, press_events.size());
ASSERT_EQ(1u, release_events.size());
const auto& press_event = press_events.back();
const auto& release_event = release_events.back();
ASSERT_TRUE(press_event.IsOnlyLeftMouseButton());
ASSERT_EQ(kCenter, press_event.root_location());
// Assert that the press event is for a triple click.
ASSERT_TRUE(ui::EF_IS_TRIPLE_CLICK & press_event.flags());
ASSERT_TRUE(release_event.IsOnlyLeftMouseButton());
ASSERT_EQ(kCenter, release_event.root_location());
// Assert that the release event is for a triple click.
ASSERT_TRUE(ui::EF_IS_TRIPLE_CLICK & release_event.flags());
// Release doesn't trigger anything else.
event_handler().ClearEvents();
utils()->ProcessFaceLandmarkerResult(MockFaceLandmarkerResult().WithGesture(
MediapipeGesture::MOUTH_FUNNEL, 30));
ASSERT_EQ(0u, event_handler().mouse_events().size());
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, AcceptDialog) {
auto* controller = ash::Shell::Get()->accessibility_controller();
auto* prefs = GetPrefs();
base::RunLoop dialog_waiter;
controller->AddShowConfirmationDialogCallbackForTesting(
base::BindLambdaForTesting([&dialog_waiter]() { dialog_waiter.Quit(); }));
// Enabling FaceGaze should show the confirmation dialog.
utils()->EnableFaceGaze(Config().Default().WithDialogAccepted(false));
dialog_waiter.Run();
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
ASSERT_FALSE(prefs->GetBoolean(
prefs::kAccessibilityFaceGazeAcceleratorDialogHasBeenAccepted));
ASSERT_NE(nullptr, controller->GetConfirmationDialogForTest());
base::RunLoop settings_waiter;
AccessibilityManager::Get()->SetOpenSettingsSubpageObserverForTest(
base::BindLambdaForTesting(
[&settings_waiter]() { settings_waiter.Quit(); }));
// Accepting the dialog should initialize the FaceLandmarker and open the
// settings page.
controller->GetConfirmationDialogForTest()->Accept();
utils()->WaitForFaceLandmarker();
settings_waiter.Run();
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
// Verify that the dialog accepted pref is now true.
ASSERT_TRUE(prefs->GetBoolean(
prefs::kAccessibilityFaceGazeAcceleratorDialogHasBeenAccepted));
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, CancelDialog) {
auto* controller = ash::Shell::Get()->accessibility_controller();
auto* prefs = GetPrefs();
base::RunLoop dialog_waiter;
controller->AddShowConfirmationDialogCallbackForTesting(
base::BindLambdaForTesting([&dialog_waiter]() { dialog_waiter.Quit(); }));
// Enabling FaceGaze should show the confirmation dialog.
utils()->EnableFaceGaze(Config().Default().WithDialogAccepted(false));
dialog_waiter.Run();
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
ASSERT_FALSE(prefs->GetBoolean(
prefs::kAccessibilityFaceGazeAcceleratorDialogHasBeenAccepted));
ASSERT_NE(nullptr, controller->GetConfirmationDialogForTest());
base::RunLoop pref_waiter;
PrefChangeRegistrar change_observer;
change_observer.Init(prefs);
change_observer.Add(prefs::kAccessibilityFaceGazeEnabled,
pref_waiter.QuitClosure());
// Canceling the dialog should turn off FaceGaze.
controller->GetConfirmationDialogForTest()->Cancel();
pref_waiter.Run();
ASSERT_FALSE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
// Verify that the dialog accepted pref is still false.
ASSERT_FALSE(prefs->GetBoolean(
prefs::kAccessibilityFaceGazeAcceleratorDialogHasBeenAccepted));
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, ScrollMode) {
const base::flat_map<FaceGazeGesture, MacroName> gestures_to_macros = {
{FaceGazeGesture::JAW_LEFT, MacroName::TOGGLE_SCROLL_MODE}};
const base::flat_map<FaceGazeGesture, int> gestures_to_confidences = {
{FaceGazeGesture::JAW_LEFT, 30}};
utils()->EnableFaceGaze(
Config()
.Default()
.WithBindings(gestures_to_macros, gestures_to_confidences)
// Ensure speeds are high so that head movements exceed the scroll
// mode movement threshold.
.WithCursorSpeeds({/*up=*/5, /*down=*/5, /*left=*/5, /*right=*/5})
.WithGestureRepeatDelayMs(0));
// Move jaw left to enter scroll mode.
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult().WithGesture(MediapipeGesture::JAW_LEFT, 40));
utils()->AssertScrollMode(true);
event_handler().ClearEvents();
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult()
.WithNormalizedForeheadLocation(std::make_pair(0.9, 0.9))
.WithGesture(MediapipeGesture::JAW_LEFT, 0));
utils()->TriggerMouseControllerInterval();
// Head movement should cause one scroll event to be sent.
ASSERT_EQ(1u,
event_handler().mouse_events(ui::EventType::kMousewheel).size());
// No mouse movement events should be sent.
ASSERT_EQ(0u,
event_handler().mouse_events(ui::EventType::kMouseMoved).size());
// Move jaw left again to exit scroll mode.
utils()->ProcessFaceLandmarkerResult(
MockFaceLandmarkerResult().WithGesture(MediapipeGesture::JAW_LEFT, 40));
utils()->AssertScrollMode(false);
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, DefaultBehavior) {
utils()->EnableFaceGaze(Config().Default());
// Default gesture-to-macro and gesture-to-confidence mappings should be
// installed if we didn't specify them.
const auto& gestures_to_macros =
GetPrefs()->GetDict(prefs::kAccessibilityFaceGazeGesturesToMacros);
const auto& gestures_to_confidences =
GetPrefs()->GetDict(prefs::kAccessibilityFaceGazeGesturesToConfidence);
ASSERT_EQ(gestures_to_macros.size(), 2u);
ASSERT_EQ(gestures_to_confidences.size(), 2u);
ASSERT_EQ(/* MOUSE_CLICK_LEFT */ 35,
gestures_to_macros.FindInt(
FaceGazeTestUtils::ToString(FaceGazeGesture::MOUTH_SMILE)));
ASSERT_EQ(/* SCROLL */ 50,
gestures_to_macros.FindInt(
FaceGazeTestUtils::ToString(FaceGazeGesture::JAW_OPEN)));
ASSERT_EQ(60, gestures_to_confidences.FindInt(
FaceGazeTestUtils::ToString(FaceGazeGesture::MOUTH_SMILE)));
ASSERT_EQ(60, gestures_to_confidences.FindInt(
FaceGazeTestUtils::ToString(FaceGazeGesture::JAW_OPEN)));
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, DisableDialogAccept) {
auto* controller = ash::Shell::Get()->accessibility_controller();
auto* prefs = GetPrefs();
base::RunLoop dialog_waiter;
controller->AddFeatureDisableDialogCallbackForTesting(
base::BindLambdaForTesting([&dialog_waiter]() { dialog_waiter.Quit(); }));
// Enabling FaceGaze should not show the feature disable dialog.
utils()->EnableFaceGaze(Config().Default());
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
ASSERT_EQ(nullptr, controller->GetFeatureDisableDialogForTest());
// Showing the feature disable dialog should leave the enabled pref unchanged.
controller->RequestDisableFaceGaze();
dialog_waiter.Run();
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
ASSERT_NE(nullptr, controller->GetFeatureDisableDialogForTest());
base::RunLoop pref_waiter;
PrefChangeRegistrar change_observer;
change_observer.Init(prefs);
change_observer.Add(prefs::kAccessibilityFaceGazeEnabled,
pref_waiter.QuitClosure());
// Accepting the dialog should turn off FaceGaze.
controller->GetFeatureDisableDialogForTest()->Accept();
pref_waiter.Run();
ASSERT_FALSE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, DisableDialogCancel) {
auto* controller = ash::Shell::Get()->accessibility_controller();
auto* prefs = GetPrefs();
base::RunLoop dialog_waiter;
controller->AddFeatureDisableDialogCallbackForTesting(
base::BindLambdaForTesting([&dialog_waiter]() { dialog_waiter.Quit(); }));
// Enabling FaceGaze should not show the feature disable dialog.
utils()->EnableFaceGaze(Config().Default());
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
ASSERT_EQ(nullptr, controller->GetFeatureDisableDialogForTest());
// Showing the feature disable dialog should leave the enabled pref unchanged.
controller->RequestDisableFaceGaze();
dialog_waiter.Run();
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
ASSERT_NE(nullptr, controller->GetFeatureDisableDialogForTest());
base::RunLoop pref_waiter;
PrefChangeRegistrar change_observer;
change_observer.Init(prefs);
change_observer.Add(prefs::kAccessibilityFaceGazeEnabledSentinel,
pref_waiter.QuitClosure());
// Cancelling the dialog should leave FaceGaze on.
controller->GetFeatureDisableDialogForTest()->Cancel();
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
}
// TODO(crbug.com/383757982): Add test API for .WithCursorControlEnabled() and
// .WithActionsEnabled() and update tests accordingly.
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, EnableCursorControlNoDialog) {
auto* controller = ash::Shell::Get()->accessibility_controller();
auto* prefs = GetPrefs();
base::RunLoop dialog_waiter;
controller->AddFeatureDisableDialogCallbackForTesting(
base::BindLambdaForTesting([&dialog_waiter]() { dialog_waiter.Quit(); }));
// Enabling FaceGaze should not show the feature disable dialog.
utils()->EnableFaceGaze(Config().Default());
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
ASSERT_EQ(nullptr, controller->GetFeatureDisableDialogForTest());
// Setting sentinel value to true should not show the feature disable dialog.
prefs->SetBoolean(prefs::kAccessibilityFaceGazeCursorControlEnabledSentinel,
true);
ASSERT_TRUE(
prefs->GetBoolean(prefs::kAccessibilityFaceGazeCursorControlEnabled));
ASSERT_EQ(nullptr, controller->GetFeatureDisableDialogForTest());
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest,
DisableCursorControlDialogAccept) {
auto* controller = ash::Shell::Get()->accessibility_controller();
auto* prefs = GetPrefs();
base::RunLoop dialog_waiter;
controller->AddFeatureDisableDialogCallbackForTesting(
base::BindLambdaForTesting([&dialog_waiter]() { dialog_waiter.Quit(); }));
// Enabling FaceGaze should not show the feature disable dialog.
utils()->EnableFaceGaze(Config().Default());
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
ASSERT_EQ(nullptr, controller->GetFeatureDisableDialogForTest());
prefs->SetBoolean(prefs::kAccessibilityFaceGazeCursorControlEnabled, true);
ASSERT_TRUE(prefs->GetBoolean(
prefs::kAccessibilityFaceGazeCursorControlEnabledSentinel));
// Setting sentinel value to false should show the feature disable dialog and
// leave the behavior pref unchanged.
prefs->SetBoolean(prefs::kAccessibilityFaceGazeCursorControlEnabledSentinel,
false);
dialog_waiter.Run();
ASSERT_TRUE(
prefs->GetBoolean(prefs::kAccessibilityFaceGazeCursorControlEnabled));
ASSERT_FALSE(prefs->GetBoolean(
prefs::kAccessibilityFaceGazeCursorControlEnabledSentinel));
ASSERT_NE(nullptr, controller->GetFeatureDisableDialogForTest());
base::RunLoop pref_waiter;
PrefChangeRegistrar change_observer;
change_observer.Init(prefs);
change_observer.Add(prefs::kAccessibilityFaceGazeCursorControlEnabled,
pref_waiter.QuitClosure());
// Accepting the dialog should turn off FaceGaze cursor control.
controller->GetFeatureDisableDialogForTest()->Accept();
pref_waiter.Run();
// Assert behavior and sentinel prefs are in sync.
ASSERT_FALSE(
prefs->GetBoolean(prefs::kAccessibilityFaceGazeCursorControlEnabled));
ASSERT_FALSE(prefs->GetBoolean(
prefs::kAccessibilityFaceGazeCursorControlEnabledSentinel));
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest,
DisableCursorControlDialogCancel) {
auto* controller = ash::Shell::Get()->accessibility_controller();
auto* prefs = GetPrefs();
base::RunLoop dialog_waiter;
controller->AddFeatureDisableDialogCallbackForTesting(
base::BindLambdaForTesting([&dialog_waiter]() { dialog_waiter.Quit(); }));
// Enabling FaceGaze should not show the feature disable dialog.
utils()->EnableFaceGaze(Config().Default());
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
ASSERT_EQ(nullptr, controller->GetFeatureDisableDialogForTest());
prefs->SetBoolean(prefs::kAccessibilityFaceGazeCursorControlEnabled, true);
ASSERT_TRUE(prefs->GetBoolean(
prefs::kAccessibilityFaceGazeCursorControlEnabledSentinel));
// Setting sentinel value to false should show the feature disable dialog and
// leave the behavior pref unchanged.
prefs->SetBoolean(prefs::kAccessibilityFaceGazeCursorControlEnabledSentinel,
false);
dialog_waiter.Run();
ASSERT_TRUE(
prefs->GetBoolean(prefs::kAccessibilityFaceGazeCursorControlEnabled));
ASSERT_NE(nullptr, controller->GetFeatureDisableDialogForTest());
base::RunLoop pref_waiter;
PrefChangeRegistrar change_observer;
change_observer.Init(prefs);
change_observer.Add(prefs::kAccessibilityFaceGazeCursorControlEnabledSentinel,
pref_waiter.QuitClosure());
// Cancelling the dialog should leave FaceGaze cursor control on and set the
// sentinel to true.
controller->GetFeatureDisableDialogForTest()->Cancel();
pref_waiter.Run();
// Assert behavior and sentinel prefs are in sync.
ASSERT_TRUE(
prefs->GetBoolean(prefs::kAccessibilityFaceGazeCursorControlEnabled));
ASSERT_TRUE(prefs->GetBoolean(
prefs::kAccessibilityFaceGazeCursorControlEnabledSentinel));
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, EnableActionsNoDialog) {
auto* controller = ash::Shell::Get()->accessibility_controller();
auto* prefs = GetPrefs();
base::RunLoop dialog_waiter;
controller->AddFeatureDisableDialogCallbackForTesting(
base::BindLambdaForTesting([&dialog_waiter]() { dialog_waiter.Quit(); }));
// Enabling FaceGaze should not show the feature disable dialog.
utils()->EnableFaceGaze(Config().Default());
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
ASSERT_EQ(nullptr, controller->GetFeatureDisableDialogForTest());
// Setting sentinel value to true should not show the feature disable dialog.
prefs->SetBoolean(prefs::kAccessibilityFaceGazeActionsEnabledSentinel, true);
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeActionsEnabled));
ASSERT_EQ(nullptr, controller->GetFeatureDisableDialogForTest());
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, DisableActionsDialogAccept) {
auto* controller = ash::Shell::Get()->accessibility_controller();
auto* prefs = GetPrefs();
base::RunLoop dialog_waiter;
controller->AddFeatureDisableDialogCallbackForTesting(
base::BindLambdaForTesting([&dialog_waiter]() { dialog_waiter.Quit(); }));
// Setting sentinel value to true should not show the feature disable dialog.
utils()->EnableFaceGaze(Config().Default());
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
ASSERT_EQ(nullptr, controller->GetFeatureDisableDialogForTest());
prefs->SetBoolean(prefs::kAccessibilityFaceGazeActionsEnabled, true);
ASSERT_TRUE(
prefs->GetBoolean(prefs::kAccessibilityFaceGazeActionsEnabledSentinel));
// Setting sentinel value to false should show the feature disable dialog and
// leave the behavior pref unchanged.
prefs->SetBoolean(prefs::kAccessibilityFaceGazeActionsEnabledSentinel, false);
dialog_waiter.Run();
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeActionsEnabled));
ASSERT_FALSE(
prefs->GetBoolean(prefs::kAccessibilityFaceGazeActionsEnabledSentinel));
ASSERT_NE(nullptr, controller->GetFeatureDisableDialogForTest());
base::RunLoop pref_waiter;
PrefChangeRegistrar change_observer;
change_observer.Init(prefs);
change_observer.Add(prefs::kAccessibilityFaceGazeActionsEnabled,
pref_waiter.QuitClosure());
// Accepting the dialog should turn off FaceGaze actions.
controller->GetFeatureDisableDialogForTest()->Accept();
pref_waiter.Run();
// Assert behavior and sentinel prefs are in sync.
ASSERT_FALSE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeActionsEnabled));
ASSERT_FALSE(
prefs->GetBoolean(prefs::kAccessibilityFaceGazeActionsEnabledSentinel));
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, DisableActionsDialogCancel) {
auto* controller = ash::Shell::Get()->accessibility_controller();
auto* prefs = GetPrefs();
base::RunLoop dialog_waiter;
controller->AddFeatureDisableDialogCallbackForTesting(
base::BindLambdaForTesting([&dialog_waiter]() { dialog_waiter.Quit(); }));
// Setting sentinel value to true should not show the feature disable dialog.
utils()->EnableFaceGaze(Config().Default());
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
ASSERT_EQ(nullptr, controller->GetFeatureDisableDialogForTest());
prefs->SetBoolean(prefs::kAccessibilityFaceGazeActionsEnabled, true);
ASSERT_TRUE(
prefs->GetBoolean(prefs::kAccessibilityFaceGazeActionsEnabledSentinel));
// Setting sentinel value to false should show the feature disable dialog and
// leave the behavior pref unchanged.
prefs->SetBoolean(prefs::kAccessibilityFaceGazeActionsEnabledSentinel, false);
dialog_waiter.Run();
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeActionsEnabled));
ASSERT_NE(nullptr, controller->GetFeatureDisableDialogForTest());
base::RunLoop pref_waiter;
PrefChangeRegistrar change_observer;
change_observer.Init(prefs);
change_observer.Add(prefs::kAccessibilityFaceGazeActionsEnabledSentinel,
pref_waiter.QuitClosure());
// Cancelling the dialog should leave FaceGaze actions on and set the sentinel
// to true.
controller->GetFeatureDisableDialogForTest()->Cancel();
pref_waiter.Run();
// Assert behavior and sentinel prefs are in sync.
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeActionsEnabled));
ASSERT_TRUE(
prefs->GetBoolean(prefs::kAccessibilityFaceGazeActionsEnabledSentinel));
}
IN_PROC_BROWSER_TEST_P(FaceGazeIntegrationTest, CloseButton) {
auto* controller = ash::Shell::Get()->accessibility_controller();
auto* prefs = GetPrefs();
base::RunLoop dialog_waiter;
controller->AddFeatureDisableDialogCallbackForTesting(
base::BindLambdaForTesting([&dialog_waiter]() { dialog_waiter.Quit(); }));
// Setup FaceGaze.
const base::flat_map<FaceGazeGesture, MacroName> gestures_to_macros = {
{FaceGazeGesture::MOUTH_PUCKER, MacroName::MOUSE_CLICK_LEFT}};
const base::flat_map<FaceGazeGesture, int> gestures_to_confidences = {
{FaceGazeGesture::MOUTH_PUCKER, 50}};
utils()->EnableFaceGaze(Config().Default().WithBindings(
gestures_to_macros, gestures_to_confidences));
// Assert initial state.
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
ASSERT_EQ(nullptr, controller->GetFeatureDisableDialogForTest());
// Move mouse to close button.
gfx::Point close_button = bubble_helper()->GetCloseButtonCenterPoint();
utils()->MoveMouseTo(close_button);
utils()->AssertCursorAt(close_button);
ASSERT_TRUE(bubble_helper()->IsVisible());
// Clicking the close button will show the dialog to turn off FaceGaze. Note
// that the feature remains on until the dialog is accepted.
utils()->ProcessFaceLandmarkerResult(MockFaceLandmarkerResult().WithGesture(
MediapipeGesture::MOUTH_PUCKER, 95));
dialog_waiter.Run();
ASSERT_TRUE(prefs->GetBoolean(prefs::kAccessibilityFaceGazeEnabled));
ASSERT_NE(nullptr, controller->GetFeatureDisableDialogForTest());
base::RunLoop pref_waiter;
PrefChangeRegistrar change_observer;
change_observer.Init(prefs);
change_observer.Add(prefs::kAccessibilityFaceGazeEnabled,
pref_waiter.QuitClosure());
// Accepting the dialog should turn off FaceGaze.
controller->GetFeatureDisableDialogForTest()->Accept();
pref_waiter.Run();
}
} // namespace ash
|