| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #import "ios/chrome/browser/ui/settings/translate_collection_view_controller.h" | 5 #import "ios/chrome/browser/ui/settings/translate_collection_view_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/test/scoped_task_environment.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "components/pref_registry/pref_registry_syncable.h" | 13 #include "components/pref_registry/pref_registry_syncable.h" |
| 14 #include "components/prefs/pref_member.h" | 14 #include "components/prefs/pref_member.h" |
| 15 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
| 16 #include "components/strings/grit/components_locale_settings.h" | 16 #include "components/strings/grit/components_locale_settings.h" |
| 17 #include "components/sync_preferences/pref_service_mock_factory.h" | 17 #include "components/sync_preferences/pref_service_mock_factory.h" |
| 18 #include "components/translate/core/browser/translate_pref_names.h" | 18 #include "components/translate/core/browser/translate_pref_names.h" |
| 19 #include "components/translate/core/browser/translate_prefs.h" | 19 #include "components/translate/core/browser/translate_prefs.h" |
| 20 #include "ios/chrome/browser/pref_names.h" | 20 #include "ios/chrome/browser/pref_names.h" |
| 21 #import "ios/chrome/browser/translate/chrome_ios_translate_client.h" | 21 #import "ios/chrome/browser/translate/chrome_ios_translate_client.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 const char kBlacklistedSite[] = "http://blacklistedsite.com"; | 38 const char kBlacklistedSite[] = "http://blacklistedsite.com"; |
| 39 const char kLanguage1[] = "klingon"; | 39 const char kLanguage1[] = "klingon"; |
| 40 const char kLanguage2[] = "pirate"; | 40 const char kLanguage2[] = "pirate"; |
| 41 | 41 |
| 42 class TranslateCollectionViewControllerTest | 42 class TranslateCollectionViewControllerTest |
| 43 : public CollectionViewControllerTest { | 43 : public CollectionViewControllerTest { |
| 44 protected: | 44 protected: |
| 45 TranslateCollectionViewControllerTest() |
| 46 : scoped_task_environment_( |
| 47 base::test::ScopedTaskEnvironment::MainThreadType::UI) {} |
| 48 |
| 45 void SetUp() override { | 49 void SetUp() override { |
| 46 CollectionViewControllerTest::SetUp(); | 50 CollectionViewControllerTest::SetUp(); |
| 47 pref_service_ = CreateLocalState(); | 51 pref_service_ = CreateLocalState(); |
| 48 } | 52 } |
| 49 | 53 |
| 50 CollectionViewController* InstantiateController() override { | 54 CollectionViewController* InstantiateController() override { |
| 51 return [[TranslateCollectionViewController alloc] | 55 return [[TranslateCollectionViewController alloc] |
| 52 initWithPrefs:pref_service_.get()]; | 56 initWithPrefs:pref_service_.get()]; |
| 53 } | 57 } |
| 54 | 58 |
| 55 std::unique_ptr<PrefService> CreateLocalState() { | 59 std::unique_ptr<PrefService> CreateLocalState() { |
| 56 scoped_refptr<PrefRegistrySyncable> registry = new PrefRegistrySyncable(); | 60 scoped_refptr<PrefRegistrySyncable> registry = new PrefRegistrySyncable(); |
| 57 registry->RegisterBooleanPref(prefs::kEnableTranslate, false, | 61 registry->RegisterBooleanPref(prefs::kEnableTranslate, false, |
| 58 PrefRegistrySyncable::SYNCABLE_PREF); | 62 PrefRegistrySyncable::SYNCABLE_PREF); |
| 59 translate::TranslatePrefs::RegisterProfilePrefs(registry.get()); | 63 translate::TranslatePrefs::RegisterProfilePrefs(registry.get()); |
| 60 registry->RegisterStringPref( | 64 registry->RegisterStringPref( |
| 61 prefs::kAcceptLanguages, | 65 prefs::kAcceptLanguages, |
| 62 l10n_util::GetStringUTF8(IDS_ACCEPT_LANGUAGES)); | 66 l10n_util::GetStringUTF8(IDS_ACCEPT_LANGUAGES)); |
| 63 base::FilePath path("TranslateCollectionViewControllerTest.pref"); | 67 base::FilePath path("TranslateCollectionViewControllerTest.pref"); |
| 64 sync_preferences::PrefServiceMockFactory factory; | 68 sync_preferences::PrefServiceMockFactory factory; |
| 65 factory.SetUserPrefsFile(path, base::ThreadTaskRunnerHandle::Get().get()); | 69 factory.SetUserPrefsFile(path, base::ThreadTaskRunnerHandle::Get().get()); |
| 66 return factory.Create(registry.get()); | 70 return factory.Create(registry.get()); |
| 67 } | 71 } |
| 68 | 72 |
| 69 base::MessageLoopForUI message_loop_; | 73 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 70 std::unique_ptr<PrefService> pref_service_; | 74 std::unique_ptr<PrefService> pref_service_; |
| 71 }; | 75 }; |
| 72 | 76 |
| 73 TEST_F(TranslateCollectionViewControllerTest, TestModelTranslateOff) { | 77 TEST_F(TranslateCollectionViewControllerTest, TestModelTranslateOff) { |
| 74 CreateController(); | 78 CreateController(); |
| 75 CheckController(); | 79 CheckController(); |
| 76 EXPECT_EQ(2, NumberOfSections()); | 80 EXPECT_EQ(2, NumberOfSections()); |
| 77 EXPECT_EQ(2, NumberOfItemsInSection(0)); | 81 EXPECT_EQ(2, NumberOfItemsInSection(0)); |
| 78 CheckSwitchCellStateAndTitleWithId(NO, IDS_IOS_TRANSLATE_SETTING, 0, 0); | 82 CheckSwitchCellStateAndTitleWithId(NO, IDS_IOS_TRANSLATE_SETTING, 0, 0); |
| 79 CheckTextCellTitleWithId(IDS_IOS_TRANSLATE_SETTING_RESET, 0, 1); | 83 CheckTextCellTitleWithId(IDS_IOS_TRANSLATE_SETTING_RESET, 0, 1); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 109 [controller collectionView:[controller collectionView] | 113 [controller collectionView:[controller collectionView] |
| 110 didSelectItemAtIndexPath:[NSIndexPath indexPathForItem:1 inSection:0]]; | 114 didSelectItemAtIndexPath:[NSIndexPath indexPathForItem:1 inSection:0]]; |
| 111 // Check that preferences are gone. | 115 // Check that preferences are gone. |
| 112 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(kBlacklistedSite)); | 116 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(kBlacklistedSite)); |
| 113 EXPECT_FALSE(translate_prefs->IsBlockedLanguage(kLanguage1)); | 117 EXPECT_FALSE(translate_prefs->IsBlockedLanguage(kLanguage1)); |
| 114 EXPECT_FALSE( | 118 EXPECT_FALSE( |
| 115 translate_prefs->IsLanguagePairWhitelisted(kLanguage1, kLanguage2)); | 119 translate_prefs->IsLanguagePairWhitelisted(kLanguage1, kLanguage2)); |
| 116 } | 120 } |
| 117 | 121 |
| 118 } // namespace | 122 } // namespace |
| OLD | NEW |