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

Side by Side Diff: ios/chrome/browser/ui/first_run/first_run_egtest.mm

Issue 2823913002: Delete TapButtonWithLabelId from first_run_egtest.mm. (Closed)
Patch Set: don't use fixup 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
« no previous file with comments | « no previous file | ios/chrome/test/earl_grey/chrome_matchers.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <EarlGrey/EarlGrey.h> 5 #import <EarlGrey/EarlGrey.h>
6 #import <XCTest/XCTest.h> 6 #import <XCTest/XCTest.h>
7 7
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "components/metrics/metrics_pref_names.h" 9 #include "components/metrics/metrics_pref_names.h"
10 #include "components/metrics/metrics_reporting_default_state.h" 10 #include "components/metrics/metrics_reporting_default_state.h"
(...skipping 16 matching lines...) Expand all
27 #import "ios/chrome/test/earl_grey/chrome_matchers.h" 27 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
28 #import "ios/chrome/test/earl_grey/chrome_test_case.h" 28 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
29 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" 29 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
30 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service. h" 30 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service. 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) 33 #if !defined(__has_feature) || !__has_feature(objc_arc)
34 #error "This file requires ARC support." 34 #error "This file requires ARC support."
35 #endif 35 #endif
36 36
37 using chrome_test_util::AccountConsistencySetupSigninButton;
38 using chrome_test_util::ButtonWithAccessibilityLabel;
39 using chrome_test_util::ButtonWithAccessibilityLabelId;
40 using chrome_test_util::NavigationBarDoneButton;
41
37 namespace { 42 namespace {
38 43
39 // Returns a fake identity. 44 // Returns a fake identity.
40 ChromeIdentity* GetFakeIdentity() { 45 ChromeIdentity* GetFakeIdentity() {
41 return [FakeChromeIdentity identityWithEmail:@"foo@gmail.com" 46 return [FakeChromeIdentity identityWithEmail:@"foo@gmail.com"
42 gaiaID:@"fooID" 47 gaiaID:@"fooID"
43 name:@"Fake Foo"]; 48 name:@"Fake Foo"];
44 } 49 }
45 50
46 // Taps the button with accessibility labelId |message_id|. 51 // Returns matcher for the opt in accept button.
47 void TapButtonWithLabelId(int message_id) { 52 id<GREYMatcher> FirstRunOptInAcceptButton() {
48 id<GREYMatcher> matcher = chrome_test_util::ButtonWithAccessibilityLabel( 53 return ButtonWithAccessibilityLabel(
49 l10n_util::GetNSString(message_id)); 54 l10n_util::GetNSString(IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON));
50 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()]; 55 }
56
57 // Returns matcher for the skip sign in button.
58 id<GREYMatcher> SkipSigninButton() {
59 return grey_accessibilityID(kSignInSkipButtonAccessibilityIdentifier);
60 }
61
62 // Returns matcher for the first run account consistency skip button.
63 id<GREYMatcher> FirstRunAccountConsistencySkipButton() {
64 return ButtonWithAccessibilityLabelId(
65 IDS_IOS_FIRSTRUN_ACCOUNT_CONSISTENCY_SKIP_BUTTON);
66 }
67
68 // Returns matcher for the undo sign in button.
69 id<GREYMatcher> UndoAccountConsistencyButton() {
70 return ButtonWithAccessibilityLabelId(
71 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_UNDO_BUTTON);
51 } 72 }
52 73
53 // Asserts that |identity| is actually signed in to the active profile. 74 // Asserts that |identity| is actually signed in to the active profile.
54 void AssertAuthenticatedIdentityInActiveProfile(ChromeIdentity* identity) { 75 void AssertAuthenticatedIdentityInActiveProfile(ChromeIdentity* identity) {
55 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; 76 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
56 77
57 ios::ChromeBrowserState* browser_state = 78 ios::ChromeBrowserState* browser_state =
58 chrome_test_util::GetOriginalBrowserState(); 79 chrome_test_util::GetOriginalBrowserState();
59 AccountInfo info = 80 AccountInfo info =
60 ios::SigninManagerFactory::GetForBrowserState(browser_state) 81 ios::SigninManagerFactory::GetForBrowserState(browser_state)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 149 }
129 150
130 // Toggle the UMA checkbox. 151 // Toggle the UMA checkbox.
131 - (void)testToggleMetricsOn { 152 - (void)testToggleMetricsOn {
132 [chrome_test_util::GetMainController() showFirstRunUI]; 153 [chrome_test_util::GetMainController() showFirstRunUI];
133 154
134 id<GREYMatcher> metrics = 155 id<GREYMatcher> metrics =
135 grey_accessibilityID(kUMAMetricsButtonAccessibilityIdentifier); 156 grey_accessibilityID(kUMAMetricsButtonAccessibilityIdentifier);
136 [[EarlGrey selectElementWithMatcher:metrics] performAction:grey_tap()]; 157 [[EarlGrey selectElementWithMatcher:metrics] performAction:grey_tap()];
137 158
138 id<GREYMatcher> optInAccept = chrome_test_util::ButtonWithAccessibilityLabel( 159 [[EarlGrey selectElementWithMatcher:FirstRunOptInAcceptButton()]
139 l10n_util::GetNSString(IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON)); 160 performAction:grey_tap()];
140 [[EarlGrey selectElementWithMatcher:optInAccept] performAction:grey_tap()];
141 161
142 BOOL metricsOptIn = GetApplicationContext()->GetLocalState()->GetBoolean( 162 BOOL metricsOptIn = GetApplicationContext()->GetLocalState()->GetBoolean(
143 metrics::prefs::kMetricsReportingEnabled); 163 metrics::prefs::kMetricsReportingEnabled);
144 GREYAssert( 164 GREYAssert(
145 metricsOptIn != [WelcomeToChromeViewController defaultStatsCheckboxValue], 165 metricsOptIn != [WelcomeToChromeViewController defaultStatsCheckboxValue],
146 @"Metrics reporting pref is incorrect."); 166 @"Metrics reporting pref is incorrect.");
147 } 167 }
148 168
149 // Dismisses the first run screens. 169 // Dismisses the first run screens.
150 - (void)testDismissFirstRun { 170 - (void)testDismissFirstRun {
151 [chrome_test_util::GetMainController() showFirstRunUI]; 171 [chrome_test_util::GetMainController() showFirstRunUI];
152 172
153 id<GREYMatcher> optInAccept = chrome_test_util::ButtonWithAccessibilityLabel( 173 [[EarlGrey selectElementWithMatcher:FirstRunOptInAcceptButton()]
154 l10n_util::GetNSString(IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON)); 174 performAction:grey_tap()];
155 [[EarlGrey selectElementWithMatcher:optInAccept] performAction:grey_tap()];
156 175
157 PrefService* preferences = GetApplicationContext()->GetLocalState(); 176 PrefService* preferences = GetApplicationContext()->GetLocalState();
158 GREYAssert( 177 GREYAssert(
159 preferences->GetBoolean(metrics::prefs::kMetricsReportingEnabled) == 178 preferences->GetBoolean(metrics::prefs::kMetricsReportingEnabled) ==
160 [WelcomeToChromeViewController defaultStatsCheckboxValue], 179 [WelcomeToChromeViewController defaultStatsCheckboxValue],
161 @"Metrics reporting does not match."); 180 @"Metrics reporting does not match.");
162 181
163 id<GREYMatcher> skipSignIn = 182 [[EarlGrey selectElementWithMatcher:SkipSigninButton()]
164 grey_accessibilityID(kSignInSkipButtonAccessibilityIdentifier); 183 performAction:grey_tap()];
165 [[EarlGrey selectElementWithMatcher:skipSignIn] performAction:grey_tap()];
166 184
167 id<GREYMatcher> newTab = 185 id<GREYMatcher> newTab =
168 grey_kindOfClass(NSClassFromString(@"NewTabPageView")); 186 grey_kindOfClass(NSClassFromString(@"NewTabPageView"));
169 [[EarlGrey selectElementWithMatcher:newTab] 187 [[EarlGrey selectElementWithMatcher:newTab]
170 assertWithMatcher:grey_sufficientlyVisible()]; 188 assertWithMatcher:grey_sufficientlyVisible()];
171 } 189 }
172 190
173 // Signs in to an account and then taps the Undo button to sign out. 191 // Signs in to an account and then taps the Undo button to sign out.
174 - (void)testSignInAndUndo { 192 - (void)testSignInAndUndo {
175 ChromeIdentity* identity = GetFakeIdentity(); 193 ChromeIdentity* identity = GetFakeIdentity();
176 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( 194 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
177 identity); 195 identity);
178 196
179 // Launch First Run and accept tems of services. 197 // Launch First Run and accept tems of services.
180 [chrome_test_util::GetMainController() showFirstRunUI]; 198 [chrome_test_util::GetMainController() showFirstRunUI];
181 TapButtonWithLabelId(IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON); 199 [[EarlGrey selectElementWithMatcher:FirstRunOptInAcceptButton()]
200 performAction:grey_tap()];
182 201
183 // Sign In |identity|. 202 // Sign In |identity|.
184 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON); 203 [[EarlGrey selectElementWithMatcher:AccountConsistencySetupSigninButton()]
204 performAction:grey_tap()];
205
185 AssertAuthenticatedIdentityInActiveProfile(identity); 206 AssertAuthenticatedIdentityInActiveProfile(identity);
186 207
187 // Undo the sign-in and dismiss the Sign In screen. 208 // Undo the sign-in and dismiss the Sign In screen.
188 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_UNDO_BUTTON); 209 [[EarlGrey selectElementWithMatcher:UndoAccountConsistencyButton()]
189 TapButtonWithLabelId(IDS_IOS_FIRSTRUN_ACCOUNT_CONSISTENCY_SKIP_BUTTON); 210 performAction:grey_tap()];
211 [[EarlGrey selectElementWithMatcher:FirstRunAccountConsistencySkipButton()]
212 performAction:grey_tap()];
190 213
191 // |identity| shouldn't be signed in. 214 // |identity| shouldn't be signed in.
192 AssertAuthenticatedIdentityInActiveProfile(nil); 215 AssertAuthenticatedIdentityInActiveProfile(nil);
193 } 216 }
194 217
195 // Signs in to an account and then taps the Advanced link to go to settings. 218 // Signs in to an account and then taps the Advanced link to go to settings.
196 - (void)testSignInAndTapSettingsLink { 219 - (void)testSignInAndTapSettingsLink {
197 ChromeIdentity* identity = GetFakeIdentity(); 220 ChromeIdentity* identity = GetFakeIdentity();
198 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( 221 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
199 identity); 222 identity);
200 223
201 // Launch First Run and accept tems of services. 224 // Launch First Run and accept tems of services.
202 [chrome_test_util::GetMainController() showFirstRunUI]; 225 [chrome_test_util::GetMainController() showFirstRunUI];
203 TapButtonWithLabelId(IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON); 226 [[EarlGrey selectElementWithMatcher:FirstRunOptInAcceptButton()]
227 performAction:grey_tap()];
204 228
205 // Sign In |identity|. 229 // Sign In |identity|.
206 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON); 230 [[EarlGrey selectElementWithMatcher:AccountConsistencySetupSigninButton()]
231 performAction:grey_tap()];
207 AssertAuthenticatedIdentityInActiveProfile(identity); 232 AssertAuthenticatedIdentityInActiveProfile(identity);
208 233
209 // Tap Settings link. 234 // Tap Settings link.
210 id<GREYMatcher> settings_link_matcher = grey_allOf( 235 id<GREYMatcher> settings_link_matcher = grey_allOf(
211 grey_accessibilityLabel(@"Settings"), grey_sufficientlyVisible(), nil); 236 grey_accessibilityLabel(@"Settings"), grey_sufficientlyVisible(), nil);
212 [[EarlGrey selectElementWithMatcher:settings_link_matcher] 237 [[EarlGrey selectElementWithMatcher:settings_link_matcher]
213 performAction:grey_tap()]; 238 performAction:grey_tap()];
214 239
215 // Check Sync hasn't started yet, allowing the user to change somes settings. 240 // Check Sync hasn't started yet, allowing the user to change somes settings.
216 SyncSetupService* sync_service = SyncSetupServiceFactory::GetForBrowserState( 241 SyncSetupService* sync_service = SyncSetupServiceFactory::GetForBrowserState(
217 chrome_test_util::GetOriginalBrowserState()); 242 chrome_test_util::GetOriginalBrowserState());
218 GREYAssertFalse(sync_service->HasFinishedInitialSetup(), 243 GREYAssertFalse(sync_service->HasFinishedInitialSetup(),
219 @"Sync shouldn't have finished its original setup yet"); 244 @"Sync shouldn't have finished its original setup yet");
220 245
221 // Close Settings, user is still signed in and sync is now starting. 246 // Close Settings, user is still signed in and sync is now starting.
222 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON); 247 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()]
248 performAction:grey_tap()];
223 AssertAuthenticatedIdentityInActiveProfile(identity); 249 AssertAuthenticatedIdentityInActiveProfile(identity);
224 GREYAssertTrue(sync_service->HasFinishedInitialSetup(), 250 GREYAssertTrue(sync_service->HasFinishedInitialSetup(),
225 @"Sync should have finished its original setup"); 251 @"Sync should have finished its original setup");
226 } 252 }
227 253
228 @end 254 @end
OLDNEW
« no previous file with comments | « no previous file | ios/chrome/test/earl_grey/chrome_matchers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698