| 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 "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/extensions/extension_service_test_base.h" | 10 #include "chrome/browser/extensions/extension_service_test_base.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 INSTANTIATE_TEST_CASE_P(HotwordServiceTests, | 110 INSTANTIATE_TEST_CASE_P(HotwordServiceTests, |
| 111 HotwordServiceTest, | 111 HotwordServiceTest, |
| 112 ::testing::Values( | 112 ::testing::Values( |
| 113 extension_misc::kHotwordExtensionId, | 113 extension_misc::kHotwordExtensionId, |
| 114 extension_misc::kHotwordSharedModuleId)); | 114 extension_misc::kHotwordSharedModuleId)); |
| 115 | 115 |
| 116 TEST_P(HotwordServiceTest, IsHotwordAllowedBadFieldTrial) { | 116 TEST_P(HotwordServiceTest, IsHotwordAllowedBadFieldTrial) { |
| 117 TestingProfile::Builder profile_builder; | 117 TestingProfile::Builder profile_builder; |
| 118 scoped_ptr<TestingProfile> profile = profile_builder.Build(); | 118 scoped_ptr<TestingProfile> profile = profile_builder.Build(); |
| 119 | 119 |
| 120 HotwordServiceFactory* hotword_service_factory = | |
| 121 HotwordServiceFactory::GetInstance(); | |
| 122 | |
| 123 // Check that the service exists so that a NULL service be ruled out in | 120 // Check that the service exists so that a NULL service be ruled out in |
| 124 // following tests. | 121 // following tests. |
| 125 HotwordService* hotword_service = | 122 HotwordService* hotword_service = |
| 126 hotword_service_factory->GetForProfile(profile.get()); | 123 HotwordServiceFactory::GetInstance()->GetForProfile(profile.get()); |
| 127 EXPECT_TRUE(hotword_service != NULL); | 124 EXPECT_TRUE(hotword_service != NULL); |
| 128 | 125 |
| 129 // When the field trial is empty or Disabled, it should not be allowed. | 126 // When the field trial is empty or Disabled, it should not be allowed. |
| 130 std::string group = base::FieldTrialList::FindFullName( | 127 std::string group = base::FieldTrialList::FindFullName( |
| 131 hotword_internal::kHotwordFieldTrialName); | 128 hotword_internal::kHotwordFieldTrialName); |
| 132 EXPECT_TRUE(group.empty()); | 129 EXPECT_TRUE(group.empty()); |
| 133 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 130 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
| 134 | 131 |
| 135 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 132 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 136 hotword_internal::kHotwordFieldTrialName, | 133 hotword_internal::kHotwordFieldTrialName, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 147 | 144 |
| 148 // Test that incognito returns false as well. | 145 // Test that incognito returns false as well. |
| 149 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed( | 146 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed( |
| 150 profile->GetOffTheRecordProfile())); | 147 profile->GetOffTheRecordProfile())); |
| 151 } | 148 } |
| 152 | 149 |
| 153 TEST_P(HotwordServiceTest, IsHotwordAllowedLocale) { | 150 TEST_P(HotwordServiceTest, IsHotwordAllowedLocale) { |
| 154 TestingProfile::Builder profile_builder; | 151 TestingProfile::Builder profile_builder; |
| 155 scoped_ptr<TestingProfile> profile = profile_builder.Build(); | 152 scoped_ptr<TestingProfile> profile = profile_builder.Build(); |
| 156 | 153 |
| 157 HotwordServiceFactory* hotword_service_factory = | |
| 158 HotwordServiceFactory::GetInstance(); | |
| 159 | |
| 160 // Check that the service exists so that a NULL service be ruled out in | 154 // Check that the service exists so that a NULL service be ruled out in |
| 161 // following tests. | 155 // following tests. |
| 162 HotwordService* hotword_service = | 156 HotwordService* hotword_service = |
| 163 hotword_service_factory->GetForProfile(profile.get()); | 157 HotwordServiceFactory::GetInstance()->GetForProfile(profile.get()); |
| 164 EXPECT_TRUE(hotword_service != NULL); | 158 EXPECT_TRUE(hotword_service != NULL); |
| 165 | 159 |
| 166 // Set the field trial to a valid one. | 160 // Set the field trial to a valid one. |
| 167 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 161 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 168 hotword_internal::kHotwordFieldTrialName, "Good")); | 162 hotword_internal::kHotwordFieldTrialName, "Good")); |
| 169 | 163 |
| 170 // Set the language to an invalid one. | 164 // Set the language to an invalid one. |
| 171 SetApplicationLocale(static_cast<Profile*>(profile.get()), "non-valid"); | 165 SetApplicationLocale(static_cast<Profile*>(profile.get()), "non-valid"); |
| 172 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 166 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
| 173 | 167 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 187 // still returns false. | 181 // still returns false. |
| 188 Profile* otr_profile = profile->GetOffTheRecordProfile(); | 182 Profile* otr_profile = profile->GetOffTheRecordProfile(); |
| 189 SetApplicationLocale(otr_profile, "en"); | 183 SetApplicationLocale(otr_profile, "en"); |
| 190 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(otr_profile)); | 184 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(otr_profile)); |
| 191 } | 185 } |
| 192 | 186 |
| 193 TEST_P(HotwordServiceTest, AudioLoggingPrefSetCorrectly) { | 187 TEST_P(HotwordServiceTest, AudioLoggingPrefSetCorrectly) { |
| 194 TestingProfile::Builder profile_builder; | 188 TestingProfile::Builder profile_builder; |
| 195 scoped_ptr<TestingProfile> profile = profile_builder.Build(); | 189 scoped_ptr<TestingProfile> profile = profile_builder.Build(); |
| 196 | 190 |
| 197 HotwordServiceFactory* hotword_service_factory = | |
| 198 HotwordServiceFactory::GetInstance(); | |
| 199 HotwordService* hotword_service = | 191 HotwordService* hotword_service = |
| 200 hotword_service_factory->GetForProfile(profile.get()); | 192 HotwordServiceFactory::GetInstance()->GetForProfile(profile.get()); |
| 201 EXPECT_TRUE(hotword_service != NULL); | 193 EXPECT_TRUE(hotword_service != NULL); |
| 202 | 194 |
| 203 // If it's a fresh profile, although the default value is true, | 195 // If it's a fresh profile, although the default value is true, |
| 204 // it should return false if the preference has never been set. | 196 // it should return false if the preference has never been set. |
| 205 EXPECT_FALSE(hotword_service->IsOptedIntoAudioLogging()); | 197 EXPECT_FALSE(hotword_service->IsOptedIntoAudioLogging()); |
| 206 } | 198 } |
| 207 | 199 |
| 208 TEST_P(HotwordServiceTest, ShouldReinstallExtension) { | 200 TEST_P(HotwordServiceTest, ShouldReinstallExtension) { |
| 209 // Set the field trial to a valid one. | 201 // Set the field trial to a valid one. |
| 210 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 202 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); | 393 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); |
| 402 EXPECT_TRUE(hotword_service->IsAlwaysOnEnabled()); | 394 EXPECT_TRUE(hotword_service->IsAlwaysOnEnabled()); |
| 403 | 395 |
| 404 // If the locale is set back to the last valid one, then an uninstall-install | 396 // If the locale is set back to the last valid one, then an uninstall-install |
| 405 // shouldn't be needed. | 397 // shouldn't be needed. |
| 406 SetApplicationLocale(profile(), "fr_fr"); | 398 SetApplicationLocale(profile(), "fr_fr"); |
| 407 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile())); | 399 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile())); |
| 408 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); | 400 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); |
| 409 EXPECT_TRUE(hotword_service->IsAlwaysOnEnabled()); | 401 EXPECT_TRUE(hotword_service->IsAlwaysOnEnabled()); |
| 410 } | 402 } |
| OLD | NEW |