14e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
24e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
34e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// found in the LICENSE file.
44e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
54e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/apps/app_browsertest_util.h"
64e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "content/public/common/content_switches.h"
74e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "content/public/test/fake_speech_recognition_manager.h"
8cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "media/base/media_switches.h"
94e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class SpeechRecognitionTest : public extensions::PlatformAppBrowserTest {
114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) public:
124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)   SpeechRecognitionTest() {}
134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)   virtual ~SpeechRecognitionTest() {}
144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) protected:
164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual void SetUp() OVERRIDE {
174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    const testing::TestInfo* const test_info =
184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)        testing::UnitTest::GetInstance()->current_test_info();
194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // For SpeechRecognitionTest.SpeechFromBackgroundPage test, we need to
204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // fake the speech input to make tests run OK in bots.
214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    if (!strcmp(test_info->name(), "SpeechFromBackgroundPage")) {
224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      fake_speech_recognition_manager_.reset(
234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)          new content::FakeSpeechRecognitionManager());
244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      fake_speech_recognition_manager_->set_should_send_fake_response(true);
254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      // Inject the fake manager factory so that the test result is returned to
264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      // the web page.
274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      content::SpeechRecognitionManager::SetManagerForTesting(
284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)          fake_speech_recognition_manager_.get());
294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    extensions::PlatformAppBrowserTest::SetUp();
324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    command_line->AppendSwitch(switches::kUseFakeUIForMediaStream);
374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) private:
414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<content::FakeSpeechRecognitionManager>
424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      fake_speech_recognition_manager_;
434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionTest);
454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)};
464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(SpeechRecognitionTest, SpeechFromBackgroundPage) {
484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ASSERT_TRUE(RunPlatformAppTest("platform_apps/speech/background_page"))
494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      << message_;
504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(SpeechRecognitionTest,
534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                       SpeechFromBackgroundPageWithoutPermission) {
544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ASSERT_TRUE(
554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      RunPlatformAppTest("platform_apps/speech/background_page_no_permission"))
564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)          << message_;
574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
58