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

Side by Side Diff: ios/chrome/browser/ui/authentication/signin_interaction_controller_egtest.mm

Issue 2586993002: Upstream Chrome on iOS source code [3/11]. (Closed)
Patch Set: Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #import <EarlGrey/EarlGrey.h>
6 #import <XCTest/XCTest.h>
7
8 #include "base/strings/sys_string_conversions.h"
9 #import "base/test/ios/wait_util.h"
10 #include "components/signin/core/browser/signin_manager.h"
11 #include "ios/chrome/browser/experimental_flags.h"
12 #include "ios/chrome/browser/signin/signin_manager_factory.h"
13 #import "ios/chrome/browser/ui/commands/open_url_command.h"
14 #import "ios/chrome/browser/ui/settings/accounts_collection_view_controller.h"
15 #import "ios/chrome/browser/ui/settings/import_data_collection_view_controller.h "
16 #import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h"
17 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h"
18 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h"
19 #include "ios/chrome/browser/ui/ui_util.h"
20 #include "ios/chrome/grit/ios_strings.h"
21 #import "ios/chrome/test/app/chrome_test_util.h"
22 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
23 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
24 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
25 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
26 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service. h"
27 #import "ios/testing/earl_grey/disabled_test_macros.h"
28 #import "ios/testing/wait_util.h"
29
30 namespace {
31
32 // Returns a fake identity.
33 ChromeIdentity* GetFakeIdentity1() {
34 return [FakeChromeIdentity identityWithEmail:@"foo@gmail.com"
35 gaiaID:@"fooID"
36 name:@"Fake Foo"];
37 }
38
39 // Returns a second fake identity.
40 ChromeIdentity* GetFakeIdentity2() {
41 return [FakeChromeIdentity identityWithEmail:@"bar@gmail.com"
42 gaiaID:@"barID"
43 name:@"Fake Bar"];
44 }
45
46 ChromeIdentity* GetFakeManagedIdentity() {
47 return [FakeChromeIdentity identityWithEmail:@"managed@foo.com"
48 gaiaID:@"managedID"
49 name:@"Fake Managed"];
50 }
51
52 // Changes the EarlGrey synchronization status to |enabled|.
53 void SetEarlGreySynchronizationEnabled(BOOL enabled) {
54 [[GREYConfiguration sharedInstance]
55 setValue:[NSNumber numberWithBool:enabled]
56 forConfigKey:kGREYConfigKeySynchronizationEnabled];
57 }
58
59 // Taps the view with acessibility identifier |accessibility_id|.
60 void TapViewWithAccessibilityId(NSString* accessiblity_id) {
61 // grey_sufficientlyVisible() is necessary because reloading a cell in a
62 // collection view might duplicate it (with the old one being hidden but
63 // EarlGrey can find it).
64 id<GREYMatcher> matcher = grey_allOf(grey_accessibilityID(accessiblity_id),
65 grey_sufficientlyVisible(), nil);
66 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
67 }
68
69 // Taps the button with accessibility label |label|.
70 void TapButtonWithAccessibilityLabel(NSString* label) {
71 id<GREYMatcher> matcher =
72 chrome_test_util::buttonWithAccessibilityLabel(label);
73 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
74 }
75
76 // Taps the button with accessibility labelId |message_id|.
77 void TapButtonWithLabelId(int message_id) {
78 id<GREYMatcher> matcher =
79 chrome_test_util::buttonWithAccessibilityLabelId(message_id);
80 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
81 }
82
83 // Opens the signin screen from the settings page. Must be called from the NTP.
84 // User must not be signed in.
85 void OpenSignInFromSettings() {
86 const CGFloat scroll_displacement = 50.0;
87
88 [ChromeEarlGreyUI openToolsMenu];
89 [[[EarlGrey
90 selectElementWithMatcher:grey_accessibilityID(kToolsMenuSettingsId)]
91 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown,
92 scroll_displacement)
93 onElementWithMatcher:grey_accessibilityID(kToolsMenuTableViewId)]
94 performAction:grey_tap()];
95
96 TapViewWithAccessibilityId(kSettingsSignInCellId);
97 }
98
99 // Wait until |matcher| is accessible (not nil)
100 void WaitForMatcher(id<GREYMatcher> matcher) {
101 ConditionBlock condition = ^{
102 NSError* error = nil;
103 [[EarlGrey selectElementWithMatcher:matcher] assertWithMatcher:grey_notNil()
104 error:&error];
105 return error == nil;
106 };
107 GREYAssert(
108 testing::WaitUntilConditionOrTimeout(testing::kWaitForUIElementTimeout,
109 condition),
110 [NSString stringWithFormat:@"Waiting for matcher %@ failed.", matcher]);
111 }
112
113 // Asserts that |identity| is actually signed in to the active profile.
114 void AssertAuthenticatedIdentityInActiveProfile(ChromeIdentity* identity) {
115 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
116
117 ios::ChromeBrowserState* browser_state =
118 chrome_test_util::GetOriginalBrowserState();
119 AccountInfo info =
120 ios::SigninManagerFactory::GetForBrowserState(browser_state)
121 ->GetAuthenticatedAccountInfo();
122
123 GREYAssertEqual(base::SysNSStringToUTF8(identity.gaiaID), info.gaia,
124 @"Gaia ID of signed in user isn't %@ but %s", identity.gaiaID,
125 info.gaia.c_str());
126 }
127
128 } // namespace
129
130 @interface SigninInteractionControllerTestCase : ChromeTestCase
131 @end
132
133 @implementation SigninInteractionControllerTestCase
134
135 // Tests that opening the sign-in screen from the Settings and signing in works
136 // correctly when there is already an identity on the device.
137 - (void)testSignInOneUser {
138 // Set up a fake identity.
139 ChromeIdentity* identity = GetFakeIdentity1();
140 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
141 identity);
142
143 // Open the sign in screen.
144 OpenSignInFromSettings();
145
146 // Select the user.
147 TapButtonWithAccessibilityLabel(identity.userEmail);
148
149 // Sign in and confirm.
150 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON);
151 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON);
152
153 // Close Settings.
154 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON);
155
156 // Check |identity| is signed-in.
157 AssertAuthenticatedIdentityInActiveProfile(identity);
158 }
159
160 // Tests signing in with one account, switching sync account to a second and
161 // choosing to keep the browsing data separate during the switch.
162 - (void)testSignInSwitchAccountsAndKeepDataSeparate {
163 // Set up the fake identities.
164 ios::FakeChromeIdentityService* identity_service =
165 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider();
166 ChromeIdentity* identity1 = GetFakeIdentity1();
167 ChromeIdentity* identity2 = GetFakeIdentity2();
168 identity_service->AddIdentity(identity1);
169 identity_service->AddIdentity(identity2);
170
171 // Sign in to |identity1|.
172 OpenSignInFromSettings();
173 TapButtonWithAccessibilityLabel(identity1.userEmail);
174 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON);
175 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON);
176 AssertAuthenticatedIdentityInActiveProfile(identity1);
177
178 // Open accounts settings, then sync settings.
179 TapViewWithAccessibilityId(kSettingsAccountCellId);
180 TapViewWithAccessibilityId(kSettingsAccountsSyncCellId);
181
182 // Switch Sync account to |identity2|.
183 TapButtonWithAccessibilityLabel(identity2.userEmail);
184
185 // Keep data separate, with synchronization off due to an infinite spinner.
186 SetEarlGreySynchronizationEnabled(NO);
187 WaitForMatcher(grey_accessibilityID(kImportDataKeepSeparateCellId));
188 TapViewWithAccessibilityId(kImportDataKeepSeparateCellId);
189 TapButtonWithLabelId(IDS_IOS_OPTIONS_IMPORT_DATA_CONTINUE_BUTTON);
190 SetEarlGreySynchronizationEnabled(YES);
191
192 // Check the signed-in user did change.
193 AssertAuthenticatedIdentityInActiveProfile(identity2);
194
195 // Close Settings.
196 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON);
197 }
198
199 // Tests signing in with one account, switching sync account to a second and
200 // choosing to import the browsing data during the switch.
201 - (void)testSignInSwitchAccountsAndImportData {
202 // Set up the fake identities.
203 ios::FakeChromeIdentityService* identity_service =
204 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider();
205 ChromeIdentity* identity1 = GetFakeIdentity1();
206 ChromeIdentity* identity2 = GetFakeIdentity2();
207 identity_service->AddIdentity(identity1);
208 identity_service->AddIdentity(identity2);
209
210 // Sign in to |identity1|.
211 OpenSignInFromSettings();
212 TapButtonWithAccessibilityLabel(identity1.userEmail);
213 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON);
214 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON);
215 AssertAuthenticatedIdentityInActiveProfile(identity1);
216
217 // Open accounts settings, then sync settings.
218 TapViewWithAccessibilityId(kSettingsAccountCellId);
219 TapViewWithAccessibilityId(kSettingsAccountsSyncCellId);
220
221 // Switch Sync account to |identity2|.
222 TapButtonWithAccessibilityLabel(identity2.userEmail);
223
224 // Import data, with synchronization off due to an infinite spinner.
225 SetEarlGreySynchronizationEnabled(NO);
226 WaitForMatcher(grey_accessibilityID(kImportDataImportCellId));
227 TapViewWithAccessibilityId(kImportDataImportCellId);
228 TapButtonWithLabelId(IDS_IOS_OPTIONS_IMPORT_DATA_CONTINUE_BUTTON);
229 SetEarlGreySynchronizationEnabled(YES);
230
231 // Check the signed-in user did change.
232 AssertAuthenticatedIdentityInActiveProfile(identity2);
233
234 // Close Settings.
235 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON);
236 }
237
238 // Tests that switching from a managed account to a non-managed account works
239 // correctly and displays the expected warnings.
240 - (void)testSignInSwitchManagedAccount {
241 if (!experimental_flags::IsMDMIntegrationEnabled()) {
242 EARL_GREY_TEST_SKIPPED(@"Only enabled with MDM integration.");
243 }
244
245 // Set up the fake identities.
246 ios::FakeChromeIdentityService* identity_service =
247 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider();
248 ChromeIdentity* managed_identity = GetFakeManagedIdentity();
249 ChromeIdentity* identity = GetFakeIdentity1();
250 identity_service->AddIdentity(managed_identity);
251 identity_service->AddIdentity(identity);
252
253 // Sign in to |managed_identity|.
254 OpenSignInFromSettings();
255 TapButtonWithAccessibilityLabel(managed_identity.userEmail);
256 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON);
257
258 // Accept warning for signing into a managed identity, with synchronization
259 // off due to an infinite spinner.
260 SetEarlGreySynchronizationEnabled(NO);
261 WaitForMatcher(chrome_test_util::buttonWithAccessibilityLabelId(
262 IDS_IOS_MANAGED_SIGNIN_ACCEPT_BUTTON));
263 TapButtonWithLabelId(IDS_IOS_MANAGED_SIGNIN_ACCEPT_BUTTON);
264 SetEarlGreySynchronizationEnabled(YES);
265
266 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON);
267 AssertAuthenticatedIdentityInActiveProfile(managed_identity);
268
269 // Switch Sync account to |identity|.
270 TapViewWithAccessibilityId(kSettingsAccountCellId);
271 TapViewWithAccessibilityId(kSettingsAccountsSyncCellId);
272 TapButtonWithAccessibilityLabel(identity.userEmail);
273
274 // Accept warning for signout out of a managed identity, with synchronization
275 // off due to an infinite spinner.
276 SetEarlGreySynchronizationEnabled(NO);
277 WaitForMatcher(chrome_test_util::buttonWithAccessibilityLabelId(
278 IDS_IOS_MANAGED_SWITCH_ACCEPT_BUTTON));
279 TapButtonWithLabelId(IDS_IOS_MANAGED_SWITCH_ACCEPT_BUTTON);
280 SetEarlGreySynchronizationEnabled(YES);
281
282 AssertAuthenticatedIdentityInActiveProfile(identity);
283
284 // Close Settings.
285 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON);
286 }
287
288 // Tests that signing out from the Settings works correctly.
289 - (void)testSignInDisconnectFromChrome {
290 ChromeIdentity* identity = GetFakeIdentity1();
291 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
292 identity);
293
294 // Sign in to |identity|.
295 OpenSignInFromSettings();
296 TapButtonWithAccessibilityLabel(identity.userEmail);
297 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON);
298 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON);
299 AssertAuthenticatedIdentityInActiveProfile(identity);
300
301 // Go to Accounts Settings and tap the sign out button.
302 TapViewWithAccessibilityId(kSettingsAccountCellId);
303 const CGFloat scroll_displacement = 100.0;
304 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
305 kSettingsAccountsSignoutCellId)]
306 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown,
307 scroll_displacement)
308 onElementWithMatcher:grey_accessibilityID(kSettingsAccountsId)]
309 performAction:grey_tap()];
310 TapButtonWithLabelId(IDS_IOS_DISCONNECT_DIALOG_CONTINUE_BUTTON_MOBILE);
311
312 // Check that the settings home screen is shown.
313 WaitForMatcher(grey_accessibilityID(kSettingsSignInCellId));
314
315 // Close Settings.
316 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON);
317
318 // Check that there is no signed in user.
319 AssertAuthenticatedIdentityInActiveProfile(nil);
320 }
321
322 // Tests that signing out of a managed account from the Settings works
323 // correctly.
324 - (void)testSignInDisconnectFromChromeManaged {
325 if (!experimental_flags::IsMDMIntegrationEnabled()) {
326 EARL_GREY_TEST_SKIPPED(@"Only enabled with MDM integration.");
327 }
328
329 ChromeIdentity* identity = GetFakeManagedIdentity();
330 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
331 identity);
332
333 // Sign in to |identity|.
334 OpenSignInFromSettings();
335 TapButtonWithAccessibilityLabel(identity.userEmail);
336 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON);
337 // Synchronization off due to an infinite spinner.
338 SetEarlGreySynchronizationEnabled(NO);
339 WaitForMatcher(chrome_test_util::buttonWithAccessibilityLabelId(
340 IDS_IOS_MANAGED_SIGNIN_ACCEPT_BUTTON));
341 TapButtonWithLabelId(IDS_IOS_MANAGED_SIGNIN_ACCEPT_BUTTON);
342 SetEarlGreySynchronizationEnabled(YES);
343 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON);
344 AssertAuthenticatedIdentityInActiveProfile(identity);
345
346 // Go to Accounts Settings and tap the sign out button.
347 TapViewWithAccessibilityId(kSettingsAccountCellId);
348 const CGFloat scroll_displacement = 100.0;
349 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
350 kSettingsAccountsSignoutCellId)]
351 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown,
352 scroll_displacement)
353 onElementWithMatcher:grey_accessibilityID(kSettingsAccountsId)]
354 performAction:grey_tap()];
355 TapButtonWithLabelId(IDS_IOS_MANAGED_DISCONNECT_DIALOG_ACCEPT);
356
357 // Check that the settings home screen is shown.
358 WaitForMatcher(grey_accessibilityID(kSettingsSignInCellId));
359
360 // Close Settings.
361 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON);
362
363 // Check that there is no signed in user.
364 AssertAuthenticatedIdentityInActiveProfile(nil);
365 }
366
367 // Tests that signing in, tapping the Settings link on the confirmation screen
368 // and closing the Settings correctly leaves the user signed in without any
369 // Settings shown.
370 - (void)testSignInOpenSettings {
371 ChromeIdentity* identity = GetFakeIdentity1();
372 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
373 identity);
374
375 // Sign in to |identity|.
376 OpenSignInFromSettings();
377 TapButtonWithAccessibilityLabel(identity.userEmail);
378 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON);
379
380 // Tap Settings link.
381 id<GREYMatcher> settings_link_matcher = grey_allOf(
382 grey_accessibilityLabel(@"Settings"), grey_sufficientlyVisible(), nil);
383 [[EarlGrey selectElementWithMatcher:settings_link_matcher]
384 performAction:grey_tap()];
385
386 // Close Settings.
387 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON);
388
389 // All Settings should be gone and user signed in.
390 id<GREYMatcher> settings_matcher =
391 chrome_test_util::staticTextWithAccessibilityLabelId(
392 IDS_IOS_SETTINGS_TITLE);
393 [[EarlGrey selectElementWithMatcher:settings_matcher]
394 assertWithMatcher:grey_notVisible()];
395 AssertAuthenticatedIdentityInActiveProfile(identity);
396 }
397
398 // Opens the sign in screen and then cancel it by opening a new tab. Ensures
399 // that the sign in screen is correctly dismissed. crbug.com/462200
400 - (void)testSignInCancelIdentityPicker {
401 // Add an identity to avoid arriving on the Add Account screen when opening
402 // sign-in.
403 ChromeIdentity* identity = GetFakeIdentity1();
404 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
405 identity);
406
407 OpenSignInFromSettings();
408
409 // Open new tab to cancel sign-in.
410 base::scoped_nsobject<OpenUrlCommand> command(
411 [[OpenUrlCommand alloc] initWithURLFromChrome:GURL("about:blank")]);
412 chrome_test_util::RunCommandWithActiveViewController(command);
413
414 // Re-open the sign-in screen. If it wasn't correctly dismissed previously,
415 // this will fail.
416 OpenSignInFromSettings();
417 id<GREYMatcher> signin_matcher =
418 chrome_test_util::staticTextWithAccessibilityLabelId(
419 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION);
420 [[EarlGrey selectElementWithMatcher:signin_matcher]
421 assertWithMatcher:grey_sufficientlyVisible()];
422
423 // Close sign-in screen and Settings.
424 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON);
425 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON);
426 }
427
428 // Opens the add account screen and then cancels it by opening a new tab.
429 // Ensures that the add account screen is correctly dismissed. crbug.com/462200
430 - (void)testSignInCancelAddAccount {
431 // Add an identity to avoid arriving on the Add Account screen when opening
432 // sign-in.
433 ChromeIdentity* identity = GetFakeIdentity1();
434 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
435 identity);
436
437 OpenSignInFromSettings();
438
439 // Open Add Account screen.
440 id<GREYMatcher> add_account_matcher =
441 chrome_test_util::staticTextWithAccessibilityLabelId(
442 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_ADD_ACCOUNT_BUTTON);
443 [[EarlGrey selectElementWithMatcher:add_account_matcher]
444 performAction:grey_tap()];
445 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
446
447 // Open new tab to cancel sign-in.
448 base::scoped_nsobject<OpenUrlCommand> command(
449 [[OpenUrlCommand alloc] initWithURLFromChrome:GURL("about:blank")]);
450 chrome_test_util::RunCommandWithActiveViewController(command);
451
452 // Re-open the sign-in screen. If it wasn't correctly dismissed previously,
453 // this will fail.
454 OpenSignInFromSettings();
455 id<GREYMatcher> signin_matcher =
456 chrome_test_util::staticTextWithAccessibilityLabelId(
457 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION);
458 [[EarlGrey selectElementWithMatcher:signin_matcher]
459 assertWithMatcher:grey_sufficientlyVisible()];
460
461 // Close sign-in screen and Settings.
462 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON);
463 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON);
464 }
465
466 // Starts an authentication flow and cancel it by opening a new tab. Ensures
467 // that the authentication flow is correctly canceled and dismissed.
468 // crbug.com/462202
469 - (void)testSignInCancelAuthenticationFlow {
470 // Set up the fake identities.
471 ios::FakeChromeIdentityService* identity_service =
472 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider();
473 ChromeIdentity* identity1 = GetFakeIdentity1();
474 ChromeIdentity* identity2 = GetFakeIdentity2();
475 identity_service->AddIdentity(identity1);
476 identity_service->AddIdentity(identity2);
477
478 // This signs in |identity2| first, ensuring that the "Clear Data Before
479 // Syncing" dialog is shown during the second sign-in. This dialog will
480 // effectively block the authentication flow, ensuring that the authentication
481 // flow is always still running when the sign-in is being cancelled.
482 OpenSignInFromSettings();
483 TapButtonWithAccessibilityLabel(identity2.userEmail);
484 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON);
485 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON);
486 AssertAuthenticatedIdentityInActiveProfile(identity2);
487
488 // Go to Accounts Settings and tap the sign out button.
489 TapViewWithAccessibilityId(kSettingsAccountCellId);
490 const CGFloat scroll_displacement = 100.0;
491 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
492 kSettingsAccountsSignoutCellId)]
493 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown,
494 scroll_displacement)
495 onElementWithMatcher:grey_accessibilityID(kSettingsAccountsId)]
496 performAction:grey_tap()];
497 TapButtonWithLabelId(IDS_IOS_DISCONNECT_DIALOG_CONTINUE_BUTTON_MOBILE);
498 AssertAuthenticatedIdentityInActiveProfile(nil);
499
500 // Start sign-in with |identity1|.
501 WaitForMatcher(grey_accessibilityID(kSettingsSignInCellId));
502 TapViewWithAccessibilityId(kSettingsSignInCellId);
503 TapButtonWithAccessibilityLabel(identity1.userEmail);
504 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON);
505
506 // Open new tab to cancel sign-in.
507 base::scoped_nsobject<OpenUrlCommand> command(
508 [[OpenUrlCommand alloc] initWithURLFromChrome:GURL("about:blank")]);
509 chrome_test_util::RunCommandWithActiveViewController(command);
510
511 // Re-open the sign-in screen. If it wasn't correctly dismissed previously,
512 // this will fail.
513 OpenSignInFromSettings();
514 id<GREYMatcher> signin_matcher =
515 chrome_test_util::staticTextWithAccessibilityLabelId(
516 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION);
517 [[EarlGrey selectElementWithMatcher:signin_matcher]
518 assertWithMatcher:grey_sufficientlyVisible()];
519
520 // Close sign-in screen and Settings.
521 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON);
522 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON);
523 AssertAuthenticatedIdentityInActiveProfile(nil);
524 }
525
526 // Opens the sign in screen from the bookmarks and then cancel it by opening a
527 // new tab. Ensures that the sign in screen is correctly dismissed.
528 // Regression test for crbug.com/596029.
529 - (void)testSignInCancelFromBookmarks {
530 ChromeIdentity* identity = GetFakeIdentity1();
531 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
532 identity);
533
534 // Open Bookmarks and tap on Sign In promo button.
535 const CGFloat scroll_displacement = 50.0;
536 [ChromeEarlGreyUI openToolsMenu];
537 [[[EarlGrey
538 selectElementWithMatcher:grey_accessibilityID(kToolsMenuBookmarksId)]
539 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown,
540 scroll_displacement)
541 onElementWithMatcher:grey_accessibilityID(kToolsMenuTableViewId)]
542 performAction:grey_tap()];
543
544 if (!IsIPadIdiom()) {
545 // Opens the bookmark manager sidebar on handsets.
546 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Menu")]
547 performAction:grey_tap()];
548 }
549
550 // Selects the top level folder (Sign In promo is only shown there).
551 NSString* topLevelFolderTitle = experimental_flags::IsAllBookmarksEnabled()
552 ? @"All Bookmarks"
553 : @"Mobile Bookmarks";
554 id<GREYMatcher> all_bookmarks_matcher =
555 grey_allOf(grey_kindOfClass(NSClassFromString(@"BookmarkMenuCell")),
556 grey_descendant(grey_text(topLevelFolderTitle)), nil);
557 [[EarlGrey selectElementWithMatcher:all_bookmarks_matcher]
558 performAction:grey_tap()];
559
560 TapButtonWithLabelId(IDS_IOS_BOOKMARK_PROMO_SIGN_IN_BUTTON);
561
562 // Assert sign-in screen was shown.
563 id<GREYMatcher> signin_matcher =
564 chrome_test_util::staticTextWithAccessibilityLabelId(
565 IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_DESCRIPTION);
566 [[EarlGrey selectElementWithMatcher:signin_matcher]
567 assertWithMatcher:grey_sufficientlyVisible()];
568
569 // Open new tab to cancel sign-in.
570 base::scoped_nsobject<OpenUrlCommand> command(
571 [[OpenUrlCommand alloc] initWithURLFromChrome:GURL("about:blank")]);
572 chrome_test_util::RunCommandWithActiveViewController(command);
573
574 // Re-open the sign-in screen. If it wasn't correctly dismissed previously,
575 // this will fail.
576 [ChromeEarlGreyUI openToolsMenu];
577 [[[EarlGrey
578 selectElementWithMatcher:grey_accessibilityID(kToolsMenuBookmarksId)]
579 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown,
580 scroll_displacement)
581 onElementWithMatcher:grey_accessibilityID(kToolsMenuTableViewId)]
582 performAction:grey_tap()];
583 if (!IsIPadIdiom()) {
584 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Menu")]
585 performAction:grey_tap()];
586 }
587 [[EarlGrey selectElementWithMatcher:all_bookmarks_matcher]
588 performAction:grey_tap()];
589 TapButtonWithLabelId(IDS_IOS_BOOKMARK_PROMO_SIGN_IN_BUTTON);
590 [[EarlGrey selectElementWithMatcher:signin_matcher]
591 assertWithMatcher:grey_sufficientlyVisible()];
592
593 // Close sign-in screen and Bookmarks.
594 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SKIP_BUTTON);
595 if (!IsIPadIdiom()) {
596 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON);
597 }
598 }
599
600 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698