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