| 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 "base/test/scoped_feature_list.h" | |
| 13 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 14 #include "components/infobars/core/infobar.h" | 13 #include "components/infobars/core/infobar.h" |
| 15 #include "components/pref_registry/pref_registry_syncable.h" | 14 #include "components/pref_registry/pref_registry_syncable.h" |
| 16 #include "components/pref_registry/testing_pref_service_syncable.h" | 15 #include "components/pref_registry/testing_pref_service_syncable.h" |
| 17 #include "components/translate/core/browser/mock_translate_driver.h" | 16 #include "components/translate/core/browser/mock_translate_driver.h" |
| 18 #include "components/translate/core/browser/translate_client.h" | 17 #include "components/translate/core/browser/translate_client.h" |
| 19 #include "components/translate/core/browser/translate_infobar_delegate.h" | 18 #include "components/translate/core/browser/translate_infobar_delegate.h" |
| 20 #include "components/translate/core/browser/translate_manager.h" | 19 #include "components/translate/core/browser/translate_manager.h" |
| 21 #include "components/translate/core/browser/translate_prefs.h" | 20 #include "components/translate/core/browser/translate_prefs.h" |
| 22 #include "components/variations/variations_associated_data.h" | 21 #include "components/variations/variations_associated_data.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 88 |
| 90 manager_.reset(new TranslateManager(client_.get(), "hi")); | 89 manager_.reset(new TranslateManager(client_.get(), "hi")); |
| 91 manager_->GetLanguageState().set_translation_declined(false); | 90 manager_->GetLanguageState().set_translation_declined(false); |
| 92 | 91 |
| 93 delegate_.reset( | 92 delegate_.reset( |
| 94 new TranslateUIDelegate(manager_->GetWeakPtr(), "ar", "fr")); | 93 new TranslateUIDelegate(manager_->GetWeakPtr(), "ar", "fr")); |
| 95 | 94 |
| 96 ASSERT_FALSE(client_->GetTranslatePrefs()->IsTooOftenDenied("ar")); | 95 ASSERT_FALSE(client_->GetTranslatePrefs()->IsTooOftenDenied("ar")); |
| 97 } | 96 } |
| 98 | 97 |
| 99 void TurnOnTranslate2016Q2UIFlag() { | |
| 100 scoped_feature_list_.InitAndEnableFeature(translate::kTranslateUI2016Q2); | |
| 101 } | |
| 102 | |
| 103 MockTranslateDriver driver_; | 98 MockTranslateDriver driver_; |
| 104 std::unique_ptr<MockTranslateClient> client_; | 99 std::unique_ptr<MockTranslateClient> client_; |
| 105 std::unique_ptr<user_prefs::TestingPrefServiceSyncable> pref_service_; | 100 std::unique_ptr<user_prefs::TestingPrefServiceSyncable> pref_service_; |
| 106 std::unique_ptr<TranslateManager> manager_; | 101 std::unique_ptr<TranslateManager> manager_; |
| 107 std::unique_ptr<TranslateUIDelegate> delegate_; | 102 std::unique_ptr<TranslateUIDelegate> delegate_; |
| 108 base::test::ScopedFeatureList scoped_feature_list_; | |
| 109 | 103 |
| 110 private: | 104 private: |
| 111 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegateTest); | 105 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegateTest); |
| 112 }; | 106 }; |
| 113 | 107 |
| 114 TEST_F(TranslateUIDelegateTest, CheckDeclinedFalse) { | 108 TEST_F(TranslateUIDelegateTest, CheckDeclinedFalse) { |
| 115 std::unique_ptr<TranslatePrefs> prefs(client_->GetTranslatePrefs()); | 109 std::unique_ptr<TranslatePrefs> prefs(client_->GetTranslatePrefs()); |
| 116 for (int i = 0; i < 10; i++) { | 110 for (int i = 0; i < 10; i++) { |
| 117 prefs->IncrementTranslationAcceptedCount("ar"); | 111 prefs->IncrementTranslationAcceptedCount("ar"); |
| 118 } | 112 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 prefs->IncrementTranslationAcceptedCount("ar"); | 196 prefs->IncrementTranslationAcceptedCount("ar"); |
| 203 | 197 |
| 204 EXPECT_FALSE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); | 198 EXPECT_FALSE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); |
| 205 } | 199 } |
| 206 | 200 |
| 207 // TODO(ftang) Currently this file only test TranslationDeclined(), we | 201 // TODO(ftang) Currently this file only test TranslationDeclined(), we |
| 208 // need to add the test for other functions soon to increase the test | 202 // need to add the test for other functions soon to increase the test |
| 209 // coverage. | 203 // coverage. |
| 210 | 204 |
| 211 } // namespace translate | 205 } // namespace translate |
| OLD | NEW |