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