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

Side by Side Diff: chrome/browser/ui/app_list/speech_recognizer_browsertest.cc

Issue 676593003: Implement native speech recognition for the launcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor and address review comments. Created 6 years, 1 month 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/app_list/speech_recognizer.h"
6
7 #include "base/command_line.h"
8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/ui/app_list/speech_recognizer_delegate.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chrome/test/base/testing_profile.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/test/fake_speech_recognition_manager.h"
17 #include "content/public/test/web_contents_tester.h"
18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20
21 using ::testing::InvokeWithoutArgs;
22 using ::testing::Return;
23
24 namespace app_list {
25
26 class MockSpeechRecognizerDelegate : public SpeechRecognizerDelegate {
27 public:
28 MockSpeechRecognizerDelegate() {}
29
30 MOCK_METHOD2(OnSpeechResult, void(const base::string16&, bool));
31 MOCK_METHOD1(OnSpeechSoundLevelChanged, void(int16_t));
32 MOCK_METHOD1(OnSpeechRecognitionStateChanged, void(SpeechRecognitionState));
33 MOCK_METHOD0(GetSpeechContents, content::WebContents*());
34 };
35
36 class AppListSpeechRecognizerBrowserTest : public InProcessBrowserTest {
37 public:
38 AppListSpeechRecognizerBrowserTest() {}
39
40 void SetUpOnMainThread() override {
41 InProcessBrowserTest::SetUpOnMainThread();
42
43 fake_speech_recognition_manager_.reset(
44 new content::FakeSpeechRecognitionManager());
45 fake_speech_recognition_manager_->set_should_send_fake_response(true);
46 content::SpeechRecognitionManager::SetManagerForTesting(
47 fake_speech_recognition_manager_.get());
48 mock_speech_delegate_.reset(new MockSpeechRecognizerDelegate());
49 test_contents_.reset(content::WebContentsTester::CreateTestWebContents(
50 browser()->profile(), NULL));
51 }
52
53 void SetUpCommandLine(base::CommandLine* command_line) override {
54 command_line->AppendSwitch(switches::kEnableExperimentalHotwording);
55 }
56
57 void TearDownOnMainThread() override {
58 // This puts stuff on the IO loop which needs to be executed.
59 test_contents_.reset();
60
61 // Poor-person's way of ensuring IO loop is idle.
62 auto io_loop = content::BrowserThread::UnsafeGetMessageLoopForThread(
63 content::BrowserThread::IO);
64 while (io_loop->IsIdleForTesting()) {}
65 }
66
67 protected:
68 scoped_ptr<content::FakeSpeechRecognitionManager>
69 fake_speech_recognition_manager_;
70 scoped_ptr<MockSpeechRecognizerDelegate> mock_speech_delegate_;
71 scoped_ptr<content::WebContents> test_contents_;
72
73 private:
74 DISALLOW_COPY_AND_ASSIGN(AppListSpeechRecognizerBrowserTest);
75 };
76
77 IN_PROC_BROWSER_TEST_F(AppListSpeechRecognizerBrowserTest, RecognizeSpeech) {
78 scoped_refptr<SpeechRecognizer> recognizer =
79 new SpeechRecognizer(mock_speech_delegate_.get(),
80 browser()->profile()->GetRequestContext(),
81 "en");
82
83 base::RunLoop run_loop;
84 EXPECT_CALL(*mock_speech_delegate_, GetSpeechContents())
85 .WillOnce(Return(test_contents_.get()));
86 EXPECT_CALL(*mock_speech_delegate_,
87 OnSpeechResult(base::ASCIIToUTF16("Pictures of the moon"), true));
88 EXPECT_CALL(*mock_speech_delegate_,
89 OnSpeechRecognitionStateChanged(SPEECH_RECOGNITION_READY))
90 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
91 recognizer->Start();
92 run_loop.Run();
93
94 recognizer->Stop();
95 }
96
97 } // namespace app_list
98
99
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698