Commit c866f66e authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[multiball] Cleanup SceneController guts from test forwarding.

Makes tests use SceneState and SceneController directly, bypassing the
MainController. Cleans up the Guts protocol accordingly.

Note that we should probably get rid of all these test helpers anyway,
but it's not a priority right now.

Bug: 1045660
Change-Id: Ia02a80ad287b915a79e19fbca070b803d5379c82
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2132139
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756219}
parent 6120259b
......@@ -96,6 +96,9 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
// -performActionForShortcutItem or -openURL.
- (void)launchFromURLHandled:(BOOL)URLHandled;
// Returns the foreground and active scene, if there is one.
- (SceneState*)foregroundActiveScene;
// Returns a list of all connected scenes.
- (NSArray<SceneState*>*)connectedScenes;
......
......@@ -505,6 +505,16 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
#pragma mark - Multiwindow-related
- (SceneState*)foregroundActiveScene {
for (SceneState* sceneState in self.connectedScenes) {
if (sceneState.activationLevel == SceneActivationLevelForegroundActive) {
return sceneState;
}
}
return nil;
}
- (NSArray<SceneState*>*)connectedScenes {
if (IsMultiwindowSupported()) {
NSMutableArray* sceneStates = [[NSMutableArray alloc] init];
......
......@@ -374,6 +374,12 @@
return _appState;
}
+ (AppState*)sharedAppState {
return base::mac::ObjCCast<MainApplicationDelegate>(
[[UIApplication sharedApplication] delegate])
.appState;
}
+ (MainController*)sharedMainController {
return base::mac::ObjCCast<MainApplicationDelegate>(
[[UIApplication sharedApplication] delegate])
......
......@@ -15,6 +15,7 @@
@property(nonatomic, readonly) AppState* appState;
+ (MainController*)sharedMainController;
+ (AppState*)sharedAppState;
@end
#endif // IOS_CHROME_APP_MAIN_APPLICATION_DELEGATE_TESTING_H_
......@@ -1244,24 +1244,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
@implementation MainController (TestingOnly)
- (BOOL)tabSwitcherActive {
return self.sceneController.isTabSwitcherActive;
}
- (void)dismissModalDialogsWithCompletion:(ProceduralBlock)completion
dismissOmnibox:(BOOL)dismissOmnibox {
[self.sceneController dismissModalDialogsWithCompletion:completion
dismissOmnibox:dismissOmnibox];
}
- (void)setTabSwitcher:(id<TabSwitcher>)switcher {
[self.sceneController setTabSwitcher:switcher];
}
- (id<TabSwitcher>)tabSwitcher {
return self.sceneController.tabSwitcher;
}
- (void)setStartupParametersWithURL:(const GURL&)launchURL {
NSString* sourceApplication = @"Fake App";
self.startupParameters = [ChromeAppStartupParameters
......@@ -1269,9 +1251,4 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
fromSourceApplication:sourceApplication];
}
// Defined in FirstRunAppInterface for EGTests.
- (void)showFirstRunUI {
[self.sceneController showFirstRunUI];
}
@end
......@@ -25,20 +25,10 @@ class GURL;
// Methods that only exist for tests.
@interface MainController (TestingOnly)
// Tab switcher state.
- (BOOL)tabSwitcherActive;
@property(nonatomic, strong) id<TabSwitcher> tabSwitcher;
// Sets the internal startup state to indicate that the launch was triggered
// by an external app opening the given URL.
- (void)setStartupParametersWithURL:(const GURL&)launchURL;
// Dismisses all modal dialogs, excluding the omnibox if |dismissOmnibox| is
// NO, then call |completion|.
- (void)dismissModalDialogsWithCompletion:(ProceduralBlock)completion
dismissOmnibox:(BOOL)dismissOmnibox;
@end
#endif // IOS_CHROME_APP_MAIN_CONTROLLER_PRIVATE_H_
......@@ -158,6 +158,8 @@ source_set("eg_test_support") {
"//ios/chrome/app:app_internal",
"//ios/chrome/browser",
"//ios/chrome/browser/sync",
"//ios/chrome/browser/ui/main:scene",
"//ios/chrome/browser/ui/main:scene_testing",
"//ios/chrome/test/app:test_support",
]
}
......@@ -180,6 +182,8 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/app:app_internal",
"//ios/chrome/browser",
"//ios/chrome/browser/sync",
"//ios/chrome/browser/ui/main:scene",
"//ios/chrome/browser/ui/main:scene_testing",
"//ios/chrome/test/app:test_support",
"//ios/third_party/earl_grey2:app_framework+link",
]
......
......@@ -12,22 +12,18 @@
#include "ios/chrome/browser/sync/sync_setup_service.h"
#include "ios/chrome/browser/sync/sync_setup_service_factory.h"
#include "ios/chrome/browser/ui/first_run/welcome_to_chrome_view_controller.h"
#import "ios/chrome/browser/ui/main/scene_controller.h"
#import "ios/chrome/browser/ui/main/scene_controller_testing.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// TODO(crbug.com/1019942): Develop a better way to show the first run UI that
// doesn't require exposing private API.
@interface MainController (ExposedForTesting)
- (void)showFirstRunUI;
@end
@implementation FirstRunAppInterface
+ (void)showFirstRunUI {
[chrome_test_util::GetMainController() showFirstRunUI];
[chrome_test_util::GetForegroundActiveSceneController() showFirstRunUI];
}
+ (void)setUMACollectionEnabled:(BOOL)enabled {
......
......@@ -4,6 +4,12 @@
import("//ios/build/chrome_build.gni")
source_set("scene_testing") {
sources = [ "scene_controller_testing.h" ]
deps = [ "//ios/chrome/browser:utils" ]
libs = [ "UIKit.framework" ]
}
source_set("scene_guts") {
sources = [ "scene_controller_guts.h" ]
deps = [
......@@ -31,6 +37,7 @@ source_set("scene") {
deps = [
":main",
":scene_guts",
":scene_testing",
"//base",
"//components/signin/public/identity_manager",
"//components/url_formatter",
......
......@@ -17,9 +17,6 @@
@protocol SceneControllerGuts <WebStateListObserving>
- (void)startUpChromeUIPostCrash:(BOOL)isPostCrashLaunch
needRestoration:(BOOL)needsRestoration;
- (void)dismissModalsAndOpenSelectedTabInMode:
(ApplicationModeForTabOpening)targetMode
withUrlLoadParams:
......@@ -27,17 +24,11 @@
dismissOmnibox:(BOOL)dismissOmnibox
completion:(ProceduralBlock)completion;
// Testing only.
- (void)showFirstRunUI;
- (void)setTabSwitcher:(id<TabSwitcher>)switcher;
- (id<TabSwitcher>)tabSwitcher;
- (BOOL)isTabSwitcherActive;
- (void)dismissModalDialogsWithCompletion:(ProceduralBlock)completion
dismissOmnibox:(BOOL)dismissOmnibox;
#pragma mark - iOS 12 compat
- (void)startUpChromeUIPostCrash:(BOOL)isPostCrashLaunch
needRestoration:(BOOL)needsRestoration;
// Method called on SceneController when the scene disconnects. Exposed here for
// iOS 12 compatibility.
- (void)teardownUI;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_MAIN_SCENE_CONTROLLER_TESTING_H_
#define IOS_CHROME_BROWSER_UI_MAIN_SCENE_CONTROLLER_TESTING_H_
#import "ios/chrome/browser/procedural_block_types.h"
@protocol TabSwitcher;
// Methods exposed for testing. This is terrible and should be rewritten.
@interface SceneController ()
- (void)showFirstRunUI;
- (void)setTabSwitcher:(id<TabSwitcher>)switcher;
- (id<TabSwitcher>)tabSwitcher;
- (BOOL)isTabSwitcherActive;
// Dismisses all modal dialogs, excluding the omnibox if |dismissOmnibox| is
// NO, then call |completion|.
- (void)dismissModalDialogsWithCompletion:(ProceduralBlock)completion
dismissOmnibox:(BOOL)dismissOmnibox;
@end
#endif // IOS_CHROME_BROWSER_UI_MAIN_SCENE_CONTROLLER_TESTING_H_
......@@ -72,6 +72,8 @@ source_set("test_support") {
"//ios/chrome/browser/ui/browser_view",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/main",
"//ios/chrome/browser/ui/main:scene",
"//ios/chrome/browser/ui/main:scene_testing",
"//ios/chrome/browser/ui/settings",
"//ios/chrome/browser/ui/settings:settings_root",
"//ios/chrome/browser/ui/settings/password",
......
......@@ -14,6 +14,8 @@
class ChromeBrowserState;
@class MainController;
@class NewTabPageController;
@class SceneController;
@class SceneState;
@class UIViewController;
namespace chrome_test_util {
......@@ -21,6 +23,12 @@ namespace chrome_test_util {
// Returns the main controller.
MainController* GetMainController();
// Returns the foreground, active scene.
SceneState* GetForegroundActiveScene();
// Returns the foreground, active scene controller.
SceneController* GetForegroundActiveSceneController();
// Returns the current, non-incognito ChromeBrowserState.
ChromeBrowserState* GetOriginalBrowserState();
......
......@@ -9,6 +9,7 @@
#import "base/test/ios/wait_util.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/metrics_service.h"
#import "ios/chrome/app/application_delegate/app_state.h"
#import "ios/chrome/app/application_delegate/metrics_mediator.h"
#import "ios/chrome/app/application_delegate/metrics_mediator_testing.h"
#import "ios/chrome/app/chrome_overlay_window.h"
......@@ -24,6 +25,9 @@
#import "ios/chrome/browser/metrics/previous_session_info_private.h"
#import "ios/chrome/browser/ui/browser_view/browser_view_controller.h"
#import "ios/chrome/browser/ui/main/bvc_container_view_controller.h"
#import "ios/chrome/browser/ui/main/scene_controller.h"
#import "ios/chrome/browser/ui/main/scene_controller_testing.h"
#import "ios/chrome/browser/ui/main/scene_state.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/chrome/test/app/tab_test_util.h"
#import "ios/web/public/navigation/navigation_context.h"
......@@ -78,6 +82,15 @@ MainController* GetMainController() {
return [MainApplicationDelegate sharedMainController];
}
SceneState* GetForegroundActiveScene() {
return MainApplicationDelegate.sharedAppState.foregroundActiveScene;
}
SceneController* GetForegroundActiveSceneController() {
return MainApplicationDelegate.sharedAppState.foregroundActiveScene
.controller;
}
ChromeBrowserState* GetOriginalBrowserState() {
return GetBrowserState(false);
}
......@@ -132,8 +145,8 @@ void RemoveAllInfoBars() {
}
void ClearPresentedState() {
[GetMainController() dismissModalDialogsWithCompletion:nil
dismissOmnibox:YES];
[GetForegroundActiveSceneController() dismissModalDialogsWithCompletion:nil
dismissOmnibox:YES];
}
void SetBooleanLocalStatePref(const char* pref_name, bool value) {
......
......@@ -17,6 +17,8 @@
#import "ios/chrome/browser/tabs/tab_title_util.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/main/scene_controller.h"
#import "ios/chrome/browser/ui/main/scene_controller_testing.h"
#import "ios/chrome/browser/ui/tab_grid/tab_switcher.h"
#import "ios/chrome/browser/url_loading/url_loading_params.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h"
......@@ -57,12 +59,12 @@ BOOL IsIncognitoMode() {
void OpenNewTab() {
@autoreleasepool { // Make sure that all internals are deallocated.
OpenNewTabCommand* command = [OpenNewTabCommand command];
if (GetMainController().tabSwitcherActive) {
if (GetForegroundActiveSceneController().isTabSwitcherActive) {
// The TabGrid is currently presented.
Browser* browser =
GetMainController().interfaceProvider.mainInterface.browser;
GetForegroundActiveScene().interfaceProvider.mainInterface.browser;
UrlLoadParams params = UrlLoadParams::InNewTab(GURL(kChromeUINewTabURL));
[GetMainController().tabSwitcher
[GetForegroundActiveSceneController().tabSwitcher
dismissWithNewTabAnimationToBrowser:browser
withUrlLoadParams:params
atIndex:INT_MAX];
......@@ -84,12 +86,12 @@ void SimulateExternalAppURLOpening() {
void OpenNewIncognitoTab() {
@autoreleasepool { // Make sure that all internals are deallocated.
OpenNewTabCommand* command = [OpenNewTabCommand incognitoTabCommand];
if (GetMainController().tabSwitcherActive) {
if (GetForegroundActiveSceneController().isTabSwitcherActive) {
// The TabGrid is currently presented.
Browser* browser =
GetMainController().interfaceProvider.incognitoInterface.browser;
Browser* browser = GetForegroundActiveScene()
.interfaceProvider.incognitoInterface.browser;
UrlLoadParams params = UrlLoadParams::InNewTab(GURL(kChromeUINewTabURL));
[GetMainController().tabSwitcher
[GetForegroundActiveSceneController().tabSwitcher
dismissWithNewTabAnimationToBrowser:browser
withUrlLoadParams:params
atIndex:INT_MAX];
......@@ -147,7 +149,7 @@ void CloseTabAtIndex(NSUInteger index) {
}
NSUInteger GetIndexOfActiveNormalTab() {
TabModel* model = chrome_test_util::GetMainController()
TabModel* model = chrome_test_util::GetForegroundActiveSceneController()
.interfaceProvider.mainInterface.tabModel;
return model.webStateList->active_index();
}
......@@ -158,11 +160,12 @@ void CloseAllTabsInCurrentMode() {
void CloseAllTabs() {
if (GetIncognitoTabCount()) {
[GetMainController()
[GetForegroundActiveSceneController()
.interfaceProvider.incognitoInterface.tabModel closeAllTabs];
}
if (GetMainTabCount()) {
[GetMainController().interfaceProvider.mainInterface.tabModel closeAllTabs];
[GetForegroundActiveScene()
.interfaceProvider.mainInterface.tabModel closeAllTabs];
}
}
......
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