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

Side by Side Diff: content/browser/speech/speech_recognition_browsertest.cc

Issue 10820043: Convert speech and session history browser_tests to run under content_browsertests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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
« no previous file with comments | « content/browser/session_history_browsertest.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h"
9 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
10 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
11 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_tabstrip.h"
14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/ui_test_utils.h"
16 #include "content/browser/renderer_host/render_view_host_impl.h" 13 #include "content/browser/renderer_host/render_view_host_impl.h"
17 #include "content/browser/speech/input_tag_speech_dispatcher_host.h" 14 #include "content/browser/speech/input_tag_speech_dispatcher_host.h"
18 #include "content/browser/web_contents/web_contents_impl.h" 15 #include "content/browser/web_contents/web_contents_impl.h"
19 #include "content/public/browser/notification_types.h" 16 #include "content/public/browser/notification_types.h"
20 #include "content/public/browser/speech_recognition_manager.h" 17 #include "content/public/browser/speech_recognition_manager.h"
21 #include "content/public/browser/speech_recognition_session_config.h" 18 #include "content/public/browser/speech_recognition_session_config.h"
22 #include "content/public/browser/speech_recognition_session_context.h" 19 #include "content/public/browser/speech_recognition_session_context.h"
20 #include "content/public/browser/web_contents.h"
23 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
24 #include "content/public/common/speech_recognition_error.h" 22 #include "content/public/common/speech_recognition_error.h"
25 #include "content/public/common/speech_recognition_result.h" 23 #include "content/public/common/speech_recognition_result.h"
24 #include "content/public/common/url_constants.h"
25 #include "content/public/test/test_utils.h"
26 #include "content/shell/shell.h"
27 #include "content/test/content_browser_test.h"
28 #include "content/test/content_browser_test_utils.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
27 30
28 using content::SpeechRecognitionEventListener; 31 using content::SpeechRecognitionEventListener;
29 using content::SpeechRecognitionSessionConfig; 32 using content::SpeechRecognitionSessionConfig;
30 using content::SpeechRecognitionSessionContext; 33 using content::SpeechRecognitionSessionContext;
31 using content::NavigationController; 34 using content::NavigationController;
32 using content::WebContents; 35 using content::WebContents;
33 36
34 namespace speech { 37 namespace speech {
35 class FakeSpeechRecognitionManager; 38 class FakeSpeechRecognitionManager;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 int session_id_; 177 int session_id_;
175 SpeechRecognitionEventListener* listener_; 178 SpeechRecognitionEventListener* listener_;
176 SpeechRecognitionSessionConfig session_config_; 179 SpeechRecognitionSessionConfig session_config_;
177 SpeechRecognitionSessionContext session_ctx_; 180 SpeechRecognitionSessionContext session_ctx_;
178 std::string grammar_; 181 std::string grammar_;
179 bool did_cancel_all_; 182 bool did_cancel_all_;
180 bool should_send_fake_response_; 183 bool should_send_fake_response_;
181 base::WaitableEvent recognition_started_event_; 184 base::WaitableEvent recognition_started_event_;
182 }; 185 };
183 186
184 class SpeechRecognitionBrowserTest : public InProcessBrowserTest { 187 class SpeechRecognitionBrowserTest : public content::ContentBrowserTest {
185 public: 188 public:
186 // InProcessBrowserTest methods 189 // ContentBrowserTest methods
187 virtual void SetUpCommandLine(CommandLine* command_line) { 190 virtual void SetUpCommandLine(CommandLine* command_line) {
188 EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableSpeechInput)); 191 EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableSpeechInput));
189 } 192 }
190 193
191 GURL testUrl(const FilePath::CharType* filename) {
192 const FilePath kTestDir(FILE_PATH_LITERAL("speech"));
193 return ui_test_utils::GetTestUrl(kTestDir, FilePath(filename));
194 }
195
196 protected: 194 protected:
197 void LoadAndStartSpeechRecognitionTest(const FilePath::CharType* filename) { 195 void LoadAndStartSpeechRecognitionTest(const char* filename) {
198 // The test page calculates the speech button's coordinate in the page on 196 // The test page calculates the speech button's coordinate in the page on
199 // load & sets that coordinate in the URL fragment. We send mouse down & up 197 // load & sets that coordinate in the URL fragment. We send mouse down & up
200 // events at that coordinate to trigger speech recognition. 198 // events at that coordinate to trigger speech recognition.
201 GURL test_url = testUrl(filename); 199 GURL test_url = content::GetTestUrl("speech", filename);
202 ui_test_utils::NavigateToURL(browser(), test_url); 200 content::NavigateToURL(shell(), test_url);
203 201
204 WebKit::WebMouseEvent mouse_event; 202 WebKit::WebMouseEvent mouse_event;
205 mouse_event.type = WebKit::WebInputEvent::MouseDown; 203 mouse_event.type = WebKit::WebInputEvent::MouseDown;
206 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; 204 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft;
207 mouse_event.x = 0; 205 mouse_event.x = 0;
208 mouse_event.y = 0; 206 mouse_event.y = 0;
209 mouse_event.clickCount = 1; 207 mouse_event.clickCount = 1;
210 WebContents* web_contents = chrome::GetActiveWebContents(browser()); 208 WebContents* web_contents = shell()->web_contents();
211 209
212 content::WindowedNotificationObserver observer( 210 content::WindowedNotificationObserver observer(
213 content::NOTIFICATION_LOAD_STOP, 211 content::NOTIFICATION_LOAD_STOP,
214 content::Source<NavigationController>(&web_contents->GetController())); 212 content::Source<NavigationController>(&web_contents->GetController()));
215 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); 213 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
216 mouse_event.type = WebKit::WebInputEvent::MouseUp; 214 mouse_event.type = WebKit::WebInputEvent::MouseUp;
217 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); 215 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
218 fake_speech_recognition_manager_.recognition_started_event().Wait(); 216 fake_speech_recognition_manager_.recognition_started_event().Wait();
219 217
220 // We should wait for a navigation event, raised by the test page JS code 218 // We should wait for a navigation event, raised by the test page JS code
221 // upon the onwebkitspeechchange event, in all cases except when the 219 // upon the onwebkitspeechchange event, in all cases except when the
222 // speech response is inhibited. 220 // speech response is inhibited.
223 if (fake_speech_recognition_manager_.should_send_fake_response()) 221 if (fake_speech_recognition_manager_.should_send_fake_response())
224 observer.Wait(); 222 observer.Wait();
225 } 223 }
226 224
227 void RunSpeechRecognitionTest(const FilePath::CharType* filename) { 225 void RunSpeechRecognitionTest(const char* filename) {
228 // The fake speech input manager would receive the speech input 226 // The fake speech input manager would receive the speech input
229 // request and return the test string as recognition result. The test page 227 // request and return the test string as recognition result. The test page
230 // then sets the URL fragment as 'pass' if it received the expected string. 228 // then sets the URL fragment as 'pass' if it received the expected string.
231 LoadAndStartSpeechRecognitionTest(filename); 229 LoadAndStartSpeechRecognitionTest(filename);
232 230
233 EXPECT_EQ("pass", chrome::GetActiveWebContents(browser())->GetURL().ref()); 231 EXPECT_EQ("pass", shell()->web_contents()->GetURL().ref());
234 } 232 }
235 233
236 // InProcessBrowserTest methods. 234 // ContentBrowserTest methods.
237 virtual void SetUpInProcessBrowserTestFixture() { 235 virtual void SetUpInProcessBrowserTestFixture() {
238 fake_speech_recognition_manager_.set_should_send_fake_response(true); 236 fake_speech_recognition_manager_.set_should_send_fake_response(true);
239 speech_recognition_manager_ = &fake_speech_recognition_manager_; 237 speech_recognition_manager_ = &fake_speech_recognition_manager_;
240 238
241 // Inject the fake manager factory so that the test result is returned to 239 // Inject the fake manager factory so that the test result is returned to
242 // the web page. 240 // the web page.
243 InputTagSpeechDispatcherHost::SetManagerForTests( 241 InputTagSpeechDispatcherHost::SetManagerForTests(
244 speech_recognition_manager_); 242 speech_recognition_manager_);
245 } 243 }
246 244
(...skipping 14 matching lines...) Expand all
261 // TODO(satish): Once this flakiness has been fixed, add a second test here to 259 // TODO(satish): Once this flakiness has been fixed, add a second test here to
262 // check for sending many clicks in succession to the speech button and verify 260 // check for sending many clicks in succession to the speech button and verify
263 // that it doesn't cause any crash but works as expected. This should act as the 261 // that it doesn't cause any crash but works as expected. This should act as the
264 // test for http://crbug.com/59173 262 // test for http://crbug.com/59173
265 // 263 //
266 // TODO(satish): Similar to above, once this flakiness has been fixed add 264 // TODO(satish): Similar to above, once this flakiness has been fixed add
267 // another test here to check that when speech recognition is in progress and 265 // another test here to check that when speech recognition is in progress and
268 // a renderer crashes, we get a call to 266 // a renderer crashes, we get a call to
269 // SpeechRecognitionManager::CancelAllRequestsWithDelegate. 267 // SpeechRecognitionManager::CancelAllRequestsWithDelegate.
270 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, TestBasicRecognition) { 268 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, TestBasicRecognition) {
271 RunSpeechRecognitionTest(FILE_PATH_LITERAL("basic_recognition.html")); 269 RunSpeechRecognitionTest("basic_recognition.html");
272 EXPECT_TRUE(fake_speech_recognition_manager_.grammar().empty()); 270 EXPECT_TRUE(fake_speech_recognition_manager_.grammar().empty());
273 } 271 }
274 272
275 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, GrammarAttribute) { 273 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, GrammarAttribute) {
276 RunSpeechRecognitionTest(FILE_PATH_LITERAL("grammar_attribute.html")); 274 RunSpeechRecognitionTest("grammar_attribute.html");
277 EXPECT_EQ("http://example.com/grammar.xml", 275 EXPECT_EQ("http://example.com/grammar.xml",
278 fake_speech_recognition_manager_.grammar()); 276 fake_speech_recognition_manager_.grammar());
279 } 277 }
280 278
281 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, TestCancelAll) { 279 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, TestCancelAll) {
282 // The test checks that the cancel-all callback gets issued when a session 280 // The test checks that the cancel-all callback gets issued when a session
283 // is pending, so don't send a fake response. 281 // is pending, so don't send a fake response.
284 // We are not expecting a navigation event being raised from the JS of the 282 // We are not expecting a navigation event being raised from the JS of the
285 // test page JavaScript in this case. 283 // test page JavaScript in this case.
286 fake_speech_recognition_manager_.set_should_send_fake_response(false); 284 fake_speech_recognition_manager_.set_should_send_fake_response(false);
287 285
288 LoadAndStartSpeechRecognitionTest( 286 LoadAndStartSpeechRecognitionTest("basic_recognition.html");
289 FILE_PATH_LITERAL("basic_recognition.html"));
290 287
291 // Make the renderer crash. This should trigger 288 // Make the renderer crash. This should trigger
292 // InputTagSpeechDispatcherHost to cancel all pending sessions. 289 // InputTagSpeechDispatcherHost to cancel all pending sessions.
293 GURL test_url("about:crash"); 290 content::NavigateToURL(shell(), GURL(chrome::kChromeUICrashURL));
294 ui_test_utils::NavigateToURL(browser(), test_url);
295 291
296 EXPECT_TRUE(fake_speech_recognition_manager_.did_cancel_all()); 292 EXPECT_TRUE(fake_speech_recognition_manager_.did_cancel_all());
297 } 293 }
298 294
299 } // namespace speech 295 } // namespace speech
OLDNEW
« no previous file with comments | « content/browser/session_history_browsertest.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698