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

Side by Side Diff: ios/chrome/test/earl_grey/chrome_test_case.mm

Issue 2684023003: [ObjC ARC] Converts ios/chrome/test/earl_grey:test_support to ARC. (Closed)
Patch Set: Add __unsafe_unretained Created 3 years, 10 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 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 #import "ios/chrome/test/earl_grey/chrome_test_case.h" 5 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
6 6
7 #import <objc/runtime.h> 7 #import <objc/runtime.h>
8 8
9 #import <EarlGrey/EarlGrey.h> 9 #import <EarlGrey/EarlGrey.h>
10 10
11 #include "base/mac/scoped_block.h" 11 #include "base/mac/scoped_block.h"
12 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
13 #import "ios/chrome/test/app/chrome_test_util.h" 13 #import "ios/chrome/test/app/chrome_test_util.h"
14 #include "ios/chrome/test/app/settings_test_util.h" 14 #include "ios/chrome/test/app/settings_test_util.h"
15 #include "ios/chrome/test/app/signin_test_util.h" 15 #include "ios/chrome/test/app/signin_test_util.h"
16 #import "ios/chrome/test/app/sync_test_util.h" 16 #import "ios/chrome/test/app/sync_test_util.h"
17 #import "ios/chrome/test/app/tab_test_util.h" 17 #import "ios/chrome/test/app/tab_test_util.h"
18 #import "ios/web/public/test/http_server.h" 18 #import "ios/web/public/test/http_server.h"
19 19
20 #if !defined(__has_feature) || !__has_feature(objc_arc)
21 #error "This file requires ARC support."
22 #endif
23
20 namespace { 24 namespace {
21 25
22 NSString* const kFlakyEarlGreyTestTargetSuffix = @"_flaky_egtests"; 26 NSString* const kFlakyEarlGreyTestTargetSuffix = @"_flaky_egtests";
23 27
24 // Contains a list of test names that run in multitasking test suite. 28 // Contains a list of test names that run in multitasking test suite.
25 NSArray* whiteListedMultitaskingTests = @[ 29 NSArray* whiteListedMultitaskingTests = @[
26 // Integration tests 30 // Integration tests
27 @"testContextMenuOpenInNewTab", // ContextMenuTestCase 31 @"testContextMenuOpenInNewTab", // ContextMenuTestCase
28 @"testSwitchToMain", // CookiesTestCase 32 @"testSwitchToMain", // CookiesTestCase
29 @"testSwitchToIncognito", // CookiesTestCase 33 @"testSwitchToIncognito", // CookiesTestCase
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 @"testOpenAndCloseToolsMenu", // ToolsPopupMenuTestCase 73 @"testOpenAndCloseToolsMenu", // ToolsPopupMenuTestCase
70 @"testUserFeedbackPageOpenPrivacyPolicy", // UserFeedbackTestCase 74 @"testUserFeedbackPageOpenPrivacyPolicy", // UserFeedbackTestCase
71 @"testVersion", // WebUITestCase 75 @"testVersion", // WebUITestCase
72 ]; 76 ];
73 77
74 const CFTimeInterval kDrainTimeout = 5; 78 const CFTimeInterval kDrainTimeout = 5;
75 } // namespace 79 } // namespace
76 80
77 @interface ChromeTestCase () { 81 @interface ChromeTestCase () {
78 // Block to be executed during object tearDown. 82 // Block to be executed during object tearDown.
79 base::mac::ScopedBlock<ProceduralBlock> _tearDownHandler; 83 ProceduralBlock _tearDownHandler;
80 84
81 BOOL _isHTTPServerStopped; 85 BOOL _isHTTPServerStopped;
82 BOOL _isMockAuthenticationDisabled; 86 BOOL _isMockAuthenticationDisabled;
83 } 87 }
84 88
85 // Cleans up mock authentication. 89 // Cleans up mock authentication.
86 + (void)disableMockAuthentication; 90 + (void)disableMockAuthentication;
87 91
88 // Sets up mock authentication. 92 // Sets up mock authentication.
89 + (void)enableMockAuthentication; 93 + (void)enableMockAuthentication;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 [[self class] disableMockAuthentication]; 154 [[self class] disableMockAuthentication];
151 [[self class] stopHTTPServer]; 155 [[self class] stopHTTPServer];
152 [super tearDown]; 156 [super tearDown];
153 } 157 }
154 158
155 // Set up called once per test, to open a new tab. 159 // Set up called once per test, to open a new tab.
156 - (void)setUp { 160 - (void)setUp {
157 [super setUp]; 161 [super setUp];
158 _isHTTPServerStopped = NO; 162 _isHTTPServerStopped = NO;
159 _isMockAuthenticationDisabled = NO; 163 _isMockAuthenticationDisabled = NO;
160 _tearDownHandler.reset(); 164 _tearDownHandler = nil;
161 165
162 chrome_test_util::OpenNewTab(); 166 chrome_test_util::OpenNewTab();
163 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; 167 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
164 } 168 }
165 169
166 // Tear down called once per test, to close all tabs and menus, and clear the 170 // Tear down called once per test, to close all tabs and menus, and clear the
167 // tracked tests accounts. It also makes sure mock authentication and the HTTP 171 // tracked tests accounts. It also makes sure mock authentication and the HTTP
168 // server are running. 172 // server are running.
169 - (void)tearDown { 173 - (void)tearDown {
170 if (_tearDownHandler) { 174 if (_tearDownHandler) {
171 _tearDownHandler.get()(); 175 _tearDownHandler();
172 } 176 }
173 177
174 // Clear any remaining test accounts and signed in users. 178 // Clear any remaining test accounts and signed in users.
175 chrome_test_util::SignOutAndClearAccounts(); 179 chrome_test_util::SignOutAndClearAccounts();
176 180
177 // Re-start anything that was disabled this test, so it is running when the 181 // Re-start anything that was disabled this test, so it is running when the
178 // next test starts. 182 // next test starts.
179 if (_isHTTPServerStopped) { 183 if (_isHTTPServerStopped) {
180 [[self class] startHTTPServer]; 184 [[self class] startHTTPServer];
181 _isHTTPServerStopped = NO; 185 _isHTTPServerStopped = NO;
182 } 186 }
183 if (_isMockAuthenticationDisabled) { 187 if (_isMockAuthenticationDisabled) {
184 [[self class] enableMockAuthentication]; 188 [[self class] enableMockAuthentication];
185 _isMockAuthenticationDisabled = NO; 189 _isMockAuthenticationDisabled = NO;
186 } 190 }
187 191
188 // Clean up any UI that may remain open so the next test starts in a clean 192 // Clean up any UI that may remain open so the next test starts in a clean
189 // state. 193 // state.
190 [[self class] removeAnyOpenMenusAndInfoBars]; 194 [[self class] removeAnyOpenMenusAndInfoBars];
191 [[self class] closeAllTabs]; 195 [[self class] closeAllTabs];
192 [super tearDown]; 196 [super tearDown];
193 } 197 }
194 198
195 #pragma mark - Public methods 199 #pragma mark - Public methods
196 200
197 - (void)setTearDownHandler:(ProceduralBlock)tearDownHandler { 201 - (void)setTearDownHandler:(ProceduralBlock)tearDownHandler {
198 // Enforce that only one |_tearDownHandler| is set per test. 202 // Enforce that only one |_tearDownHandler| is set per test.
199 DCHECK(!_tearDownHandler); 203 DCHECK(!_tearDownHandler);
200 _tearDownHandler.reset([tearDownHandler copy]); 204 _tearDownHandler = [tearDownHandler copy];
201 } 205 }
202 206
203 + (void)removeAnyOpenMenusAndInfoBars { 207 + (void)removeAnyOpenMenusAndInfoBars {
204 chrome_test_util::RemoveAllInfoBars(); 208 chrome_test_util::RemoveAllInfoBars();
205 chrome_test_util::ClearPresentedState(); 209 chrome_test_util::ClearPresentedState();
206 // After programatically removing UI elements, allow Earl Grey's 210 // After programatically removing UI elements, allow Earl Grey's
207 // UI synchronization to become idle, so subsequent steps won't start before 211 // UI synchronization to become idle, so subsequent steps won't start before
208 // the UI is in a good state. 212 // the UI is in a good state.
209 [[GREYUIThreadExecutor sharedInstance] 213 [[GREYUIThreadExecutor sharedInstance]
210 drainUntilIdleWithTimeout:kDrainTimeout]; 214 drainUntilIdleWithTimeout:kDrainTimeout];
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 [NSInvocation invocationWithMethodSignature:methodSignature]; 298 [NSInvocation invocationWithMethodSignature:methodSignature];
295 invocation.selector = selector; 299 invocation.selector = selector;
296 [multitaskingTestNames addObject:invocation]; 300 [multitaskingTestNames addObject:invocation];
297 } 301 }
298 } 302 }
299 free(methods); 303 free(methods);
300 return multitaskingTestNames; 304 return multitaskingTestNames;
301 } 305 }
302 306
303 @end 307 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698