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

Side by Side Diff: chrome/browser/speech/extension_api/tts_extension_apitest.cc

Issue 58513003: Disable remote TTS services when offline. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "chrome/browser/extensions/component_loader.h" 9 #include "chrome/browser/extensions/component_loader.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_system.h" 12 #include "chrome/browser/extensions/extension_system.h"
13 #include "chrome/browser/speech/extension_api/tts_extension_api.h" 13 #include "chrome/browser/speech/extension_api/tts_extension_api.h"
14 #include "chrome/browser/speech/tts_controller.h" 14 #include "chrome/browser/speech/tts_controller.h"
15 #include "chrome/browser/speech/tts_platform.h" 15 #include "chrome/browser/speech/tts_platform.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "net/base/network_change_notifier.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 // Needed for CreateFunctor. 21 // Needed for CreateFunctor.
21 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING 22 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING
22 #include "testing/gmock_mutant.h" 23 #include "testing/gmock_mutant.h"
23 24
24 using ::testing::AnyNumber; 25 using ::testing::AnyNumber;
25 using ::testing::CreateFunctor; 26 using ::testing::CreateFunctor;
26 using ::testing::DoAll; 27 using ::testing::DoAll;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 return; 139 return;
139 } 140 }
140 141
141 controller->OnTtsEvent(utterance_id, event_type, char_index, message); 142 controller->OnTtsEvent(utterance_id, event_type, char_index, message);
142 } 143 }
143 144
144 private: 145 private:
145 base::WeakPtrFactory<MockTtsPlatformImpl> ptr_factory_; 146 base::WeakPtrFactory<MockTtsPlatformImpl> ptr_factory_;
146 }; 147 };
147 148
149 class FakeNetworkOnlineStateForTest : public net::NetworkChangeNotifier {
150 public:
151 explicit FakeNetworkOnlineStateForTest(bool online) : online_(online) {}
152 virtual ~FakeNetworkOnlineStateForTest() {}
153
154 virtual ConnectionType GetCurrentConnectionType() const OVERRIDE {
155 return online_ ?
156 net::NetworkChangeNotifier::CONNECTION_ETHERNET :
157 net::NetworkChangeNotifier::CONNECTION_NONE;
158 }
159
160 private:
161 bool online_;
162 DISALLOW_COPY_AND_ASSIGN(FakeNetworkOnlineStateForTest);
163 };
164
148 class TtsApiTest : public ExtensionApiTest { 165 class TtsApiTest : public ExtensionApiTest {
149 public: 166 public:
150 virtual void SetUpInProcessBrowserTestFixture() { 167 virtual void SetUpInProcessBrowserTestFixture() {
151 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); 168 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
152 TtsController::GetInstance()->SetPlatformImpl(&mock_platform_impl_); 169 TtsController::GetInstance()->SetPlatformImpl(&mock_platform_impl_);
153 EXPECT_CALL(mock_platform_impl_, GetVoices(_)) 170 EXPECT_CALL(mock_platform_impl_, GetVoices(_))
154 .Times(AnyNumber()); 171 .Times(AnyNumber());
155 } 172 }
156 173
157 protected: 174 protected:
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 391
375 IN_PROC_BROWSER_TEST_F(TtsApiTest, LangMatching) { 392 IN_PROC_BROWSER_TEST_F(TtsApiTest, LangMatching) {
376 EXPECT_CALL(mock_platform_impl_, IsSpeaking()); 393 EXPECT_CALL(mock_platform_impl_, IsSpeaking());
377 EXPECT_CALL(mock_platform_impl_, StopSpeaking()) 394 EXPECT_CALL(mock_platform_impl_, StopSpeaking())
378 .WillRepeatedly(Return(true)); 395 .WillRepeatedly(Return(true));
379 396
380 ASSERT_TRUE(RunExtensionTest("tts_engine/lang_matching")) << message_; 397 ASSERT_TRUE(RunExtensionTest("tts_engine/lang_matching")) << message_;
381 } 398 }
382 399
383 IN_PROC_BROWSER_TEST_F(TtsApiTest, NetworkSpeechEngine) { 400 IN_PROC_BROWSER_TEST_F(TtsApiTest, NetworkSpeechEngine) {
401 // Simulate online network state.
402 net::NetworkChangeNotifier::DisableForTest disable_for_test;
403 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
404
384 ExtensionService* service = extensions::ExtensionSystem::Get( 405 ExtensionService* service = extensions::ExtensionSystem::Get(
385 profile())->extension_service(); 406 profile())->extension_service();
386 service->component_loader()->AddNetworkSpeechSynthesisExtension(); 407 service->component_loader()->AddNetworkSpeechSynthesisExtension();
387 ASSERT_TRUE(RunExtensionTest("tts_engine/network_speech_engine")) << message_; 408 ASSERT_TRUE(RunExtensionTest("tts_engine/network_speech_engine")) << message_;
388 } 409 }
389 410
411 IN_PROC_BROWSER_TEST_F(TtsApiTest, NoNetworkSpeechEngineWhenOffline) {
412 // Simulate offline network state.
413 net::NetworkChangeNotifier::DisableForTest disable_for_test;
414 FakeNetworkOnlineStateForTest fake_online_state(false);
415
416 ExtensionService* service = extensions::ExtensionSystem::Get(
417 profile())->extension_service();
418 service->component_loader()->AddNetworkSpeechSynthesisExtension();
419 // Test should fail when offline.
420 ASSERT_FALSE(RunExtensionTest("tts_engine/network_speech_engine"));
421 }
422
390 // http://crbug.com/122474 423 // http://crbug.com/122474
391 IN_PROC_BROWSER_TEST_F(TtsApiTest, EngineApi) { 424 IN_PROC_BROWSER_TEST_F(TtsApiTest, EngineApi) {
392 ASSERT_TRUE(RunExtensionTest("tts_engine/engine_api")) << message_; 425 ASSERT_TRUE(RunExtensionTest("tts_engine/engine_api")) << message_;
393 } 426 }
394 427
395 } // namespace extensions 428 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698