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