OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <queue> |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/strings/string_util.h" |
| 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 11 #include "chrome/browser/chromeos/login/login_display_host.h" |
| 12 #include "chrome/browser/chromeos/login/login_display_host_impl.h" |
| 13 #include "chrome/browser/chromeos/login/user_manager.h" |
| 14 #include "chrome/browser/chromeos/login/webui_login_view.h" |
| 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 16 #include "chrome/browser/extensions/api/braille_display_private/stub_braille_con
troller.h" |
| 17 #include "chrome/browser/speech/tts_controller.h" |
| 18 #include "chrome/browser/speech/tts_platform.h" |
| 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_commands.h" |
| 21 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/test/base/in_process_browser_test.h" |
| 23 #include "chrome/test/base/testing_profile.h" |
| 24 #include "chrome/test/base/ui_test_utils.h" |
| 25 #include "chromeos/chromeos_switches.h" |
| 26 #include "content/public/common/url_constants.h" |
| 27 #include "content/public/test/test_utils.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "ui/base/test/ui_controls.h" |
| 30 #include "ui/views/widget/widget.h" |
| 31 |
| 32 using extensions::api::braille_display_private::StubBrailleController; |
| 33 |
| 34 namespace chromeos { |
| 35 |
| 36 namespace { |
| 37 const char kChromeVoxEnabledMessage[] = "chrome vox spoken feedback is ready"; |
| 38 } // anonymous namespace |
| 39 |
| 40 // Installs itself as the platform speech synthesis engine, allowing it to |
| 41 // intercept all speech calls, and then provides a method to block until the |
| 42 // next utterance is spoken. |
| 43 class SpeechMonitor : public TtsPlatformImpl { |
| 44 public: |
| 45 SpeechMonitor(); |
| 46 virtual ~SpeechMonitor(); |
| 47 |
| 48 // Blocks until the next utterance is spoken, and returns its text. |
| 49 std::string GetNextUtterance(); |
| 50 |
| 51 // TtsPlatformImpl implementation. |
| 52 virtual bool PlatformImplAvailable() OVERRIDE { return true; } |
| 53 virtual bool Speak( |
| 54 int utterance_id, |
| 55 const std::string& utterance, |
| 56 const std::string& lang, |
| 57 const VoiceData& voice, |
| 58 const UtteranceContinuousParameters& params) OVERRIDE { |
| 59 TtsController::GetInstance()->OnTtsEvent( |
| 60 utterance_id, |
| 61 TTS_EVENT_END, |
| 62 static_cast<int>(utterance.size()), |
| 63 std::string()); |
| 64 return true; |
| 65 } |
| 66 virtual bool StopSpeaking() OVERRIDE { return true; } |
| 67 virtual bool IsSpeaking() OVERRIDE { return false; } |
| 68 virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE { |
| 69 out_voices->push_back(VoiceData()); |
| 70 VoiceData& voice = out_voices->back(); |
| 71 voice.native = true; |
| 72 voice.name = "SpeechMonitor"; |
| 73 voice.events.insert(TTS_EVENT_END); |
| 74 } |
| 75 virtual void Pause() OVERRIDE {} |
| 76 virtual void Resume() OVERRIDE {} |
| 77 virtual std::string error() OVERRIDE { return ""; } |
| 78 virtual void clear_error() OVERRIDE {} |
| 79 virtual void set_error(const std::string& error) OVERRIDE {} |
| 80 virtual void WillSpeakUtteranceWithVoice( |
| 81 const Utterance* utterance, const VoiceData& voice_data) OVERRIDE; |
| 82 |
| 83 private: |
| 84 scoped_refptr<content::MessageLoopRunner> loop_runner_; |
| 85 std::deque<std::string> utterance_queue_; |
| 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(SpeechMonitor); |
| 88 }; |
| 89 |
| 90 SpeechMonitor::SpeechMonitor() { |
| 91 TtsController::GetInstance()->SetPlatformImpl(this); |
| 92 } |
| 93 |
| 94 SpeechMonitor::~SpeechMonitor() { |
| 95 TtsController::GetInstance()->SetPlatformImpl(TtsPlatformImpl::GetInstance()); |
| 96 } |
| 97 |
| 98 void SpeechMonitor::WillSpeakUtteranceWithVoice(const Utterance* utterance, |
| 99 const VoiceData& voice_data) { |
| 100 utterance_queue_.push_back(utterance->text()); |
| 101 if (loop_runner_.get()) |
| 102 loop_runner_->Quit(); |
| 103 } |
| 104 |
| 105 std::string SpeechMonitor::GetNextUtterance() { |
| 106 if (utterance_queue_.empty()) { |
| 107 loop_runner_ = new content::MessageLoopRunner(); |
| 108 loop_runner_->Run(); |
| 109 loop_runner_ = NULL; |
| 110 } |
| 111 std::string result = utterance_queue_.front(); |
| 112 utterance_queue_.pop_front(); |
| 113 return result; |
| 114 } |
| 115 |
| 116 // |
| 117 // Spoken feedback tests in a normal browser window. |
| 118 // |
| 119 |
| 120 class SpokenFeedbackTest : public InProcessBrowserTest { |
| 121 protected: |
| 122 SpokenFeedbackTest() {} |
| 123 virtual ~SpokenFeedbackTest() {} |
| 124 |
| 125 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 126 AccessibilityManager::SetBrailleControllerForTest(&braille_controller_); |
| 127 } |
| 128 |
| 129 virtual void CleanUpOnMainThread() OVERRIDE { |
| 130 AccessibilityManager::SetBrailleControllerForTest(NULL); |
| 131 } |
| 132 |
| 133 private: |
| 134 StubBrailleController braille_controller_; |
| 135 DISALLOW_COPY_AND_ASSIGN(SpokenFeedbackTest); |
| 136 }; |
| 137 |
| 138 IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, EnableSpokenFeedback) { |
| 139 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); |
| 140 |
| 141 SpeechMonitor monitor; |
| 142 AccessibilityManager::Get()->EnableSpokenFeedback( |
| 143 true, ash::A11Y_NOTIFICATION_NONE); |
| 144 EXPECT_EQ(kChromeVoxEnabledMessage, monitor.GetNextUtterance()); |
| 145 } |
| 146 |
| 147 IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, FocusToolbar) { |
| 148 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); |
| 149 |
| 150 SpeechMonitor monitor; |
| 151 AccessibilityManager::Get()->EnableSpokenFeedback( |
| 152 true, ash::A11Y_NOTIFICATION_NONE); |
| 153 EXPECT_EQ(kChromeVoxEnabledMessage, monitor.GetNextUtterance()); |
| 154 |
| 155 chrome::ExecuteCommand(browser(), IDC_FOCUS_TOOLBAR); |
| 156 // Might be "Google Chrome Toolbar" or "Chromium Toolbar". |
| 157 EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "*oolbar*")); |
| 158 EXPECT_EQ("Reload,", monitor.GetNextUtterance()); |
| 159 EXPECT_EQ("button", monitor.GetNextUtterance()); |
| 160 } |
| 161 |
| 162 // |
| 163 // Spoken feedback tests of the out-of-box experience. |
| 164 // |
| 165 |
| 166 class OobeSpokenFeedbackTest : public InProcessBrowserTest { |
| 167 protected: |
| 168 OobeSpokenFeedbackTest() {} |
| 169 virtual ~OobeSpokenFeedbackTest() {} |
| 170 |
| 171 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 172 command_line->AppendSwitch(chromeos::switches::kLoginManager); |
| 173 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); |
| 174 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); |
| 175 } |
| 176 |
| 177 virtual void SetUpOnMainThread() OVERRIDE { |
| 178 AccessibilityManager::Get()-> |
| 179 SetProfileForTest(ProfileHelper::GetSigninProfile()); |
| 180 } |
| 181 |
| 182 private: |
| 183 DISALLOW_COPY_AND_ASSIGN(OobeSpokenFeedbackTest); |
| 184 }; |
| 185 |
| 186 IN_PROC_BROWSER_TEST_F(OobeSpokenFeedbackTest, SpokenFeedbackInOobe) { |
| 187 ui_controls::EnableUIControls(); |
| 188 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); |
| 189 |
| 190 LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host(); |
| 191 WebUILoginView* web_ui_login_view = login_display_host->GetWebUILoginView(); |
| 192 views::Widget* widget = web_ui_login_view->GetWidget(); |
| 193 gfx::NativeWindow window = widget->GetNativeWindow(); |
| 194 |
| 195 SpeechMonitor monitor; |
| 196 AccessibilityManager::Get()->EnableSpokenFeedback( |
| 197 true, ash::A11Y_NOTIFICATION_NONE); |
| 198 EXPECT_EQ(kChromeVoxEnabledMessage, monitor.GetNextUtterance()); |
| 199 |
| 200 EXPECT_EQ("Select your language:", monitor.GetNextUtterance()); |
| 201 EXPECT_EQ("English ( United States)", monitor.GetNextUtterance()); |
| 202 EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "Combo box * of *")); |
| 203 ui_controls::SendKeyPress(window, ui::VKEY_TAB, false, false, false, false); |
| 204 EXPECT_EQ("Select your keyboard:", monitor.GetNextUtterance()); |
| 205 } |
| 206 |
| 207 } // namespace chromeos |
OLD | NEW |