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
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/accessibility/accessibility_controller_client.h"
#include <optional>
#include "ash/accessibility/accessibility_controller.h"
#include "ash/public/cpp/accessibility_controller_enums.h"
#include "ash/test/ash_test_base.h"
#include "base/time/time.h"
#include "chromeos/ash/components/audio/sounds.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/gfx/geometry/point_f.h"
namespace {
using ::ash::Sound;
constexpr base::TimeDelta kShutdownSoundDuration = base::Milliseconds(1000);
class FakeAccessibilityControllerClient : public AccessibilityControllerClient {
public:
FakeAccessibilityControllerClient() = default;
FakeAccessibilityControllerClient(const FakeAccessibilityControllerClient&) =
delete;
FakeAccessibilityControllerClient& operator=(
const FakeAccessibilityControllerClient&) = delete;
~FakeAccessibilityControllerClient() override = default;
// AccessibilityControllerClient:
void TriggerAccessibilityAlert(ash::AccessibilityAlert alert) override {
last_a11y_alert_ = alert;
}
void PlayEarcon(Sound sound_key) override { last_sound_key_ = sound_key; }
base::TimeDelta PlayShutdownSound() override {
return kShutdownSoundDuration;
}
void HandleAccessibilityGesture(ax::mojom::Gesture gesture,
gfx::PointF location) override {
last_a11y_gesture_ = gesture;
last_a11y_gesture_point_ = location;
}
bool ToggleDictation() override {
++toggle_dictation_count_;
dictation_on_ = !dictation_on_;
return dictation_on_;
}
void SilenceSpokenFeedback() override { ++silence_spoken_feedback_count_; }
bool ShouldToggleSpokenFeedbackViaTouch() const override { return true; }
void PlaySpokenFeedbackToggleCountdown(int tick_count) override {
spoken_feedback_toggle_count_down_ = tick_count;
}
void RequestSelectToSpeakStateChange() override {
++select_to_speak_state_changes_;
}
void OnSelectToSpeakPanelAction(ash::SelectToSpeakPanelAction action,
double value) override {
last_select_to_speak_panel_action_ = action;
last_select_to_speak_panel_value_ = value;
}
ash::AccessibilityAlert last_a11y_alert_ = ash::AccessibilityAlert::NONE;
std::optional<Sound> last_sound_key_;
ax::mojom::Gesture last_a11y_gesture_ = ax::mojom::Gesture::kNone;
gfx::PointF last_a11y_gesture_point_;
int toggle_dictation_count_ = 0;
int silence_spoken_feedback_count_ = 0;
int on_two_finger_touch_start_count_ = 0;
int on_two_finger_touch_stop_count_ = 0;
int spoken_feedback_toggle_count_down_ = -1;
int select_to_speak_state_changes_ = 0;
ash::SelectToSpeakPanelAction last_select_to_speak_panel_action_ =
ash::SelectToSpeakPanelAction::kNone;
double last_select_to_speak_panel_value_ = 0.0;
private:
bool dictation_on_ = false;
};
} // namespace
class AccessibilityControllerClientTest : public ash::AshTestBase {
public:
AccessibilityControllerClientTest() = default;
AccessibilityControllerClientTest(const AccessibilityControllerClientTest&) =
delete;
AccessibilityControllerClientTest& operator=(
const AccessibilityControllerClientTest&) = delete;
~AccessibilityControllerClientTest() override = default;
};
TEST_F(AccessibilityControllerClientTest, MethodCalls) {
FakeAccessibilityControllerClient client;
ash::AccessibilityController* controller =
ash::AccessibilityController::Get();
controller->SetClient(&client);
// Tests TriggerAccessibilityAlert method call.
const ash::AccessibilityAlert alert = ash::AccessibilityAlert::SCREEN_ON;
client.TriggerAccessibilityAlert(alert);
EXPECT_EQ(alert, client.last_a11y_alert_);
// Tests PlayEarcon method call.
const Sound sound_key = Sound::kShutdown;
client.PlayEarcon(sound_key);
EXPECT_EQ(sound_key, client.last_sound_key_);
// Tests PlayShutdownSound method call.
EXPECT_EQ(kShutdownSoundDuration, client.PlayShutdownSound());
// Tests HandleAccessibilityGesture method call.
ax::mojom::Gesture gesture = ax::mojom::Gesture::kClick;
gfx::PointF gesture_point(1, 1);
client.HandleAccessibilityGesture(gesture, gesture_point);
EXPECT_EQ(gesture, client.last_a11y_gesture_);
EXPECT_EQ(gesture_point, client.last_a11y_gesture_point_);
// Tests ToggleDictation method call.
EXPECT_EQ(0, client.toggle_dictation_count_);
EXPECT_TRUE(client.ToggleDictation());
EXPECT_EQ(1, client.toggle_dictation_count_);
EXPECT_EQ(0, client.silence_spoken_feedback_count_);
client.SilenceSpokenFeedback();
EXPECT_EQ(1, client.silence_spoken_feedback_count_);
// Tests ShouldToggleSpokenFeedbackViaTouch method call.
EXPECT_TRUE(client.ShouldToggleSpokenFeedbackViaTouch());
// Tests PlaySpokenFeedbackToggleCountdown method call.
const int tick_count = 2;
client.PlaySpokenFeedbackToggleCountdown(tick_count);
EXPECT_EQ(tick_count, client.spoken_feedback_toggle_count_down_);
// Tests RequestSelectToSpeakStateChange method call.
client.RequestSelectToSpeakStateChange();
EXPECT_EQ(1, client.select_to_speak_state_changes_);
// Tests OnSelectToSpeakPanelAction method call.
const ash::SelectToSpeakPanelAction action =
ash::SelectToSpeakPanelAction::kChangeSpeed;
double panel_value = 1.5;
client.OnSelectToSpeakPanelAction(action, panel_value);
EXPECT_EQ(action, client.last_select_to_speak_panel_action_);
EXPECT_EQ(panel_value, client.last_select_to_speak_panel_value_);
}
|