| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
| 7 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h" | 7 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h" |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_test_message_listener.h" | 10 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 } | 31 } |
| 32 | 32 |
| 33 void setServiceAvailable(bool available) { | 33 void setServiceAvailable(bool available) { |
| 34 service_available_ = available; | 34 service_available_ = available; |
| 35 } | 35 } |
| 36 | 36 |
| 37 static KeyedService* Build(content::BrowserContext* profile) { | 37 static KeyedService* Build(content::BrowserContext* profile) { |
| 38 return new MockHotwordService(static_cast<Profile*>(profile)); | 38 return new MockHotwordService(static_cast<Profile*>(profile)); |
| 39 } | 39 } |
| 40 | 40 |
| 41 virtual LaunchMode GetHotwordAudioVerificationLaunchMode() OVERRIDE { |
| 42 return launch_mode_; |
| 43 } |
| 44 |
| 45 void SetHotwordAudioVerificationLaunchMode(const LaunchMode& launch_mode) { |
| 46 launch_mode_ = launch_mode; |
| 47 } |
| 48 |
| 41 private: | 49 private: |
| 42 bool service_available_; | 50 bool service_available_; |
| 51 LaunchMode launch_mode_; |
| 43 | 52 |
| 44 DISALLOW_COPY_AND_ASSIGN(MockHotwordService); | 53 DISALLOW_COPY_AND_ASSIGN(MockHotwordService); |
| 45 }; | 54 }; |
| 46 | 55 |
| 47 class MockHotwordClient : public HotwordClient { | 56 class MockHotwordClient : public HotwordClient { |
| 48 public: | 57 public: |
| 49 MockHotwordClient() | 58 MockHotwordClient() |
| 50 : last_enabled_(false), | 59 : last_enabled_(false), |
| 51 state_changed_count_(0), | 60 state_changed_count_(0), |
| 52 recognized_count_(0) { | 61 recognized_count_(0) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 MockHotwordClient client; | 219 MockHotwordClient client; |
| 211 service()->RequestHotwordSession(&client); | 220 service()->RequestHotwordSession(&client); |
| 212 EXPECT_TRUE(listenerStopReady.WaitUntilSatisfied()); | 221 EXPECT_TRUE(listenerStopReady.WaitUntilSatisfied()); |
| 213 service()->StopHotwordSession(&client); | 222 service()->StopHotwordSession(&client); |
| 214 EXPECT_TRUE(listenerStopped.WaitUntilSatisfied()); | 223 EXPECT_TRUE(listenerStopped.WaitUntilSatisfied()); |
| 215 | 224 |
| 216 EXPECT_TRUE(client.last_enabled()); | 225 EXPECT_TRUE(client.last_enabled()); |
| 217 EXPECT_EQ(1, client.state_changed_count()); | 226 EXPECT_EQ(1, client.state_changed_count()); |
| 218 EXPECT_EQ(1, client.recognized_count()); | 227 EXPECT_EQ(1, client.recognized_count()); |
| 219 } | 228 } |
| 229 |
| 230 IN_PROC_BROWSER_TEST_F(HotwordPrivateApiTest, GetLaunchStateHotwordOnly) { |
| 231 service()->SetHotwordAudioVerificationLaunchMode( |
| 232 HotwordService::HOTWORD_ONLY); |
| 233 ExtensionTestMessageListener listener("launchMode: 1", false); |
| 234 ASSERT_TRUE(RunComponentExtensionTest("getLaunchState")) << message_; |
| 235 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 236 } |
| 237 |
| 238 IN_PROC_BROWSER_TEST_F(HotwordPrivateApiTest, |
| 239 GetLaunchStateHotwordAudioHistory) { |
| 240 service()->SetHotwordAudioVerificationLaunchMode( |
| 241 HotwordService::HOTWORD_AND_AUDIO_HISTORY); |
| 242 ExtensionTestMessageListener listener("launchMode: 2", false); |
| 243 ASSERT_TRUE(RunComponentExtensionTest("getLaunchState")) << message_; |
| 244 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 245 } |
| OLD | NEW |