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

Side by Side Diff: ios/chrome/browser/ui/settings/settings_navigation_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/settings_navigation_controller.h" 5 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/mac/scoped_nsautorelease_pool.h"
12 #import "base/mac/scoped_nsobject.h"
13 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
14 #include "components/search_engines/template_url_service.h" 12 #include "components/search_engines/template_url_service.h"
15 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" 13 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
16 #include "ios/chrome/browser/browser_state/test_chrome_browser_state_manager.h" 14 #include "ios/chrome/browser/browser_state/test_chrome_browser_state_manager.h"
17 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" 15 #include "ios/chrome/browser/search_engines/template_url_service_factory.h"
18 #import "ios/chrome/browser/signin/authentication_service.h" 16 #import "ios/chrome/browser/signin/authentication_service.h"
19 #include "ios/chrome/browser/signin/authentication_service_factory.h" 17 #include "ios/chrome/browser/signin/authentication_service_factory.h"
20 #import "ios/chrome/browser/signin/authentication_service_fake.h" 18 #import "ios/chrome/browser/signin/authentication_service_fake.h"
21 #include "ios/chrome/browser/sync/sync_setup_service.h" 19 #include "ios/chrome/browser/sync/sync_setup_service.h"
22 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" 20 #include "ios/chrome/browser/sync/sync_setup_service_factory.h"
23 #include "ios/chrome/test/ios_chrome_scoped_testing_chrome_browser_state_manager .h" 21 #include "ios/chrome/test/ios_chrome_scoped_testing_chrome_browser_state_manager .h"
24 #include "ios/web/public/test/test_web_thread_bundle.h" 22 #include "ios/web/public/test/test_web_thread_bundle.h"
25 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
27 #import "testing/gtest_mac.h" 25 #import "testing/gtest_mac.h"
28 #include "testing/platform_test.h" 26 #include "testing/platform_test.h"
29 #import "third_party/ocmock/OCMock/OCMock.h" 27 #import "third_party/ocmock/OCMock/OCMock.h"
30 #include "third_party/ocmock/gtest_support.h" 28 #include "third_party/ocmock/gtest_support.h"
31 29
30 #if !defined(__has_feature) || !__has_feature(objc_arc)
31 #error "This file requires ARC support."
32 #endif
33
32 namespace { 34 namespace {
33 35
34 NSString* const kSpdyProxyEnabled = @"SpdyProxyEnabled"; 36 NSString* const kSpdyProxyEnabled = @"SpdyProxyEnabled";
35 37
36 using testing::ReturnRef; 38 using testing::ReturnRef;
37 39
38 class SettingsNavigationControllerTest : public PlatformTest { 40 class SettingsNavigationControllerTest : public PlatformTest {
39 protected: 41 protected:
40 SettingsNavigationControllerTest() 42 SettingsNavigationControllerTest()
41 : scoped_browser_state_manager_( 43 : scoped_browser_state_manager_(
42 base::MakeUnique<TestChromeBrowserStateManager>(base::FilePath())) { 44 base::MakeUnique<TestChromeBrowserStateManager>(base::FilePath())) {
43 TestChromeBrowserState::Builder test_cbs_builder; 45 TestChromeBrowserState::Builder test_cbs_builder;
44 test_cbs_builder.AddTestingFactory( 46 test_cbs_builder.AddTestingFactory(
45 AuthenticationServiceFactory::GetInstance(), 47 AuthenticationServiceFactory::GetInstance(),
46 &AuthenticationServiceFake::CreateAuthenticationService); 48 &AuthenticationServiceFake::CreateAuthenticationService);
47 test_cbs_builder.AddTestingFactory( 49 test_cbs_builder.AddTestingFactory(
48 ios::TemplateURLServiceFactory::GetInstance(), 50 ios::TemplateURLServiceFactory::GetInstance(),
49 ios::TemplateURLServiceFactory::GetDefaultFactory()); 51 ios::TemplateURLServiceFactory::GetDefaultFactory());
50 chrome_browser_state_ = test_cbs_builder.Build(); 52 chrome_browser_state_ = test_cbs_builder.Build();
51 53
52 mockDelegate_.reset([[OCMockObject 54 mockDelegate_ = [OCMockObject
53 niceMockForProtocol:@protocol(SettingsNavigationControllerDelegate)] 55 niceMockForProtocol:@protocol(SettingsNavigationControllerDelegate)];
54 retain]);
55 56
56 TemplateURLService* template_url_service = 57 TemplateURLService* template_url_service =
57 ios::TemplateURLServiceFactory::GetForBrowserState( 58 ios::TemplateURLServiceFactory::GetForBrowserState(
58 chrome_browser_state_.get()); 59 chrome_browser_state_.get());
59 template_url_service->Load(); 60 template_url_service->Load();
60 61
61 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; 62 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
62 initialValueForSpdyProxyEnabled_.reset( 63 initialValueForSpdyProxyEnabled_ =
63 [[defaults stringForKey:kSpdyProxyEnabled] copy]); 64 [[defaults stringForKey:kSpdyProxyEnabled] copy];
64 [defaults setObject:@"Disabled" forKey:kSpdyProxyEnabled]; 65 [defaults setObject:@"Disabled" forKey:kSpdyProxyEnabled];
65 }; 66 };
66 67
67 ~SettingsNavigationControllerTest() override { 68 ~SettingsNavigationControllerTest() override {
68 if (initialValueForSpdyProxyEnabled_) { 69 if (initialValueForSpdyProxyEnabled_) {
69 [[NSUserDefaults standardUserDefaults] 70 [[NSUserDefaults standardUserDefaults]
70 setObject:initialValueForSpdyProxyEnabled_.get() 71 setObject:initialValueForSpdyProxyEnabled_
71 forKey:kSpdyProxyEnabled]; 72 forKey:kSpdyProxyEnabled];
72 } else { 73 } else {
73 [[NSUserDefaults standardUserDefaults] 74 [[NSUserDefaults standardUserDefaults]
74 removeObjectForKey:kSpdyProxyEnabled]; 75 removeObjectForKey:kSpdyProxyEnabled];
75 } 76 }
76 } 77 }
77 78
78 web::TestWebThreadBundle thread_bundle_; 79 web::TestWebThreadBundle thread_bundle_;
79 IOSChromeScopedTestingChromeBrowserStateManager scoped_browser_state_manager_; 80 IOSChromeScopedTestingChromeBrowserStateManager scoped_browser_state_manager_;
80 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; 81 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
81 base::mac::ScopedNSAutoreleasePool pool_; 82 id mockDelegate_;
82 base::scoped_nsprotocol<id> mockDelegate_; 83 NSString* initialValueForSpdyProxyEnabled_;
83 base::scoped_nsobject<NSString> initialValueForSpdyProxyEnabled_;
84 }; 84 };
85 85
86 // When navigation stack has more than one view controller, 86 // When navigation stack has more than one view controller,
87 // -popViewControllerAnimated: successfully removes the top view controller. 87 // -popViewControllerAnimated: successfully removes the top view controller.
88 TEST_F(SettingsNavigationControllerTest, PopController) { 88 TEST_F(SettingsNavigationControllerTest, PopController) {
89 base::scoped_nsobject<SettingsNavigationController> settingsController( 89 @autoreleasepool {
90 [SettingsNavigationController 90 SettingsNavigationController* settingsController =
91 newSettingsMainControllerWithMainBrowserState:chrome_browser_state_ 91 [SettingsNavigationController
92 .get() 92 newSettingsMainControllerWithMainBrowserState:chrome_browser_state_
93 currentBrowserState:chrome_browser_state_ 93 .get()
94 .get() 94 currentBrowserState:chrome_browser_state_
95 delegate:nil]); 95 .get()
96 base::scoped_nsobject<UIViewController> viewController( 96 delegate:nil];
97 [[UIViewController alloc] initWithNibName:nil bundle:nil]); 97 UIViewController* viewController =
98 [settingsController pushViewController:viewController animated:NO]; 98 [[UIViewController alloc] initWithNibName:nil bundle:nil];
99 EXPECT_EQ(2U, [[settingsController viewControllers] count]); 99 [settingsController pushViewController:viewController animated:NO];
100 EXPECT_EQ(2U, [[settingsController viewControllers] count]);
100 101
101 UIViewController* poppedViewController = 102 UIViewController* poppedViewController =
102 [settingsController popViewControllerAnimated:NO]; 103 [settingsController popViewControllerAnimated:NO];
103 EXPECT_NSEQ(viewController, poppedViewController); 104 EXPECT_NSEQ(viewController, poppedViewController);
104 EXPECT_EQ(1U, [[settingsController viewControllers] count]); 105 EXPECT_EQ(1U, [[settingsController viewControllers] count]);
106 }
105 } 107 }
106 108
107 // When the navigation stack has only one view controller, 109 // When the navigation stack has only one view controller,
108 // -popViewControllerAnimated: returns false. 110 // -popViewControllerAnimated: returns false.
109 TEST_F(SettingsNavigationControllerTest, DontPopRootController) { 111 TEST_F(SettingsNavigationControllerTest, DontPopRootController) {
110 base::scoped_nsobject<SettingsNavigationController> settingsController( 112 @autoreleasepool {
111 [SettingsNavigationController 113 SettingsNavigationController* settingsController =
112 newSettingsMainControllerWithMainBrowserState:chrome_browser_state_ 114 [SettingsNavigationController
113 .get() 115 newSettingsMainControllerWithMainBrowserState:chrome_browser_state_
114 currentBrowserState:chrome_browser_state_ 116 .get()
115 .get() 117 currentBrowserState:chrome_browser_state_
116 delegate:nil]); 118 .get()
117 EXPECT_EQ(1U, [[settingsController viewControllers] count]); 119 delegate:nil];
120 EXPECT_EQ(1U, [[settingsController viewControllers] count]);
118 121
119 EXPECT_FALSE([settingsController popViewControllerAnimated:NO]); 122 EXPECT_FALSE([settingsController popViewControllerAnimated:NO]);
123 }
120 } 124 }
121 125
122 // When the settings navigation stack has more than one view controller, calling 126 // When the settings navigation stack has more than one view controller, calling
123 // -popViewControllerOrCloseSettingsAnimated: pops the top view controller to 127 // -popViewControllerOrCloseSettingsAnimated: pops the top view controller to
124 // reveal the view controller underneath. 128 // reveal the view controller underneath.
125 TEST_F(SettingsNavigationControllerTest, 129 TEST_F(SettingsNavigationControllerTest,
126 PopWhenNavigationStackSizeIsGreaterThanOne) { 130 PopWhenNavigationStackSizeIsGreaterThanOne) {
127 base::scoped_nsobject<SettingsNavigationController> settingsController( 131 @autoreleasepool {
128 [SettingsNavigationController 132 SettingsNavigationController* settingsController =
129 newSettingsMainControllerWithMainBrowserState:chrome_browser_state_ 133 [SettingsNavigationController
130 .get() 134 newSettingsMainControllerWithMainBrowserState:chrome_browser_state_
131 currentBrowserState:chrome_browser_state_ 135 .get()
132 .get() 136 currentBrowserState:chrome_browser_state_
133 delegate:mockDelegate_]); 137 .get()
134 base::scoped_nsobject<UIViewController> viewController( 138 delegate:mockDelegate_];
135 [[UIViewController alloc] initWithNibName:nil bundle:nil]); 139 UIViewController* viewController =
136 [settingsController pushViewController:viewController animated:NO]; 140 [[UIViewController alloc] initWithNibName:nil bundle:nil];
137 EXPECT_EQ(2U, [[settingsController viewControllers] count]); 141 [settingsController pushViewController:viewController animated:NO];
138 [[mockDelegate_ reject] closeSettings]; 142 EXPECT_EQ(2U, [[settingsController viewControllers] count]);
139 [settingsController popViewControllerOrCloseSettingsAnimated:NO]; 143 [[mockDelegate_ reject] closeSettings];
140 EXPECT_EQ(1U, [[settingsController viewControllers] count]); 144 [settingsController popViewControllerOrCloseSettingsAnimated:NO];
141 EXPECT_OCMOCK_VERIFY(mockDelegate_); 145 EXPECT_EQ(1U, [[settingsController viewControllers] count]);
146 EXPECT_OCMOCK_VERIFY(mockDelegate_);
147 }
142 } 148 }
143 149
144 // When the settings navigation stack only has one view controller, calling 150 // When the settings navigation stack only has one view controller, calling
145 // -popViewControllerOrCloseSettingsAnimated: calls -closeSettings on the 151 // -popViewControllerOrCloseSettingsAnimated: calls -closeSettings on the
146 // delegate. 152 // delegate.
147 TEST_F(SettingsNavigationControllerTest, 153 TEST_F(SettingsNavigationControllerTest,
148 CloseSettingsWhenNavigationStackSizeIsOne) { 154 CloseSettingsWhenNavigationStackSizeIsOne) {
149 base::scoped_nsobject<SettingsNavigationController> settingsController( 155 @autoreleasepool {
150 [SettingsNavigationController 156 SettingsNavigationController* settingsController =
151 newSettingsMainControllerWithMainBrowserState:chrome_browser_state_ 157 [SettingsNavigationController
152 .get() 158 newSettingsMainControllerWithMainBrowserState:chrome_browser_state_
153 currentBrowserState:chrome_browser_state_ 159 .get()
154 .get() 160 currentBrowserState:chrome_browser_state_
155 delegate:mockDelegate_]); 161 .get()
156 EXPECT_EQ(1U, [[settingsController viewControllers] count]); 162 delegate:mockDelegate_];
157 [[mockDelegate_ expect] closeSettings]; 163 EXPECT_EQ(1U, [[settingsController viewControllers] count]);
158 [settingsController popViewControllerOrCloseSettingsAnimated:NO]; 164 [[mockDelegate_ expect] closeSettings];
159 EXPECT_OCMOCK_VERIFY(mockDelegate_); 165 [settingsController popViewControllerOrCloseSettingsAnimated:NO];
166 EXPECT_OCMOCK_VERIFY(mockDelegate_);
167 }
160 } 168 }
161 169
162 } // namespace 170 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698