This source file includes following definitions.
- SetUpCommandLine
- LoadAndStartSpeechRecognitionTest
- RunSpeechRecognitionTest
- SetUpInProcessBrowserTestFixture
- TearDownInProcessBrowserTestFixture
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/speech_recognition_error.h"
#include "content/public/common/speech_recognition_result.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/fake_speech_recognition_manager.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
namespace content {
class InputTagSpeechBrowserTest : public ContentBrowserTest {
public:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
EXPECT_TRUE(!command_line->HasSwitch(switches::kDisableSpeechInput));
}
protected:
void LoadAndStartSpeechRecognitionTest(const char* filename) {
GURL test_url = GetTestUrl("speech", filename);
NavigateToURL(shell(), test_url);
blink::WebMouseEvent mouse_event;
mouse_event.type = blink::WebInputEvent::MouseDown;
mouse_event.button = blink::WebMouseEvent::ButtonLeft;
mouse_event.x = 0;
mouse_event.y = 0;
mouse_event.clickCount = 1;
WebContents* web_contents = shell()->web_contents();
WindowedNotificationObserver observer(
NOTIFICATION_LOAD_STOP,
Source<NavigationController>(&web_contents->GetController()));
web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
mouse_event.type = blink::WebInputEvent::MouseUp;
web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
fake_speech_recognition_manager_.WaitForRecognitionStarted();
if (fake_speech_recognition_manager_.should_send_fake_response())
observer.Wait();
}
void RunSpeechRecognitionTest(const char* filename) {
LoadAndStartSpeechRecognitionTest(filename);
EXPECT_EQ("pass", shell()->web_contents()->GetLastCommittedURL().ref());
}
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
fake_speech_recognition_manager_.set_should_send_fake_response(true);
speech_recognition_manager_ = &fake_speech_recognition_manager_;
SpeechRecognitionManager::SetManagerForTesting(speech_recognition_manager_);
}
virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
speech_recognition_manager_ = NULL;
}
FakeSpeechRecognitionManager fake_speech_recognition_manager_;
static SpeechRecognitionManager* speech_recognition_manager_;
};
SpeechRecognitionManager*
InputTagSpeechBrowserTest::speech_recognition_manager_ = NULL;
IN_PROC_BROWSER_TEST_F(InputTagSpeechBrowserTest, TestBasicRecognition) {
RunSpeechRecognitionTest("basic_recognition.html");
EXPECT_TRUE(fake_speech_recognition_manager_.grammar().empty());
}
IN_PROC_BROWSER_TEST_F(InputTagSpeechBrowserTest, GrammarAttribute) {
RunSpeechRecognitionTest("grammar_attribute.html");
EXPECT_EQ("http://example.com/grammar.xml",
fake_speech_recognition_manager_.grammar());
}
IN_PROC_BROWSER_TEST_F(InputTagSpeechBrowserTest, DISABLED_TestCancelAll) {
fake_speech_recognition_manager_.set_should_send_fake_response(false);
LoadAndStartSpeechRecognitionTest("basic_recognition.html");
NavigateToURL(shell(), GURL(kChromeUICrashURL));
EXPECT_TRUE(fake_speech_recognition_manager_.did_cancel_all());
}
}