Index: chrome/browser/speech/extension_api/tts_extension_apitest.cc |
diff --git a/chrome/browser/speech/extension_api/tts_extension_apitest.cc b/chrome/browser/speech/extension_api/tts_extension_apitest.cc |
index b9e7a9a0248605a4c5b8910a752f179b4f24dfad..2fe5f52ef4565a5a1f0380f54b2ca14cdeb6eaee 100644 |
--- a/chrome/browser/speech/extension_api/tts_extension_apitest.cc |
+++ b/chrome/browser/speech/extension_api/tts_extension_apitest.cc |
@@ -14,6 +14,7 @@ |
#include "chrome/browser/speech/tts_controller.h" |
#include "chrome/browser/speech/tts_platform.h" |
#include "chrome/common/chrome_switches.h" |
+#include "net/base/network_change_notifier.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -145,6 +146,22 @@ class MockTtsPlatformImpl : public TtsPlatformImpl { |
base::WeakPtrFactory<MockTtsPlatformImpl> ptr_factory_; |
}; |
+class FakeNetworkOnlineStateForTest : public net::NetworkChangeNotifier { |
+ public: |
+ explicit FakeNetworkOnlineStateForTest(bool online) : online_(online) {} |
+ virtual ~FakeNetworkOnlineStateForTest() {} |
+ |
+ virtual ConnectionType GetCurrentConnectionType() const OVERRIDE { |
+ return online_ ? |
+ net::NetworkChangeNotifier::CONNECTION_ETHERNET : |
+ net::NetworkChangeNotifier::CONNECTION_NONE; |
+ } |
+ |
+ private: |
+ bool online_; |
+ DISALLOW_COPY_AND_ASSIGN(FakeNetworkOnlineStateForTest); |
+}; |
+ |
class TtsApiTest : public ExtensionApiTest { |
public: |
virtual void SetUpInProcessBrowserTestFixture() { |
@@ -381,12 +398,28 @@ IN_PROC_BROWSER_TEST_F(TtsApiTest, LangMatching) { |
} |
IN_PROC_BROWSER_TEST_F(TtsApiTest, NetworkSpeechEngine) { |
+ // Simulate online network state. |
+ net::NetworkChangeNotifier::DisableForTest disable_for_test; |
+ FakeNetworkOnlineStateForTest fake_online_state(true); |
not at google - send to devlin
2013/11/04 23:30:43
how... does this get installed? but sure.
dmazzoni
2013/11/04 23:38:15
It's a little odd, but a NetworkChangeNotifier reg
not at google - send to devlin
2013/11/04 23:40:45
You could make the DisableForTest a member of Fake
|
+ |
ExtensionService* service = extensions::ExtensionSystem::Get( |
profile())->extension_service(); |
service->component_loader()->AddNetworkSpeechSynthesisExtension(); |
ASSERT_TRUE(RunExtensionTest("tts_engine/network_speech_engine")) << message_; |
} |
+IN_PROC_BROWSER_TEST_F(TtsApiTest, NoNetworkSpeechEngineWhenOffline) { |
+ // Simulate offline network state. |
+ net::NetworkChangeNotifier::DisableForTest disable_for_test; |
+ FakeNetworkOnlineStateForTest fake_online_state(false); |
+ |
+ ExtensionService* service = extensions::ExtensionSystem::Get( |
+ profile())->extension_service(); |
+ service->component_loader()->AddNetworkSpeechSynthesisExtension(); |
+ // Test should fail when offline. |
+ ASSERT_FALSE(RunExtensionTest("tts_engine/network_speech_engine")); |
+} |
+ |
// http://crbug.com/122474 |
IN_PROC_BROWSER_TEST_F(TtsApiTest, EngineApi) { |
ASSERT_TRUE(RunExtensionTest("tts_engine/engine_api")) << message_; |