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

Side by Side Diff: chrome/browser/search/hotword_service_unittest.cc

Issue 1160243004: Add build flag to disable hotwording. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Back to flag and enable by default. Created 5 years, 6 months 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
« no previous file with comments | « chrome/browser/search/hotword_service.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
150 150
151 std::string extension_id_; 151 std::string extension_id_;
152 }; 152 };
153 153
154 INSTANTIATE_TEST_CASE_P(HotwordServiceTests, 154 INSTANTIATE_TEST_CASE_P(HotwordServiceTests,
155 HotwordServiceTest, 155 HotwordServiceTest,
156 ::testing::Values( 156 ::testing::Values(
157 extension_misc::kHotwordSharedModuleId)); 157 extension_misc::kHotwordSharedModuleId));
158 158
159 TEST_P(HotwordServiceTest, IsHotwordAllowedLocale) { 159 TEST_P(HotwordServiceTest, IsHotwordAllowedLocale) {
160 #if defined(ENABLE_HOTWORDING)
160 TestingProfile::Builder profile_builder; 161 TestingProfile::Builder profile_builder;
161 scoped_ptr<TestingProfile> profile = profile_builder.Build(); 162 scoped_ptr<TestingProfile> profile = profile_builder.Build();
162 163
163 // Check that the service exists so that a NULL service be ruled out in 164 // Check that the service exists so that a NULL service be ruled out in
164 // following tests. 165 // following tests.
165 HotwordService* hotword_service = 166 HotwordService* hotword_service =
166 HotwordServiceFactory::GetForProfile(profile.get()); 167 HotwordServiceFactory::GetForProfile(profile.get());
167 EXPECT_TRUE(hotword_service != NULL); 168 EXPECT_TRUE(hotword_service != NULL);
168 169
169 // Set the language to an invalid one. 170 // Set the language to an invalid one.
(...skipping 10 matching lines...) Expand all
180 SetApplicationLocale(static_cast<Profile*>(profile.get()), "de_DE"); 181 SetApplicationLocale(static_cast<Profile*>(profile.get()), "de_DE");
181 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); 182 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get()));
182 SetApplicationLocale(static_cast<Profile*>(profile.get()), "fr_fr"); 183 SetApplicationLocale(static_cast<Profile*>(profile.get()), "fr_fr");
183 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); 184 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get()));
184 185
185 // Test that incognito even with a valid locale and valid field trial 186 // Test that incognito even with a valid locale and valid field trial
186 // still returns false. 187 // still returns false.
187 Profile* otr_profile = profile->GetOffTheRecordProfile(); 188 Profile* otr_profile = profile->GetOffTheRecordProfile();
188 SetApplicationLocale(otr_profile, "en"); 189 SetApplicationLocale(otr_profile, "en");
189 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(otr_profile)); 190 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(otr_profile));
191 #endif // defined(ENABLE_HOTWORDING)
190 } 192 }
191 193
192 TEST_P(HotwordServiceTest, ShouldReinstallExtension) { 194 TEST_P(HotwordServiceTest, ShouldReinstallExtension) {
193 InitializeEmptyExtensionService(); 195 InitializeEmptyExtensionService();
194 196
195 HotwordServiceFactory* hotword_service_factory = 197 HotwordServiceFactory* hotword_service_factory =
196 HotwordServiceFactory::GetInstance(); 198 HotwordServiceFactory::GetInstance();
197 199
198 MockHotwordService* hotword_service = static_cast<MockHotwordService*>( 200 MockHotwordService* hotword_service = static_cast<MockHotwordService*>(
199 hotword_service_factory->SetTestingFactoryAndUse( 201 hotword_service_factory->SetTestingFactoryAndUse(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 SetApplicationLocale(profile(), "test_locale"); 238 SetApplicationLocale(profile(), "test_locale");
237 239
238 hotword_service->InstallHotwordExtensionFromWebstore(1); 240 hotword_service->InstallHotwordExtensionFromWebstore(1);
239 base::MessageLoop::current()->RunUntilIdle(); 241 base::MessageLoop::current()->RunUntilIdle();
240 242
241 EXPECT_EQ("test_locale", 243 EXPECT_EQ("test_locale",
242 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage)); 244 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage));
243 } 245 }
244 246
245 TEST_P(HotwordServiceTest, UninstallReinstallTriggeredCorrectly) { 247 TEST_P(HotwordServiceTest, UninstallReinstallTriggeredCorrectly) {
248 #if defined(ENABLE_HOTWORDING)
246 InitializeEmptyExtensionService(); 249 InitializeEmptyExtensionService();
247 service_->Init(); 250 service_->Init();
248 251
249 HotwordServiceFactory* hotword_service_factory = 252 HotwordServiceFactory* hotword_service_factory =
250 HotwordServiceFactory::GetInstance(); 253 HotwordServiceFactory::GetInstance();
251 254
252 MockHotwordService* hotword_service = static_cast<MockHotwordService*>( 255 MockHotwordService* hotword_service = static_cast<MockHotwordService*>(
253 hotword_service_factory->SetTestingFactoryAndUse( 256 hotword_service_factory->SetTestingFactoryAndUse(
254 profile(), BuildMockHotwordService)); 257 profile(), BuildMockHotwordService));
255 ASSERT_TRUE(hotword_service != NULL); 258 ASSERT_TRUE(hotword_service != NULL);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); 309 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension());
307 EXPECT_EQ("fr_fr", 310 EXPECT_EQ("fr_fr",
308 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage)); 311 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage));
309 312
310 // If the locale is set back to the last valid one, then an uninstall-install 313 // If the locale is set back to the last valid one, then an uninstall-install
311 // shouldn't be needed. 314 // shouldn't be needed.
312 SetApplicationLocale(profile(), "fr_fr"); 315 SetApplicationLocale(profile(), "fr_fr");
313 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile())); 316 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile()));
314 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); 317 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension());
315 EXPECT_EQ(1, hotword_service->uninstall_count()); // no change 318 EXPECT_EQ(1, hotword_service->uninstall_count()); // no change
319 #endif // defined(ENABLE_HOTWORDING)
316 } 320 }
317 321
318 TEST_P(HotwordServiceTest, DisableAlwaysOnOnLanguageChange) { 322 TEST_P(HotwordServiceTest, DisableAlwaysOnOnLanguageChange) {
319 // Bypass test for old hotwording. 323 // Bypass test for old hotwording.
320 if (extension_id_ != extension_misc::kHotwordSharedModuleId) 324 if (extension_id_ != extension_misc::kHotwordSharedModuleId)
321 return; 325 return;
322 326
323 // Turn on Always On 327 // Turn on Always On
324 base::CommandLine::ForCurrentProcess()->AppendSwitch( 328 base::CommandLine::ForCurrentProcess()->AppendSwitch(
325 switches::kEnableExperimentalHotwordHardware); 329 switches::kEnableExperimentalHotwordHardware);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 EXPECT_EQ(1, audio_history_handler->GetAudioHistoryCalls()); 499 EXPECT_EQ(1, audio_history_handler->GetAudioHistoryCalls());
496 // We expect the next check for audio history to be in the queue. 500 // We expect the next check for audio history to be in the queue.
497 EXPECT_EQ(base::TimeDelta::FromDays(1), 501 EXPECT_EQ(base::TimeDelta::FromDays(1),
498 test_task_runner->NextPendingTaskDelay()); 502 test_task_runner->NextPendingTaskDelay());
499 EXPECT_TRUE(test_task_runner->HasPendingTask()); 503 EXPECT_TRUE(test_task_runner->HasPendingTask());
500 test_task_runner->RunPendingTasks(); 504 test_task_runner->RunPendingTasks();
501 EXPECT_EQ(2, audio_history_handler->GetAudioHistoryCalls()); 505 EXPECT_EQ(2, audio_history_handler->GetAudioHistoryCalls());
502 EXPECT_TRUE(test_task_runner->HasPendingTask()); 506 EXPECT_TRUE(test_task_runner->HasPendingTask());
503 test_task_runner->ClearPendingTasks(); 507 test_task_runner->ClearPendingTasks();
504 } 508 }
OLDNEW
« no previous file with comments | « chrome/browser/search/hotword_service.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698