#include <vector>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/speech/extension_api/tts_engine_extension_api.h"
#include "chrome/browser/speech/extension_api/tts_extension_api.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/tts_controller.h"
#include "content/public/browser/tts_platform.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_host_test_helper.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/mojom/view_type.mojom.h"
#include "net/base/network_change_notifier.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/speech/extension_api/tts_engine_extension_observer_chromeos.h"
#include "chromeos/services/tts/tts_service.h"
#endif
_;
AnyNumber;
DoAll;
InSequence;
Invoke;
InvokeWithoutArgs;
Return;
SaveArg;
SetArgPointee;
StrictMock;
namespace {
int g_saved_utterance_id;
}
namespace extensions {
class MockTtsPlatformImpl : public content::TtsPlatform { … };
class FakeNetworkOnlineStateForTest : public net::NetworkChangeNotifier { … };
class EventRouterAddListenerWaiter : public EventRouter::Observer { … };
ContextType;
class TtsApiTest : public ExtensionApiTest,
public testing::WithParamInterface<ContextType> { … };
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
IN_PROC_BROWSER_TEST_P(TtsApiTest, PlatformSpeakOptionalArgs) { … }
IN_PROC_BROWSER_TEST_P(TtsApiTest, PlatformSpeakFinishesImmediately) { … }
IN_PROC_BROWSER_TEST_P(TtsApiTest, PlatformSpeakInterrupt) { … }
IN_PROC_BROWSER_TEST_P(TtsApiTest, PlatformSpeakQueueInterrupt) { … }
IN_PROC_BROWSER_TEST_P(TtsApiTest, PlatformSpeakEnqueue) { … }
IN_PROC_BROWSER_TEST_P(TtsApiTest, PlatformSpeakError) { … }
IN_PROC_BROWSER_TEST_P(TtsApiTest, PlatformWordCallbacks) { … }
IN_PROC_BROWSER_TEST_P(TtsApiTest, PlatformPauseResume) { … }
IN_PROC_BROWSER_TEST_P(TtsApiTest, PlatformPauseSpeakNoEnqueue) { … }
TtsApiServiceWorkerTest;
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(TtsApiServiceWorkerTest, Enqueue) { … }
IN_PROC_BROWSER_TEST_P(TtsApiServiceWorkerTest, SpeakError) { … }
IN_PROC_BROWSER_TEST_P(TtsApiTest, RegisterEngine) { … }
#endif
#if BUILDFLAG(IS_POSIX)
#define MAYBE_EngineError …
#else
#define MAYBE_EngineError …
#endif
IN_PROC_BROWSER_TEST_P(TtsApiTest, MAYBE_EngineError) { … }
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
IN_PROC_BROWSER_TEST_P(TtsApiTest, EngineWordCallbacks) { … }
IN_PROC_BROWSER_TEST_P(TtsApiTest, LangMatching) { … }
#endif
IN_PROC_BROWSER_TEST_P(TtsApiTest, NetworkSpeechEngine) { … }
IN_PROC_BROWSER_TEST_P(TtsApiTest, NoNetworkSpeechEngineWhenOffline) { … }
IN_PROC_BROWSER_TEST_P(TtsApiTest, EngineApi) { … }
IN_PROC_BROWSER_TEST_P(TtsApiTest, UpdateVoicesApi) { … }
IN_PROC_BROWSER_TEST_P(TtsApiTest, PRE_VoicesAreCached) { … }
IN_PROC_BROWSER_TEST_P(TtsApiTest, VoicesAreCached) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_P(TtsApiTest, OnSpeakWithAudioStream) {
TtsExtensionEngine::GetInstance()->DisableBuiltInTTSEngineForTesting();
TtsEngineExtensionObserverChromeOS* engine_observer =
TtsEngineExtensionObserverChromeOS::GetInstance(profile());
mojo::Remote<chromeos::tts::mojom::TtsService>* tts_service_remote =
engine_observer->tts_service_for_testing();
chromeos::tts::TtsService tts_service(
tts_service_remote->BindNewPipeAndPassReceiver());
EXPECT_CALL(mock_platform_impl_, IsSpeaking()).Times(AnyNumber());
EXPECT_CALL(mock_platform_impl_, StopSpeaking()).WillRepeatedly(Return(true));
ASSERT_TRUE(RunExtensionTest("tts_engine/on_speak_with_audio_stream"))
<< message_;
}
IN_PROC_BROWSER_TEST_P(TtsApiTest, OnSpeakWithAudioStreamAudioOptions) {
TtsExtensionEngine::GetInstance()->DisableBuiltInTTSEngineForTesting();
TtsEngineExtensionObserverChromeOS* engine_observer =
TtsEngineExtensionObserverChromeOS::GetInstance(profile());
mojo::Remote<chromeos::tts::mojom::TtsService>* tts_service_remote =
engine_observer->tts_service_for_testing();
chromeos::tts::TtsService tts_service(
tts_service_remote->BindNewPipeAndPassReceiver());
EXPECT_CALL(mock_platform_impl_, IsSpeaking()).Times(AnyNumber());
EXPECT_CALL(mock_platform_impl_, StopSpeaking()).WillRepeatedly(Return(true));
ASSERT_TRUE(RunExtensionTest(
"tts_engine/on_speak_with_audio_stream_using_audio_options"))
<< message_;
}
#endif
}