Commit 51b77306 authored by Qiang(Joe) Xu's avatar Qiang(Joe) Xu Committed by Commit Bot

Revert "mash: convert PlayEarcon/PlayShutdownSound through mojo call"

This reverts commit 09d525a9.

Reason for revert: revert for a clean revert of crrev.com/c/777780

Original change's description:
> mash: convert PlayEarcon/PlayShutdownSound through mojo call
> 
> changes:
> - Remove PlayEarcon/PlayShutdownSound from ash::AccessibilityDelegate.
>   Convert them calling into chrome through mojo call.
> - PlayShutdownSound gets shutdown sound duration asynchronously from
>   chrome in ash::AccessibilityController. Synchronize the real shutdown
>   timer's beginning when getting shutdown sound duration.
> 
> TBR=xiyuan@chromium.org
> 
> work when SpokenFeedbackEnabled is moved to ash. And add several test
> coverage.
> 
> Bug: 618070
> Test: tested on device without --mash, it works fine. --mash should
> Change-Id: I82b3ce684983e3de658e8d165f90a47cf754f4f6
> Reviewed-on: https://chromium-review.googlesource.com/773629
> Commit-Queue: Qiang(Joe) Xu <warx@chromium.org>
> Reviewed-by: Qiang(Joe) Xu <warx@chromium.org>
> Reviewed-by: James Cook <jamescook@chromium.org>
> Reviewed-by: Tom Sepez <tsepez@chromium.org>
> Reviewed-by: Dominic Mazzoni <dmazzoni@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#520441}

TBR=jamescook@chromium.org,xiyuan@chromium.org,dmazzoni@chromium.org,dtseng@chromium.org,tsepez@chromium.org,warx@chromium.org

