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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 150 |
151 base::FieldTrialList field_trial_list_; | 151 base::FieldTrialList field_trial_list_; |
152 std::string extension_id_; | 152 std::string extension_id_; |
153 }; | 153 }; |
154 | 154 |
155 INSTANTIATE_TEST_CASE_P(HotwordServiceTests, | 155 INSTANTIATE_TEST_CASE_P(HotwordServiceTests, |
156 HotwordServiceTest, | 156 HotwordServiceTest, |
157 ::testing::Values( | 157 ::testing::Values( |
158 extension_misc::kHotwordSharedModuleId)); | 158 extension_misc::kHotwordSharedModuleId)); |
159 | 159 |
160 TEST_P(HotwordServiceTest, IsHotwordAllowedDisabledFieldTrial) { | 160 // Disabled due to http://crbug.com/503963. |
161 #if defined(ENABLE_HOTWORDING) | 161 TEST_P(HotwordServiceTest, DISABLED_IsHotwordAllowedDisabledFieldTrial) { |
162 TestingProfile::Builder profile_builder; | 162 TestingProfile::Builder profile_builder; |
163 scoped_ptr<TestingProfile> profile = profile_builder.Build(); | 163 scoped_ptr<TestingProfile> profile = profile_builder.Build(); |
164 | 164 |
165 // Check that the service exists so that a NULL service be ruled out in | 165 // Check that the service exists so that a NULL service be ruled out in |
166 // following tests. | 166 // following tests. |
167 HotwordService* hotword_service = | 167 HotwordService* hotword_service = |
168 HotwordServiceFactory::GetForProfile(profile.get()); | 168 HotwordServiceFactory::GetForProfile(profile.get()); |
169 EXPECT_TRUE(hotword_service != NULL); | 169 EXPECT_TRUE(hotword_service != NULL); |
170 | 170 |
171 // When the field trial is empty, it should be allowed. | 171 // When the field trial is empty, it should be allowed. |
(...skipping 12 matching lines...) Expand all Loading... |
184 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 184 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
185 | 185 |
186 // Set a valid locale with invalid field trial to be sure it is | 186 // Set a valid locale with invalid field trial to be sure it is |
187 // still false. | 187 // still false. |
188 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en"); | 188 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en"); |
189 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 189 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
190 | 190 |
191 // Test that incognito returns false as well. | 191 // Test that incognito returns false as well. |
192 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed( | 192 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed( |
193 profile->GetOffTheRecordProfile())); | 193 profile->GetOffTheRecordProfile())); |
194 #endif | |
195 } | 194 } |
196 | 195 |
197 TEST_P(HotwordServiceTest, IsHotwordAllowedInvalidFieldTrial) { | 196 // Disabled due to http://crbug.com/503963. |
198 #if defined(ENABLE_HOTWORDING) | 197 TEST_P(HotwordServiceTest, DISABLED_IsHotwordAllowedInvalidFieldTrial) { |
199 TestingProfile::Builder profile_builder; | 198 TestingProfile::Builder profile_builder; |
200 scoped_ptr<TestingProfile> profile = profile_builder.Build(); | 199 scoped_ptr<TestingProfile> profile = profile_builder.Build(); |
201 | 200 |
202 // Check that the service exists so that a NULL service be ruled out in | 201 // Check that the service exists so that a NULL service be ruled out in |
203 // following tests. | 202 // following tests. |
204 HotwordService* hotword_service = | 203 HotwordService* hotword_service = |
205 HotwordServiceFactory::GetForProfile(profile.get()); | 204 HotwordServiceFactory::GetForProfile(profile.get()); |
206 EXPECT_TRUE(hotword_service != NULL); | 205 EXPECT_TRUE(hotword_service != NULL); |
207 | 206 |
208 // When the field trial is set, but not 'Disabled', it should be allowed. | 207 // When the field trial is set, but not 'Disabled', it should be allowed. |
209 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 208 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
210 hotword_internal::kHotwordFieldTrialName, "foo")); | 209 hotword_internal::kHotwordFieldTrialName, "foo")); |
211 std::string group = base::FieldTrialList::FindFullName( | 210 std::string group = base::FieldTrialList::FindFullName( |
212 hotword_internal::kHotwordFieldTrialName); | 211 hotword_internal::kHotwordFieldTrialName); |
213 EXPECT_TRUE(group == "foo"); | 212 EXPECT_TRUE(group == "foo"); |
214 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 213 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
215 | 214 |
216 // Test that incognito returns false as well. | 215 // Test that incognito returns false as well. |
217 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed( | 216 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed( |
218 profile->GetOffTheRecordProfile())); | 217 profile->GetOffTheRecordProfile())); |
219 #endif | |
220 } | 218 } |
221 | 219 |
222 TEST_P(HotwordServiceTest, IsHotwordAllowedLocale) { | 220 // Disabled due to http://crbug.com/503963. |
223 #if defined(ENABLE_HOTWORDING) | 221 TEST_P(HotwordServiceTest, DISABLED_IsHotwordAllowedLocale) { |
224 TestingProfile::Builder profile_builder; | 222 TestingProfile::Builder profile_builder; |
225 scoped_ptr<TestingProfile> profile = profile_builder.Build(); | 223 scoped_ptr<TestingProfile> profile = profile_builder.Build(); |
226 | 224 |
| 225 #if defined(ENABLE_HOTWORDING) |
| 226 bool hotwording_enabled = true; |
| 227 #else |
| 228 bool hotwording_enabled = false; |
| 229 #endif |
| 230 |
227 // Check that the service exists so that a NULL service be ruled out in | 231 // Check that the service exists so that a NULL service be ruled out in |
228 // following tests. | 232 // following tests. |
229 HotwordService* hotword_service = | 233 HotwordService* hotword_service = |
230 HotwordServiceFactory::GetForProfile(profile.get()); | 234 HotwordServiceFactory::GetForProfile(profile.get()); |
231 EXPECT_TRUE(hotword_service != NULL); | 235 EXPECT_TRUE(hotword_service != NULL); |
232 | 236 |
233 // Set the language to an invalid one. | 237 // Set the language to an invalid one. |
234 SetApplicationLocale(static_cast<Profile*>(profile.get()), "non-valid"); | 238 SetApplicationLocale(static_cast<Profile*>(profile.get()), "non-valid"); |
235 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 239 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
236 | 240 |
237 // Now with valid locales it should be fine. | 241 // Now with valid locales it should be fine. |
238 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en"); | 242 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en"); |
239 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 243 EXPECT_EQ(hotwording_enabled, |
| 244 HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
240 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en-US"); | 245 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en-US"); |
241 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 246 EXPECT_EQ(hotwording_enabled, |
| 247 HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
242 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en_us"); | 248 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en_us"); |
243 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 249 EXPECT_EQ(hotwording_enabled, |
| 250 HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
244 SetApplicationLocale(static_cast<Profile*>(profile.get()), "de_DE"); | 251 SetApplicationLocale(static_cast<Profile*>(profile.get()), "de_DE"); |
245 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 252 EXPECT_EQ(hotwording_enabled, |
| 253 HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
246 SetApplicationLocale(static_cast<Profile*>(profile.get()), "fr_fr"); | 254 SetApplicationLocale(static_cast<Profile*>(profile.get()), "fr_fr"); |
247 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 255 EXPECT_EQ(hotwording_enabled, |
| 256 HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
248 | 257 |
249 // Test that incognito even with a valid locale and valid field trial | 258 // Test that incognito even with a valid locale and valid field trial |
250 // still returns false. | 259 // still returns false. |
251 Profile* otr_profile = profile->GetOffTheRecordProfile(); | 260 Profile* otr_profile = profile->GetOffTheRecordProfile(); |
252 SetApplicationLocale(otr_profile, "en"); | 261 SetApplicationLocale(otr_profile, "en"); |
253 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(otr_profile)); | 262 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(otr_profile)); |
254 #endif // defined(ENABLE_HOTWORDING) | |
255 } | 263 } |
256 | 264 |
257 TEST_P(HotwordServiceTest, ShouldReinstallExtension) { | 265 TEST_P(HotwordServiceTest, ShouldReinstallExtension) { |
258 InitializeEmptyExtensionService(); | 266 InitializeEmptyExtensionService(); |
259 | 267 |
260 HotwordServiceFactory* hotword_service_factory = | 268 HotwordServiceFactory* hotword_service_factory = |
261 HotwordServiceFactory::GetInstance(); | 269 HotwordServiceFactory::GetInstance(); |
262 | 270 |
263 MockHotwordService* hotword_service = static_cast<MockHotwordService*>( | 271 MockHotwordService* hotword_service = static_cast<MockHotwordService*>( |
264 hotword_service_factory->SetTestingFactoryAndUse( | 272 hotword_service_factory->SetTestingFactoryAndUse( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 SetApplicationLocale(profile(), "test_locale"); | 309 SetApplicationLocale(profile(), "test_locale"); |
302 | 310 |
303 hotword_service->InstallHotwordExtensionFromWebstore(1); | 311 hotword_service->InstallHotwordExtensionFromWebstore(1); |
304 base::MessageLoop::current()->RunUntilIdle(); | 312 base::MessageLoop::current()->RunUntilIdle(); |
305 | 313 |
306 EXPECT_EQ("test_locale", | 314 EXPECT_EQ("test_locale", |
307 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage)); | 315 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage)); |
308 } | 316 } |
309 | 317 |
310 TEST_P(HotwordServiceTest, UninstallReinstallTriggeredCorrectly) { | 318 TEST_P(HotwordServiceTest, UninstallReinstallTriggeredCorrectly) { |
311 #if defined(ENABLE_HOTWORDING) | |
312 InitializeEmptyExtensionService(); | 319 InitializeEmptyExtensionService(); |
313 service_->Init(); | 320 service_->Init(); |
314 | 321 |
315 HotwordServiceFactory* hotword_service_factory = | 322 HotwordServiceFactory* hotword_service_factory = |
316 HotwordServiceFactory::GetInstance(); | 323 HotwordServiceFactory::GetInstance(); |
317 | 324 |
318 MockHotwordService* hotword_service = static_cast<MockHotwordService*>( | 325 MockHotwordService* hotword_service = static_cast<MockHotwordService*>( |
319 hotword_service_factory->SetTestingFactoryAndUse( | 326 hotword_service_factory->SetTestingFactoryAndUse( |
320 profile(), BuildMockHotwordService)); | 327 profile(), BuildMockHotwordService)); |
321 ASSERT_TRUE(hotword_service != NULL); | 328 ASSERT_TRUE(hotword_service != NULL); |
(...skipping 21 matching lines...) Expand all Loading... |
343 EXPECT_EQ(1U, registry()->disabled_extensions().size()); | 350 EXPECT_EQ(1U, registry()->disabled_extensions().size()); |
344 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension_id_)); | 351 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension_id_)); |
345 } | 352 } |
346 | 353 |
347 // The previous locale should be set but should match the current | 354 // The previous locale should be set but should match the current |
348 // locale. No reason to uninstall. | 355 // locale. No reason to uninstall. |
349 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); | 356 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); |
350 | 357 |
351 // Switch the locale to a valid but different one. | 358 // Switch the locale to a valid but different one. |
352 SetApplicationLocale(profile(), "fr_fr"); | 359 SetApplicationLocale(profile(), "fr_fr"); |
| 360 #if defined(ENABLE_HOTWORDING) |
353 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile())); | 361 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile())); |
| 362 #else |
| 363 // Disabled due to http://crbug.com/503963. |
| 364 // EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile())); |
| 365 #endif |
354 | 366 |
355 // Different but valid locale so expect uninstall. | 367 // Different but valid locale so expect uninstall. |
356 EXPECT_TRUE(hotword_service->MaybeReinstallHotwordExtension()); | 368 EXPECT_TRUE(hotword_service->MaybeReinstallHotwordExtension()); |
357 EXPECT_EQ(1, hotword_service->uninstall_count()); | 369 EXPECT_EQ(1, hotword_service->uninstall_count()); |
358 EXPECT_EQ("fr_fr", | 370 EXPECT_EQ("fr_fr", |
359 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage)); | 371 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage)); |
360 | 372 |
361 if (extension_id_ == extension_misc::kHotwordSharedModuleId) { | 373 if (extension_id_ == extension_misc::kHotwordSharedModuleId) { |
362 // Shared module is installed and enabled. | 374 // Shared module is installed and enabled. |
363 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id_)); | 375 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id_)); |
364 } else { | 376 } else { |
365 // Verify the extension is installed. It's still disabled. | 377 // Verify the extension is installed. It's still disabled. |
366 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension_id_)); | 378 EXPECT_TRUE(registry()->disabled_extensions().Contains(extension_id_)); |
367 } | 379 } |
368 | 380 |
369 // Switch the locale to an invalid one. | 381 // Switch the locale to an invalid one. |
370 SetApplicationLocale(profile(), "invalid"); | 382 SetApplicationLocale(profile(), "invalid"); |
371 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile())); | 383 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile())); |
372 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); | 384 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); |
373 EXPECT_EQ("fr_fr", | 385 EXPECT_EQ("fr_fr", |
374 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage)); | 386 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage)); |
375 | 387 |
376 // If the locale is set back to the last valid one, then an uninstall-install | 388 // If the locale is set back to the last valid one, then an uninstall-install |
377 // shouldn't be needed. | 389 // shouldn't be needed. |
378 SetApplicationLocale(profile(), "fr_fr"); | 390 SetApplicationLocale(profile(), "fr_fr"); |
| 391 #if defined(ENABLE_HOTWORDING) |
379 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile())); | 392 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile())); |
| 393 #else |
| 394 // Disabled due to http://crbug.com/503963. |
| 395 // EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile())); |
| 396 #endif |
380 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); | 397 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); |
381 EXPECT_EQ(1, hotword_service->uninstall_count()); // no change | 398 EXPECT_EQ(1, hotword_service->uninstall_count()); // no change |
382 #endif // defined(ENABLE_HOTWORDING) | |
383 } | 399 } |
384 | 400 |
385 TEST_P(HotwordServiceTest, DisableAlwaysOnOnLanguageChange) { | 401 TEST_P(HotwordServiceTest, DisableAlwaysOnOnLanguageChange) { |
386 // Bypass test for old hotwording. | 402 // Bypass test for old hotwording. |
387 if (extension_id_ != extension_misc::kHotwordSharedModuleId) | 403 if (extension_id_ != extension_misc::kHotwordSharedModuleId) |
388 return; | 404 return; |
389 | 405 |
390 // Turn on Always On | 406 // Turn on Always On |
391 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 407 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
392 switches::kEnableExperimentalHotwordHardware); | 408 switches::kEnableExperimentalHotwordHardware); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 EXPECT_EQ(1, audio_history_handler->GetAudioHistoryCalls()); | 578 EXPECT_EQ(1, audio_history_handler->GetAudioHistoryCalls()); |
563 // We expect the next check for audio history to be in the queue. | 579 // We expect the next check for audio history to be in the queue. |
564 EXPECT_EQ(base::TimeDelta::FromDays(1), | 580 EXPECT_EQ(base::TimeDelta::FromDays(1), |
565 test_task_runner->NextPendingTaskDelay()); | 581 test_task_runner->NextPendingTaskDelay()); |
566 EXPECT_TRUE(test_task_runner->HasPendingTask()); | 582 EXPECT_TRUE(test_task_runner->HasPendingTask()); |
567 test_task_runner->RunPendingTasks(); | 583 test_task_runner->RunPendingTasks(); |
568 EXPECT_EQ(2, audio_history_handler->GetAudioHistoryCalls()); | 584 EXPECT_EQ(2, audio_history_handler->GetAudioHistoryCalls()); |
569 EXPECT_TRUE(test_task_runner->HasPendingTask()); | 585 EXPECT_TRUE(test_task_runner->HasPendingTask()); |
570 test_task_runner->ClearPendingTasks(); | 586 test_task_runner->ClearPendingTasks(); |
571 } | 587 } |
OLD | NEW |