Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: ios/chrome/browser/ui/settings/privacy_collection_view_controller_unittest.mm

Issue 2806323003: [ObjC ARC] Converts ios/chrome/browser/ui/settings:unit_tests to ARC. (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/privacy_collection_view_controller.h" 5 #import "ios/chrome/browser/ui/settings/privacy_collection_view_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/ios/ios_util.h" 9 #include "base/ios/ios_util.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 12 matching lines...) Expand all
23 #import "ios/chrome/browser/ui/contextual_search/touch_to_search_permissions_med iator.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" 24 #import "ios/chrome/browser/ui/settings/physical_web_collection_view_controller. h"
25 #include "ios/chrome/grit/ios_chromium_strings.h" 25 #include "ios/chrome/grit/ios_chromium_strings.h"
26 #include "ios/chrome/grit/ios_strings.h" 26 #include "ios/chrome/grit/ios_strings.h"
27 #include "ios/chrome/test/ios_chrome_scoped_testing_local_state.h" 27 #include "ios/chrome/test/ios_chrome_scoped_testing_local_state.h"
28 #include "ios/web/public/test/test_web_thread_bundle.h" 28 #include "ios/web/public/test/test_web_thread_bundle.h"
29 #include "ios/web/public/web_capabilities.h" 29 #include "ios/web/public/web_capabilities.h"
30 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
32 32
33 #if !defined(__has_feature) || !__has_feature(objc_arc)
34 #error "This file requires ARC support."
35 #endif
36
33 namespace { 37 namespace {
34 38
35 NSString* const kSpdyProxyEnabled = @"SpdyProxyEnabled"; 39 NSString* const kSpdyProxyEnabled = @"SpdyProxyEnabled";
36 40
37 class PrivacyCollectionViewControllerTest 41 class PrivacyCollectionViewControllerTest
38 : public CollectionViewControllerTest { 42 : public CollectionViewControllerTest {
39 protected: 43 protected:
40 void SetUp() override { 44 void SetUp() override {
41 CollectionViewControllerTest::SetUp(); 45 CollectionViewControllerTest::SetUp();
42 TestChromeBrowserState::Builder test_cbs_builder; 46 TestChromeBrowserState::Builder test_cbs_builder;
43 test_cbs_builder.SetPrefService(CreatePrefService()); 47 test_cbs_builder.SetPrefService(CreatePrefService());
44 chrome_browser_state_ = test_cbs_builder.Build(); 48 chrome_browser_state_ = test_cbs_builder.Build();
45 49
46 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; 50 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
47 initialValueForSpdyProxyEnabled_.reset( 51 initialValueForSpdyProxyEnabled_ =
48 [[defaults valueForKey:kSpdyProxyEnabled] copy]); 52 [[defaults valueForKey:kSpdyProxyEnabled] copy];
49 [defaults setValue:@"Disabled" forKey:kSpdyProxyEnabled]; 53 [defaults setValue:@"Disabled" forKey:kSpdyProxyEnabled];
50 CreateController(); 54 CreateController();
51 } 55 }
52 56
53 void TearDown() override { 57 void TearDown() override {
54 if (initialValueForSpdyProxyEnabled_) { 58 if (initialValueForSpdyProxyEnabled_) {
55 [[NSUserDefaults standardUserDefaults] 59 [[NSUserDefaults standardUserDefaults]
56 setObject:initialValueForSpdyProxyEnabled_.get() 60 setObject:initialValueForSpdyProxyEnabled_
57 forKey:kSpdyProxyEnabled]; 61 forKey:kSpdyProxyEnabled];
58 } else { 62 } else {
59 [[NSUserDefaults standardUserDefaults] 63 [[NSUserDefaults standardUserDefaults]
60 removeObjectForKey:kSpdyProxyEnabled]; 64 removeObjectForKey:kSpdyProxyEnabled];
61 } 65 }
62 CollectionViewControllerTest::TearDown(); 66 CollectionViewControllerTest::TearDown();
63 } 67 }
64 68
65 // Makes a PrefService to be used by the test. 69 // Makes a PrefService to be used by the test.
66 std::unique_ptr<sync_preferences::PrefServiceSyncable> CreatePrefService() { 70 std::unique_ptr<sync_preferences::PrefServiceSyncable> CreatePrefService() {
67 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( 71 scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
68 new user_prefs::PrefRegistrySyncable); 72 new user_prefs::PrefRegistrySyncable);
69 RegisterBrowserStatePrefs(registry.get()); 73 RegisterBrowserStatePrefs(registry.get());
70 sync_preferences::PrefServiceMockFactory factory; 74 sync_preferences::PrefServiceMockFactory factory;
71 return factory.CreateSyncable(registry.get()); 75 return factory.CreateSyncable(registry.get());
72 } 76 }
73 77
74 CollectionViewController* NewController() override { 78 CollectionViewController* InstantiateController() override {
75 return [[PrivacyCollectionViewController alloc] 79 return [[PrivacyCollectionViewController alloc]
76 initWithBrowserState:chrome_browser_state_.get()]; 80 initWithBrowserState:chrome_browser_state_.get()];
77 } 81 }
78 82
79 web::TestWebThreadBundle thread_bundle_; 83 web::TestWebThreadBundle thread_bundle_;
80 IOSChromeScopedTestingLocalState local_state_; 84 IOSChromeScopedTestingLocalState local_state_;
81 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; 85 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
82 base::scoped_nsobject<NSString> initialValueForSpdyProxyEnabled_; 86 NSString* initialValueForSpdyProxyEnabled_;
83 }; 87 };
84 88
85 // Tests PrivacyCollectionViewController is set up with all appropriate items 89 // Tests PrivacyCollectionViewController is set up with all appropriate items
86 // and sections. 90 // and sections.
87 TEST_F(PrivacyCollectionViewControllerTest, TestModel) { 91 TEST_F(PrivacyCollectionViewControllerTest, TestModel) {
88 CheckController(); 92 CheckController();
89 EXPECT_EQ(4, NumberOfSections()); 93 EXPECT_EQ(4, NumberOfSections());
90 94
91 int sectionIndex = 0; 95 int sectionIndex = 0;
92 EXPECT_EQ(1, NumberOfItemsInSection(sectionIndex)); 96 EXPECT_EQ(1, NumberOfItemsInSection(sectionIndex));
(...skipping 11 matching lines...) Expand all
104 108
105 if ([TouchToSearchPermissionsMediator isTouchToSearchAvailableOnDevice]) 109 if ([TouchToSearchPermissionsMediator isTouchToSearchAvailableOnDevice])
106 expectedRows++; 110 expectedRows++;
107 if (web::IsDoNotTrackSupported()) 111 if (web::IsDoNotTrackSupported())
108 expectedRows++; 112 expectedRows++;
109 if (experimental_flags::IsPhysicalWebEnabled()) 113 if (experimental_flags::IsPhysicalWebEnabled())
110 expectedRows++; 114 expectedRows++;
111 EXPECT_EQ(expectedRows, NumberOfItemsInSection(sectionIndex)); 115 EXPECT_EQ(expectedRows, NumberOfItemsInSection(sectionIndex));
112 116
113 CheckSectionHeaderWithId(IDS_IOS_OPTIONS_WEB_SERVICES_LABEL, sectionIndex); 117 CheckSectionHeaderWithId(IDS_IOS_OPTIONS_WEB_SERVICES_LABEL, sectionIndex);
114 base::scoped_nsobject<TouchToSearchPermissionsMediator> 118 TouchToSearchPermissionsMediator* touchToSearchPermissions =
115 touchToSearchPermissions([[TouchToSearchPermissionsMediator alloc] 119 [[TouchToSearchPermissionsMediator alloc]
116 initWithBrowserState:chrome_browser_state_.get()]); 120 initWithBrowserState:chrome_browser_state_.get()];
117 NSString* contextualSearchSubtitle = 121 NSString* contextualSearchSubtitle =
118 ([touchToSearchPermissions preferenceState] == TouchToSearch::DISABLED) 122 ([touchToSearchPermissions preferenceState] == TouchToSearch::DISABLED)
119 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) 123 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
120 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); 124 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
121 int row = 0; 125 int row = 0;
122 126
123 CheckSwitchCellStateAndTitleWithId( 127 CheckSwitchCellStateAndTitleWithId(
124 YES, IDS_IOS_OPTIONS_SEARCH_URL_SUGGESTIONS, sectionIndex, row++); 128 YES, IDS_IOS_OPTIONS_SEARCH_URL_SUGGESTIONS, sectionIndex, row++);
125 129
126 if ([TouchToSearchPermissionsMediator isTouchToSearchAvailableOnDevice]) { 130 if ([TouchToSearchPermissionsMediator isTouchToSearchAvailableOnDevice]) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 EXPECT_EQ(1, NumberOfItemsInSection(sectionIndex)); 164 EXPECT_EQ(1, NumberOfItemsInSection(sectionIndex));
161 CheckSectionFooterWithId(IDS_IOS_OPTIONS_PRIVACY_FOOTER, sectionIndex); 165 CheckSectionFooterWithId(IDS_IOS_OPTIONS_PRIVACY_FOOTER, sectionIndex);
162 166
163 sectionIndex++; 167 sectionIndex++;
164 EXPECT_EQ(1, NumberOfItemsInSection(sectionIndex)); 168 EXPECT_EQ(1, NumberOfItemsInSection(sectionIndex));
165 CheckTextCellTitle(l10n_util::GetNSString(IDS_IOS_CLEAR_BROWSING_DATA_TITLE), 169 CheckTextCellTitle(l10n_util::GetNSString(IDS_IOS_CLEAR_BROWSING_DATA_TITLE),
166 sectionIndex, 0); 170 sectionIndex, 0);
167 } 171 }
168 172
169 } // namespace 173 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698