Change-Id: I3673182425fa0cb4702036d326b83a275415d5de
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 618070, 790750
Reviewed-on: https://chromium-review.googlesource.com/802614Reviewed-by: default avatarQiang(Joe) Xu <warx@chromium.org>
Commit-Queue: Qiang(Joe) Xu <warx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520780}
parent 7102717f
...@@ -1712,6 +1712,8 @@ static_library("test_support_common") { ...@@ -1712,6 +1712,8 @@ static_library("test_support_common") {
sources = [ sources = [
"accessibility/test_accessibility_controller_client.cc", "accessibility/test_accessibility_controller_client.cc",
"accessibility/test_accessibility_controller_client.h", "accessibility/test_accessibility_controller_client.h",
"accessibility/test_accessibility_delegate.cc",
"accessibility/test_accessibility_delegate.h",
"app_list/test_app_list_presenter_impl.cc", "app_list/test_app_list_presenter_impl.cc",
"app_list/test_app_list_presenter_impl.h", "app_list/test_app_list_presenter_impl.h",
"display/display_configuration_controller_test_api.cc", "display/display_configuration_controller_test_api.cc",
......
...@@ -139,17 +139,6 @@ void AccessibilityController::TriggerAccessibilityAlert( ...@@ -139,17 +139,6 @@ void AccessibilityController::TriggerAccessibilityAlert(
client_->TriggerAccessibilityAlert(alert); client_->TriggerAccessibilityAlert(alert);
} }
void AccessibilityController::PlayEarcon(int32_t sound_key) {
if (client_)
client_->PlayEarcon(sound_key);
}
void AccessibilityController::PlayShutdownSound(
base::OnceCallback<void(base::TimeDelta)> callback) {
if (client_)
client_->PlayShutdownSound(std::move(callback));
}
void AccessibilityController::SetClient( void AccessibilityController::SetClient(
mojom::AccessibilityControllerClientPtr client) { mojom::AccessibilityControllerClientPtr client) {
client_ = std::move(client); client_ = std::move(client);
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "ash/public/interfaces/accessibility_controller.mojom.h" #include "ash/public/interfaces/accessibility_controller.mojom.h"
#include "ash/session/session_observer.h" #include "ash/session/session_observer.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/time/time.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
class PrefChangeRegistrar; class PrefChangeRegistrar;
...@@ -58,15 +57,6 @@ class ASH_EXPORT AccessibilityController ...@@ -58,15 +57,6 @@ class ASH_EXPORT AccessibilityController
// Triggers an accessibility alert to give the user feedback. // Triggers an accessibility alert to give the user feedback.
void TriggerAccessibilityAlert(mojom::AccessibilityAlert alert); void TriggerAccessibilityAlert(mojom::AccessibilityAlert alert);
// Plays an earcon. Earcons are brief and distinctive sounds that indicate
// that their mapped event has occurred. The |sound_key| enums can be found in
// chromeos/audio/chromeos_sounds.h.
void PlayEarcon(int32_t sound_key);
// Initiates play of shutdown sound. The base::TimeDelta parameter gets the
// shutdown duration.
void PlayShutdownSound(base::OnceCallback<void(base::TimeDelta)> callback);
// mojom::AccessibilityController: // mojom::AccessibilityController:
void SetClient(mojom::AccessibilityControllerClientPtr client) override; void SetClient(mojom::AccessibilityControllerClientPtr client) override;
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "ash/accessibility/accessibility_controller.h" #include "ash/accessibility/accessibility_controller.h"
#include "ash/accessibility/test_accessibility_controller_client.h"
#include "ash/ash_constants.h" #include "ash/ash_constants.h"
#include "ash/public/cpp/ash_pref_names.h" #include "ash/public/cpp/ash_pref_names.h"
#include "ash/session/session_controller.h" #include "ash/session/session_controller.h"
...@@ -16,10 +15,6 @@ ...@@ -16,10 +15,6 @@
namespace ash { namespace ash {
void CopyResult(base::TimeDelta* dest, base::TimeDelta src) {
*dest = src;
}
class TestAccessibilityObserver : public AccessibilityObserver { class TestAccessibilityObserver : public AccessibilityObserver {
public: public:
TestAccessibilityObserver() = default; TestAccessibilityObserver() = default;
...@@ -157,22 +152,6 @@ TEST_F(AccessibilityControllerTest, SetSpokenFeedbackEnabled) { ...@@ -157,22 +152,6 @@ TEST_F(AccessibilityControllerTest, SetSpokenFeedbackEnabled) {
Shell::Get()->system_tray_notifier()->RemoveAccessibilityObserver(&observer); Shell::Get()->system_tray_notifier()->RemoveAccessibilityObserver(&observer);
} }
// Tests that ash's controller gets shutdown sound duration properly from
// remote client.
TEST_F(AccessibilityControllerTest, GetShutdownSoundDuration) {
AccessibilityController* controller =
Shell::Get()->accessibility_controller();
TestAccessibilityControllerClient client;
controller->SetClient(client.CreateInterfacePtrAndBind());
base::TimeDelta sound_duration;
controller->PlayShutdownSound(
base::Bind(&CopyResult, base::Unretained(&sound_duration)));
controller->FlushMojoForTest();
EXPECT_EQ(TestAccessibilityControllerClient::kShutdownSoundDuration,
sound_duration);
}
using AccessibilityControllerSigninTest = NoSessionAshTestBase; using AccessibilityControllerSigninTest = NoSessionAshTestBase;
TEST_F(AccessibilityControllerSigninTest, SigninScreenPrefs) { TEST_F(AccessibilityControllerSigninTest, SigninScreenPrefs) {
......
...@@ -112,6 +112,14 @@ class ASH_EXPORT AccessibilityDelegate { ...@@ -112,6 +112,14 @@ class ASH_EXPORT AccessibilityDelegate {
// Play tick sound indicating spoken feedback will be toggled after countdown. // Play tick sound indicating spoken feedback will be toggled after countdown.
virtual void PlaySpokenFeedbackToggleCountdown(int tick_count) = 0; virtual void PlaySpokenFeedbackToggleCountdown(int tick_count) = 0;
// Plays an earcon. Earcons are brief and distinctive sounds that indicate
// when their mapped event has occurred. The sound key enums can be found in
// chromeos/audio/chromeos_sounds.h.
virtual void PlayEarcon(int sound_key) = 0;
// Initiates play of shutdown sound and returns it's duration.
virtual base::TimeDelta PlayShutdownSound() const = 0;
// Forward an accessibility gesture from the touch exploration controller to // Forward an accessibility gesture from the touch exploration controller to
// ChromeVox. // ChromeVox.
virtual void HandleAccessibilityGesture(ui::AXGesture gesture) = 0; virtual void HandleAccessibilityGesture(ui::AXGesture gesture) = 0;
......
...@@ -124,6 +124,12 @@ bool DefaultAccessibilityDelegate::ShouldToggleSpokenFeedbackViaTouch() { ...@@ -124,6 +124,12 @@ bool DefaultAccessibilityDelegate::ShouldToggleSpokenFeedbackViaTouch() {
void DefaultAccessibilityDelegate::PlaySpokenFeedbackToggleCountdown( void DefaultAccessibilityDelegate::PlaySpokenFeedbackToggleCountdown(
int tick_count) {} int tick_count) {}
void DefaultAccessibilityDelegate::PlayEarcon(int sound_key) {}
base::TimeDelta DefaultAccessibilityDelegate::PlayShutdownSound() const {
return base::TimeDelta();
}
void DefaultAccessibilityDelegate::HandleAccessibilityGesture( void DefaultAccessibilityDelegate::HandleAccessibilityGesture(
ui::AXGesture gesture) {} ui::AXGesture gesture) {}
......
...@@ -44,6 +44,8 @@ class ASH_EXPORT DefaultAccessibilityDelegate : public AccessibilityDelegate { ...@@ -44,6 +44,8 @@ class ASH_EXPORT DefaultAccessibilityDelegate : public AccessibilityDelegate {
double GetSavedScreenMagnifierScale() override; double GetSavedScreenMagnifierScale() override;
bool ShouldToggleSpokenFeedbackViaTouch() override; bool ShouldToggleSpokenFeedbackViaTouch() override;
void PlaySpokenFeedbackToggleCountdown(int tick_count) override; void PlaySpokenFeedbackToggleCountdown(int tick_count) override;
void PlayEarcon(int sound_key) override;
base::TimeDelta PlayShutdownSound() const override;
void HandleAccessibilityGesture(ui::AXGesture gesture) override; void HandleAccessibilityGesture(ui::AXGesture gesture) override;
private: private:
......
...@@ -6,9 +6,6 @@ ...@@ -6,9 +6,6 @@
namespace ash { namespace ash {
constexpr base::TimeDelta
TestAccessibilityControllerClient::kShutdownSoundDuration;
TestAccessibilityControllerClient::TestAccessibilityControllerClient() TestAccessibilityControllerClient::TestAccessibilityControllerClient()
: binding_(this) {} : binding_(this) {}
...@@ -27,19 +24,4 @@ void TestAccessibilityControllerClient::TriggerAccessibilityAlert( ...@@ -27,19 +24,4 @@ void TestAccessibilityControllerClient::TriggerAccessibilityAlert(
last_a11y_alert_ = alert; last_a11y_alert_ = alert;
} }
void TestAccessibilityControllerClient::PlayEarcon(int32_t sound_key) {
sound_key_ = sound_key;
}
void TestAccessibilityControllerClient::PlayShutdownSound(
PlayShutdownSoundCallback callback) {
std::move(callback).Run(kShutdownSoundDuration);
}
int32_t TestAccessibilityControllerClient::GetPlayedEarconAndReset() {
int32_t tmp = sound_key_;
sound_key_ = -1;
return tmp;
}
} // namespace ash } // namespace ash
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "ash/public/interfaces/accessibility_controller.mojom.h" #include "ash/public/interfaces/accessibility_controller.mojom.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/time/time.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
namespace ash { namespace ash {
...@@ -21,25 +20,16 @@ class TestAccessibilityControllerClient ...@@ -21,25 +20,16 @@ class TestAccessibilityControllerClient
TestAccessibilityControllerClient(); TestAccessibilityControllerClient();
~TestAccessibilityControllerClient() override; ~TestAccessibilityControllerClient() override;
static constexpr base::TimeDelta kShutdownSoundDuration =
base::TimeDelta::FromMilliseconds(1000);
mojom::AccessibilityControllerClientPtr CreateInterfacePtrAndBind(); mojom::AccessibilityControllerClientPtr CreateInterfacePtrAndBind();
// mojom::AccessibilityControllerClient: // mojom::AccessibilityControllerClient:
void TriggerAccessibilityAlert(mojom::AccessibilityAlert alert) override; void TriggerAccessibilityAlert(mojom::AccessibilityAlert alert) override;
void PlayEarcon(int32_t sound_key) override;
void PlayShutdownSound(PlayShutdownSoundCallback callback) override;
int32_t GetPlayedEarconAndReset();
mojom::AccessibilityAlert last_a11y_alert() const { return last_a11y_alert_; } mojom::AccessibilityAlert last_a11y_alert() const { return last_a11y_alert_; }
private: private:
mojom::AccessibilityAlert last_a11y_alert_ = mojom::AccessibilityAlert::NONE; mojom::AccessibilityAlert last_a11y_alert_ = mojom::AccessibilityAlert::NONE;
int32_t sound_key_ = -1;
mojo::Binding<mojom::AccessibilityControllerClient> binding_; mojo::Binding<mojom::AccessibilityControllerClient> binding_;
DISALLOW_COPY_AND_ASSIGN(TestAccessibilityControllerClient); DISALLOW_COPY_AND_ASSIGN(TestAccessibilityControllerClient);
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/accessibility/test_accessibility_delegate.h"
namespace ash {
void TestAccessibilityDelegate::PlayEarcon(int sound_key) {
sound_key_ = sound_key;
}
int TestAccessibilityDelegate::GetPlayedEarconAndReset() {
int tmp = sound_key_;
sound_key_ = -1;
return tmp;
}
} // namespace ash
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_ACCESSIBILITY_TEST_ACCESSIBILITY_DELEGATE_H_
#define ASH_ACCESSIBILITY_TEST_ACCESSIBILITY_DELEGATE_H_
#include "ash/accessibility/default_accessibility_delegate.h"
#include "base/macros.h"
namespace ash {
class TestAccessibilityDelegate : public DefaultAccessibilityDelegate {
public:
TestAccessibilityDelegate() {}
~TestAccessibilityDelegate() override {}
// AccessibilityDelegate:
void PlayEarcon(int sound_key) override;
int GetPlayedEarconAndReset();
private:
int sound_key_ = -1;
DISALLOW_COPY_AND_ASSIGN(TestAccessibilityDelegate);
};
} // namespace ash
#endif // ASH_ACCESSIBILITY_TEST_ACCESSIBILITY_DELEGATE_H_
...@@ -77,23 +77,23 @@ void AshTouchExplorationManager::PlayVolumeAdjustEarcon() { ...@@ -77,23 +77,23 @@ void AshTouchExplorationManager::PlayVolumeAdjustEarcon() {
return; return;
if (!audio_handler_->IsOutputMuted() && if (!audio_handler_->IsOutputMuted() &&
audio_handler_->GetOutputVolumePercent() != 100) { audio_handler_->GetOutputVolumePercent() != 100) {
Shell::Get()->accessibility_controller()->PlayEarcon( Shell::Get()->accessibility_delegate()->PlayEarcon(
chromeos::SOUND_VOLUME_ADJUST); chromeos::SOUND_VOLUME_ADJUST);
} }
} }
void AshTouchExplorationManager::PlayPassthroughEarcon() { void AshTouchExplorationManager::PlayPassthroughEarcon() {
Shell::Get()->accessibility_controller()->PlayEarcon( Shell::Get()->accessibility_delegate()->PlayEarcon(
chromeos::SOUND_PASSTHROUGH); chromeos::SOUND_PASSTHROUGH);
} }
void AshTouchExplorationManager::PlayExitScreenEarcon() { void AshTouchExplorationManager::PlayExitScreenEarcon() {
Shell::Get()->accessibility_controller()->PlayEarcon( Shell::Get()->accessibility_delegate()->PlayEarcon(
chromeos::SOUND_EXIT_SCREEN); chromeos::SOUND_EXIT_SCREEN);
} }
void AshTouchExplorationManager::PlayEnterScreenEarcon() { void AshTouchExplorationManager::PlayEnterScreenEarcon() {
Shell::Get()->accessibility_controller()->PlayEarcon( Shell::Get()->accessibility_delegate()->PlayEarcon(
chromeos::SOUND_ENTER_SCREEN); chromeos::SOUND_ENTER_SCREEN);
} }
...@@ -130,7 +130,7 @@ void AshTouchExplorationManager::PlaySpokenFeedbackToggleCountdown( ...@@ -130,7 +130,7 @@ void AshTouchExplorationManager::PlaySpokenFeedbackToggleCountdown(
} }
void AshTouchExplorationManager::PlayTouchTypeEarcon() { void AshTouchExplorationManager::PlayTouchTypeEarcon() {
Shell::Get()->accessibility_controller()->PlayEarcon( Shell::Get()->accessibility_delegate()->PlayEarcon(
chromeos::SOUND_TOUCH_TYPE); chromeos::SOUND_TOUCH_TYPE);
} }
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
module ash.mojom; module ash.mojom;
import "mojo/common/time.mojom";
// Alert sent to the accessibility api. // Alert sent to the accessibility api.
enum AccessibilityAlert { enum AccessibilityAlert {
// Default value, indicates no accessibility alert. // Default value, indicates no accessibility alert.
...@@ -49,14 +47,4 @@ interface AccessibilityController { ...@@ -49,14 +47,4 @@ interface AccessibilityController {
interface AccessibilityControllerClient { interface AccessibilityControllerClient {
// Triggers an accessibility alert to give the user feedback. // Triggers an accessibility alert to give the user feedback.
TriggerAccessibilityAlert(AccessibilityAlert alert); TriggerAccessibilityAlert(AccessibilityAlert alert);
// Plays an earcon. Earcons are brief and distinctive sounds that indicate
// that their mapped event has occurred. The |sound_key| enums can be found in
// chromeos/audio/chromeos_sounds.h. This method exists because the browser
// owns all media playback.
PlayEarcon(int32 sound_key);
// Initiates play of shutdown sound and returns sound duration. This method
// exists because the browser owns all media playback.
PlayShutdownSound() => (mojo.common.mojom.TimeDelta sound_duration);
}; };
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "ash/test_shell_delegate.h" #include "ash/test_shell_delegate.h"
#include "ash/accessibility/default_accessibility_delegate.h" #include "ash/accessibility/test_accessibility_delegate.h"
#include "ash/keyboard/test_keyboard_ui.h" #include "ash/keyboard/test_keyboard_ui.h"
#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/system_tray_notifier.h"
#include "ash/test_screenshot_delegate.h" #include "ash/test_screenshot_delegate.h"
...@@ -59,7 +59,7 @@ TestShellDelegate::CreateWallpaperDelegate() { ...@@ -59,7 +59,7 @@ TestShellDelegate::CreateWallpaperDelegate() {
} }
AccessibilityDelegate* TestShellDelegate::CreateAccessibilityDelegate() { AccessibilityDelegate* TestShellDelegate::CreateAccessibilityDelegate() {
return new DefaultAccessibilityDelegate; return new TestAccessibilityDelegate();
} }
base::string16 TestShellDelegate::GetProductName() const { base::string16 TestShellDelegate::GetProductName() const {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "ash/accessibility/accessibility_controller.h" #include "ash/accessibility/accessibility_delegate.h"
#include "ash/cancel_mode.h" #include "ash/cancel_mode.h"
#include "ash/public/cpp/shell_window_ids.h" #include "ash/public/cpp/shell_window_ids.h"
#include "ash/public/interfaces/shutdown.mojom.h" #include "ash/public/interfaces/shutdown.mojom.h"
...@@ -310,20 +310,18 @@ void LockStateController::StartRealShutdownTimer(bool with_animation_time) { ...@@ -310,20 +310,18 @@ void LockStateController::StartRealShutdownTimer(bool with_animation_time) {
duration += duration +=
animator_->GetDuration(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); animator_->GetDuration(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
} }
// Play and get shutdown sound duration from chrome in |sound_duration|. And
// start real shutdown after a delay of |duration|. base::TimeDelta sound_duration =
Shell::Get()->accessibility_controller()->PlayShutdownSound(base::BindOnce( Shell::Get()->accessibility_delegate()->PlayShutdownSound();
[](base::WeakPtr<LockStateController> self, base::TimeDelta duration, sound_duration =
base::TimeDelta sound_duration) { std::min(sound_duration,
sound_duration = std::min( base::TimeDelta::FromMilliseconds(kMaxShutdownSoundDurationMs));
sound_duration, duration = std::max(duration, sound_duration);
base::TimeDelta::FromMilliseconds(kMaxShutdownSoundDurationMs));
duration = std::max(duration, sound_duration); real_shutdown_timer_.Start(
self->real_shutdown_timer_.Start( FROM_HERE, duration,
FROM_HERE, duration, self.get(), base::Bind(&LockStateController::OnRealPowerTimeout,
&LockStateController::OnRealPowerTimeout); base::Unretained(this)));
},
weak_ptr_factory_.GetWeakPtr(), duration));
} }
void LockStateController::OnRealPowerTimeout() { void LockStateController::OnRealPowerTimeout() {
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "ash/accessibility/accessibility_controller.h"
#include "ash/accessibility/test_accessibility_controller_client.h"
#include "ash/public/cpp/ash_switches.h" #include "ash/public/cpp/ash_switches.h"
#include "ash/public/cpp/config.h" #include "ash/public/cpp/config.h"
#include "ash/session/session_controller.h" #include "ash/session/session_controller.h"
...@@ -76,9 +74,6 @@ class LockStateControllerTest : public PowerButtonTestBase { ...@@ -76,9 +74,6 @@ class LockStateControllerTest : public PowerButtonTestBase {
test_animator_ = new TestSessionStateAnimator; test_animator_ = new TestSessionStateAnimator;
lock_state_controller_->set_animator_for_test(test_animator_); lock_state_controller_->set_animator_for_test(test_animator_);
lock_state_test_api_->set_shutdown_controller(&test_shutdown_controller_); lock_state_test_api_->set_shutdown_controller(&test_shutdown_controller_);
a11y_controller_ = Shell::Get()->accessibility_controller();
a11y_controller_->SetClient(a11y_client_.CreateInterfacePtrAndBind());
} }
protected: protected:
...@@ -269,13 +264,8 @@ class LockStateControllerTest : public PowerButtonTestBase { ...@@ -269,13 +264,8 @@ class LockStateControllerTest : public PowerButtonTestBase {
lock_state_controller_->OnLockScreenHide(closure); lock_state_controller_->OnLockScreenHide(closure);
} }
// Simulate that shutdown sound duration callback is done.
void ShutdownSoundPlayed() { a11y_controller_->FlushMojoForTest(); }
TestShutdownController test_shutdown_controller_; TestShutdownController test_shutdown_controller_;
TestSessionStateAnimator* test_animator_ = nullptr; // not owned TestSessionStateAnimator* test_animator_ = nullptr; // not owned
AccessibilityController* a11y_controller_;
TestAccessibilityControllerClient a11y_client_;
private: private:
DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest); DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest);
...@@ -330,7 +320,6 @@ TEST_F(LockStateControllerTest, LegacyLockAndShutDown) { ...@@ -330,7 +320,6 @@ TEST_F(LockStateControllerTest, LegacyLockAndShutDown) {
if (Shell::GetAshConfig() != Config::MASH) if (Shell::GetAshConfig() != Config::MASH)
EXPECT_FALSE(cursor_visible()); EXPECT_FALSE(cursor_visible());
ShutdownSoundPlayed();
EXPECT_TRUE(lock_state_test_api_->real_shutdown_timer_is_running()); EXPECT_TRUE(lock_state_test_api_->real_shutdown_timer_is_running());
lock_state_test_api_->trigger_real_shutdown_timeout(); lock_state_test_api_->trigger_real_shutdown_timeout();
EXPECT_EQ(1, NumShutdownRequests()); EXPECT_EQ(1, NumShutdownRequests());
...@@ -344,7 +333,6 @@ TEST_F(LockStateControllerTest, LegacyNotLoggedIn) { ...@@ -344,7 +333,6 @@ TEST_F(LockStateControllerTest, LegacyNotLoggedIn) {
PressPowerButton(); PressPowerButton();
ExpectShutdownAnimationStarted(); ExpectShutdownAnimationStarted();
ShutdownSoundPlayed();
EXPECT_TRUE(lock_state_test_api_->real_shutdown_timer_is_running()); EXPECT_TRUE(lock_state_test_api_->real_shutdown_timer_is_running());
} }
...@@ -356,7 +344,6 @@ TEST_F(LockStateControllerTest, LegacyGuest) { ...@@ -356,7 +344,6 @@ TEST_F(LockStateControllerTest, LegacyGuest) {
PressPowerButton(); PressPowerButton();
ExpectShutdownAnimationStarted(); ExpectShutdownAnimationStarted();
ShutdownSoundPlayed();
EXPECT_TRUE(lock_state_test_api_->real_shutdown_timer_is_running()); EXPECT_TRUE(lock_state_test_api_->real_shutdown_timer_is_running());
} }
...@@ -391,7 +378,6 @@ TEST_F(LockStateControllerTest, ShutdownWhenNotLoggedIn) { ...@@ -391,7 +378,6 @@ TEST_F(LockStateControllerTest, ShutdownWhenNotLoggedIn) {
ExpectShutdownAnimationFinished(); ExpectShutdownAnimationFinished();
lock_state_test_api_->trigger_shutdown_timeout(); lock_state_test_api_->trigger_shutdown_timeout();
ShutdownSoundPlayed();
EXPECT_TRUE(lock_state_test_api_->real_shutdown_timer_is_running()); EXPECT_TRUE(lock_state_test_api_->real_shutdown_timer_is_running());
EXPECT_EQ(0, NumShutdownRequests()); EXPECT_EQ(0, NumShutdownRequests());
...@@ -553,7 +539,6 @@ TEST_F(LockStateControllerTest, LockToShutdown) { ...@@ -553,7 +539,6 @@ TEST_F(LockStateControllerTest, LockToShutdown) {
ExpectShutdownAnimationFinished(); ExpectShutdownAnimationFinished();
lock_state_test_api_->trigger_shutdown_timeout(); lock_state_test_api_->trigger_shutdown_timeout();
ShutdownSoundPlayed();
EXPECT_TRUE(lock_state_test_api_->real_shutdown_timer_is_running()); EXPECT_TRUE(lock_state_test_api_->real_shutdown_timer_is_running());
EXPECT_EQ(0, NumShutdownRequests()); EXPECT_EQ(0, NumShutdownRequests());
lock_state_test_api_->trigger_real_shutdown_timeout(); lock_state_test_api_->trigger_real_shutdown_timeout();
...@@ -769,7 +754,6 @@ TEST_F(LockStateControllerTest, RequestShutdownFromLoginScreen) { ...@@ -769,7 +754,6 @@ TEST_F(LockStateControllerTest, RequestShutdownFromLoginScreen) {
EXPECT_FALSE(cursor_visible()); EXPECT_FALSE(cursor_visible());
EXPECT_EQ(0, NumShutdownRequests()); EXPECT_EQ(0, NumShutdownRequests());
ShutdownSoundPlayed();
EXPECT_TRUE(lock_state_test_api_->real_shutdown_timer_is_running()); EXPECT_TRUE(lock_state_test_api_->real_shutdown_timer_is_running());
lock_state_test_api_->trigger_real_shutdown_timeout(); lock_state_test_api_->trigger_real_shutdown_timeout();
EXPECT_EQ(1, NumShutdownRequests()); EXPECT_EQ(1, NumShutdownRequests());
...@@ -795,7 +779,6 @@ TEST_F(LockStateControllerTest, RequestShutdownFromLockScreen) { ...@@ -795,7 +779,6 @@ TEST_F(LockStateControllerTest, RequestShutdownFromLockScreen) {
EXPECT_FALSE(cursor_visible()); EXPECT_FALSE(cursor_visible());
EXPECT_EQ(0, NumShutdownRequests()); EXPECT_EQ(0, NumShutdownRequests());
ShutdownSoundPlayed();
EXPECT_TRUE(lock_state_test_api_->real_shutdown_timer_is_running()); EXPECT_TRUE(lock_state_test_api_->real_shutdown_timer_is_running());
lock_state_test_api_->trigger_real_shutdown_timeout(); lock_state_test_api_->trigger_real_shutdown_timeout();
EXPECT_EQ(1, NumShutdownRequests()); EXPECT_EQ(1, NumShutdownRequests());
......
...@@ -48,7 +48,7 @@ class BackdropEventHandler : public ui::EventHandler { ...@@ -48,7 +48,7 @@ class BackdropEventHandler : public ui::EventHandler {
case ui::ET_GESTURE_BEGIN: case ui::ET_GESTURE_BEGIN:
case ui::ET_SCROLL: case ui::ET_SCROLL:
case ui::ET_SCROLL_FLING_START: case ui::ET_SCROLL_FLING_START:
Shell::Get()->accessibility_controller()->PlayEarcon( Shell::Get()->accessibility_delegate()->PlayEarcon(
chromeos::SOUND_VOLUME_ADJUST); chromeos::SOUND_VOLUME_ADJUST);
break; break;
default: default:
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <utility> #include <utility>
#include "ash/accessibility/accessibility_controller.h" #include "ash/accessibility/accessibility_controller.h"
#include "ash/accessibility/test_accessibility_controller_client.h" #include "ash/accessibility/test_accessibility_delegate.h"
#include "ash/app_list/test_app_list_presenter_impl.h" #include "ash/app_list/test_app_list_presenter_impl.h"
#include "ash/frame/custom_frame_view_ash.h" #include "ash/frame/custom_frame_view_ash.h"
#include "ash/public/cpp/app_types.h" #include "ash/public/cpp/app_types.h"
...@@ -1302,10 +1302,9 @@ TEST_F(WorkspaceLayoutManagerBackdropTest, BackdropTest) { ...@@ -1302,10 +1302,9 @@ TEST_F(WorkspaceLayoutManagerBackdropTest, BackdropTest) {
TEST_F(WorkspaceLayoutManagerBackdropTest, SpokenFeedbackFullscreenBackground) { TEST_F(WorkspaceLayoutManagerBackdropTest, SpokenFeedbackFullscreenBackground) {
WorkspaceController* wc = ShellTestApi(Shell::Get()).workspace_controller(); WorkspaceController* wc = ShellTestApi(Shell::Get()).workspace_controller();
WorkspaceControllerTestApi test_helper(wc); WorkspaceControllerTestApi test_helper(wc);
AccessibilityController* controller = TestAccessibilityDelegate* accessibility_delegate =
Shell::Get()->accessibility_controller(); static_cast<TestAccessibilityDelegate*>(
TestAccessibilityControllerClient client; Shell::Get()->accessibility_delegate());
controller->SetClient(client.CreateInterfacePtrAndBind());
aura::test::TestWindowDelegate delegate; aura::test::TestWindowDelegate delegate;
std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
...@@ -1319,27 +1318,26 @@ TEST_F(WorkspaceLayoutManagerBackdropTest, SpokenFeedbackFullscreenBackground) { ...@@ -1319,27 +1318,26 @@ TEST_F(WorkspaceLayoutManagerBackdropTest, SpokenFeedbackFullscreenBackground) {
generator.MoveMouseTo(300, 300); generator.MoveMouseTo(300, 300);
generator.ClickLeftButton(); generator.ClickLeftButton();
controller->FlushMojoForTest(); EXPECT_EQ(kNoSoundKey, accessibility_delegate->GetPlayedEarconAndReset());
EXPECT_EQ(kNoSoundKey, client.GetPlayedEarconAndReset());
generator.MoveMouseRelativeTo(window.get(), 10, 10); generator.MoveMouseRelativeTo(window.get(), 10, 10);
generator.ClickLeftButton(); generator.ClickLeftButton();
controller->FlushMojoForTest(); EXPECT_EQ(kNoSoundKey, accessibility_delegate->GetPlayedEarconAndReset());
EXPECT_EQ(kNoSoundKey, client.GetPlayedEarconAndReset());
// Enable spoken feedback. // Enable spoken feedback.
AccessibilityController* controller =
Shell::Get()->accessibility_controller();
controller->SetSpokenFeedbackEnabled(true, A11Y_NOTIFICATION_NONE); controller->SetSpokenFeedbackEnabled(true, A11Y_NOTIFICATION_NONE);
EXPECT_TRUE(controller->IsSpokenFeedbackEnabled()); EXPECT_TRUE(controller->IsSpokenFeedbackEnabled());
generator.MoveMouseTo(300, 300); generator.MoveMouseTo(300, 300);
generator.ClickLeftButton(); generator.ClickLeftButton();
controller->FlushMojoForTest(); EXPECT_EQ(chromeos::SOUND_VOLUME_ADJUST,
EXPECT_EQ(chromeos::SOUND_VOLUME_ADJUST, client.GetPlayedEarconAndReset()); accessibility_delegate->GetPlayedEarconAndReset());
generator.MoveMouseRelativeTo(window.get(), 10, 10); generator.MoveMouseRelativeTo(window.get(), 10, 10);
generator.ClickLeftButton(); generator.ClickLeftButton();
controller->FlushMojoForTest(); EXPECT_EQ(kNoSoundKey, accessibility_delegate->GetPlayedEarconAndReset());
EXPECT_EQ(kNoSoundKey, client.GetPlayedEarconAndReset());
// Disable spoken feedback. Shadow underlay is restored. // Disable spoken feedback. Shadow underlay is restored.
controller->SetSpokenFeedbackEnabled(false, A11Y_NOTIFICATION_NONE); controller->SetSpokenFeedbackEnabled(false, A11Y_NOTIFICATION_NONE);
...@@ -1347,13 +1345,11 @@ TEST_F(WorkspaceLayoutManagerBackdropTest, SpokenFeedbackFullscreenBackground) { ...@@ -1347,13 +1345,11 @@ TEST_F(WorkspaceLayoutManagerBackdropTest, SpokenFeedbackFullscreenBackground) {
generator.MoveMouseTo(300, 300); generator.MoveMouseTo(300, 300);
generator.ClickLeftButton(); generator.ClickLeftButton();
controller->FlushMojoForTest(); EXPECT_EQ(kNoSoundKey, accessibility_delegate->GetPlayedEarconAndReset());
EXPECT_EQ(kNoSoundKey, client.GetPlayedEarconAndReset());
generator.MoveMouseTo(70, 70); generator.MoveMouseTo(70, 70);
generator.ClickLeftButton(); generator.ClickLeftButton();
controller->FlushMojoForTest(); EXPECT_EQ(kNoSoundKey, accessibility_delegate->GetPlayedEarconAndReset());
EXPECT_EQ(kNoSoundKey, client.GetPlayedEarconAndReset());
} }
TEST_F(WorkspaceLayoutManagerBackdropTest, TEST_F(WorkspaceLayoutManagerBackdropTest,
...@@ -1436,10 +1432,11 @@ TEST_F(WorkspaceLayoutManagerBackdropTest, ...@@ -1436,10 +1432,11 @@ TEST_F(WorkspaceLayoutManagerBackdropTest,
TEST_F(WorkspaceLayoutManagerBackdropTest, SpokenFeedbackForArc) { TEST_F(WorkspaceLayoutManagerBackdropTest, SpokenFeedbackForArc) {
WorkspaceController* wc = ShellTestApi(Shell::Get()).workspace_controller(); WorkspaceController* wc = ShellTestApi(Shell::Get()).workspace_controller();
WorkspaceControllerTestApi test_helper(wc); WorkspaceControllerTestApi test_helper(wc);
TestAccessibilityDelegate* accessibility_delegate =
static_cast<TestAccessibilityDelegate*>(
Shell::Get()->accessibility_delegate());
AccessibilityController* controller = AccessibilityController* controller =
Shell::Get()->accessibility_controller(); Shell::Get()->accessibility_controller();
TestAccessibilityControllerClient client;
controller->SetClient(client.CreateInterfacePtrAndBind());
controller->SetSpokenFeedbackEnabled(true, A11Y_NOTIFICATION_NONE); controller->SetSpokenFeedbackEnabled(true, A11Y_NOTIFICATION_NONE);
EXPECT_TRUE(controller->IsSpokenFeedbackEnabled()); EXPECT_TRUE(controller->IsSpokenFeedbackEnabled());
...@@ -1471,13 +1468,12 @@ TEST_F(WorkspaceLayoutManagerBackdropTest, SpokenFeedbackForArc) { ...@@ -1471,13 +1468,12 @@ TEST_F(WorkspaceLayoutManagerBackdropTest, SpokenFeedbackForArc) {
ui::test::EventGenerator& generator = GetEventGenerator(); ui::test::EventGenerator& generator = GetEventGenerator();
generator.MoveMouseTo(300, 300); generator.MoveMouseTo(300, 300);
generator.ClickLeftButton(); generator.ClickLeftButton();
controller->FlushMojoForTest(); EXPECT_EQ(chromeos::SOUND_VOLUME_ADJUST,
EXPECT_EQ(chromeos::SOUND_VOLUME_ADJUST, client.GetPlayedEarconAndReset()); accessibility_delegate->GetPlayedEarconAndReset());
generator.MoveMouseTo(70, 70); generator.MoveMouseTo(70, 70);
generator.ClickLeftButton(); generator.ClickLeftButton();
controller->FlushMojoForTest(); EXPECT_EQ(kNoSoundKey, accessibility_delegate->GetPlayedEarconAndReset());
EXPECT_EQ(kNoSoundKey, client.GetPlayedEarconAndReset());
} }
class WorkspaceLayoutManagerKeyboardTest : public AshTestBase { class WorkspaceLayoutManagerKeyboardTest : public AshTestBase {
......
...@@ -101,11 +101,11 @@ namespace chromeos { ...@@ -101,11 +101,11 @@ namespace chromeos {
namespace { namespace {
// When this flag is set, system sounds will not be played. // When this flag is set, system sounds will not be played.
constexpr char kAshDisableSystemSounds[] = "ash-disable-system-sounds"; const char kAshDisableSystemSounds[] = "ash-disable-system-sounds";
static chromeos::AccessibilityManager* g_accessibility_manager = nullptr; static chromeos::AccessibilityManager* g_accessibility_manager = NULL;
static BrailleController* g_braille_controller_for_test = nullptr; static BrailleController* g_braille_controller_for_test = NULL;
BrailleController* GetBrailleController() { BrailleController* GetBrailleController() {
if (g_braille_controller_for_test) if (g_braille_controller_for_test)
...@@ -527,7 +527,7 @@ bool AccessibilityManager::PlayEarcon(int sound_key, PlaySoundOption option) { ...@@ -527,7 +527,7 @@ bool AccessibilityManager::PlayEarcon(int sound_key, PlaySoundOption option) {
base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
if (cl->HasSwitch(kAshDisableSystemSounds)) if (cl->HasSwitch(kAshDisableSystemSounds))
return false; return false;
if (option == PlaySoundOption::ONLY_IF_SPOKEN_FEEDBACK_ENABLED && if (option == PlaySoundOption::SPOKEN_FEEDBACK_ENABLED &&
!IsSpokenFeedbackEnabled()) { !IsSpokenFeedbackEnabled()) {
return false; return false;
} }
...@@ -1239,10 +1239,8 @@ void AccessibilityManager::SetBrailleControllerForTest( ...@@ -1239,10 +1239,8 @@ void AccessibilityManager::SetBrailleControllerForTest(
} }
base::TimeDelta AccessibilityManager::PlayShutdownSound() { base::TimeDelta AccessibilityManager::PlayShutdownSound() {
if (!PlayEarcon(SOUND_SHUTDOWN, if (!PlayEarcon(SOUND_SHUTDOWN, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED))
PlaySoundOption::ONLY_IF_SPOKEN_FEEDBACK_ENABLED)) {
return base::TimeDelta(); return base::TimeDelta();
}
return media::SoundsManager::Get()->GetDuration(SOUND_SHUTDOWN); return media::SoundsManager::Get()->GetDuration(SOUND_SHUTDOWN);
} }
...@@ -1444,7 +1442,6 @@ void AccessibilityManager::PostLoadChromeVox() { ...@@ -1444,7 +1442,6 @@ void AccessibilityManager::PostLoadChromeVox() {
void AccessibilityManager::PostUnloadChromeVox() { void AccessibilityManager::PostUnloadChromeVox() {
// Do any teardown work needed immediately after ChromeVox actually unloads. // Do any teardown work needed immediately after ChromeVox actually unloads.
PlayEarcon(SOUND_SPOKEN_FEEDBACK_DISABLED, PlaySoundOption::ALWAYS); PlayEarcon(SOUND_SPOKEN_FEEDBACK_DISABLED, PlaySoundOption::ALWAYS);
// Clear the accessibility focus ring. // Clear the accessibility focus ring.
ash::AccessibilityFocusRingController::GetInstance()->SetFocusRing( ash::AccessibilityFocusRingController::GetInstance()->SetFocusRing(
std::vector<gfx::Rect>(), std::vector<gfx::Rect>(),
......
...@@ -79,12 +79,10 @@ typedef AccessibilityStatusCallbackList::Subscription ...@@ -79,12 +79,10 @@ typedef AccessibilityStatusCallbackList::Subscription
class ChromeVoxPanelWidgetObserver; class ChromeVoxPanelWidgetObserver;
enum class PlaySoundOption { enum class PlaySoundOption {
// The sound is always played. ALWAYS = 0, // The sound is always played.
ALWAYS = 0, SPOKEN_FEEDBACK_ENABLED, // The sound is played only if spoken feedback is
// enabled, or --ash-enable-system-sounds flag is
// The sound is played only if spoken feedback is enabled, or // used.
// --ash-enable-system-sounds flag is used.
ONLY_IF_SPOKEN_FEEDBACK_ENABLED,
}; };
// AccessibilityManager changes the statuses of accessibility features // AccessibilityManager changes the statuses of accessibility features
...@@ -263,7 +261,7 @@ class AccessibilityManager ...@@ -263,7 +261,7 @@ class AccessibilityManager
void OnViewFocusedInArc(const gfx::Rect& bounds_in_screen); void OnViewFocusedInArc(const gfx::Rect& bounds_in_screen);
// Plays an earcon. Earcons are brief and distinctive sounds that indicate // Plays an earcon. Earcons are brief and distinctive sounds that indicate
// the their mapped event has occurred. The |sound_key| enums can be found in // when their mapped event has occurred. The sound key enums can be found in
// chromeos/audio/chromeos_sounds.h. // chromeos/audio/chromeos_sounds.h.
bool PlayEarcon(int sound_key, PlaySoundOption option); bool PlayEarcon(int sound_key, PlaySoundOption option);
......
...@@ -434,7 +434,7 @@ void ScreenLocker::OnStartLockCallback(bool locked) { ...@@ -434,7 +434,7 @@ void ScreenLocker::OnStartLockCallback(bool locked) {
delegate_->OnAshLockAnimationFinished(); delegate_->OnAshLockAnimationFinished();
AccessibilityManager::Get()->PlayEarcon( AccessibilityManager::Get()->PlayEarcon(
SOUND_LOCK, PlaySoundOption::ONLY_IF_SPOKEN_FEEDBACK_ENABLED); chromeos::SOUND_LOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED);
} }
void ScreenLocker::ClearErrors() { void ScreenLocker::ClearErrors() {
...@@ -560,7 +560,7 @@ void ScreenLocker::ScheduleDeletion() { ...@@ -560,7 +560,7 @@ void ScreenLocker::ScheduleDeletion() {
VLOG(1) << "Deleting ScreenLocker " << screen_locker_; VLOG(1) << "Deleting ScreenLocker " << screen_locker_;
AccessibilityManager::Get()->PlayEarcon( AccessibilityManager::Get()->PlayEarcon(
SOUND_UNLOCK, PlaySoundOption::ONLY_IF_SPOKEN_FEEDBACK_ENABLED); SOUND_UNLOCK, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED);
delete screen_locker_; delete screen_locker_;
screen_locker_ = nullptr; screen_locker_ = nullptr;
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "chrome/browser/ui/ash/accessibility/accessibility_controller_client.h" #include "chrome/browser/ui/ash/accessibility/accessibility_controller_client.h"
#include "ash/public/interfaces/constants.mojom.h" #include "ash/public/interfaces/constants.mojom.h"
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h" #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -15,6 +14,8 @@ ...@@ -15,6 +14,8 @@
namespace { namespace {
AccessibilityControllerClient* g_instance = nullptr;
void SetAutomationManagerEnabled(content::BrowserContext* context, void SetAutomationManagerEnabled(content::BrowserContext* context,
bool enabled) { bool enabled) {
DCHECK(context); DCHECK(context);
...@@ -28,9 +29,20 @@ void SetAutomationManagerEnabled(content::BrowserContext* context, ...@@ -28,9 +29,20 @@ void SetAutomationManagerEnabled(content::BrowserContext* context,
} // namespace } // namespace
AccessibilityControllerClient::AccessibilityControllerClient() AccessibilityControllerClient::AccessibilityControllerClient()
: binding_(this) {} : binding_(this) {
DCHECK(!g_instance);
g_instance = this;
}
AccessibilityControllerClient::~AccessibilityControllerClient() = default; AccessibilityControllerClient::~AccessibilityControllerClient() {
DCHECK_EQ(this, g_instance);
g_instance = nullptr;
}
// static
AccessibilityControllerClient* AccessibilityControllerClient::Get() {
return g_instance;
}
void AccessibilityControllerClient::Init() { void AccessibilityControllerClient::Init() {
content::ServiceManagerConnection::GetForProcess() content::ServiceManagerConnection::GetForProcess()
...@@ -47,6 +59,8 @@ void AccessibilityControllerClient::InitForTesting( ...@@ -47,6 +59,8 @@ void AccessibilityControllerClient::InitForTesting(
void AccessibilityControllerClient::TriggerAccessibilityAlert( void AccessibilityControllerClient::TriggerAccessibilityAlert(
ash::mojom::AccessibilityAlert alert) { ash::mojom::AccessibilityAlert alert) {
last_a11y_alert_for_test_ = alert;
Profile* profile = ProfileManager::GetActiveUserProfile(); Profile* profile = ProfileManager::GetActiveUserProfile();
if (!profile) if (!profile)
return; return;
...@@ -101,18 +115,6 @@ void AccessibilityControllerClient::TriggerAccessibilityAlert( ...@@ -101,18 +115,6 @@ void AccessibilityControllerClient::TriggerAccessibilityAlert(
} }
} }
void AccessibilityControllerClient::PlayEarcon(int32_t sound_key) {
chromeos::AccessibilityManager::Get()->PlayEarcon(
sound_key, chromeos::PlaySoundOption::ONLY_IF_SPOKEN_FEEDBACK_ENABLED);
}
void AccessibilityControllerClient::PlayShutdownSound(
PlayShutdownSoundCallback callback) {
base::TimeDelta sound_duration =
chromeos::AccessibilityManager::Get()->PlayShutdownSound();
std::move(callback).Run(sound_duration);
}
void AccessibilityControllerClient::FlushForTesting() { void AccessibilityControllerClient::FlushForTesting() {
accessibility_controller_.FlushForTesting(); accessibility_controller_.FlushForTesting();
} }
......
...@@ -16,6 +16,8 @@ class AccessibilityControllerClient ...@@ -16,6 +16,8 @@ class AccessibilityControllerClient
AccessibilityControllerClient(); AccessibilityControllerClient();
~AccessibilityControllerClient() override; ~AccessibilityControllerClient() override;
static AccessibilityControllerClient* Get();
// Initializes and connects to ash. // Initializes and connects to ash.
void Init(); void Init();
...@@ -24,12 +26,14 @@ class AccessibilityControllerClient ...@@ -24,12 +26,14 @@ class AccessibilityControllerClient
// ash::mojom::AccessibilityControllerClient: // ash::mojom::AccessibilityControllerClient:
void TriggerAccessibilityAlert(ash::mojom::AccessibilityAlert alert) override; void TriggerAccessibilityAlert(ash::mojom::AccessibilityAlert alert) override;
void PlayEarcon(int32_t sound_key) override;
void PlayShutdownSound(PlayShutdownSoundCallback callback) override;
// Flushes the mojo pipe to ash. // Flushes the mojo pipe to ash.
void FlushForTesting(); void FlushForTesting();
ash::mojom::AccessibilityAlert last_a11y_alert_for_test() const {
return last_a11y_alert_for_test_;
}
private: private:
// Binds this object to its mojo interface and sets it as the ash client. // Binds this object to its mojo interface and sets it as the ash client.
void BindAndSetClient(); void BindAndSetClient();
...@@ -41,6 +45,9 @@ class AccessibilityControllerClient ...@@ -41,6 +45,9 @@ class AccessibilityControllerClient
// keeps the pipe alive to receive mojo return values. // keeps the pipe alive to receive mojo return values.
ash::mojom::AccessibilityControllerPtr accessibility_controller_; ash::mojom::AccessibilityControllerPtr accessibility_controller_;
ash::mojom::AccessibilityAlert last_a11y_alert_for_test_ =
ash::mojom::AccessibilityAlert::NONE;
DISALLOW_COPY_AND_ASSIGN(AccessibilityControllerClient); DISALLOW_COPY_AND_ASSIGN(AccessibilityControllerClient);
}; };
......
...@@ -6,22 +6,12 @@ ...@@ -6,22 +6,12 @@
#include "ash/public/interfaces/accessibility_controller.mojom.h" #include "ash/public/interfaces/accessibility_controller.mojom.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/run_loop.h"
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "base/time/time.h"
#include "chromeos/audio/chromeos_sounds.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace { namespace {
constexpr base::TimeDelta kShutdownSoundDuration =
base::TimeDelta::FromMilliseconds(1000);
void CopyResult(base::TimeDelta* dest, base::TimeDelta src) {
*dest = src;
}
class TestAccessibilityController : ash::mojom::AccessibilityController { class TestAccessibilityController : ash::mojom::AccessibilityController {
public: public:
TestAccessibilityController() : binding_(this) {} TestAccessibilityController() : binding_(this) {}
...@@ -47,36 +37,6 @@ class TestAccessibilityController : ash::mojom::AccessibilityController { ...@@ -47,36 +37,6 @@ class TestAccessibilityController : ash::mojom::AccessibilityController {
DISALLOW_COPY_AND_ASSIGN(TestAccessibilityController); DISALLOW_COPY_AND_ASSIGN(TestAccessibilityController);
}; };
class FakeAccessibilityControllerClient : public AccessibilityControllerClient {
public:
FakeAccessibilityControllerClient() = default;
~FakeAccessibilityControllerClient() override = default;
// AccessibilityControllerClient:
void TriggerAccessibilityAlert(
ash::mojom::AccessibilityAlert alert) override {
last_a11y_alert_ = alert;
}
void PlayEarcon(int32_t sound_key) override { last_sound_key_ = sound_key; }
void PlayShutdownSound(PlayShutdownSoundCallback callback) override {
std::move(callback).Run(kShutdownSoundDuration);
}
ash::mojom::AccessibilityAlert last_a11y_alert() const {
return last_a11y_alert_;
}
int32_t last_sound_key() const { return last_sound_key_; }
private:
ash::mojom::AccessibilityAlert last_a11y_alert_ =
ash::mojom::AccessibilityAlert::NONE;
int32_t last_sound_key_ = -1;
DISALLOW_COPY_AND_ASSIGN(FakeAccessibilityControllerClient);
};
} // namespace } // namespace
class AccessibilityControllerClientTest : public testing::Test { class AccessibilityControllerClientTest : public testing::Test {
...@@ -90,30 +50,19 @@ class AccessibilityControllerClientTest : public testing::Test { ...@@ -90,30 +50,19 @@ class AccessibilityControllerClientTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(AccessibilityControllerClientTest); DISALLOW_COPY_AND_ASSIGN(AccessibilityControllerClientTest);
}; };
TEST_F(AccessibilityControllerClientTest, MethodCalls) { TEST_F(AccessibilityControllerClientTest, TriggerAccessibilityAlert) {
FakeAccessibilityControllerClient client; AccessibilityControllerClient client;
TestAccessibilityController controller; TestAccessibilityController controller;
client.InitForTesting(controller.CreateInterfacePtr()); client.InitForTesting(controller.CreateInterfacePtr());
client.FlushForTesting(); client.FlushForTesting();
// Tests client is set. // Tests that singleton was initialized and client is set.
EXPECT_EQ(&client, AccessibilityControllerClient::Get());
EXPECT_TRUE(controller.was_client_set()); EXPECT_TRUE(controller.was_client_set());
// Tests TriggerAccessibilityAlert method call. // Tests TriggerAccessibilityAlert method call.
const ash::mojom::AccessibilityAlert alert = const ash::mojom::AccessibilityAlert alert =
ash::mojom::AccessibilityAlert::SCREEN_ON; ash::mojom::AccessibilityAlert::SCREEN_ON;
client.TriggerAccessibilityAlert(alert); client.TriggerAccessibilityAlert(alert);
EXPECT_EQ(alert, client.last_a11y_alert()); EXPECT_EQ(alert, client.last_a11y_alert_for_test());
}
// Tests PlayEarcon method call. \ No newline at end of file
const int32_t sound_key = chromeos::SOUND_SHUTDOWN;
client.PlayEarcon(sound_key);
EXPECT_EQ(sound_key, client.last_sound_key());
// Tests PlayShutdownSound method call.
base::TimeDelta sound_duration;
client.PlayShutdownSound(
base::Bind(&CopyResult, base::Unretained(&sound_duration)));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(kShutdownSoundDuration, sound_duration);
}
...@@ -250,6 +250,16 @@ class AccessibilityDelegateImpl : public ash::AccessibilityDelegate { ...@@ -250,6 +250,16 @@ class AccessibilityDelegateImpl : public ash::AccessibilityDelegate {
AccessibilityManager::Get()->PlaySpokenFeedbackToggleCountdown(tick_count); AccessibilityManager::Get()->PlaySpokenFeedbackToggleCountdown(tick_count);
} }
void PlayEarcon(int sound_key) override {
DCHECK(AccessibilityManager::Get());
AccessibilityManager::Get()->PlayEarcon(
sound_key, chromeos::PlaySoundOption::SPOKEN_FEEDBACK_ENABLED);
}
base::TimeDelta PlayShutdownSound() const override {
return AccessibilityManager::Get()->PlayShutdownSound();
}
void HandleAccessibilityGesture(ui::AXGesture gesture) override { void HandleAccessibilityGesture(ui::AXGesture gesture) override {
AccessibilityManager::Get()->HandleAccessibilityGesture(gesture); AccessibilityManager::Get()->HandleAccessibilityGesture(gesture);
} }
......
...@@ -31,7 +31,7 @@ void PlayVolumeAdjustSound() { ...@@ -31,7 +31,7 @@ void PlayVolumeAdjustSound() {
if (VolumeAdjustSoundEnabled()) { if (VolumeAdjustSoundEnabled()) {
chromeos::AccessibilityManager::Get()->PlayEarcon( chromeos::AccessibilityManager::Get()->PlayEarcon(
chromeos::SOUND_VOLUME_ADJUST, chromeos::SOUND_VOLUME_ADJUST,
chromeos::PlaySoundOption::ONLY_IF_SPOKEN_FEEDBACK_ENABLED); chromeos::PlaySoundOption::SPOKEN_FEEDBACK_ENABLED);
} }
} }
......
...@@ -423,12 +423,12 @@ void SupervisedUserCreationScreenHandler::HandlePhotoTaken ...@@ -423,12 +423,12 @@ void SupervisedUserCreationScreenHandler::HandlePhotoTaken
void SupervisedUserCreationScreenHandler::HandleTakePhoto() { void SupervisedUserCreationScreenHandler::HandleTakePhoto() {
AccessibilityManager::Get()->PlayEarcon( AccessibilityManager::Get()->PlayEarcon(
SOUND_CAMERA_SNAP, PlaySoundOption::ONLY_IF_SPOKEN_FEEDBACK_ENABLED); SOUND_CAMERA_SNAP, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED);
} }
void SupervisedUserCreationScreenHandler::HandleDiscardPhoto() { void SupervisedUserCreationScreenHandler::HandleDiscardPhoto() {
AccessibilityManager::Get()->PlayEarcon( AccessibilityManager::Get()->PlayEarcon(
SOUND_OBJECT_DELETE, PlaySoundOption::ONLY_IF_SPOKEN_FEEDBACK_ENABLED); SOUND_OBJECT_DELETE, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED);
} }
void SupervisedUserCreationScreenHandler::HandleSelectImage( void SupervisedUserCreationScreenHandler::HandleSelectImage(
......
...@@ -136,7 +136,7 @@ void UserImageScreenHandler::HandleScreenReady() { ...@@ -136,7 +136,7 @@ void UserImageScreenHandler::HandleScreenReady() {
void UserImageScreenHandler::HandlePhotoTaken(const std::string& image_url) { void UserImageScreenHandler::HandlePhotoTaken(const std::string& image_url) {
AccessibilityManager::Get()->PlayEarcon( AccessibilityManager::Get()->PlayEarcon(
SOUND_CAMERA_SNAP, PlaySoundOption::ONLY_IF_SPOKEN_FEEDBACK_ENABLED); SOUND_CAMERA_SNAP, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED);
std::string raw_data; std::string raw_data;
base::StringPiece url(image_url); base::StringPiece url(image_url);
...@@ -154,7 +154,7 @@ void UserImageScreenHandler::HandlePhotoTaken(const std::string& image_url) { ...@@ -154,7 +154,7 @@ void UserImageScreenHandler::HandlePhotoTaken(const std::string& image_url) {
void UserImageScreenHandler::HandleDiscardPhoto() { void UserImageScreenHandler::HandleDiscardPhoto() {
AccessibilityManager::Get()->PlayEarcon( AccessibilityManager::Get()->PlayEarcon(
SOUND_OBJECT_DELETE, PlaySoundOption::ONLY_IF_SPOKEN_FEEDBACK_ENABLED); SOUND_OBJECT_DELETE, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED);
} }
void UserImageScreenHandler::HandleSelectImage(const std::string& image_type, void UserImageScreenHandler::HandleSelectImage(const std::string& image_type,
......
...@@ -164,13 +164,13 @@ void ChangePictureHandler::HandleChooseFile(const base::ListValue* args) { ...@@ -164,13 +164,13 @@ void ChangePictureHandler::HandleChooseFile(const base::ListValue* args) {
void ChangePictureHandler::HandleDiscardPhoto(const base::ListValue* args) { void ChangePictureHandler::HandleDiscardPhoto(const base::ListValue* args) {
DCHECK(args->empty()); DCHECK(args->empty());
AccessibilityManager::Get()->PlayEarcon( AccessibilityManager::Get()->PlayEarcon(
SOUND_OBJECT_DELETE, PlaySoundOption::ONLY_IF_SPOKEN_FEEDBACK_ENABLED); SOUND_OBJECT_DELETE, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED);
} }
void ChangePictureHandler::HandlePhotoTaken(const base::ListValue* args) { void ChangePictureHandler::HandlePhotoTaken(const base::ListValue* args) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
AccessibilityManager::Get()->PlayEarcon( AccessibilityManager::Get()->PlayEarcon(
SOUND_CAMERA_SNAP, PlaySoundOption::ONLY_IF_SPOKEN_FEEDBACK_ENABLED); SOUND_CAMERA_SNAP, PlaySoundOption::SPOKEN_FEEDBACK_ENABLED);
std::string image_url; std::string image_url;
if (!args || args->GetSize() != 1 || !args->GetString(0, &image_url)) if (!args || args->GetSize() != 1 || !args->GetString(0, &image_url))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment