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/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/test/test_simple_task_runner.h" | 9 #include "base/test/test_simple_task_runner.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 152 |
153 std::string extension_id_; | 153 std::string extension_id_; |
154 }; | 154 }; |
155 | 155 |
156 INSTANTIATE_TEST_CASE_P(HotwordServiceTests, | 156 INSTANTIATE_TEST_CASE_P(HotwordServiceTests, |
157 HotwordServiceTest, | 157 HotwordServiceTest, |
158 ::testing::Values( | 158 ::testing::Values( |
159 extension_misc::kHotwordSharedModuleId)); | 159 extension_misc::kHotwordSharedModuleId)); |
160 | 160 |
161 TEST_P(HotwordServiceTest, IsHotwordAllowedLocale) { | 161 TEST_P(HotwordServiceTest, IsHotwordAllowedLocale) { |
162 #if defined(ENABLE_HOTWORDING) | |
163 TestingProfile::Builder profile_builder; | 162 TestingProfile::Builder profile_builder; |
164 scoped_ptr<TestingProfile> profile = profile_builder.Build(); | 163 scoped_ptr<TestingProfile> profile = profile_builder.Build(); |
165 | 164 |
| 165 #if defined(ENABLE_HOTWORDING) |
| 166 bool hotwording_enabled = true; |
| 167 #else |
| 168 bool hotwording_enabled = false; |
| 169 #endif |
| 170 |
166 // Check that the service exists so that a NULL service be ruled out in | 171 // Check that the service exists so that a NULL service be ruled out in |
167 // following tests. | 172 // following tests. |
168 HotwordService* hotword_service = | 173 HotwordService* hotword_service = |
169 HotwordServiceFactory::GetForProfile(profile.get()); | 174 HotwordServiceFactory::GetForProfile(profile.get()); |
170 EXPECT_TRUE(hotword_service != NULL); | 175 EXPECT_TRUE(hotword_service != NULL); |
171 | 176 |
172 // Set the language to an invalid one. | 177 // Set the language to an invalid one. |
173 SetApplicationLocale(static_cast<Profile*>(profile.get()), "non-valid"); | 178 SetApplicationLocale(static_cast<Profile*>(profile.get()), "non-valid"); |
174 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 179 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
175 | 180 |
176 // Now with valid locales it should be fine. | 181 // Now with valid locales it should be fine. |
177 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en"); | 182 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en"); |
178 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 183 EXPECT_EQ(hotwording_enabled, |
| 184 HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
179 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en-US"); | 185 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en-US"); |
180 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 186 EXPECT_EQ(hotwording_enabled, |
| 187 HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
181 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en_us"); | 188 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en_us"); |
182 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 189 EXPECT_EQ(hotwording_enabled, |
| 190 HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
183 SetApplicationLocale(static_cast<Profile*>(profile.get()), "de_DE"); | 191 SetApplicationLocale(static_cast<Profile*>(profile.get()), "de_DE"); |
184 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 192 EXPECT_EQ(hotwording_enabled, |
| 193 HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
185 SetApplicationLocale(static_cast<Profile*>(profile.get()), "fr_fr"); | 194 SetApplicationLocale(static_cast<Profile*>(profile.get()), "fr_fr"); |
186 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 195 EXPECT_EQ(hotwording_enabled, |
| 196 HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
187 | 197 |
188 // Test that incognito even with a valid locale and valid field trial | 198 // Test that incognito even with a valid locale and valid field trial |
189 // still returns false. | 199 // still returns false. |
190 Profile* otr_profile = profile->GetOffTheRecordProfile(); | 200 Profile* otr_profile = profile->GetOffTheRecordProfile(); |
191 SetApplicationLocale(otr_profile, "en"); | 201 SetApplicationLocale(otr_profile, "en"); |
192 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(otr_profile)); | 202 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(otr_profile)); |
193 #endif // defined(ENABLE_HOTWORDING) | |
194 } | 203 } |
195 | 204 |
196 TEST_P(HotwordServiceTest, ShouldReinstallExtension) { | 205 TEST_P(HotwordServiceTest, ShouldReinstallExtension) { |
197 InitializeEmptyExtensionService(); | 206 InitializeEmptyExtensionService(); |
198 | 207 |
199 HotwordServiceFactory* hotword_service_factory = | 208 HotwordServiceFactory* hotword_service_factory = |
200 HotwordServiceFactory::GetInstance(); | 209 HotwordServiceFactory::GetInstance(); |
201 | 210 |
202 MockHotwordService* hotword_service = static_cast<MockHotwordService*>( | 211 MockHotwordService* hotword_service = static_cast<MockHotwordService*>( |
203 hotword_service_factory->SetTestingFactoryAndUse( | 212 hotword_service_factory->SetTestingFactoryAndUse( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 SetApplicationLocale(profile(), "test_locale"); | 249 SetApplicationLocale(profile(), "test_locale"); |
241 | 250 |
242 hotword_service->InstallHotwordExtensionFromWebstore(1); | 251 hotword_service->InstallHotwordExtensionFromWebstore(1); |
243 base::MessageLoop::current()->RunUntilIdle(); | 252 base::MessageLoop::current()->RunUntilIdle(); |
244 | 253 |
245 EXPECT_EQ("test_locale", | 254 EXPECT_EQ("test_locale", |
246 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage)); | 255 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage)); |
247 } | 256 } |
248 | 257 |
249 TEST_P(HotwordServiceTest, UninstallReinstallTriggeredCorrectly) { | 258 TEST_P(HotwordServiceTest, UninstallReinstallTriggeredCorrectly) { |
250 #if defined(ENABLE_HOTWORDING) | |
251 InitializeEmptyExtensionService(); | 259 InitializeEmptyExtensionService(); |
252 service_->Init(); | 260 service_->Init(); |
253 | 261 |
254 HotwordServiceFactory* hotword_service_factory = | 262 HotwordServiceFactory* hotword_service_factory = |
255 HotwordServiceFactory::GetInstance(); | 263 HotwordServiceFactory::GetInstance(); |
256 | 264 |
257 MockHotwordService* hotword_service = static_cast<MockHotwordService*>( | 265 MockHotwordService* hotword_service = static_cast<MockHotwordService*>( |
258 hotword_service_factory->SetTestingFactoryAndUse( | 266 hotword_service_factory->SetTestingFactoryAndUse( |
259 profile(), BuildMockHotwordService)); | 267 profile(), BuildMockHotwordService)); |
260 ASSERT_TRUE(hotword_service != NULL); | 268 ASSERT_TRUE(hotword_service != NULL); |
(...skipping 21 matching lines...) Expand all Loading... |
282 EXPECT_EQ(1U, registry()->disabled_extensions().size()); | 290 EXPECT_EQ(1U, registry()->disabled_extensions().size()); |
283 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension_id_)); | 291 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension_id_)); |
284 } | 292 } |
285 | 293 |
286 // The previous locale should be set but should match the current | 294 // The previous locale should be set but should match the current |
287 // locale. No reason to uninstall. | 295 // locale. No reason to uninstall. |
288 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); | 296 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); |
289 | 297 |
290 // Switch the locale to a valid but different one. | 298 // Switch the locale to a valid but different one. |
291 SetApplicationLocale(profile(), "fr_fr"); | 299 SetApplicationLocale(profile(), "fr_fr"); |
| 300 #if defined(ENABLE_HOTWORDING) |
292 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile())); | 301 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile())); |
| 302 #else |
| 303 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile())); |
| 304 #endif |
293 | 305 |
294 // Different but valid locale so expect uninstall. | 306 // Different but valid locale so expect uninstall. |
295 EXPECT_TRUE(hotword_service->MaybeReinstallHotwordExtension()); | 307 EXPECT_TRUE(hotword_service->MaybeReinstallHotwordExtension()); |
296 EXPECT_EQ(1, hotword_service->uninstall_count()); | 308 EXPECT_EQ(1, hotword_service->uninstall_count()); |
297 EXPECT_EQ("fr_fr", | 309 EXPECT_EQ("fr_fr", |
298 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage)); | 310 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage)); |
299 | 311 |
300 if (extension_id_ == extension_misc::kHotwordSharedModuleId) { | 312 if (extension_id_ == extension_misc::kHotwordSharedModuleId) { |
301 // Shared module is installed and enabled. | 313 // Shared module is installed and enabled. |
302 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id_)); | 314 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id_)); |
303 } else { | 315 } else { |
304 // Verify the extension is installed. It's still disabled. | 316 // Verify the extension is installed. It's still disabled. |
305 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension_id_)); | 317 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension_id_)); |
306 } | 318 } |
307 | 319 |
308 // Switch the locale to an invalid one. | 320 // Switch the locale to an invalid one. |
309 SetApplicationLocale(profile(), "invalid"); | 321 SetApplicationLocale(profile(), "invalid"); |
310 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile())); | 322 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile())); |
311 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); | 323 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); |
312 EXPECT_EQ("fr_fr", | 324 EXPECT_EQ("fr_fr", |
313 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage)); | 325 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage)); |
314 | 326 |
315 // If the locale is set back to the last valid one, then an uninstall-install | 327 // If the locale is set back to the last valid one, then an uninstall-install |
316 // shouldn't be needed. | 328 // shouldn't be needed. |
317 SetApplicationLocale(profile(), "fr_fr"); | 329 SetApplicationLocale(profile(), "fr_fr"); |
| 330 #if defined(ENABLE_HOTWORDING) |
318 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile())); | 331 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile())); |
| 332 #else |
| 333 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile())); |
| 334 #endif |
319 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); | 335 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); |
320 EXPECT_EQ(1, hotword_service->uninstall_count()); // no change | 336 EXPECT_EQ(1, hotword_service->uninstall_count()); // no change |
321 #endif // defined(ENABLE_HOTWORDING) | |
322 } | 337 } |
323 | 338 |
324 TEST_P(HotwordServiceTest, DisableAlwaysOnOnLanguageChange) { | 339 TEST_P(HotwordServiceTest, DisableAlwaysOnOnLanguageChange) { |
325 // Bypass test for old hotwording. | 340 // Bypass test for old hotwording. |
326 if (extension_id_ != extension_misc::kHotwordSharedModuleId) | 341 if (extension_id_ != extension_misc::kHotwordSharedModuleId) |
327 return; | 342 return; |
328 | 343 |
329 // Turn on Always On | 344 // Turn on Always On |
330 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 345 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
331 switches::kEnableExperimentalHotwordHardware); | 346 switches::kEnableExperimentalHotwordHardware); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 EXPECT_EQ(1, audio_history_handler->GetAudioHistoryCalls()); | 516 EXPECT_EQ(1, audio_history_handler->GetAudioHistoryCalls()); |
502 // We expect the next check for audio history to be in the queue. | 517 // We expect the next check for audio history to be in the queue. |
503 EXPECT_EQ(base::TimeDelta::FromDays(1), | 518 EXPECT_EQ(base::TimeDelta::FromDays(1), |
504 test_task_runner->NextPendingTaskDelay()); | 519 test_task_runner->NextPendingTaskDelay()); |
505 EXPECT_TRUE(test_task_runner->HasPendingTask()); | 520 EXPECT_TRUE(test_task_runner->HasPendingTask()); |
506 test_task_runner->RunPendingTasks(); | 521 test_task_runner->RunPendingTasks(); |
507 EXPECT_EQ(2, audio_history_handler->GetAudioHistoryCalls()); | 522 EXPECT_EQ(2, audio_history_handler->GetAudioHistoryCalls()); |
508 EXPECT_TRUE(test_task_runner->HasPendingTask()); | 523 EXPECT_TRUE(test_task_runner->HasPendingTask()); |
509 test_task_runner->ClearPendingTasks(); | 524 test_task_runner->ClearPendingTasks(); |
510 } | 525 } |
OLD | NEW |