Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc

Issue 153263006: Add test for ChromeVox injection into webview (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <queue> 5 #include <queue>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" 10 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
11 #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
11 #include "chrome/browser/chromeos/login/login_display_host.h" 12 #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/login_display_host_impl.h"
13 #include "chrome/browser/chromeos/login/user_manager.h" 14 #include "chrome/browser/chromeos/login/user_manager.h"
14 #include "chrome/browser/chromeos/login/webui_login_view.h" 15 #include "chrome/browser/chromeos/login/webui_login_view.h"
15 #include "chrome/browser/chromeos/profiles/profile_helper.h" 16 #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/extensions/api/braille_display_private/stub_braille_con troller.h"
17 #include "chrome/browser/speech/tts_controller.h" 18 #include "chrome/browser/speech/tts_controller.h"
18 #include "chrome/browser/speech/tts_platform.h" 19 #include "chrome/browser/speech/tts_platform.h"
19 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_commands.h" 21 #include "chrome/browser/ui/browser_commands.h"
21 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
22 #include "chrome/test/base/in_process_browser_test.h" 23 #include "chrome/test/base/in_process_browser_test.h"
23 #include "chrome/test/base/testing_profile.h" 24 #include "chrome/test/base/testing_profile.h"
24 #include "chrome/test/base/ui_test_utils.h" 25 #include "chrome/test/base/ui_test_utils.h"
25 #include "chromeos/chromeos_switches.h" 26 #include "chromeos/chromeos_switches.h"
26 #include "content/public/common/url_constants.h" 27 #include "content/public/common/url_constants.h"
27 #include "content/public/test/test_utils.h" 28 #include "content/public/test/test_utils.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 #include "ui/base/test/ui_controls.h" 30 #include "ui/base/test/ui_controls.h"
30 #include "ui/views/widget/widget.h" 31 #include "ui/views/widget/widget.h"
31 32
32 using extensions::api::braille_display_private::StubBrailleController; 33 using extensions::api::braille_display_private::StubBrailleController;
33 34
34 namespace chromeos { 35 namespace chromeos {
35 36
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 // 37 //
117 // Spoken feedback tests in a normal browser window. 38 // Spoken feedback tests in a normal browser window.
118 // 39 //
119 40
120 class SpokenFeedbackTest : public InProcessBrowserTest { 41 class SpokenFeedbackTest : public InProcessBrowserTest {
121 protected: 42 protected:
122 SpokenFeedbackTest() {} 43 SpokenFeedbackTest() {}
123 virtual ~SpokenFeedbackTest() {} 44 virtual ~SpokenFeedbackTest() {}
124 45
125 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 46 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
126 AccessibilityManager::SetBrailleControllerForTest(&braille_controller_); 47 AccessibilityManager::SetBrailleControllerForTest(&braille_controller_);
127 } 48 }
128 49
129 virtual void CleanUpOnMainThread() OVERRIDE { 50 virtual void CleanUpOnMainThread() OVERRIDE {
130 AccessibilityManager::SetBrailleControllerForTest(NULL); 51 AccessibilityManager::SetBrailleControllerForTest(NULL);
131 } 52 }
132 53
133 private: 54 private:
134 StubBrailleController braille_controller_; 55 StubBrailleController braille_controller_;
135 DISALLOW_COPY_AND_ASSIGN(SpokenFeedbackTest); 56 DISALLOW_COPY_AND_ASSIGN(SpokenFeedbackTest);
136 }; 57 };
137 58
138 IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, EnableSpokenFeedback) { 59 IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, EnableSpokenFeedback) {
139 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); 60 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
140 61
141 SpeechMonitor monitor; 62 SpeechMonitor monitor;
142 AccessibilityManager::Get()->EnableSpokenFeedback( 63 AccessibilityManager::Get()->EnableSpokenFeedback(
143 true, ash::A11Y_NOTIFICATION_NONE); 64 true, ash::A11Y_NOTIFICATION_NONE);
144 EXPECT_EQ(kChromeVoxEnabledMessage, monitor.GetNextUtterance()); 65 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
145 } 66 }
146 67
147 IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, FocusToolbar) { 68 IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, FocusToolbar) {
148 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); 69 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
149 70
150 SpeechMonitor monitor; 71 SpeechMonitor monitor;
151 AccessibilityManager::Get()->EnableSpokenFeedback( 72 AccessibilityManager::Get()->EnableSpokenFeedback(
152 true, ash::A11Y_NOTIFICATION_NONE); 73 true, ash::A11Y_NOTIFICATION_NONE);
153 EXPECT_EQ(kChromeVoxEnabledMessage, monitor.GetNextUtterance()); 74 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
154 75
155 chrome::ExecuteCommand(browser(), IDC_FOCUS_TOOLBAR); 76 chrome::ExecuteCommand(browser(), IDC_FOCUS_TOOLBAR);
156 // Might be "Google Chrome Toolbar" or "Chromium Toolbar". 77 // Might be "Google Chrome Toolbar" or "Chromium Toolbar".
157 EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "*oolbar*")); 78 EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "*oolbar*"));
158 EXPECT_EQ("Reload,", monitor.GetNextUtterance()); 79 EXPECT_EQ("Reload,", monitor.GetNextUtterance());
159 EXPECT_EQ("button", monitor.GetNextUtterance()); 80 EXPECT_EQ("button", monitor.GetNextUtterance());
160 } 81 }
161 82
162 // 83 //
163 // Spoken feedback tests of the out-of-box experience. 84 // Spoken feedback tests of the out-of-box experience.
(...skipping 24 matching lines...) Expand all
188 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled()); 109 EXPECT_FALSE(AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
189 110
190 LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host(); 111 LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host();
191 WebUILoginView* web_ui_login_view = login_display_host->GetWebUILoginView(); 112 WebUILoginView* web_ui_login_view = login_display_host->GetWebUILoginView();
192 views::Widget* widget = web_ui_login_view->GetWidget(); 113 views::Widget* widget = web_ui_login_view->GetWidget();
193 gfx::NativeWindow window = widget->GetNativeWindow(); 114 gfx::NativeWindow window = widget->GetNativeWindow();
194 115
195 SpeechMonitor monitor; 116 SpeechMonitor monitor;
196 AccessibilityManager::Get()->EnableSpokenFeedback( 117 AccessibilityManager::Get()->EnableSpokenFeedback(
197 true, ash::A11Y_NOTIFICATION_NONE); 118 true, ash::A11Y_NOTIFICATION_NONE);
198 EXPECT_EQ(kChromeVoxEnabledMessage, monitor.GetNextUtterance()); 119 EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
199 120
200 EXPECT_EQ("Select your language:", monitor.GetNextUtterance()); 121 EXPECT_EQ("Select your language:", monitor.GetNextUtterance());
201 EXPECT_EQ("English ( United States)", monitor.GetNextUtterance()); 122 EXPECT_EQ("English ( United States)", monitor.GetNextUtterance());
202 EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "Combo box * of *")); 123 EXPECT_TRUE(MatchPattern(monitor.GetNextUtterance(), "Combo box * of *"));
203 ui_controls::SendKeyPress(window, ui::VKEY_TAB, false, false, false, false); 124 ui_controls::SendKeyPress(window, ui::VKEY_TAB, false, false, false, false);
204 EXPECT_EQ("Select your keyboard:", monitor.GetNextUtterance()); 125 EXPECT_EQ("Select your keyboard:", monitor.GetNextUtterance());
205 } 126 }
206 127
207 } // namespace chromeos 128 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698