| OLD | NEW |
| 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/signin/core/browser/signin_manager.h" | 9 #include "components/signin/core/browser/signin_manager.h" |
| 10 #include "components/strings/grit/components_strings.h" | 10 #include "components/strings/grit/components_strings.h" |
| 11 #include "ios/chrome/browser/signin/signin_manager_factory.h" | 11 #include "ios/chrome/browser/signin/signin_manager_factory.h" |
| 12 #import "ios/chrome/browser/ui/settings/accounts_collection_view_controller.h" | 12 #import "ios/chrome/browser/ui/settings/accounts_collection_view_controller.h" |
| 13 #import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h" | 13 #import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h" |
| 14 #include "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h" | 14 #include "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h" |
| 15 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" | 15 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" |
| 16 #include "ios/chrome/grit/ios_strings.h" | 16 #include "ios/chrome/grit/ios_strings.h" |
| 17 #import "ios/chrome/test/app/chrome_test_util.h" | 17 #import "ios/chrome/test/app/chrome_test_util.h" |
| 18 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" | 18 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" |
| 19 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 19 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 20 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 20 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 21 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" | 21 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" |
| 22 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.
h" | 22 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.
h" |
| 23 | 23 |
| 24 #if !defined(__has_feature) || !__has_feature(objc_arc) | 24 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 25 #error "This file requires ARC support." | 25 #error "This file requires ARC support." |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 using chrome_test_util::NavigationBarDoneButton; |
| 29 |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 30 // Returns a fake identity. | 32 // Returns a fake identity. |
| 31 ChromeIdentity* GetFakeIdentity1() { | 33 ChromeIdentity* GetFakeIdentity1() { |
| 32 return [FakeChromeIdentity identityWithEmail:@"foo@gmail.com" | 34 return [FakeChromeIdentity identityWithEmail:@"foo@gmail.com" |
| 33 gaiaID:@"fooID" | 35 gaiaID:@"fooID" |
| 34 name:@"Fake Foo"]; | 36 name:@"Fake Foo"]; |
| 35 } | 37 } |
| 36 | 38 |
| 37 // Returns a second fake identity. | 39 // Returns a second fake identity. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 // Forget |identity|, screens should be popped back to the Main Settings. | 116 // Forget |identity|, screens should be popped back to the Main Settings. |
| 115 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 117 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 116 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider() | 118 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider() |
| 117 ->ForgetIdentity(identity, nil); | 119 ->ForgetIdentity(identity, nil); |
| 118 | 120 |
| 119 [[EarlGrey | 121 [[EarlGrey |
| 120 selectElementWithMatcher:grey_accessibilityID(kSettingsSignInCellId)] | 122 selectElementWithMatcher:grey_accessibilityID(kSettingsSignInCellId)] |
| 121 assertWithMatcher:grey_sufficientlyVisible()]; | 123 assertWithMatcher:grey_sufficientlyVisible()]; |
| 122 AssertAuthenticatedIdentityInActiveProfile(nil); | 124 AssertAuthenticatedIdentityInActiveProfile(nil); |
| 123 | 125 |
| 124 // Close Settings. | 126 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] |
| 125 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON); | 127 performAction:grey_tap()]; |
| 126 } | 128 } |
| 127 | 129 |
| 128 // Tests that the Account Settings screen is correctly popped if the signed in | 130 // Tests that the Account Settings screen is correctly popped if the signed in |
| 129 // account is removed while the "Disconnect Account" dialog is up. | 131 // account is removed while the "Disconnect Account" dialog is up. |
| 130 - (void)testSignInPopUpAccountOnDisconnectAccount { | 132 - (void)testSignInPopUpAccountOnDisconnectAccount { |
| 131 ChromeIdentity* identity = GetFakeIdentity1(); | 133 ChromeIdentity* identity = GetFakeIdentity1(); |
| 132 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( | 134 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( |
| 133 identity); | 135 identity); |
| 134 | 136 |
| 135 // Sign In |identity|, then open the Account Settings. | 137 // Sign In |identity|, then open the Account Settings. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 152 // Forget |identity|, screens should be popped back to the Main Settings. | 154 // Forget |identity|, screens should be popped back to the Main Settings. |
| 153 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 155 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 154 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider() | 156 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider() |
| 155 ->ForgetIdentity(identity, nil); | 157 ->ForgetIdentity(identity, nil); |
| 156 | 158 |
| 157 [[EarlGrey | 159 [[EarlGrey |
| 158 selectElementWithMatcher:grey_accessibilityID(kSettingsSignInCellId)] | 160 selectElementWithMatcher:grey_accessibilityID(kSettingsSignInCellId)] |
| 159 assertWithMatcher:grey_sufficientlyVisible()]; | 161 assertWithMatcher:grey_sufficientlyVisible()]; |
| 160 AssertAuthenticatedIdentityInActiveProfile(nil); | 162 AssertAuthenticatedIdentityInActiveProfile(nil); |
| 161 | 163 |
| 162 // Close Settings. | 164 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] |
| 163 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON); | 165 performAction:grey_tap()]; |
| 164 } | 166 } |
| 165 | 167 |
| 166 // Tests that the Account Settings screen is correctly reloaded when one of | 168 // Tests that the Account Settings screen is correctly reloaded when one of |
| 167 // the non-primary account is removed. | 169 // the non-primary account is removed. |
| 168 - (void)testSignInReloadOnRemoveAccount { | 170 - (void)testSignInReloadOnRemoveAccount { |
| 169 ios::FakeChromeIdentityService* identity_service = | 171 ios::FakeChromeIdentityService* identity_service = |
| 170 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider(); | 172 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider(); |
| 171 ChromeIdentity* identity1 = GetFakeIdentity1(); | 173 ChromeIdentity* identity1 = GetFakeIdentity1(); |
| 172 ChromeIdentity* identity2 = GetFakeIdentity2(); | 174 ChromeIdentity* identity2 = GetFakeIdentity2(); |
| 173 identity_service->AddIdentity(identity1); | 175 identity_service->AddIdentity(identity1); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 186 TapButtonWithAccessibilityLabel(@"Remove account"); | 188 TapButtonWithAccessibilityLabel(@"Remove account"); |
| 187 | 189 |
| 188 // Check that |identity2| isn't available anymore on the Account Settings. | 190 // Check that |identity2| isn't available anymore on the Account Settings. |
| 189 [[EarlGrey | 191 [[EarlGrey |
| 190 selectElementWithMatcher:grey_allOf( | 192 selectElementWithMatcher:grey_allOf( |
| 191 grey_accessibilityLabel(identity2.userEmail), | 193 grey_accessibilityLabel(identity2.userEmail), |
| 192 grey_sufficientlyVisible(), nil)] | 194 grey_sufficientlyVisible(), nil)] |
| 193 assertWithMatcher:grey_nil()]; | 195 assertWithMatcher:grey_nil()]; |
| 194 AssertAuthenticatedIdentityInActiveProfile(identity1); | 196 AssertAuthenticatedIdentityInActiveProfile(identity1); |
| 195 | 197 |
| 196 // Close Settings. | 198 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] |
| 197 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON); | 199 performAction:grey_tap()]; |
| 198 } | 200 } |
| 199 | 201 |
| 200 // Tests that the Sync Settings screen is correctly reloaded when one of the | 202 // Tests that the Sync Settings screen is correctly reloaded when one of the |
| 201 // secondary accounts disappears. | 203 // secondary accounts disappears. |
| 202 - (void)testSignInReloadSyncOnForgetIdentity { | 204 - (void)testSignInReloadSyncOnForgetIdentity { |
| 203 ios::FakeChromeIdentityService* identity_service = | 205 ios::FakeChromeIdentityService* identity_service = |
| 204 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider(); | 206 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider(); |
| 205 ChromeIdentity* identity1 = GetFakeIdentity1(); | 207 ChromeIdentity* identity1 = GetFakeIdentity1(); |
| 206 ChromeIdentity* identity2 = GetFakeIdentity2(); | 208 ChromeIdentity* identity2 = GetFakeIdentity2(); |
| 207 identity_service->AddIdentity(identity1); | 209 identity_service->AddIdentity(identity1); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 227 grey_accessibilityLabel(identity1.userEmail), | 229 grey_accessibilityLabel(identity1.userEmail), |
| 228 grey_sufficientlyVisible(), nil)] | 230 grey_sufficientlyVisible(), nil)] |
| 229 assertWithMatcher:grey_nil()]; | 231 assertWithMatcher:grey_nil()]; |
| 230 [[EarlGrey | 232 [[EarlGrey |
| 231 selectElementWithMatcher:grey_allOf( | 233 selectElementWithMatcher:grey_allOf( |
| 232 grey_accessibilityLabel(identity2.userEmail), | 234 grey_accessibilityLabel(identity2.userEmail), |
| 233 grey_sufficientlyVisible(), nil)] | 235 grey_sufficientlyVisible(), nil)] |
| 234 assertWithMatcher:grey_nil()]; | 236 assertWithMatcher:grey_nil()]; |
| 235 AssertAuthenticatedIdentityInActiveProfile(identity1); | 237 AssertAuthenticatedIdentityInActiveProfile(identity1); |
| 236 | 238 |
| 237 // Close Settings. | 239 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] |
| 238 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON); | 240 performAction:grey_tap()]; |
| 239 } | 241 } |
| 240 | 242 |
| 241 // Tests that the Account Settings screen is popped and the user signed out | 243 // Tests that the Account Settings screen is popped and the user signed out |
| 242 // when the account is removed. | 244 // when the account is removed. |
| 243 - (void)testSignOutOnRemoveAccount { | 245 - (void)testSignOutOnRemoveAccount { |
| 244 ChromeIdentity* identity = GetFakeIdentity1(); | 246 ChromeIdentity* identity = GetFakeIdentity1(); |
| 245 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( | 247 ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( |
| 246 identity); | 248 identity); |
| 247 | 249 |
| 248 // Sign In |identity|, then open the Account Settings. | 250 // Sign In |identity|, then open the Account Settings. |
| 249 OpenSignInFromSettings(); | 251 OpenSignInFromSettings(); |
| 250 TapButtonWithAccessibilityLabel(identity.userEmail); | 252 TapButtonWithAccessibilityLabel(identity.userEmail); |
| 251 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON); | 253 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_SETUP_SIGNIN_BUTTON); |
| 252 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON); | 254 TapButtonWithLabelId(IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OK_BUTTON); |
| 253 AssertAuthenticatedIdentityInActiveProfile(identity); | 255 AssertAuthenticatedIdentityInActiveProfile(identity); |
| 254 TapViewWithAccessibilityId(kSettingsAccountCellId); | 256 TapViewWithAccessibilityId(kSettingsAccountCellId); |
| 255 | 257 |
| 256 // Remove |identity| from the device. | 258 // Remove |identity| from the device. |
| 257 TapButtonWithAccessibilityLabel(identity.userEmail); | 259 TapButtonWithAccessibilityLabel(identity.userEmail); |
| 258 TapButtonWithAccessibilityLabel(@"Remove account"); | 260 TapButtonWithAccessibilityLabel(@"Remove account"); |
| 259 | 261 |
| 260 // Check that the user is signed out and the Main Settings screen is shown. | 262 // Check that the user is signed out and the Main Settings screen is shown. |
| 261 [[EarlGrey | 263 [[EarlGrey |
| 262 selectElementWithMatcher:grey_accessibilityID(kSettingsSignInCellId)] | 264 selectElementWithMatcher:grey_accessibilityID(kSettingsSignInCellId)] |
| 263 assertWithMatcher:grey_sufficientlyVisible()]; | 265 assertWithMatcher:grey_sufficientlyVisible()]; |
| 264 AssertAuthenticatedIdentityInActiveProfile(nil); | 266 AssertAuthenticatedIdentityInActiveProfile(nil); |
| 265 | 267 |
| 266 // Close Settings. | 268 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] |
| 267 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON); | 269 performAction:grey_tap()]; |
| 268 } | 270 } |
| 269 | 271 |
| 270 // Tests that the user isn't signed out and the UI is correct when the | 272 // Tests that the user isn't signed out and the UI is correct when the |
| 271 // disconnect is cancelled in the Account Settings screen. | 273 // disconnect is cancelled in the Account Settings screen. |
| 272 - (void)testSignInDisconnectCancelled { | 274 - (void)testSignInDisconnectCancelled { |
| 273 // TODO(crbug.com/669613): Re-enable this test on devices. | 275 // TODO(crbug.com/669613): Re-enable this test on devices. |
| 274 #if !TARGET_IPHONE_SIMULATOR | 276 #if !TARGET_IPHONE_SIMULATOR |
| 275 EARL_GREY_TEST_DISABLED(@"Test disabled on device."); | 277 EARL_GREY_TEST_DISABLED(@"Test disabled on device."); |
| 276 #endif | 278 #endif |
| 277 ChromeIdentity* identity = GetFakeIdentity1(); | 279 ChromeIdentity* identity = GetFakeIdentity1(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 294 scroll_displacement) | 296 scroll_displacement) |
| 295 onElementWithMatcher:grey_accessibilityID(kSettingsAccountsId)] | 297 onElementWithMatcher:grey_accessibilityID(kSettingsAccountsId)] |
| 296 performAction:grey_tap()]; | 298 performAction:grey_tap()]; |
| 297 TapButtonWithLabelId(IDS_CANCEL); | 299 TapButtonWithLabelId(IDS_CANCEL); |
| 298 | 300 |
| 299 // Check that Account Settings screen is open and |identity| is signed in. | 301 // Check that Account Settings screen is open and |identity| is signed in. |
| 300 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(kSettingsAccountsId)] | 302 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(kSettingsAccountsId)] |
| 301 assertWithMatcher:grey_sufficientlyVisible()]; | 303 assertWithMatcher:grey_sufficientlyVisible()]; |
| 302 AssertAuthenticatedIdentityInActiveProfile(identity); | 304 AssertAuthenticatedIdentityInActiveProfile(identity); |
| 303 | 305 |
| 304 // Close Settings. | 306 [[EarlGrey selectElementWithMatcher:NavigationBarDoneButton()] |
| 305 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON); | 307 performAction:grey_tap()]; |
| 306 } | 308 } |
| 307 | 309 |
| 308 @end | 310 @end |
| OLD | NEW |