| 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 const char kGroupName[] = "GroupA"; |
| 211 std::map<std::string, std::string> params = { |
| 212 {kAlwaysTranslateOfferThreshold, "2"}}; |
| 213 variations::AssociateVariationParams(translate::kTranslateUI2016Q2TrialName, |
| 214 kGroupName, params); |
| 215 // need a trial_list to init the global instance used internally |
| 216 // inside CreateFieldTrial(). |
| 217 base::FieldTrialList trial_list(nullptr); |
| 218 base::FieldTrialList::CreateFieldTrial(translate::kTranslateUI2016Q2TrialName, |
| 219 kGroupName); |
| 220 |
| 221 std::unique_ptr<TranslatePrefs> prefs(client_->GetTranslatePrefs()); |
| 222 prefs->ResetTranslationAcceptedCount("ar"); |
| 223 |
| 202 for (int i = 0; i < 2; i++) { | 224 for (int i = 0; i < 2; i++) { |
| 203 EXPECT_FALSE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); | 225 EXPECT_FALSE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); |
| 204 prefs->IncrementTranslationAcceptedCount("ar"); | 226 prefs->IncrementTranslationAcceptedCount("ar"); |
| 205 } | 227 } |
| 206 EXPECT_TRUE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); | 228 EXPECT_TRUE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); |
| 207 prefs->IncrementTranslationAcceptedCount("ar"); | 229 prefs->IncrementTranslationAcceptedCount("ar"); |
| 208 | 230 |
| 209 EXPECT_FALSE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); | 231 EXPECT_FALSE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); |
| 210 } | 232 } |
| 211 | 233 |
| 212 // TODO(ftang) Currently this file only test TranslationDeclined(), we | 234 // TODO(ftang) Currently this file only test TranslationDeclined(), we |
| 213 // need to add the test for other functions soon to increase the test | 235 // need to add the test for other functions soon to increase the test |
| 214 // coverage. | 236 // coverage. |
| 215 | 237 |
| 216 } // namespace translate | 238 } // namespace translate |
| OLD | NEW |