Commit ce2e1f30 authored by Jérôme Lebel's avatar Jérôme Lebel Committed by Commit Bot

[iOS] Fixing dismiss signin from MainController

Fixing
-[MainController dismissModalDialogsWithCompletion:dismissOmnibox:] to
get it working.
This is a temporary fix. A better implementation can be done once
crbug.com/966414 is fixed.

Bug: 966061
Change-Id: If6245c71e386cfc42ed73bbe333f5464006de339
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626860
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#669820}
parent 547cf77f
......@@ -443,8 +443,6 @@ enum class EnterTabSwitcherSnapshotResult {
- (void)showTabSwitcher;
// Starts a voice search on the current BVC.
- (void)startVoiceSearchInCurrentBVC;
// Dismisses |signinInteractionCoordinator|.
- (void)dismissSigninInteractionCoordinator;
// Called when the last incognito tab was closed.
- (void)lastIncognitoTabClosed;
// Called when the last regular tab was closed.
......@@ -2214,12 +2212,6 @@ enum class EnterTabSwitcherSnapshotResult {
completion:nil];
}
- (void)dismissSigninInteractionCoordinator {
// The SigninInteractionCoordinator must not be destroyed at this point, as
// it may dismiss the sign in UI in a future callback.
[self.signinInteractionCoordinator cancelAndDismiss];
}
- (void)closeSettingsAnimated:(BOOL)animated
completion:(ProceduralBlock)completion {
if (_settingsNavigationController) {
......@@ -2431,15 +2423,12 @@ enum class EnterTabSwitcherSnapshotResult {
->GetMailtoHandlerProvider()
->DismissAllMailtoHandlerInterfaces();
// Cancel interaction with SSO.
// First, cancel the signin interaction.
[self.signinInteractionCoordinator cancel];
// Then, depending on what the SSO view controller is presented on, dismiss
// it.
ProceduralBlock completionWithBVC = ^{
DCHECK(self.currentBVC);
DCHECK(![self isTabSwitcherActive]);
DCHECK(!self.signinInteractionCoordinator.isActive);
// This will dismiss the SSO view controller.
[self.interfaceProvider.currentInterface
clearPresentedStateWithCompletion:completion
......@@ -2449,7 +2438,7 @@ enum class EnterTabSwitcherSnapshotResult {
// |self.currentBVC| may exist but tab switcher should be active.
DCHECK([self isTabSwitcherActive]);
// This will dismiss the SSO view controller.
[self dismissSigninInteractionCoordinator];
[self.signinInteractionCoordinator cancelAndDismiss];
// History coordinator can be started on top of the tab grid. This is not
// true of the other tab switchers.
DCHECK(self.mainCoordinator);
......@@ -2462,7 +2451,6 @@ enum class EnterTabSwitcherSnapshotResult {
if (![self isTabSwitcherActive] && self.isSettingsViewPresented) {
// In this case, the settings are up and the BVC is showing. Close the
// settings then call the BVC completion.
DCHECK(!self.signinInteractionCoordinator.isActive);
[self closeSettingsAnimated:NO completion:completionWithBVC];
} else if (self.isSettingsViewPresented) {
// In this case, the settings are up but the BVC is not showing. Close the
......@@ -2471,6 +2459,7 @@ enum class EnterTabSwitcherSnapshotResult {
} else if (![self isTabSwitcherActive]) {
// In this case, the settings are not shown but the BVC is showing. Call the
// BVC completion.
[self.signinInteractionCoordinator cancel];
completionWithBVC();
} else {
// In this case, neither the settings nor the BVC are shown. Call the no-BVC
......
......@@ -62,23 +62,30 @@ source_set("eg_tests") {
"//base",
"//base/test:test_support",
"//components/unified_consent",
"//ios/chrome/app:app_internal",
"//ios/chrome/app/strings",
"//ios/chrome/browser",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/tabs",
"//ios/chrome/browser/ui/authentication",
"//ios/chrome/browser/ui/authentication:eg_test_support",
"//ios/chrome/browser/ui/authentication/cells",
"//ios/chrome/browser/ui/authentication/unified_consent/identity_chooser:identity_chooser_ui",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/content_suggestions:content_suggestions_constant",
"//ios/chrome/browser/ui/recent_tabs:recent_tabs_ui",
"//ios/chrome/browser/ui/settings",
"//ios/chrome/browser/ui/tab_grid:egtest_support",
"//ios/chrome/browser/ui/table_view/cells",
"//ios/chrome/browser/ui/util",
"//ios/chrome/browser/web_state_list",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support",
"//ios/public/provider/chrome/browser/signin:test_support",
"//ios/testing/earl_grey:earl_grey_support",
"//ios/third_party/earl_grey:earl_grey+link",
"//ui/base",
"//ui/base",
]
libs = [ "XCTest.framework" ]
}
......@@ -5,11 +5,14 @@
#import <EarlGrey/EarlGrey.h>
#import <XCTest/XCTest.h>
#import "base/ios/block_types.h"
#include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "base/test/scoped_feature_list.h"
#include "components/unified_consent/feature.h"
#import "ios/chrome/app/main_controller.h"
#include "ios/chrome/browser/system_flags.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/ui/authentication/cells/signin_promo_view.h"
#import "ios/chrome/browser/ui/authentication/chrome_signin_view_controller.h"
#import "ios/chrome/browser/ui/authentication/signin_earl_grey_ui.h"
......@@ -17,8 +20,11 @@
#import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/content_suggestions/ntp_home_constant.h"
#import "ios/chrome/browser/ui/recent_tabs/recent_tabs_constants.h"
#import "ios/chrome/browser/ui/signin_interaction/signin_interaction_controller_egtest_util.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_egtest_util.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
......@@ -27,16 +33,46 @@
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.h"
#import "ios/web/public/web_state/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using chrome_test_util::BookmarksNavigationBarDoneButton;
using chrome_test_util::PrimarySignInButton;
using chrome_test_util::SecondarySignInButton;
using chrome_test_util::SettingsDoneButton;
using chrome_test_util::SyncSettingsConfirmButton;
typedef NS_ENUM(NSInteger, OpenSigninMethod) {
OpenSigninMethodFromSettings,
OpenSigninMethodFromBookmarks,
OpenSigninMethodFromRecentTabs,
OpenSigninMethodFromTabSwitcher,
};
namespace {
// Taps on the primary sign-in button in recent tabs, and scroll first, if
// necessary.
void TapOnPrimarySignInButtonInRecentTabs() {
id<GREYMatcher> matcher =
grey_allOf(PrimarySignInButton(), grey_sufficientlyVisible(), nil);
const CGFloat kPixelsToScroll = 300;
id<GREYAction> searchAction =
grey_scrollInDirection(kGREYDirectionDown, kPixelsToScroll);
GREYElementInteraction* interaction =
[[EarlGrey selectElementWithMatcher:matcher]
usingSearchAction:searchAction
onElementWithMatcher:
grey_accessibilityID(
kRecentTabsTableViewControllerAccessibilityIdentifier)];
[interaction performAction:grey_tap()];
}
}
// Sign-in interaction tests that work both with Unified Consent enabled or
// disabled.
@interface SigninInteractionControllerTestCase : ChromeTestCase
......@@ -306,4 +342,107 @@ using chrome_test_util::SyncSettingsConfirmButton;
performAction:grey_tap()];
}
#pragma mark - Dismiss tests
- (void)testDismissSigninFromSettings {
[self assertOpenURLWhenSigninFromView:OpenSigninMethodFromSettings
tapSettingsLink:NO];
}
- (void)testDismissAdvancedSigninSettingsFromAdvancedSigninSettings {
[self assertOpenURLWhenSigninFromView:OpenSigninMethodFromSettings
tapSettingsLink:YES];
}
- (void)testDismissSigninFromBookmarks {
[self assertOpenURLWhenSigninFromView:OpenSigninMethodFromBookmarks
tapSettingsLink:NO];
}
- (void)testDismissAdvancedSigninBookmarksFromAdvancedSigninSettings {
[self assertOpenURLWhenSigninFromView:OpenSigninMethodFromBookmarks
tapSettingsLink:YES];
}
- (void)testDismissSigninFromRecentTabs {
[self assertOpenURLWhenSigninFromView:OpenSigninMethodFromRecentTabs
tapSettingsLink:NO];
}
- (void)testDismissSigninFromRecentTabsFromAdvancedSigninSettings {
[self assertOpenURLWhenSigninFromView:OpenSigninMethodFromRecentTabs
tapSettingsLink:YES];
}
- (void)testDismissSigninFromTabSwitcher {
[self assertOpenURLWhenSigninFromView:OpenSigninMethodFromTabSwitcher
tapSettingsLink:NO];
}
- (void)testDismissSigninFromTabSwitcherFromAdvancedSigninSettings {
[self assertOpenURLWhenSigninFromView:OpenSigninMethodFromTabSwitcher
tapSettingsLink:YES];
}
#pragma mark - Utils
- (void)assertOpenURLWhenSigninFromView:(OpenSigninMethod)openSigninMethod
tapSettingsLink:(BOOL)tapSettingsLink {
ChromeIdentity* identity = [SigninEarlGreyUtils fakeIdentity1];
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
identity);
switch (openSigninMethod) {
case OpenSigninMethodFromSettings:
[ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:PrimarySignInButton()];
break;
case OpenSigninMethodFromBookmarks:
[ChromeEarlGreyUI openToolsMenu];
[ChromeEarlGreyUI
tapToolsMenuButton:chrome_test_util::BookmarksMenuButton()];
[[EarlGrey selectElementWithMatcher:PrimarySignInButton()]
performAction:grey_tap()];
break;
case OpenSigninMethodFromRecentTabs:
[ChromeEarlGreyUI openToolsMenu];
[ChromeEarlGreyUI
tapToolsMenuButton:chrome_test_util::RecentTabsMenuButton()];
TapOnPrimarySignInButtonInRecentTabs();
break;
case OpenSigninMethodFromTabSwitcher:
[[EarlGrey selectElementWithMatcher:chrome_test_util::TabGridOpenButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::
TabGridOtherDevicesPanelButton()]
performAction:grey_tap()];
TapOnPrimarySignInButtonInRecentTabs();
break;
}
if (tapSettingsLink) {
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
[SigninEarlGreyUI tapSettingsLink];
}
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
// Open the URL as if it was opened from another app.
UIApplication* application = UIApplication.sharedApplication;
id<UIApplicationDelegate> applicationDelegate = application.delegate;
NSURL* url = [NSURL URLWithString:@"http://www.example.com/"];
[applicationDelegate application:application openURL:url options:@{}];
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
// Check if the URL was opened.
web::WebState* webState = chrome_test_util::GetMainController()
.interfaceProvider.mainInterface.tabModel
.webStateList->GetActiveWebState();
GURL expectedString(url.absoluteString.UTF8String);
GREYAssertEqual(expectedString, webState->GetVisibleURL(), @"url not loaded");
if (tapSettingsLink) {
// Should be signed in.
CHROME_EG_ASSERT_NO_ERROR(
[SigninEarlGreyUtils checkSignedInWithIdentity:identity]);
} else {
// Should be not signed in.
CHROME_EG_ASSERT_NO_ERROR([SigninEarlGreyUtils checkSignedOut]);
}
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment