summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-18 20:45:10 +0000
committersatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-18 20:45:10 +0000
commit462cd92d06aae4a9606cd50a984914c447de66e3 (patch)
treef78e049d14d6a93ca7daa78a331d3cbed638cc30
parent4060cbbae6ba9400635730cba4794ad38cafba03 (diff)
downloadchromium_src-462cd92d06aae4a9606cd50a984914c447de66e3.zip
chromium_src-462cd92d06aae4a9606cd50a984914c447de66e3.tar.gz
chromium_src-462cd92d06aae4a9606cd50a984914c447de66e3.tar.bz2
Close ongoing speech input sessions when a tab terminates.
This was working before but in r76893 a line from speech_input_dispatcher_host.cc was removed by mistake. BUG=76589 TEST=browser_tests --gtest_filter=SpeechInputBrowserTest.TestCancelAll Review URL: http://codereview.chromium.org/6712034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78746 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/speech/speech_input_browsertest.cc54
-rw-r--r--content/browser/speech/speech_input_dispatcher_host.cc2
2 files changed, 49 insertions, 7 deletions
diff --git a/content/browser/speech/speech_input_browsertest.cc b/content/browser/speech/speech_input_browsertest.cc
index 5fb38375..9170521 100644
--- a/content/browser/speech/speech_input_browsertest.cc
+++ b/content/browser/speech/speech_input_browsertest.cc
@@ -34,13 +34,23 @@ class FakeSpeechInputManager : public SpeechInputManager {
public:
FakeSpeechInputManager()
: caller_id_(0),
- delegate_(NULL) {
+ delegate_(NULL),
+ did_cancel_all_(false),
+ send_fake_response_(true) {
}
std::string grammar() {
return grammar_;
}
+ bool did_cancel_all() {
+ return did_cancel_all_;
+ }
+
+ void set_send_fake_response(bool send) {
+ send_fake_response_ = send;
+ }
+
// SpeechInputManager methods.
virtual void StartRecognition(Delegate* delegate,
int caller_id,
@@ -56,9 +66,11 @@ class FakeSpeechInputManager : public SpeechInputManager {
caller_id_ = caller_id;
delegate_ = delegate;
grammar_ = grammar;
- // Give the fake result in a short while.
- MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this,
- &FakeSpeechInputManager::SetFakeRecognitionResult));
+ if (send_fake_response_) {
+ // Give the fake result in a short while.
+ MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this,
+ &FakeSpeechInputManager::SetFakeRecognitionResult));
+ }
}
virtual void CancelRecognition(int caller_id) {
VLOG(1) << "CancelRecognition invoked.";
@@ -73,6 +85,11 @@ class FakeSpeechInputManager : public SpeechInputManager {
}
virtual void CancelAllRequestsWithDelegate(Delegate* delegate) {
VLOG(1) << "CancelAllRequestsWithDelegate invoked.";
+ // delegate_ is set to NULL if a fake result was received (see below), so
+ // check that delegate_ matches the incoming parameter only when there is
+ // no fake result sent.
+ EXPECT_TRUE(send_fake_response_ || delegate_ == delegate);
+ did_cancel_all_ = true;
}
private:
@@ -93,6 +110,8 @@ class FakeSpeechInputManager : public SpeechInputManager {
int caller_id_;
Delegate* delegate_;
std::string grammar_;
+ bool did_cancel_all_;
+ bool send_fake_response_;
};
class SpeechInputBrowserTest : public InProcessBrowserTest {
@@ -108,7 +127,7 @@ class SpeechInputBrowserTest : public InProcessBrowserTest {
}
protected:
- void LoadAndRunSpeechInputTest(const FilePath::CharType* filename) {
+ void LoadAndStartSpeechInputTest(const FilePath::CharType* filename) {
// The test page calculates the speech button's coordinate in the page on
// load & sets that coordinate in the URL fragment. We send mouse down & up
// events at that coordinate to trigger speech recognition.
@@ -125,16 +144,22 @@ class SpeechInputBrowserTest : public InProcessBrowserTest {
tab_contents->render_view_host()->ForwardMouseEvent(mouse_event);
mouse_event.type = WebKit::WebInputEvent::MouseUp;
tab_contents->render_view_host()->ForwardMouseEvent(mouse_event);
+ }
+
+ void RunSpeechInputTest(const FilePath::CharType* filename) {
+ LoadAndStartSpeechInputTest(filename);
// The fake speech input manager would receive the speech input
// request and return the test string as recognition result. The test page
// then sets the URL fragment as 'pass' if it received the expected string.
+ TabContents* tab_contents = browser()->GetSelectedTabContents();
ui_test_utils::WaitForNavigations(&tab_contents->controller(), 1);
EXPECT_EQ("pass", browser()->GetSelectedTabContents()->GetURL().ref());
}
// InProcessBrowserTest methods.
virtual void SetUpInProcessBrowserTestFixture() {
+ fake_speech_input_manager_.set_send_fake_response(true);
speech_input_manager_ = &fake_speech_input_manager_;
// Inject the fake manager factory so that the test result is returned to
@@ -179,7 +204,7 @@ SpeechInputManager* SpeechInputBrowserTest::speech_input_manager_ = NULL;
#define MAYBE_TestBasicRecognition TestBasicRecognition
#endif
IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, MAYBE_TestBasicRecognition) {
- LoadAndRunSpeechInputTest(FILE_PATH_LITERAL("basic_recognition.html"));
+ RunSpeechInputTest(FILE_PATH_LITERAL("basic_recognition.html"));
EXPECT_TRUE(fake_speech_input_manager_.grammar().empty());
}
@@ -191,9 +216,24 @@ IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, MAYBE_TestBasicRecognition) {
#define MAYBE_GrammarAttribute GrammarAttribute
#endif
IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, MAYBE_GrammarAttribute) {
- LoadAndRunSpeechInputTest(FILE_PATH_LITERAL("grammar_attribute.html"));
+ RunSpeechInputTest(FILE_PATH_LITERAL("grammar_attribute.html"));
EXPECT_EQ("http://example.com/grammar.xml",
fake_speech_input_manager_.grammar());
}
+IN_PROC_BROWSER_TEST_F(SpeechInputBrowserTest, TestCancelAll) {
+ // The test checks that the cancel-all callback gets issued when a session
+ // is pending, so don't send a fake response.
+ fake_speech_input_manager_.set_send_fake_response(false);
+
+ LoadAndStartSpeechInputTest(FILE_PATH_LITERAL("basic_recognition.html"));
+
+ // Make the renderer crash. This should trigger SpeechInputDispatcherHost to
+ // cancel all pending sessions.
+ GURL test_url("about:crash");
+ ui_test_utils::NavigateToURL(browser(), test_url);
+
+ EXPECT_TRUE(fake_speech_input_manager_.did_cancel_all());
+}
+
} // namespace speech_input
diff --git a/content/browser/speech/speech_input_dispatcher_host.cc b/content/browser/speech/speech_input_dispatcher_host.cc
index b589e3b..d286111 100644
--- a/content/browser/speech/speech_input_dispatcher_host.cc
+++ b/content/browser/speech/speech_input_dispatcher_host.cc
@@ -140,6 +140,8 @@ bool SpeechInputDispatcherHost::OnMessageReceived(
OnStopRecording)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
+ if (handled)
+ may_have_pending_requests_ = true;
return handled;
}