OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/translate/core/browser/translate_ui_delegate.h" | 5 #include "components/translate/core/browser/translate_ui_delegate.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "components/infobars/core/infobar.h" | 13 #include "components/infobars/core/infobar.h" |
14 #include "components/pref_registry/pref_registry_syncable.h" | 14 #include "components/pref_registry/pref_registry_syncable.h" |
15 #include "components/pref_registry/testing_pref_service_syncable.h" | 15 #include "components/pref_registry/testing_pref_service_syncable.h" |
16 #include "components/translate/core/browser/mock_translate_driver.h" | 16 #include "components/translate/core/browser/mock_translate_driver.h" |
17 #include "components/translate/core/browser/translate_client.h" | 17 #include "components/translate/core/browser/translate_client.h" |
18 #include "components/translate/core/browser/translate_infobar_delegate.h" | 18 #include "components/translate/core/browser/translate_infobar_delegate.h" |
19 #include "components/translate/core/browser/translate_manager.h" | 19 #include "components/translate/core/browser/translate_manager.h" |
20 #include "components/translate/core/browser/translate_prefs.h" | 20 #include "components/translate/core/browser/translate_prefs.h" |
21 #include "components/variations/variations_associated_data.h" | |
21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
24 | 25 |
25 using testing::Return; | 26 using testing::Return; |
26 using testing::Test; | 27 using testing::Test; |
27 using translate::testing::MockTranslateDriver; | 28 using translate::testing::MockTranslateDriver; |
28 | 29 |
29 namespace translate { | 30 namespace translate { |
30 | 31 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 // Reset it to true again after delegate_->SetLanguageBlocked(true) | 189 // Reset it to true again after delegate_->SetLanguageBlocked(true) |
189 // turn it to false. | 190 // turn it to false. |
190 manager_->GetLanguageState().SetTranslateEnabled(true); | 191 manager_->GetLanguageState().SetTranslateEnabled(true); |
191 | 192 |
192 delegate_->SetLanguageBlocked(false); | 193 delegate_->SetLanguageBlocked(false); |
193 | 194 |
194 EXPECT_FALSE(prefs->IsBlockedLanguage("ar")); | 195 EXPECT_FALSE(prefs->IsBlockedLanguage("ar")); |
195 EXPECT_TRUE(manager_->GetLanguageState().translate_enabled()); | 196 EXPECT_TRUE(manager_->GetLanguageState().translate_enabled()); |
196 } | 197 } |
197 | 198 |
198 TEST_F(TranslateUIDelegateTest, ShouldAlwaysTranslateBeCheckedByDefault) { | 199 TEST_F(TranslateUIDelegateTest, ShouldAlwaysTranslateBeCheckedByDefaultNever) { |
199 std::unique_ptr<TranslatePrefs> prefs(client_->GetTranslatePrefs()); | 200 std::unique_ptr<TranslatePrefs> prefs(client_->GetTranslatePrefs()); |
200 prefs->ResetTranslationAcceptedCount("ar"); | 201 prefs->ResetTranslationAcceptedCount("ar"); |
201 | 202 |
203 for (int i = 0; i < 100; i++) { | |
204 EXPECT_FALSE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); | |
205 prefs->IncrementTranslationAcceptedCount("ar"); | |
206 } | |
207 } | |
208 | |
209 TEST_F(TranslateUIDelegateTest, ShouldAlwaysTranslateBeCheckedByDefault2) { | |
210 std::unique_ptr<base::FieldTrialList> trial_list( | |
211 new base::FieldTrialList(NULL)); | |
212 const char kGroupName[] = "GroupA"; | |
213 std::map<std::string, std::string> params; | |
214 params[translate::kAlwaysTranslateOfferThreshold] = "2"; | |
groby-ooo-7-16
2016/06/28 17:35:20
Use C++11 initializer lists:
std::map<std::string
ftang
2016/06/28 21:51:12
cool. we can use C++11 in Chrome too? First time t
| |
215 variations::AssociateVariationParams(translate::kTranslateUI2016Q2TrialName, | |
216 kGroupName, params); | |
217 base::FieldTrialList::CreateFieldTrial(translate::kTranslateUI2016Q2TrialName, | |
218 kGroupName); | |
219 | |
220 std::unique_ptr<TranslatePrefs> prefs(client_->GetTranslatePrefs()); | |
221 prefs->ResetTranslationAcceptedCount("ar"); | |
222 | |
202 for (int i = 0; i < 2; i++) { | 223 for (int i = 0; i < 2; i++) { |
203 EXPECT_FALSE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); | 224 EXPECT_FALSE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); |
204 prefs->IncrementTranslationAcceptedCount("ar"); | 225 prefs->IncrementTranslationAcceptedCount("ar"); |
205 } | 226 } |
206 EXPECT_TRUE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); | 227 EXPECT_TRUE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); |
207 prefs->IncrementTranslationAcceptedCount("ar"); | 228 prefs->IncrementTranslationAcceptedCount("ar"); |
208 | 229 |
209 EXPECT_FALSE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); | 230 EXPECT_FALSE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); |
210 } | 231 } |
211 | 232 |
212 // TODO(ftang) Currently this file only test TranslationDeclined(), we | 233 // TODO(ftang) Currently this file only test TranslationDeclined(), we |
213 // need to add the test for other functions soon to increase the test | 234 // need to add the test for other functions soon to increase the test |
214 // coverage. | 235 // coverage. |
215 | 236 |
216 } // namespace translate | 237 } // namespace translate |
OLD | NEW |