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

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

Issue 556173002: Ensure incognito TestingProfiles are incognito for their whole lifetime. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: respond to comments Created 6 years, 3 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
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/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/metrics/field_trial.h" 6 #include "base/metrics/field_trial.h"
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/extension_service_test_base.h" 9 #include "chrome/browser/extensions/extension_service_test_base.h"
10 #include "chrome/browser/extensions/test_extension_service.h" 10 #include "chrome/browser/extensions/test_extension_service.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 g_browser_process->SetApplicationLocale(new_locale); 85 g_browser_process->SetApplicationLocale(new_locale);
86 #endif 86 #endif
87 } 87 }
88 88
89 private: 89 private:
90 base::FieldTrialList field_trial_list_; 90 base::FieldTrialList field_trial_list_;
91 }; 91 };
92 92
93 TEST_F(HotwordServiceTest, IsHotwordAllowedBadFieldTrial) { 93 TEST_F(HotwordServiceTest, IsHotwordAllowedBadFieldTrial) {
94 TestingProfile::Builder profile_builder; 94 TestingProfile::Builder profile_builder;
95 TestingProfile::Builder otr_profile_builder;
96 otr_profile_builder.SetIncognito();
97 scoped_ptr<TestingProfile> profile = profile_builder.Build(); 95 scoped_ptr<TestingProfile> profile = profile_builder.Build();
98 scoped_ptr<TestingProfile> otr_profile = otr_profile_builder.Build();
99 96
100 HotwordServiceFactory* hotword_service_factory = 97 HotwordServiceFactory* hotword_service_factory =
101 HotwordServiceFactory::GetInstance(); 98 HotwordServiceFactory::GetInstance();
102 99
103 // Check that the service exists so that a NULL service be ruled out in 100 // Check that the service exists so that a NULL service be ruled out in
104 // following tests. 101 // following tests.
105 HotwordService* hotword_service = 102 HotwordService* hotword_service =
106 hotword_service_factory->GetForProfile(profile.get()); 103 hotword_service_factory->GetForProfile(profile.get());
107 EXPECT_TRUE(hotword_service != NULL); 104 EXPECT_TRUE(hotword_service != NULL);
108 105
(...skipping 10 matching lines...) Expand all
119 hotword_internal::kHotwordFieldTrialName); 116 hotword_internal::kHotwordFieldTrialName);
120 EXPECT_TRUE(group ==hotword_internal::kHotwordFieldTrialDisabledGroupName); 117 EXPECT_TRUE(group ==hotword_internal::kHotwordFieldTrialDisabledGroupName);
121 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); 118 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get()));
122 119
123 // Set a valid locale with invalid field trial to be sure it is 120 // Set a valid locale with invalid field trial to be sure it is
124 // still false. 121 // still false.
125 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en"); 122 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en");
126 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); 123 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile.get()));
127 124
128 // Test that incognito returns false as well. 125 // Test that incognito returns false as well.
129 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(otr_profile.get())); 126 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(
127 profile->GetOffTheRecordProfile()));
130 } 128 }
131 129
132 TEST_F(HotwordServiceTest, IsHotwordAllowedLocale) { 130 TEST_F(HotwordServiceTest, IsHotwordAllowedLocale) {
133 TestingProfile::Builder profile_builder; 131 TestingProfile::Builder profile_builder;
134 TestingProfile::Builder otr_profile_builder;
135 otr_profile_builder.SetIncognito();
136 scoped_ptr<TestingProfile> profile = profile_builder.Build(); 132 scoped_ptr<TestingProfile> profile = profile_builder.Build();
137 scoped_ptr<TestingProfile> otr_profile = otr_profile_builder.Build();
138 133
139 HotwordServiceFactory* hotword_service_factory = 134 HotwordServiceFactory* hotword_service_factory =
140 HotwordServiceFactory::GetInstance(); 135 HotwordServiceFactory::GetInstance();
141 136
142 // Check that the service exists so that a NULL service be ruled out in 137 // Check that the service exists so that a NULL service be ruled out in
143 // following tests. 138 // following tests.
144 HotwordService* hotword_service = 139 HotwordService* hotword_service =
145 hotword_service_factory->GetForProfile(profile.get()); 140 hotword_service_factory->GetForProfile(profile.get());
146 EXPECT_TRUE(hotword_service != NULL); 141 EXPECT_TRUE(hotword_service != NULL);
147 142
(...skipping 12 matching lines...) Expand all
160 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); 155 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get()));
161 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en_us"); 156 SetApplicationLocale(static_cast<Profile*>(profile.get()), "en_us");
162 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); 157 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get()));
163 SetApplicationLocale(static_cast<Profile*>(profile.get()), "de_DE"); 158 SetApplicationLocale(static_cast<Profile*>(profile.get()), "de_DE");
164 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); 159 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get()));
165 SetApplicationLocale(static_cast<Profile*>(profile.get()), "fr_fr"); 160 SetApplicationLocale(static_cast<Profile*>(profile.get()), "fr_fr");
166 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get())); 161 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get()));
167 162
168 // Test that incognito even with a valid locale and valid field trial 163 // Test that incognito even with a valid locale and valid field trial
169 // still returns false. 164 // still returns false.
170 SetApplicationLocale(static_cast<Profile*>(otr_profile.get()), "en"); 165 Profile* otr_profile = profile->GetOffTheRecordProfile();
171 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(otr_profile.get())); 166 SetApplicationLocale(otr_profile, "en");
167 EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(otr_profile));
172 } 168 }
173 169
174 TEST_F(HotwordServiceTest, AudioLoggingPrefSetCorrectly) { 170 TEST_F(HotwordServiceTest, AudioLoggingPrefSetCorrectly) {
175 TestingProfile::Builder profile_builder; 171 TestingProfile::Builder profile_builder;
176 scoped_ptr<TestingProfile> profile = profile_builder.Build(); 172 scoped_ptr<TestingProfile> profile = profile_builder.Build();
177 173
178 HotwordServiceFactory* hotword_service_factory = 174 HotwordServiceFactory* hotword_service_factory =
179 HotwordServiceFactory::GetInstance(); 175 HotwordServiceFactory::GetInstance();
180 HotwordService* hotword_service = 176 HotwordService* hotword_service =
181 hotword_service_factory->GetForProfile(profile.get()); 177 hotword_service_factory->GetForProfile(profile.get());
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 EXPECT_EQ("fr_fr", 300 EXPECT_EQ("fr_fr",
305 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage)); 301 profile()->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage));
306 302
307 // If the locale is set back to the last valid one, then an uninstall-install 303 // If the locale is set back to the last valid one, then an uninstall-install
308 // shouldn't be needed. 304 // shouldn't be needed.
309 SetApplicationLocale(profile(), "fr_fr"); 305 SetApplicationLocale(profile(), "fr_fr");
310 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile())); 306 EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile()));
311 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension()); 307 EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension());
312 EXPECT_EQ(1, hotword_service->uninstall_count()); // no change 308 EXPECT_EQ(1, hotword_service->uninstall_count()); // no change
313 } 309 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698