Chromium Code Reviews| Index: chrome/browser/ui/app_list/app_list_speech_recognizer_browsertest.cc |
| diff --git a/chrome/browser/ui/app_list/app_list_speech_recognizer_browsertest.cc b/chrome/browser/ui/app_list/app_list_speech_recognizer_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ec93c5a8817b701025ad832194328cb83ac1d02c |
| --- /dev/null |
| +++ b/chrome/browser/ui/app_list/app_list_speech_recognizer_browsertest.cc |
| @@ -0,0 +1,102 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/app_list/app_list_speech_recognizer.h" |
| + |
| +#include "base/command_line.h" |
| +#include "base/run_loop.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "chrome/browser/ui/app_list/start_page_service.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/common/chrome_switches.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "chrome/test/base/testing_profile.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/notification_service.h" |
| +#include "content/public/test/fake_speech_recognition_manager.h" |
| +#include "content/public/test/web_contents_tester.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using ::testing::InvokeWithoutArgs; |
| +using ::testing::Return; |
| + |
| +namespace app_list { |
| + |
| +class MockStartPageService : public StartPageService { |
|
Jun Mukai
2014/10/30 07:08:34
Does it have to be a StartPageService?
If all you
Anand Mistry (off Chromium)
2014/10/31 00:50:06
Done.
|
| + public: |
| + explicit MockStartPageService(Profile* profile) : StartPageService(profile) {} |
| + |
| + MOCK_METHOD0(GetSpeechRecognitionContents, content::WebContents*()); |
| + MOCK_METHOD2(OnSpeechResult, void(const base::string16&, bool)); |
| + MOCK_METHOD1(OnSpeechRecognitionStateChanged, void(SpeechRecognitionState)); |
| +}; |
| + |
| +class AppListSpeechRecognizerBrowserTest : public InProcessBrowserTest { |
| + public: |
| + AppListSpeechRecognizerBrowserTest() {} |
| + |
| + void SetUpOnMainThread() override { |
| + InProcessBrowserTest::SetUpOnMainThread(); |
| + |
| + fake_speech_recognition_manager_.reset( |
| + new content::FakeSpeechRecognitionManager()); |
| + fake_speech_recognition_manager_->set_should_send_fake_response(true); |
| + content::SpeechRecognitionManager::SetManagerForTesting( |
| + fake_speech_recognition_manager_.get()); |
| + mock_start_page_service_.reset( |
| + new MockStartPageService(browser()->profile())); |
| + test_contents_.reset(content::WebContentsTester::CreateTestWebContents( |
| + browser()->profile(), NULL)); |
| + } |
| + |
| + void SetUpCommandLine(base::CommandLine* command_line) override { |
| + command_line->AppendSwitch(switches::kEnableExperimentalHotwording); |
| + } |
| + |
| + void TearDownOnMainThread() override { |
| + // This relies on stuff that is torn down by the time the test is |
| + // destructed. |
| + mock_start_page_service_.reset(); |
| + |
| + // This puts stuff on the IO loop which needs to be executed. |
| + test_contents_.reset(); |
| + |
| + // Poor-person's way of ensuring IO loop is idle. |
| + auto io_loop = content::BrowserThread::UnsafeGetMessageLoopForThread( |
| + content::BrowserThread::IO); |
| + while (io_loop->IsIdleForTesting()) {} |
| + } |
| + |
| + protected: |
| + scoped_ptr<content::FakeSpeechRecognitionManager> |
| + fake_speech_recognition_manager_; |
| + scoped_ptr<MockStartPageService> mock_start_page_service_; |
| + scoped_ptr<content::WebContents> test_contents_; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(AppListSpeechRecognizerBrowserTest); |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(AppListSpeechRecognizerBrowserTest, RecognizeSpeech) { |
| + scoped_refptr<AppListSpeechRecognizer> recognizer = |
| + new AppListSpeechRecognizer(mock_start_page_service_.get(), "en"); |
| + |
| + base::RunLoop run_loop; |
| + EXPECT_CALL(*mock_start_page_service_, GetSpeechRecognitionContents()) |
| + .WillOnce(Return(test_contents_.get())); |
| + EXPECT_CALL(*mock_start_page_service_, |
| + OnSpeechResult(base::ASCIIToUTF16("Pictures of the moon"), true)); |
| + EXPECT_CALL(*mock_start_page_service_, |
| + OnSpeechRecognitionStateChanged(SPEECH_RECOGNITION_READY)) |
| + .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| + recognizer->Start(); |
| + run_loop.Run(); |
| + |
| + recognizer->Stop(); |
| +} |
| + |
| +} // namespace app_list |
| + |
| + |