OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/ui/settings/privacy_collection_view_controller.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/ios/ios_util.h" |
| 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/sys_string_conversions.h" |
| 12 #include "components/handoff/pref_names_ios.h" |
| 13 #include "components/prefs/pref_service.h" |
| 14 #include "components/sync_preferences/pref_service_mock_factory.h" |
| 15 #include "components/sync_preferences/pref_service_syncable.h" |
| 16 #include "ios/chrome/browser/application_context.h" |
| 17 #import "ios/chrome/browser/autofill/autofill_controller.h" |
| 18 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| 19 #include "ios/chrome/browser/experimental_flags.h" |
| 20 #include "ios/chrome/browser/pref_names.h" |
| 21 #include "ios/chrome/browser/prefs/browser_prefs.h" |
| 22 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" |
| 23 #import "ios/chrome/browser/ui/contextual_search/touch_to_search_permissions_med
iator.h" |
| 24 #import "ios/chrome/browser/ui/settings/physical_web_collection_view_controller.
h" |
| 25 #include "ios/chrome/grit/ios_chromium_strings.h" |
| 26 #include "ios/chrome/grit/ios_strings.h" |
| 27 #include "ios/web/public/test/test_web_thread_bundle.h" |
| 28 #include "ios/web/public/web_capabilities.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 #include "ui/base/l10n/l10n_util.h" |
| 31 |
| 32 namespace { |
| 33 |
| 34 NSString* const kSpdyProxyEnabled = @"SpdyProxyEnabled"; |
| 35 |
| 36 class PrivacyCollectionViewControllerTest |
| 37 : public CollectionViewControllerTest { |
| 38 protected: |
| 39 void SetUp() override { |
| 40 CollectionViewControllerTest::SetUp(); |
| 41 TestChromeBrowserState::Builder test_cbs_builder; |
| 42 test_cbs_builder.SetPrefService(CreatePrefService()); |
| 43 chrome_browser_state_ = test_cbs_builder.Build(); |
| 44 |
| 45 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
| 46 initialValueForSpdyProxyEnabled_.reset( |
| 47 [[defaults valueForKey:kSpdyProxyEnabled] copy]); |
| 48 [defaults setValue:@"Disabled" forKey:kSpdyProxyEnabled]; |
| 49 CreateController(); |
| 50 } |
| 51 |
| 52 void TearDown() override { |
| 53 if (initialValueForSpdyProxyEnabled_) { |
| 54 [[NSUserDefaults standardUserDefaults] |
| 55 setObject:initialValueForSpdyProxyEnabled_.get() |
| 56 forKey:kSpdyProxyEnabled]; |
| 57 } else { |
| 58 [[NSUserDefaults standardUserDefaults] |
| 59 removeObjectForKey:kSpdyProxyEnabled]; |
| 60 } |
| 61 CollectionViewControllerTest::TearDown(); |
| 62 } |
| 63 |
| 64 // Makes a PrefService to be used by the test. |
| 65 std::unique_ptr<sync_preferences::PrefServiceSyncable> CreatePrefService() { |
| 66 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( |
| 67 new user_prefs::PrefRegistrySyncable); |
| 68 RegisterBrowserStatePrefs(registry.get()); |
| 69 sync_preferences::PrefServiceMockFactory factory; |
| 70 return factory.CreateSyncable(registry.get()); |
| 71 } |
| 72 |
| 73 CollectionViewController* NewController() override { |
| 74 return [[PrivacyCollectionViewController alloc] |
| 75 initWithBrowserState:chrome_browser_state_.get()]; |
| 76 } |
| 77 |
| 78 web::TestWebThreadBundle thread_bundle_; |
| 79 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
| 80 base::scoped_nsobject<NSString> initialValueForSpdyProxyEnabled_; |
| 81 }; |
| 82 |
| 83 // Tests PrivacyCollectionViewController is set up with all appropriate items |
| 84 // and sections. |
| 85 TEST_F(PrivacyCollectionViewControllerTest, TestModel) { |
| 86 CheckController(); |
| 87 EXPECT_EQ(4, NumberOfSections()); |
| 88 |
| 89 int sectionIndex = 0; |
| 90 EXPECT_EQ(1, NumberOfItemsInSection(sectionIndex)); |
| 91 CheckSectionHeaderWithId(IDS_IOS_OPTIONS_CONTINUITY_LABEL, sectionIndex); |
| 92 NSString* handoffSubtitle = chrome_browser_state_->GetPrefs()->GetBoolean( |
| 93 prefs::kIosHandoffToOtherDevices) |
| 94 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 95 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 96 CheckTextCellTitleAndSubtitle( |
| 97 l10n_util::GetNSString(IDS_IOS_OPTIONS_ENABLE_HANDOFF_TO_OTHER_DEVICES), |
| 98 handoffSubtitle, sectionIndex, 0); |
| 99 |
| 100 ++sectionIndex; |
| 101 NSInteger expectedRows = 1; |
| 102 #if defined(GOOGLE_CHROME_BUILD) |
| 103 expectedRows++; |
| 104 #endif |
| 105 if ([TouchToSearchPermissionsMediator isTouchToSearchAvailableOnDevice]) |
| 106 expectedRows++; |
| 107 if (web::IsDoNotTrackSupported()) |
| 108 expectedRows++; |
| 109 if (experimental_flags::IsPhysicalWebEnabled()) |
| 110 expectedRows++; |
| 111 EXPECT_EQ(expectedRows, NumberOfItemsInSection(sectionIndex)); |
| 112 |
| 113 CheckSectionHeaderWithId(IDS_IOS_OPTIONS_WEB_SERVICES_LABEL, sectionIndex); |
| 114 base::scoped_nsobject<TouchToSearchPermissionsMediator> |
| 115 touchToSearchPermissions([[TouchToSearchPermissionsMediator alloc] |
| 116 initWithBrowserState:chrome_browser_state_.get()]); |
| 117 NSString* contextualSearchSubtitle = |
| 118 ([touchToSearchPermissions preferenceState] == TouchToSearch::DISABLED) |
| 119 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 120 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 121 int row = 0; |
| 122 |
| 123 CheckSwitchCellStateAndTitleWithId( |
| 124 YES, IDS_IOS_OPTIONS_SEARCH_URL_SUGGESTIONS, sectionIndex, row++); |
| 125 |
| 126 if ([TouchToSearchPermissionsMediator isTouchToSearchAvailableOnDevice]) { |
| 127 CheckTextCellTitleAndSubtitle( |
| 128 l10n_util::GetNSString(IDS_IOS_CONTEXTUAL_SEARCH_TITLE), |
| 129 contextualSearchSubtitle, sectionIndex, row++); |
| 130 } |
| 131 #if defined(GOOGLE_CHROME_BUILD) |
| 132 CheckTextCellTitleWithId(IDS_IOS_OPTIONS_SEND_USAGE_DATA, sectionIndex, |
| 133 row++); |
| 134 #endif |
| 135 if (web::IsDoNotTrackSupported()) { |
| 136 NSString* doNotTrackSubtitle = |
| 137 chrome_browser_state_->GetPrefs()->GetBoolean(prefs::kEnableDoNotTrack) |
| 138 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 139 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 140 CheckTextCellTitleAndSubtitle( |
| 141 l10n_util::GetNSString(IDS_IOS_OPTIONS_DO_NOT_TRACK_MOBILE), |
| 142 doNotTrackSubtitle, sectionIndex, row++); |
| 143 } |
| 144 if (experimental_flags::IsPhysicalWebEnabled()) { |
| 145 NSInteger physicalWebState = |
| 146 GetApplicationContext()->GetLocalState()->GetInteger( |
| 147 prefs::kIosPhysicalWebEnabled); |
| 148 BOOL physicalWebEnabled = [PhysicalWebCollectionViewController |
| 149 shouldEnableForPreferenceState:physicalWebState]; |
| 150 NSString* physicalWebSubtitle = |
| 151 physicalWebEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 152 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 153 CheckTextCellTitleAndSubtitle( |
| 154 l10n_util::GetNSString(IDS_IOS_OPTIONS_ENABLE_PHYSICAL_WEB), |
| 155 physicalWebSubtitle, sectionIndex, row++); |
| 156 } |
| 157 |
| 158 sectionIndex++; |
| 159 EXPECT_EQ(1, NumberOfItemsInSection(sectionIndex)); |
| 160 CheckSectionFooterWithId(IDS_IOS_OPTIONS_PRIVACY_FOOTER, sectionIndex); |
| 161 |
| 162 sectionIndex++; |
| 163 EXPECT_EQ(1, NumberOfItemsInSection(sectionIndex)); |
| 164 CheckTextCellTitle(l10n_util::GetNSString(IDS_IOS_CLEAR_BROWSING_DATA_TITLE), |
| 165 sectionIndex, 0); |
| 166 } |
| 167 |
| 168 } // namespace |
OLD | NEW |