| 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/metrics/field_trial.h" | 5 #include "base/metrics/field_trial.h" |
| 6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/search/hotword_service.h" | 8 #include "chrome/browser/search/hotword_service.h" |
| 9 #include "chrome/browser/search/hotword_service_factory.h" | 9 #include "chrome/browser/search/hotword_service_factory.h" |
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 SetApplicationLocale(static_cast<Profile*>(profile.get()), "non-valid"); | 94 SetApplicationLocale(static_cast<Profile*>(profile.get()), "non-valid"); |
| 95 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 95 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
| 96 | 96 |
| 97 // Now with valid locales it should be fine. | 97 // Now with valid locales it should be fine. |
| 98 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en"); | 98 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en"); |
| 99 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 99 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
| 100 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en-US"); | 100 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en-US"); |
| 101 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 101 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
| 102 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en_us"); | 102 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en_us"); |
| 103 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 103 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
| 104 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en_gb"); | |
| 105 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | |
| 106 SetApplicationLocale(static_cast<Profile*>(profile.get()), "de_DE"); | 104 SetApplicationLocale(static_cast<Profile*>(profile.get()), "de_DE"); |
| 107 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 105 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
| 108 SetApplicationLocale(static_cast<Profile*>(profile.get()), "fr_fr"); | 106 SetApplicationLocale(static_cast<Profile*>(profile.get()), "fr_fr"); |
| 109 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); | 107 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); |
| 110 | 108 |
| 111 // Test that incognito even with a valid locale and valid field trial | 109 // Test that incognito even with a valid locale and valid field trial |
| 112 // still returns false. | 110 // still returns false. |
| 113 SetApplicationLocale(static_cast<Profile*>(otr_profile.get()), "en"); | 111 SetApplicationLocale(static_cast<Profile*>(otr_profile.get()), "en"); |
| 114 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(otr_profile.get())); | 112 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(otr_profile.get())); |
| 115 } | 113 } |
| 116 | 114 |
| 117 TEST_F(HotwordServiceTest, AudioLoggingPrefSetCorrectly) { | 115 TEST_F(HotwordServiceTest, AudioLoggingPrefSetCorrectly) { |
| 118 TestingProfile::Builder profile_builder; | 116 TestingProfile::Builder profile_builder; |
| 119 scoped_ptr<TestingProfile> profile = profile_builder.Build(); | 117 scoped_ptr<TestingProfile> profile = profile_builder.Build(); |
| 120 | 118 |
| 121 HotwordServiceFactory* hotword_service_factory = | 119 HotwordServiceFactory* hotword_service_factory = |
| 122 HotwordServiceFactory::GetInstance(); | 120 HotwordServiceFactory::GetInstance(); |
| 123 HotwordService* hotword_service = | 121 HotwordService* hotword_service = |
| 124 hotword_service_factory->GetForProfile(profile.get()); | 122 hotword_service_factory->GetForProfile(profile.get()); |
| 125 EXPECT_TRUE(hotword_service != NULL); | 123 EXPECT_TRUE(hotword_service != NULL); |
| 126 | 124 |
| 127 // If it's a fresh profile, although the default value is true, | 125 // If it's a fresh profile, although the default value is true, |
| 128 // it should return false if the preference has never been set. | 126 // it should return false if the preference has never been set. |
| 129 EXPECT_FALSE(hotword_service->IsOptedIntoAudioLogging()); | 127 EXPECT_FALSE(hotword_service->IsOptedIntoAudioLogging()); |
| 130 } | 128 } |
| OLD | NEW |