| 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/sync_preferences/testing_pref_service_syncable.h" | 15 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 16 #include "components/translate/core/browser/mock_translate_client.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/mock_translate_ranker.h" | 18 #include "components/translate/core/browser/mock_translate_ranker.h" |
| 18 #include "components/translate/core/browser/translate_client.h" | 19 #include "components/translate/core/browser/translate_client.h" |
| 19 #include "components/translate/core/browser/translate_infobar_delegate.h" | 20 #include "components/translate/core/browser/translate_infobar_delegate.h" |
| 20 #include "components/translate/core/browser/translate_manager.h" | 21 #include "components/translate/core/browser/translate_manager.h" |
| 21 #include "components/translate/core/browser/translate_prefs.h" | 22 #include "components/translate/core/browser/translate_prefs.h" |
| 22 #include "components/variations/variations_associated_data.h" | 23 #include "components/variations/variations_associated_data.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 26 | 27 |
| 27 using testing::Return; | 28 using testing::Return; |
| 28 using testing::Test; | 29 using testing::Test; |
| 30 using translate::testing::MockTranslateClient; |
| 29 using translate::testing::MockTranslateDriver; | 31 using translate::testing::MockTranslateDriver; |
| 30 using translate::testing::MockTranslateRanker; | 32 using translate::testing::MockTranslateRanker; |
| 31 | 33 |
| 32 namespace translate { | 34 namespace translate { |
| 33 | 35 |
| 34 #if defined(OS_CHROMEOS) | |
| 35 const char* preferred_languages_prefs = "settings.language.preferred_languages"; | |
| 36 #else | |
| 37 const char* preferred_languages_prefs = NULL; | |
| 38 #endif | |
| 39 | |
| 40 class MockTranslateClient : public TranslateClient { | |
| 41 public: | |
| 42 MockTranslateClient(TranslateDriver* driver, PrefService* prefs) | |
| 43 : driver_(driver), prefs_(prefs) {} | |
| 44 | |
| 45 TranslateDriver* GetTranslateDriver() { return driver_; } | |
| 46 PrefService* GetPrefs() { return prefs_; } | |
| 47 | |
| 48 std::unique_ptr<TranslatePrefs> GetTranslatePrefs() { | |
| 49 return base::MakeUnique<TranslatePrefs>(prefs_, "intl.accept_languages", | |
| 50 preferred_languages_prefs); | |
| 51 } | |
| 52 | |
| 53 MOCK_METHOD0(GetTranslateAcceptLanguages, TranslateAcceptLanguages*()); | |
| 54 MOCK_CONST_METHOD0(GetInfobarIconID, int()); | |
| 55 | |
| 56 MOCK_CONST_METHOD1(CreateInfoBarMock, | |
| 57 infobars::InfoBar*(TranslateInfoBarDelegate*)); | |
| 58 std::unique_ptr<infobars::InfoBar> CreateInfoBar( | |
| 59 std::unique_ptr<TranslateInfoBarDelegate> delegate) const { | |
| 60 return base::WrapUnique(CreateInfoBarMock(std::move(delegate).get())); | |
| 61 } | |
| 62 | |
| 63 MOCK_METHOD5(ShowTranslateUI, | |
| 64 void(translate::TranslateStep, | |
| 65 const std::string&, | |
| 66 const std::string&, | |
| 67 TranslateErrors::Type, | |
| 68 bool)); | |
| 69 MOCK_METHOD1(IsTranslatableURL, bool(const GURL&)); | |
| 70 MOCK_METHOD1(ShowReportLanguageDetectionErrorUI, void(const GURL&)); | |
| 71 | |
| 72 private: | |
| 73 TranslateDriver* driver_; | |
| 74 PrefService* prefs_; | |
| 75 }; | |
| 76 | |
| 77 class TranslateUIDelegateTest : public ::testing::Test { | 36 class TranslateUIDelegateTest : public ::testing::Test { |
| 78 public: | 37 public: |
| 79 TranslateUIDelegateTest() : ::testing::Test() {} | 38 TranslateUIDelegateTest() : ::testing::Test() {} |
| 80 | 39 |
| 81 void SetUp() override { | 40 void SetUp() override { |
| 82 pref_service_.reset(new sync_preferences::TestingPrefServiceSyncable()); | 41 pref_service_.reset(new sync_preferences::TestingPrefServiceSyncable()); |
| 83 pref_service_->registry()->RegisterStringPref( | 42 pref_service_->registry()->RegisterStringPref( |
| 84 "settings.language.preferred_languages", std::string()); | 43 "settings.language.preferred_languages", std::string()); |
| 85 pref_service_->registry()->RegisterStringPref("intl.accept_languages", | 44 pref_service_->registry()->RegisterStringPref("intl.accept_languages", |
| 86 std::string()); | 45 std::string()); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 prefs->IncrementTranslationAcceptedCount("ar"); | 159 prefs->IncrementTranslationAcceptedCount("ar"); |
| 201 | 160 |
| 202 EXPECT_FALSE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); | 161 EXPECT_FALSE(delegate_->ShouldAlwaysTranslateBeCheckedByDefault()); |
| 203 } | 162 } |
| 204 | 163 |
| 205 // TODO(ftang) Currently this file only test TranslationDeclined(), we | 164 // TODO(ftang) Currently this file only test TranslationDeclined(), we |
| 206 // need to add the test for other functions soon to increase the test | 165 // need to add the test for other functions soon to increase the test |
| 207 // coverage. | 166 // coverage. |
| 208 | 167 |
| 209 } // namespace translate | 168 } // namespace translate |
| OLD | NEW |